mirror of
https://github.com/FiloSottile/age.git
synced 2026-03-11 08:55:41 +00:00
tests: add expected no match and minor additions
This commit is contained in:
parent
eaa4e03cfe
commit
2088adf268
17 changed files with 39 additions and 6 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
BIN
testdata/testkit/scrypt_and_x25519
vendored
BIN
testdata/testkit/scrypt_and_x25519
vendored
Binary file not shown.
BIN
testdata/testkit/scrypt_double
vendored
Normal file
BIN
testdata/testkit/scrypt_double
vendored
Normal file
Binary file not shown.
BIN
testdata/testkit/scrypt_no_match
vendored
BIN
testdata/testkit/scrypt_no_match
vendored
Binary file not shown.
BIN
testdata/testkit/scrypt_work_factor_23
vendored
BIN
testdata/testkit/scrypt_work_factor_23
vendored
Binary file not shown.
BIN
testdata/testkit/x25519_bad_tag
vendored
BIN
testdata/testkit/x25519_bad_tag
vendored
Binary file not shown.
BIN
testdata/testkit/x25519_lowercase
vendored
BIN
testdata/testkit/x25519_lowercase
vendored
Binary file not shown.
BIN
testdata/testkit/x25519_no_match
vendored
BIN
testdata/testkit/x25519_no_match
vendored
Binary file not shown.
|
|
@ -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()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue