From 2088adf268e988965d27f68575c7193384c67706 Mon Sep 17 00:00:00 2001 From: Filippo Valsorda Date: Sun, 19 Jun 2022 00:11:23 +0200 Subject: [PATCH] tests: add expected no match and minor additions --- internal/testkit/testkit.go | 4 ++++ testdata/testkit/scrypt_and_x25519 | Bin 423 -> 508 bytes testdata/testkit/scrypt_double | Bin 0 -> 425 bytes testdata/testkit/scrypt_no_match | Bin 270 -> 264 bytes testdata/testkit/scrypt_work_factor_23 | Bin 321 -> 342 bytes testdata/testkit/x25519_bad_tag | Bin 446 -> 440 bytes testdata/testkit/x25519_lowercase | Bin 417 -> 411 bytes testdata/testkit/x25519_no_match | Bin 355 -> 349 bytes testkit_test.go | 7 +++++++ tests/header_crlf.go | 3 +-- tests/scrypt_and_x25519.go | 1 + tests/scrypt_double.go | 21 +++++++++++++++++++++ tests/scrypt_no_match.go | 2 +- tests/scrypt_work_factor_23.go | 1 + tests/x25519_bad_tag.go | 2 +- tests/x25519_lowercase.go | 2 +- tests/x25519_no_match.go | 2 +- 17 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 testdata/testkit/scrypt_double create mode 100644 tests/scrypt_double.go diff --git a/internal/testkit/testkit.go b/internal/testkit/testkit.go index 60e0823..603fd15 100644 --- a/internal/testkit/testkit.go +++ b/internal/testkit/testkit.go @@ -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 } diff --git a/testdata/testkit/scrypt_and_x25519 b/testdata/testkit/scrypt_and_x25519 index c479d3b211d07287e532283a7edf54f5d6118e0e..90a61fd0fca183b6dbe0ad6ef3bb7d50df629ecc 100644 GIT binary patch delta 347 zcmV~$O;3Vg007`Ew+?jb-ho?d!~_A64sI{1x%&S)Z&YME}?gb*msKv!eYQH`R{^(Y1;*nxQ! i?mrJt?yC=Hzu)Ia@!QvBv^zZYe)h-Dce|Gl`~4p+E^%!D delta 262 zcmV+h0r~#?1E&L!LXnqhe^f44WOm{MAD^oI5buwmYcTq@4b8KQlPBua`F-A;9 z3N1b$b7OLOaC9Iyb2({vI5tvrL``l~ZE96Gc575rK_D?O3NTePd{AO|b8I9~G&6WHc4AF6ST${EX9_JXEg)txL2r3RSXDAoHA8MUb2B)0 zNHK6mYjsO;dQfOHX<~PGNMkQIc{Wl~RSH`j=IAaC487AM$al|$Jz>{b_G{OAsWvtr M+NJ@J;!^qBOsLyj!~g&Q diff --git a/testdata/testkit/scrypt_double b/testdata/testkit/scrypt_double new file mode 100644 index 0000000000000000000000000000000000000000..da069edc64d3d0b56e23c6fbaccf5e7782f8b675 GIT binary patch literal 425 zcmY+8J5L)y9K`!AXwswYQX~iW*u|U+B!l0N1A}d_Q|8@|(&TeQ5e-5}CJP_8jNp^j&G-9oHE5>AIxtTcb)(;x!$2a@#;rz<@X!+kCpFi}k`(Iw4ZZ8k- Pf8MNJd|v;my|}*s)-scz literal 0 HcmV?d00001 diff --git a/testdata/testkit/scrypt_no_match b/testdata/testkit/scrypt_no_match index 994d64767b0a673eb3ac81207f9e6814598ee6de..3d090e184d3eb69325430b9eebd2a5cc51ab1bd9 100644 GIT binary patch delta 24 fcmeBU>R=K`ttd!MF0oR`%U8%vEJ@CoDE0#YVp9mW delta 30 lcmeBR>SGd1ttd!MF0oR`NKH&hEmBBJ%*-h*N}VY10|1>03myOf diff --git a/testdata/testkit/scrypt_work_factor_23 b/testdata/testkit/scrypt_work_factor_23 index c37ca072ddccdd3b63d41126a3da80de5d145937..4d286beb1633f84968cc49dca4cfcaf714f75e93 100644 GIT binary patch delta 30 jcmX@ebd70(lSn~gadAOLQDSkbl>&%eo?n!*(2)@Uw3Z8O delta 9 Qcmcb{bdYI+)5P%q02C?&RR910 diff --git a/testdata/testkit/x25519_bad_tag b/testdata/testkit/x25519_bad_tag index 9a087456d82f68788cca16a3d267dc39bc00c6f4..13c7c7098babf6f539b8b185e6c910bf70b6db0f 100644 GIT binary patch delta 25 gcmdnTyn|UFwW1(3xx`8#FJB=yu_QTTqu2^Y0CX7$>Hq)$ delta 31 mcmdnNypLHdwW1(3xx`8#BQ-H4wMZc?F*B#MD0QR23Pu34g9}jr diff --git a/testdata/testkit/x25519_lowercase b/testdata/testkit/x25519_lowercase index 853d408b8959df0c480915a974302f90422dc7ca..3eeb8bc5ed49d38854a53c061cea45fb10a32216 100644 GIT binary patch delta 25 gcmZ3;Jeye{wW1(3xx`8#FJB=yu_QTTqgXd10B&yxlK=n! delta 31 mcmbQuypUNewW1(3xx`8#BQ-H4wMZc?F*B#MD0QPiHzNS7eG2*j diff --git a/testdata/testkit/x25519_no_match b/testdata/testkit/x25519_no_match index c146be38234b836f75f1c5df9ef769dc5f0c9705..1bf961ff2e10c565e5c83e987a43fa6461274a46 100644 GIT binary patch delta 25 gcmaFNbeBmWwW1(3xx`8#FJB=yu_QTTqnIxv0D2_|*8l(j delta 31 mcmcc1^q5I3wW1(3xx`8#BQ-H4wMZc?F*B#MD0QQNFCzfEKMOtp diff --git a/testkit_test.go b/testkit_test.go index 3a44b48..5a2ea61 100644 --- a/testkit_test.go +++ b/testkit_test.go @@ -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) diff --git a/tests/header_crlf.go b/tests/header_crlf.go index 721626b..c28c0f0 100644 --- a/tests/header_crlf.go +++ b/tests/header_crlf.go @@ -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") diff --git a/tests/scrypt_and_x25519.go b/tests/scrypt_and_x25519.go index 03704d0..649c07b 100644 --- a/tests/scrypt_and_x25519.go +++ b/tests/scrypt_and_x25519.go @@ -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() diff --git a/tests/scrypt_double.go b/tests/scrypt_double.go new file mode 100644 index 0000000..2e947c3 --- /dev/null +++ b/tests/scrypt_double.go @@ -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() +} diff --git a/tests/scrypt_no_match.go b/tests/scrypt_no_match.go index a90f53f..ae4acae 100644 --- a/tests/scrypt_no_match.go +++ b/tests/scrypt_no_match.go @@ -15,6 +15,6 @@ func main() { f.ScryptNoRecordPassphrase("password", 10) f.HMAC() f.Payload("age") - f.ExpectHeaderFailure() + f.ExpectNoMatch() f.Generate() } diff --git a/tests/scrypt_work_factor_23.go b/tests/scrypt_work_factor_23.go index 7586195..5666f93 100644 --- a/tests/scrypt_work_factor_23.go +++ b/tests/scrypt_work_factor_23.go @@ -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() diff --git a/tests/x25519_bad_tag.go b/tests/x25519_bad_tag.go index e56cd7c..82f9758 100644 --- a/tests/x25519_bad_tag.go +++ b/tests/x25519_bad_tag.go @@ -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() } diff --git a/tests/x25519_lowercase.go b/tests/x25519_lowercase.go index 838690c..7bdce73 100644 --- a/tests/x25519_lowercase.go +++ b/tests/x25519_lowercase.go @@ -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() } diff --git a/tests/x25519_no_match.go b/tests/x25519_no_match.go index af27c51..a1644ab 100644 --- a/tests/x25519_no_match.go +++ b/tests/x25519_no_match.go @@ -16,6 +16,6 @@ func main() { f.X25519NoRecordIdentity(testkit.TestX25519Recipient) f.HMAC() f.Payload("age") - f.ExpectHeaderFailure() + f.ExpectNoMatch() f.Generate() }