Skip to content

Commit 269c6b0

Browse files
committed
fix: correct tests
1 parent fb704c3 commit 269c6b0

4 files changed

Lines changed: 24 additions & 56 deletions

File tree

crates/auths-cli/tests/cases/verify.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,16 @@ fn create_signed_attestation(
1515
device_kp: &ring::signature::Ed25519KeyPair,
1616
) -> Attestation {
1717
let device_pk: [u8; 32] = device_kp.public_key().as_ref().try_into().unwrap();
18+
let issuer_pk: [u8; 32] = issuer_kp.public_key().as_ref().try_into().unwrap();
19+
20+
let device_did = DeviceDID::from_ed25519(&device_pk);
21+
let issuer_did = DeviceDID::from_ed25519(&issuer_pk);
1822

1923
let mut att = Attestation {
2024
version: 1,
2125
rid: ResourceId::new("test-rid"),
22-
issuer: CanonicalDid::new_unchecked(format!(
23-
"did:key:{}",
24-
hex::encode(issuer_kp.public_key().as_ref())
25-
)),
26-
subject: DeviceDID::new_unchecked(format!(
27-
"did:key:{}",
28-
hex::encode(device_kp.public_key().as_ref())
29-
)),
26+
issuer: CanonicalDid::from(issuer_did),
27+
subject: device_did,
3028
device_public_key: Ed25519PublicKey::from_bytes(device_pk),
3129
identity_signature: Ed25519Signature::empty(),
3230
device_signature: Ed25519Signature::empty(),

crates/auths-id/src/keri/cache.rs

Lines changed: 12 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,8 @@ mod tests {
363363
use crate::keri::Prefix;
364364
use tempfile::TempDir;
365365

366+
const VALID_OID: &str = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
367+
366368
fn create_test_state() -> KeyState {
367369
KeyState::from_inception(
368370
Prefix::new_unchecked("ETestPrefix".to_string()),
@@ -400,15 +402,7 @@ mod tests {
400402
let tip_said = "ELatestSaid";
401403

402404
// Write cache
403-
write_kel_cache(
404-
dir.path(),
405-
did,
406-
&state,
407-
tip_said,
408-
"abc123def456",
409-
Utc::now(),
410-
)
411-
.unwrap();
405+
write_kel_cache(dir.path(), did, &state, tip_said, VALID_OID, Utc::now()).unwrap();
412406

413407
// Read it back
414408
let loaded = try_load_cached_state(dir.path(), did, tip_said);
@@ -425,7 +419,7 @@ mod tests {
425419
let state = create_test_state();
426420

427421
// Write cache with one SAID
428-
write_kel_cache(dir.path(), did, &state, "EOldSaid", "commit123", Utc::now()).unwrap();
422+
write_kel_cache(dir.path(), did, &state, "EOldSaid", VALID_OID, Utc::now()).unwrap();
429423

430424
// Try to load with different SAID - should return None
431425
let result = try_load_cached_state(dir.path(), did, "ENewSaid");
@@ -444,15 +438,7 @@ mod tests {
444438
let tip_said = "ESaid";
445439

446440
// Write cache
447-
write_kel_cache(
448-
dir.path(),
449-
did,
450-
&state,
451-
tip_said,
452-
"abc123def456",
453-
Utc::now(),
454-
)
455-
.unwrap();
441+
write_kel_cache(dir.path(), did, &state, tip_said, VALID_OID, Utc::now()).unwrap();
456442

457443
// Manually corrupt the cache by writing wrong DID
458444
let path = cache_path_for_did(dir.path(), did);
@@ -496,15 +482,7 @@ mod tests {
496482
let tip_said = "ESaid";
497483

498484
// Write cache
499-
write_kel_cache(
500-
dir.path(),
501-
did,
502-
&state,
503-
tip_said,
504-
"abc123def456",
505-
Utc::now(),
506-
)
507-
.unwrap();
485+
write_kel_cache(dir.path(), did, &state, tip_said, VALID_OID, Utc::now()).unwrap();
508486

509487
// Manually change version
510488
let path = cache_path_for_did(dir.path(), did);
@@ -525,7 +503,7 @@ mod tests {
525503
let state = create_test_state();
526504

527505
// Write and verify cache exists
528-
write_kel_cache(dir.path(), did, &state, "ESaid", "commit123", Utc::now()).unwrap();
506+
write_kel_cache(dir.path(), did, &state, "ESaid", VALID_OID, Utc::now()).unwrap();
529507
assert!(try_load_cached_state(dir.path(), did, "ESaid").is_some());
530508

531509
// Invalidate
@@ -554,7 +532,7 @@ mod tests {
554532
"did:keri:ETest1",
555533
&state,
556534
"ESaid1",
557-
"commit1",
535+
VALID_OID,
558536
Utc::now(),
559537
)
560538
.unwrap();
@@ -563,7 +541,7 @@ mod tests {
563541
"did:keri:ETest2",
564542
&state,
565543
"ESaid2",
566-
"commit2",
544+
VALID_OID,
567545
Utc::now(),
568546
)
569547
.unwrap();
@@ -587,7 +565,7 @@ mod tests {
587565
"did:keri:EClear1",
588566
&state,
589567
"ESaid",
590-
"commit1",
568+
VALID_OID,
591569
Utc::now(),
592570
)
593571
.unwrap();
@@ -596,7 +574,7 @@ mod tests {
596574
"did:keri:EClear2",
597575
&state,
598576
"ESaid",
599-
"commit2",
577+
VALID_OID,
600578
Utc::now(),
601579
)
602580
.unwrap();
@@ -617,15 +595,7 @@ mod tests {
617595
let state = create_test_state();
618596
let tip_said = "ESaid";
619597

620-
write_kel_cache(
621-
dir.path(),
622-
did,
623-
&state,
624-
tip_said,
625-
"abc123def456",
626-
Utc::now(),
627-
)
628-
.unwrap();
598+
write_kel_cache(dir.path(), did, &state, tip_said, VALID_OID, Utc::now()).unwrap();
629599

630600
let inspected = inspect_cache(dir.path(), did).unwrap();
631601
assert!(inspected.is_some());

crates/auths-sdk/src/workflows/allowed_signers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ mod tests {
616616
#[test]
617617
fn error_codes_and_suggestions() {
618618
let err = AllowedSignersError::InvalidEmail("test".to_string());
619-
assert_eq!(err.error_code(), "AUTHS_INVALID_EMAIL");
619+
assert_eq!(err.error_code(), "AUTHS-E5801");
620620
assert!(err.suggestion().is_some());
621621
}
622622
}

crates/auths-verifier/tests/cases/ssh_sig.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,19 @@ fn error_codes_are_correct() {
4242
use auths_verifier::error::AuthsErrorInfo;
4343

4444
let err = CommitVerificationError::UnsignedCommit;
45-
assert_eq!(err.error_code(), "AUTHS_UNSIGNED_COMMIT");
45+
assert_eq!(err.error_code(), "AUTHS-E2101");
4646

4747
let err = CommitVerificationError::GpgNotSupported;
48-
assert_eq!(err.error_code(), "AUTHS_GPG_NOT_SUPPORTED");
48+
assert_eq!(err.error_code(), "AUTHS-E2102");
4949

5050
let err = CommitVerificationError::UnknownSigner;
51-
assert_eq!(err.error_code(), "AUTHS_UNKNOWN_SIGNER");
51+
assert_eq!(err.error_code(), "AUTHS-E2108");
5252

5353
let err = CommitVerificationError::SignatureInvalid;
54-
assert_eq!(err.error_code(), "AUTHS_SIGNATURE_INVALID");
54+
assert_eq!(err.error_code(), "AUTHS-E2107");
5555

5656
let err = CommitVerificationError::UnsupportedKeyType {
5757
found: "ssh-rsa".into(),
5858
};
59-
assert_eq!(err.error_code(), "AUTHS_UNSUPPORTED_KEY_TYPE");
59+
assert_eq!(err.error_code(), "AUTHS-E2104");
6060
}

0 commit comments

Comments
 (0)