cmd/age: add scrypt testscript

This commit is contained in:
Filippo Valsorda
2022-06-28 21:07:39 +02:00
parent c50f1ae2e1
commit 331b242a9c
5 changed files with 60 additions and 5 deletions

View File

@@ -360,9 +360,12 @@ func encryptPass(in io.Reader, out io.Writer, armor bool) {
if err != nil {
errorf("%v", err)
}
testOnlyConfigureScryptIdentity(r)
encrypt([]age.Recipient{r}, in, out, armor)
}
var testOnlyConfigureScryptIdentity = func(*age.ScryptRecipient) {}
func encrypt(recipients []age.Recipient, in io.Reader, out io.Writer, withArmor bool) {
if withArmor {
a := armor.NewWriter(out)

View File

@@ -8,6 +8,7 @@ import (
"os"
"testing"
"filippo.io/age"
"github.com/rogpeppe/go-internal/testscript"
)
@@ -20,6 +21,9 @@ func TestMain(m *testing.M) {
exitCode = recover().(int)
}
}()
testOnlyConfigureScryptIdentity = func(r *age.ScryptRecipient) {
r.SetWorkFactor(10)
}
main()
return 0
},

42
cmd/age/testdata/scrypt.txt vendored Normal file
View File

@@ -0,0 +1,42 @@
[windows] skip # no pty support
# Encrypt with a provided passphrase.
pty terminal
age -p -o test.age
! stderr .
! stdout .
# Decrypt with a provided passphrase.
pty terminal
age -d test.age
! stderr .
! stdout .
# Decrypt with the wrong passphrase.
pty wrong
! age -d test.age
stderr 'incorrect passphrase'
# Fail when -i is present.
pty 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
! age -p -o fail.age
stderr 'passphrases didn''t match'
! exists fail.age
-- terminal --
password
password
-- wrong --
PASSWORD
password
-- input --
test
-- key.txt --
# created: 2021-02-02T13:09:43+01:00
# public key: age1xmwwc06ly3ee5rytxm9mflaz2u56jjj36s0mypdrwsvlul66mv4q47ryef
AGE-SECRET-KEY-1EGTZVFFV20835NWYV6270LXYVK2VKNX2MMDKWYKLMGR48UAWX40Q2P2LM0