mirror of
https://github.com/FiloSottile/age.git
synced 2025-12-23 05:25:14 +00:00
tests: add expected no match and minor additions
This commit is contained in:
@@ -219,6 +219,10 @@ func (f *TestFile) ExpectHMACFailure() {
|
||||
f.expect = "HMAC failure"
|
||||
}
|
||||
|
||||
func (f *TestFile) ExpectNoMatch() {
|
||||
f.expect = "no match"
|
||||
}
|
||||
|
||||
func (f *TestFile) Comment(c string) {
|
||||
f.comment = c
|
||||
}
|
||||
|
||||
13
testdata/testkit/scrypt_and_x25519
vendored
13
testdata/testkit/scrypt_and_x25519
vendored
@@ -1,12 +1,13 @@
|
||||
expect: header failure
|
||||
file key: 59454c4c4f57205355424d4152494e45
|
||||
identity: AGE-SECRET-KEY-143WN7DCXU4G8R5AXQSSYD9AEPYDNT3HXSLWSPK36CDU6E8M59SSSAGZ3KG
|
||||
passphrase: password
|
||||
comment: scrypt stanzas must be alone in the header
|
||||
|
||||
age-encryption.org/v1
|
||||
-> X25519 TEiF0ypqr+bpvcqXNyCVJpL7OuwPdVwPL7KQEbFDOCc
|
||||
hjabGXwSLQ9c3S6Lw2i+S2Tu2fiwQHHslbBN6B41FLE
|
||||
-> scrypt 7s9ix86RtDMnTmjU8vkTTA 10
|
||||
0U4Pbxsl9pr9g4nHjPgkvtYkNrGiYJ43x1vbM5X5mhg
|
||||
--- f2AoyFXU2R5Cn7s38vH1pFkuKqzPh3ibwwHc/7y6RRU
|
||||
[æè.½Ó#ÈwÏ…=a×Yök×z©66Ú¦<01>âRùÛL
|
||||
-> X25519 ajtqAvDEkVNr2B7zUOtq2mAQXDSBlNrVAuM/dKb5sT4
|
||||
U+hKlJ4isweJ9PKG7pgscmG3cPASLgTw7SOBpbZ8x2U
|
||||
-> scrypt 3d9y0G+8q1ffPQ0xJJatIQ 10
|
||||
foZolxuhRSL7IG7oaR+456IzkHtvue7j4mUjh3DB6EI
|
||||
--- yp4Z0lV1LEdkm1+uDCuPUV+9hIXbPKrBXKQ/f5Y03As
|
||||
T^kôƉ><3E>)ìÍ,r±ÌFlž'cÏô’‚ž›¸Vµ
|
||||
13
testdata/testkit/scrypt_double
vendored
Normal file
13
testdata/testkit/scrypt_double
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
expect: header failure
|
||||
file key: 59454c4c4f57205355424d4152494e45
|
||||
passphrase: password
|
||||
passphrase: hunter2
|
||||
comment: scrypt stanzas must be alone in the header
|
||||
|
||||
age-encryption.org/v1
|
||||
-> scrypt rF0/NwblUHHTpgQgRpe5CQ 10
|
||||
gUjEymFKMVXQEKdMMHL24oYexjE3TIC0O0zGSqJ2aUY
|
||||
-> scrypt GzXG5ofdANo6w3msn3QsIQ 10
|
||||
OveITuwxakv7k2oLnioNYF4Bhgz9KZ36pb098wDoAv8
|
||||
--- a5d+4Ay1evJhoDskIzuTZV9bBgKk4573VZNfuoWJDPE
|
||||
îÏbÇΑ´3'NhÔòùL·L[þ÷¾ªRÈð¼™,ƒ1ûf
|
||||
BIN
testdata/testkit/scrypt_no_match
vendored
BIN
testdata/testkit/scrypt_no_match
vendored
Binary file not shown.
1
testdata/testkit/scrypt_work_factor_23
vendored
1
testdata/testkit/scrypt_work_factor_23
vendored
@@ -1,5 +1,6 @@
|
||||
expect: header failure
|
||||
file key: 59454c4c4f57205355424d4152494e45
|
||||
passphrase: password
|
||||
comment: work factor is very high, would take a long time to compute
|
||||
|
||||
age-encryption.org/v1
|
||||
|
||||
2
testdata/testkit/x25519_bad_tag
vendored
2
testdata/testkit/x25519_bad_tag
vendored
@@ -1,4 +1,4 @@
|
||||
expect: header failure
|
||||
expect: no match
|
||||
file key: 59454c4c4f57205355424d4152494e45
|
||||
identity: AGE-SECRET-KEY-1XMWWC06LY3EE5RYTXM9MFLAZ2U56JJJ36S0MYPDRWSVLUL66MV4QX3S7F6
|
||||
comment: the ChaCha20Poly1305 authentication tag on the body of the X25519 stanza is wrong
|
||||
|
||||
2
testdata/testkit/x25519_lowercase
vendored
2
testdata/testkit/x25519_lowercase
vendored
@@ -1,4 +1,4 @@
|
||||
expect: header failure
|
||||
expect: no match
|
||||
file key: 59454c4c4f57205355424d4152494e45
|
||||
identity: AGE-SECRET-KEY-1XMWWC06LY3EE5RYTXM9MFLAZ2U56JJJ36S0MYPDRWSVLUL66MV4QX3S7F6
|
||||
comment: the first argument in the X25519 stanza is lowercase
|
||||
|
||||
2
testdata/testkit/x25519_no_match
vendored
2
testdata/testkit/x25519_no_match
vendored
@@ -1,4 +1,4 @@
|
||||
expect: header failure
|
||||
expect: no match
|
||||
file key: 59454c4c4f57205355424d4152494e45
|
||||
identity: AGE-SECRET-KEY-143WN7DCXU4G8R5AXQSSYD9AEPYDNT3HXSLWSPK36CDU6E8M59SSSAGZ3KG
|
||||
|
||||
|
||||
@@ -97,6 +97,7 @@ func testVector(t *testing.T, test []byte) {
|
||||
case "HMAC failure":
|
||||
case "header failure":
|
||||
case "payload failure":
|
||||
case "no match":
|
||||
default:
|
||||
t.Fatal("invalid test file: unknown expect value:", value)
|
||||
}
|
||||
@@ -135,6 +136,12 @@ func testVector(t *testing.T, test []byte) {
|
||||
return
|
||||
}
|
||||
t.Fatalf("expected %s, got HMAC error", expect)
|
||||
} else if _, ok := err.(*age.NoIdentityMatchError); ok {
|
||||
if expect == "no match" {
|
||||
t.Log(err)
|
||||
return
|
||||
}
|
||||
t.Fatalf("expected %s, got: %v", expect, err)
|
||||
} else if err != nil {
|
||||
if expect == "header failure" {
|
||||
t.Log(err)
|
||||
|
||||
@@ -20,8 +20,7 @@ func main() {
|
||||
f.Buf.Reset()
|
||||
f.Buf.Write(bytes.Replace(hdr, []byte("\n"), []byte("\r\n"), -1))
|
||||
f.HMAC()
|
||||
f.Buf.WriteString(f.UnreadLine())
|
||||
f.Buf.WriteString("\r\n")
|
||||
f.Buf.WriteString(f.UnreadLine() + "\r\n")
|
||||
f.Payload("age")
|
||||
f.ExpectHeaderFailure()
|
||||
f.Comment("lines in the header end with CRLF instead of LF")
|
||||
|
||||
@@ -11,6 +11,7 @@ import "filippo.io/age/internal/testkit"
|
||||
func main() {
|
||||
f := testkit.NewTestFile()
|
||||
f.VersionLine("v1")
|
||||
f.X25519RecordIdentity(f.Rand(32))
|
||||
f.X25519NoRecordIdentity(testkit.TestX25519Identity)
|
||||
f.Scrypt("password", 10)
|
||||
f.HMAC()
|
||||
|
||||
21
tests/scrypt_double.go
Normal file
21
tests/scrypt_double.go
Normal file
@@ -0,0 +1,21 @@
|
||||
// Copyright 2022 The age Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//go:build ignore
|
||||
|
||||
package main
|
||||
|
||||
import "filippo.io/age/internal/testkit"
|
||||
|
||||
func main() {
|
||||
f := testkit.NewTestFile()
|
||||
f.VersionLine("v1")
|
||||
f.Scrypt("password", 10)
|
||||
f.Scrypt("hunter2", 10)
|
||||
f.HMAC()
|
||||
f.Payload("age")
|
||||
f.ExpectHeaderFailure()
|
||||
f.Comment("scrypt stanzas must be alone in the header")
|
||||
f.Generate()
|
||||
}
|
||||
@@ -15,6 +15,6 @@ func main() {
|
||||
f.ScryptNoRecordPassphrase("password", 10)
|
||||
f.HMAC()
|
||||
f.Payload("age")
|
||||
f.ExpectHeaderFailure()
|
||||
f.ExpectNoMatch()
|
||||
f.Generate()
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ func main() {
|
||||
f.VersionLine("v1")
|
||||
// Hardcoded because it would be too slow to regenerate every time.
|
||||
// f.Scrypt("password", 23)
|
||||
f.ScryptRecordPassphrase("password")
|
||||
f.ArgsLine("scrypt", "rF0/NwblUHHTpgQgRpe5CQ", "23")
|
||||
f.TextLine("qW9eVsT0NVb/Vswtw8kPIxUnaYmm9Px1dYmq2+4+qZA")
|
||||
f.HMAC()
|
||||
|
||||
@@ -21,7 +21,7 @@ func main() {
|
||||
f.TextLine(base64.RawStdEncoding.EncodeToString(body))
|
||||
f.HMAC()
|
||||
f.Payload("age")
|
||||
f.ExpectHeaderFailure()
|
||||
f.ExpectNoMatch()
|
||||
f.Comment("the ChaCha20Poly1305 authentication tag on the body of the X25519 stanza is wrong")
|
||||
f.Generate()
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ func main() {
|
||||
f.TextLine(body)
|
||||
f.HMAC()
|
||||
f.Payload("age")
|
||||
f.ExpectHeaderFailure()
|
||||
f.ExpectNoMatch()
|
||||
f.Comment("the first argument in the X25519 stanza is lowercase")
|
||||
f.Generate()
|
||||
}
|
||||
|
||||
@@ -16,6 +16,6 @@ func main() {
|
||||
f.X25519NoRecordIdentity(testkit.TestX25519Recipient)
|
||||
f.HMAC()
|
||||
f.Payload("age")
|
||||
f.ExpectHeaderFailure()
|
||||
f.ExpectNoMatch()
|
||||
f.Generate()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user