test(credentials): seed identity/node_key in test helper so encrypt/decrypt works
Credentials tests created a fresh tempdir and immediately invoked encrypt/decrypt, but load_encryption_key reads <dir>/identity/node_key which did not exist, so every test failed with "node key not found". Add a test_dir_with_node_key() helper that writes a deterministic 32-byte key and switch all 8 call sites to it.
This commit is contained in:
@@ -129,9 +129,21 @@ pub fn is_revoked(vc: &VerifiableCredential) -> bool {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
/// Create a tempdir with a dummy `identity/node_key` so that the
|
||||||
|
/// credential store's encrypt/decrypt path can derive a key.
|
||||||
|
/// Returns the tempdir guard (drop it to clean up).
|
||||||
|
fn test_dir_with_node_key() -> tempfile::TempDir {
|
||||||
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
let identity_dir = dir.path().join("identity");
|
||||||
|
std::fs::create_dir_all(&identity_dir).unwrap();
|
||||||
|
// 32 bytes of deterministic test material; never a real key.
|
||||||
|
std::fs::write(identity_dir.join("node_key"), [0xAB; 32]).unwrap();
|
||||||
|
dir
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_issue_credential_w3c_format() {
|
async fn test_issue_credential_w3c_format() {
|
||||||
let dir = tempfile::tempdir().unwrap();
|
let dir = test_dir_with_node_key();
|
||||||
let vc = issue_credential(
|
let vc = issue_credential(
|
||||||
dir.path(),
|
dir.path(),
|
||||||
"did:key:issuer",
|
"did:key:issuer",
|
||||||
@@ -163,7 +175,7 @@ mod tests {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_issue_credential_serializes_as_jsonld() {
|
async fn test_issue_credential_serializes_as_jsonld() {
|
||||||
let dir = tempfile::tempdir().unwrap();
|
let dir = test_dir_with_node_key();
|
||||||
let vc = issue_credential(
|
let vc = issue_credential(
|
||||||
dir.path(),
|
dir.path(),
|
||||||
"did:key:issuer",
|
"did:key:issuer",
|
||||||
@@ -185,7 +197,7 @@ mod tests {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_save_and_load_roundtrip() {
|
async fn test_save_and_load_roundtrip() {
|
||||||
let dir = tempfile::tempdir().unwrap();
|
let dir = test_dir_with_node_key();
|
||||||
issue_credential(
|
issue_credential(
|
||||||
dir.path(),
|
dir.path(),
|
||||||
"did:key:a",
|
"did:key:a",
|
||||||
@@ -205,7 +217,7 @@ mod tests {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_issue_credential_sign_fn_failure_propagates() {
|
async fn test_issue_credential_sign_fn_failure_propagates() {
|
||||||
let dir = tempfile::tempdir().unwrap();
|
let dir = test_dir_with_node_key();
|
||||||
let result = issue_credential(
|
let result = issue_credential(
|
||||||
dir.path(),
|
dir.path(),
|
||||||
"did:key:issuer",
|
"did:key:issuer",
|
||||||
@@ -257,7 +269,7 @@ mod tests {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_revoke_credential() {
|
async fn test_revoke_credential() {
|
||||||
let dir = tempfile::tempdir().unwrap();
|
let dir = test_dir_with_node_key();
|
||||||
let vc = issue_credential(
|
let vc = issue_credential(
|
||||||
dir.path(),
|
dir.path(),
|
||||||
"did:key:issuer",
|
"did:key:issuer",
|
||||||
@@ -288,7 +300,7 @@ mod tests {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_revoke_nonexistent_credential_fails() {
|
async fn test_revoke_nonexistent_credential_fails() {
|
||||||
let dir = tempfile::tempdir().unwrap();
|
let dir = test_dir_with_node_key();
|
||||||
let result = revoke_credential(dir.path(), "urn:uuid:does-not-exist").await;
|
let result = revoke_credential(dir.path(), "urn:uuid:does-not-exist").await;
|
||||||
assert!(result.is_err());
|
assert!(result.is_err());
|
||||||
assert!(result
|
assert!(result
|
||||||
@@ -299,7 +311,7 @@ mod tests {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_list_credentials_no_filter() {
|
async fn test_list_credentials_no_filter() {
|
||||||
let dir = tempfile::tempdir().unwrap();
|
let dir = test_dir_with_node_key();
|
||||||
issue_credential(
|
issue_credential(
|
||||||
dir.path(),
|
dir.path(),
|
||||||
"did:key:a",
|
"did:key:a",
|
||||||
@@ -329,7 +341,7 @@ mod tests {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_list_credentials_filter_by_did() {
|
async fn test_list_credentials_filter_by_did() {
|
||||||
let dir = tempfile::tempdir().unwrap();
|
let dir = test_dir_with_node_key();
|
||||||
issue_credential(
|
issue_credential(
|
||||||
dir.path(),
|
dir.path(),
|
||||||
"did:key:alice",
|
"did:key:alice",
|
||||||
|
|||||||
Reference in New Issue
Block a user