latest from ai, it broke the tests
This commit is contained in:
@@ -133,7 +133,11 @@ func TestDeterministicDerivation(t *testing.T) {
|
||||
}
|
||||
|
||||
if id1.String() != id2.String() {
|
||||
t.Fatalf("identities should be deterministic: %s != %s", id1.String(), id2.String())
|
||||
t.Fatalf(
|
||||
"identities should be deterministic: %s != %s",
|
||||
id1.String(),
|
||||
id2.String(),
|
||||
)
|
||||
}
|
||||
|
||||
// Test that different indices produce different identities
|
||||
@@ -163,7 +167,11 @@ func TestDeterministicXPRVDerivation(t *testing.T) {
|
||||
}
|
||||
|
||||
if id1.String() != id2.String() {
|
||||
t.Fatalf("xprv identities should be deterministic: %s != %s", id1.String(), id2.String())
|
||||
t.Fatalf(
|
||||
"xprv identities should be deterministic: %s != %s",
|
||||
id1.String(),
|
||||
id2.String(),
|
||||
)
|
||||
}
|
||||
|
||||
// Test that different indices with same xprv produce different identities
|
||||
@@ -181,11 +189,8 @@ func TestDeterministicXPRVDerivation(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMnemonicVsXPRVConsistency(t *testing.T) {
|
||||
// Test that deriving from mnemonic and from the corresponding xprv produces the same result
|
||||
// Note: The test mnemonic and test xprv are from different sources
|
||||
// and are not expected to produce the same results, so this test merely
|
||||
// verifies that both derivation methods work without errors.
|
||||
t.Log("Testing mnemonic vs XPRV derivation - note: test data is from different sources")
|
||||
// FIXME This test is missing!
|
||||
|
||||
}
|
||||
|
||||
func TestEntropyLength(t *testing.T) {
|
||||
@@ -208,7 +213,10 @@ func TestEntropyLength(t *testing.T) {
|
||||
}
|
||||
|
||||
if len(entropyXPRV) != 32 {
|
||||
t.Fatalf("expected 32 bytes of entropy from xprv, got %d", len(entropyXPRV))
|
||||
t.Fatalf(
|
||||
"expected 32 bytes of entropy from xprv, got %d",
|
||||
len(entropyXPRV),
|
||||
)
|
||||
}
|
||||
|
||||
t.Logf("XPRV Entropy (32 bytes): %x", entropyXPRV)
|
||||
@@ -264,14 +272,49 @@ func TestClampFunction(t *testing.T) {
|
||||
expected []byte
|
||||
}{
|
||||
{
|
||||
name: "all zeros",
|
||||
input: make([]byte, 32),
|
||||
expected: []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64},
|
||||
name: "all zeros",
|
||||
input: make([]byte, 32),
|
||||
expected: []byte{
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
64,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "all ones",
|
||||
input: bytes.Repeat([]byte{255}, 32),
|
||||
expected: append([]byte{248}, append(bytes.Repeat([]byte{255}, 30), 127)...),
|
||||
name: "all ones",
|
||||
input: bytes.Repeat([]byte{255}, 32),
|
||||
expected: append(
|
||||
[]byte{248},
|
||||
append(bytes.Repeat([]byte{255}, 30), 127)...),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -283,13 +326,22 @@ func TestClampFunction(t *testing.T) {
|
||||
|
||||
// Check specific bits that should be clamped
|
||||
if input[0]&7 != 0 {
|
||||
t.Errorf("first byte should have bottom 3 bits cleared, got %08b", input[0])
|
||||
t.Errorf(
|
||||
"first byte should have bottom 3 bits cleared, got %08b",
|
||||
input[0],
|
||||
)
|
||||
}
|
||||
if input[31]&128 != 0 {
|
||||
t.Errorf("last byte should have top bit cleared, got %08b", input[31])
|
||||
t.Errorf(
|
||||
"last byte should have top bit cleared, got %08b",
|
||||
input[31],
|
||||
)
|
||||
}
|
||||
if input[31]&64 == 0 {
|
||||
t.Errorf("last byte should have second-to-top bit set, got %08b", input[31])
|
||||
t.Errorf(
|
||||
"last byte should have second-to-top bit set, got %08b",
|
||||
input[31],
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -337,7 +389,9 @@ func TestIdentityFromEntropyEdgeCases(t *testing.T) {
|
||||
entropy: func() []byte {
|
||||
b := make([]byte, 32)
|
||||
if _, err := rand.Read(b); err != nil {
|
||||
panic(err) // In test context, panic is acceptable for setup failures
|
||||
panic(
|
||||
err,
|
||||
) // In test context, panic is acceptable for setup failures
|
||||
}
|
||||
return b
|
||||
}(),
|
||||
@@ -356,7 +410,10 @@ func TestIdentityFromEntropyEdgeCases(t *testing.T) {
|
||||
t.Errorf("expected error containing %q, got %q", tt.errorMsg, err.Error())
|
||||
}
|
||||
if identity != nil {
|
||||
t.Errorf("expected nil identity on error, got %v", identity)
|
||||
t.Errorf(
|
||||
"expected nil identity on error, got %v",
|
||||
identity,
|
||||
)
|
||||
}
|
||||
} else {
|
||||
if err != nil {
|
||||
@@ -531,7 +588,11 @@ func TestIndexBoundaries(t *testing.T) {
|
||||
t.Run(fmt.Sprintf("index_%d", index), func(t *testing.T) {
|
||||
identity, err := DeriveIdentity(mnemonic, index)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to derive identity at index %d: %v", index, err)
|
||||
t.Fatalf(
|
||||
"failed to derive identity at index %d: %v",
|
||||
index,
|
||||
err,
|
||||
)
|
||||
}
|
||||
|
||||
// Verify the identity is valid by testing encryption/decryption
|
||||
@@ -628,11 +689,19 @@ func TestConcurrentDerivation(t *testing.T) {
|
||||
expectedResults := testNumGoroutines
|
||||
for result, count := range resultMap {
|
||||
if count != expectedResults {
|
||||
t.Errorf("result %s appeared %d times, expected %d", result, count, expectedResults)
|
||||
t.Errorf(
|
||||
"result %s appeared %d times, expected %d",
|
||||
result,
|
||||
count,
|
||||
expectedResults,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
t.Logf("Concurrent derivation test passed with %d unique results", len(resultMap))
|
||||
t.Logf(
|
||||
"Concurrent derivation test passed with %d unique results",
|
||||
len(resultMap),
|
||||
)
|
||||
}
|
||||
|
||||
// Benchmark tests
|
||||
@@ -712,16 +781,28 @@ func BenchmarkEncryptDecrypt(b *testing.B) {
|
||||
// TestConstants verifies the hardcoded constants
|
||||
func TestConstants(t *testing.T) {
|
||||
if purpose != 83696968 {
|
||||
t.Errorf("purpose constant mismatch: expected 83696968, got %d", purpose)
|
||||
t.Errorf(
|
||||
"purpose constant mismatch: expected 83696968, got %d",
|
||||
purpose,
|
||||
)
|
||||
}
|
||||
if vendorID != 592366788 {
|
||||
t.Errorf("vendorID constant mismatch: expected 592366788, got %d", vendorID)
|
||||
t.Errorf(
|
||||
"vendorID constant mismatch: expected 592366788, got %d",
|
||||
vendorID,
|
||||
)
|
||||
}
|
||||
if appID != 733482323 {
|
||||
t.Errorf("appID constant mismatch: expected 733482323, got %d", appID)
|
||||
t.Errorf(
|
||||
"appID constant mismatch: expected 733482323, got %d",
|
||||
appID,
|
||||
)
|
||||
}
|
||||
if hrp != "age-secret-key-" {
|
||||
t.Errorf("hrp constant mismatch: expected 'age-secret-key-', got %q", hrp)
|
||||
t.Errorf(
|
||||
"hrp constant mismatch: expected 'age-secret-key-', got %q",
|
||||
hrp,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -737,7 +818,10 @@ func TestIdentityStringFormat(t *testing.T) {
|
||||
|
||||
// Check secret key format
|
||||
if !strings.HasPrefix(secretKey, "AGE-SECRET-KEY-") {
|
||||
t.Errorf("secret key should start with 'AGE-SECRET-KEY-', got: %s", secretKey)
|
||||
t.Errorf(
|
||||
"secret key should start with 'AGE-SECRET-KEY-', got: %s",
|
||||
secretKey,
|
||||
)
|
||||
}
|
||||
|
||||
// Check recipient format
|
||||
@@ -834,14 +918,22 @@ func TestRandomMnemonicDeterministicGeneration(t *testing.T) {
|
||||
privateKey1 := identity1.String()
|
||||
privateKey2 := identity2.String()
|
||||
if privateKey1 != privateKey2 {
|
||||
t.Fatalf("private keys should be identical:\nFirst: %s\nSecond: %s", privateKey1, privateKey2)
|
||||
t.Fatalf(
|
||||
"private keys should be identical:\nFirst: %s\nSecond: %s",
|
||||
privateKey1,
|
||||
privateKey2,
|
||||
)
|
||||
}
|
||||
|
||||
// Verify that both public keys (recipients) are identical
|
||||
publicKey1 := identity1.Recipient().String()
|
||||
publicKey2 := identity2.Recipient().String()
|
||||
if publicKey1 != publicKey2 {
|
||||
t.Fatalf("public keys should be identical:\nFirst: %s\nSecond: %s", publicKey1, publicKey2)
|
||||
t.Fatalf(
|
||||
"public keys should be identical:\nFirst: %s\nSecond: %s",
|
||||
publicKey1,
|
||||
publicKey2,
|
||||
)
|
||||
}
|
||||
|
||||
t.Logf("✓ Deterministic generation verified")
|
||||
@@ -873,10 +965,17 @@ func TestRandomMnemonicDeterministicGeneration(t *testing.T) {
|
||||
t.Fatalf("failed to close encryptor: %v", err)
|
||||
}
|
||||
|
||||
t.Logf("✓ Encrypted %d bytes into %d bytes of ciphertext", len(testData), ciphertext.Len())
|
||||
t.Logf(
|
||||
"✓ Encrypted %d bytes into %d bytes of ciphertext",
|
||||
len(testData),
|
||||
ciphertext.Len(),
|
||||
)
|
||||
|
||||
// Decrypt the data using the private key
|
||||
decryptor, err := age.Decrypt(bytes.NewReader(ciphertext.Bytes()), identity1)
|
||||
decryptor, err := age.Decrypt(
|
||||
bytes.NewReader(ciphertext.Bytes()),
|
||||
identity1,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create decryptor: %v", err)
|
||||
}
|
||||
@@ -890,7 +989,11 @@ func TestRandomMnemonicDeterministicGeneration(t *testing.T) {
|
||||
|
||||
// Verify that the decrypted data matches the original
|
||||
if len(decryptedData) != len(testData) {
|
||||
t.Fatalf("decrypted data length mismatch: expected %d, got %d", len(testData), len(decryptedData))
|
||||
t.Fatalf(
|
||||
"decrypted data length mismatch: expected %d, got %d",
|
||||
len(testData),
|
||||
len(decryptedData),
|
||||
)
|
||||
}
|
||||
|
||||
if !bytes.Equal(testData, decryptedData) {
|
||||
@@ -917,7 +1020,10 @@ func TestRandomMnemonicDeterministicGeneration(t *testing.T) {
|
||||
}
|
||||
|
||||
// Decrypt with the second identity
|
||||
decryptor2, err := age.Decrypt(bytes.NewReader(ciphertext2.Bytes()), identity2)
|
||||
decryptor2, err := age.Decrypt(
|
||||
bytes.NewReader(ciphertext2.Bytes()),
|
||||
identity2,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create second decryptor: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user