Skip to content

Commit

Permalink
cmd/age: fix FreeBSD tests
Browse files Browse the repository at this point in the history
  • Loading branch information
FiloSottile committed Aug 6, 2023
1 parent 294b0aa commit 9305563
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 39 deletions.
20 changes: 10 additions & 10 deletions cmd/age/testdata/encrypted_keys.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# TODO: age-encrypted private keys, multiple identities, -i ordering, -e -i,
# age file password prompt during encryption

[windows] skip # no pty support
[go1.20] skip # https://go.dev/issue/61779
[!linux] [!darwin] skip # no pty support
[darwin] [go1.20] skip # https://go.dev/issue/61779

# use an encrypted OpenSSH private key without .pub file
age -R key_ed25519.pub -o ed25519.age input
rm key_ed25519.pub
pty terminal
ttyin terminal
age -d -i key_ed25519 ed25519.age
cmp stdout input
! stderr .

# -e -i with an encrypted OpenSSH private key
age -e -i key_ed25519 -o ed25519.age input
pty terminal
ttyin terminal
age -d -i key_ed25519 ed25519.age
cmp stdout input

Expand All @@ -25,7 +25,7 @@ stderr 'no identity matched any of the recipients'

# use an encrypted legacy PEM private key with a .pub file
age -R key_rsa_legacy.pub -o rsa_legacy.age input
pty terminal
ttyin terminal
age -d -i key_rsa_legacy rsa_legacy.age
cmp stdout input
! stderr .
Expand All @@ -35,7 +35,7 @@ stderr 'no identity matched any of the recipients'

# -e -i with an encrypted legacy PEM private key
age -e -i key_rsa_legacy -o rsa_legacy.age input
pty terminal
ttyin terminal
age -d -i key_rsa_legacy rsa_legacy.age
cmp stdout input

Expand All @@ -46,17 +46,17 @@ stderr 'key_rsa_legacy.pub'

# mismatched .pub file causes an error
cp key_rsa_legacy key_rsa_other
pty terminal
ttyin terminal
! age -d -i key_rsa_other rsa_other.age
stderr 'mismatched private and public SSH key'

# buffer armored ciphertext before prompting if stdin is the terminal
pty terminal
ttyin terminal
age -e -i key_ed25519 -a -o test.age input
exec cat test.age terminal # concatenated ciphertext + password
pty -stdin stdout
ttyin -stdin stdout
age -d -i key_ed25519
ptyout 'Enter passphrase'
ttyout 'Enter passphrase'
! stderr .
cmp stdout input

Expand Down
22 changes: 11 additions & 11 deletions cmd/age/testdata/scrypt.txt
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
[windows] skip # no pty support
[go1.20] skip # https://go.dev/issue/61779
[!linux] [!darwin] skip # no pty support
[darwin] [go1.20] skip # https://go.dev/issue/61779

# encrypt with a provided passphrase
stdin input
pty terminal
ttyin terminal
age -p -o test.age
ptyout 'Enter passphrase'
ttyout 'Enter passphrase'
! stderr .
! stdout .

# decrypt with a provided passphrase
pty terminal
ttyin terminal
age -d test.age
ptyout 'Enter passphrase'
ttyout 'Enter passphrase'
! stderr .
cmp stdout input

# decrypt with the wrong passphrase
pty wrong
ttyin wrong
! age -d test.age
stderr 'incorrect passphrase'

# encrypt with a generated passphrase
stdin input
pty empty
ttyin empty
age -p -o test.age
! stderr .
! stdout .
pty autogenerated
ttyin autogenerated
age -d test.age
cmp stdout input

# fail when -i is present
pty terminal
ttyin terminal
! age -d -i key.txt test.age
stderr 'file is passphrase-encrypted but identities were specified'

# fail when passphrases don't match
pty wrong
ttyin wrong
! age -p -o fail.age
stderr 'passphrases didn''t match'
! exists fail.age
Expand Down
24 changes: 12 additions & 12 deletions cmd/age/testdata/terminal.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
[windows] skip # no pty support
[go1.20] skip # https://go.dev/issue/61779
[!linux] [!darwin] skip # no pty support
[darwin] [go1.20] skip # https://go.dev/issue/61779

