tests: add expected no match and minor additions

This commit is contained in:
Filippo Valsorda
2022-06-19 00:11:23 +02:00
parent eaa4e03cfe
commit 2088adf268
17 changed files with 63 additions and 15 deletions

View File

@@ -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
}

View File

@@ -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Ïôž¸

13
testdata/testkit/scrypt_double vendored Normal file
View 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

Binary file not shown.

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -1,4 +1,4 @@
expect: header failure
expect: no match
file key: 59454c4c4f57205355424d4152494e45
identity: AGE-SECRET-KEY-143WN7DCXU4G8R5AXQSSYD9AEPYDNT3HXSLWSPK36CDU6E8M59SSSAGZ3KG

View File

@@ -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)

View File

@@ -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")

View File

@@ -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
View 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()
}

View File

@@ -15,6 +15,6 @@ func main() {
f.ScryptNoRecordPassphrase("password", 10)
f.HMAC()
f.Payload("age")
f.ExpectHeaderFailure()
f.ExpectNoMatch()
f.Generate()
}

View File

@@ -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()

View File

@@ -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()
}

View File

@@ -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()
}

View File

@@ -16,6 +16,6 @@ func main() {
f.X25519NoRecordIdentity(testkit.TestX25519Recipient)
f.HMAC()
f.Payload("age")
f.ExpectHeaderFailure()
f.ExpectNoMatch()
f.Generate()
}