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 39 additions and 6 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
}

Binary file not shown.

BIN
testdata/testkit/scrypt_double vendored Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

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