# controlling terminal is used instead of stdin/stderr
pty terminal
ttyin terminal
age -p -o test.age input
! stderr .

# autogenerated passphrase is printed to terminal
pty empty
ttyin empty
age -p -o test.age input
ptyout 'autogenerated passphrase'
ttyout 'autogenerated passphrase'
! stderr .

# with no controlling terminal, stdin terminal is used
## TODO: enable once https://golang.org/issue/53601 is fixed
## and Noctty is added to testscript.
# noctty
# pty -stdin terminal
# ttyin -stdin terminal
# age -p -o test.age input
# ! stderr .

Expand All @@ -29,22 +29,22 @@ ptyout 'autogenerated passphrase'

# prompt for password before plaintext if stdin is the terminal
exec cat terminal input # concatenated password + input
pty -stdin stdout
ttyin -stdin stdout
age -p -a -o test.age
ptyout 'Enter passphrase'
ttyout 'Enter passphrase'
! stderr .
# check the file was encrypted correctly
pty terminal
ttyin terminal
age -d test.age
cmp stdout input

# buffer armored ciphertext before prompting if stdin is the terminal
pty terminal
ttyin terminal
age -p -a -o test.age input
exec cat test.age terminal # concatenated ciphertext + password
pty -stdin stdout
ttyin -stdin stdout
age -d
ptyout 'Enter passphrase'
ttyout 'Enter passphrase'
! stderr .
cmp stdout input

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ require (
// Test dependencies.
require (
c2sp.org/CCTV/age v0.0.0-20221230231406-5ea85644bd03
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e // indirect
github.com/rogpeppe/go-internal v1.8.1
golang.org/x/tools v0.1.12 // indirect
)

// https://github.com/rogpeppe/go-internal/pull/172
replace github.com/rogpeppe/go-internal => github.com/FiloSottile/go-internal v1.8.2-0.20230102123319-d43ebe7f1660
replace github.com/rogpeppe/go-internal => github.com/FiloSottile/go-internal v1.8.2-0.20230806172430-94b0f0dc0b1e
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ c2sp.org/CCTV/age v0.0.0-20221230231406-5ea85644bd03 h1:0e2QjhWG02SgzlUOvNYaFraf
c2sp.org/CCTV/age v0.0.0-20221230231406-5ea85644bd03/go.mod h1:FomMrUJ2Lxt5jCLmZkG3FHa72zUprnhd3v/Z18Snm4w=
filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek=
filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns=
github.com/FiloSottile/go-internal v1.8.2-0.20230102123319-d43ebe7f1660 h1:o9Uw6fW8MF/K9RlbCO5e/5e6uXPdwND1NyRnn1NHjgE=
github.com/FiloSottile/go-internal v1.8.2-0.20230102123319-d43ebe7f1660/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e h1:aoZm08cpOy4WuID//EZDgcC4zIxODThtZNPirFr42+A=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/FiloSottile/go-internal v1.8.2-0.20230806172430-94b0f0dc0b1e h1:1pkMKBSmMMOXQT5lFTmciWn86GGymBssr1bOOOoo2GI=
github.com/FiloSottile/go-internal v1.8.2-0.20230806172430-94b0f0dc0b1e/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
golang.org/x/crypto v0.4.0 h1:UVQgzMY87xqpKNgb+kDsll2Igd33HszWHFLmpaRMq/8=
golang.org/x/crypto v0.4.0/go.mod h1:3quD/ATkf6oY+rnes5c3ExXTbLc8mueNue5/DoinL80=
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.3.0 h1:qoo4akIqOcDME5bhc/NgxUdovd6BSS2uMsVjB56q1xI=
golang.org/x/term v0.3.0/go.mod h1:q750SLmJuPmVoN1blW3UFBPREJfb1KmY3vwxfr+nFDA=
golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=

0 comments on commit 9305563

Please sign in to comment.