package storage import ( "crypto/rand" "crypto/rsa" "testing" "github.com/stef/pkiapi/internal/pki" ) // TestStorageConfiguration teste que la config est correctement chargée func TestStorageConfiguration(t *testing.T) { // Test MemoryStore memStore := NewMemoryStore() if memStore == nil { t.Fatalf("MemoryStore nil") } testCert := &pki.Certificate{ ID: "test-123", Subject: "CN=test.example.com", Issuer: "CN=test.example.com", IsCA: false, } memStore.SaveCertificate("test-123", testCert) retrieved, err := memStore.GetCertificate("test-123") if err != nil { t.Fatalf("Erreur récupération certificat: %v", err) } if retrieved.Subject != "CN=test.example.com" { t.Fatalf("Certificate Subject mismatch") } t.Log("✓ MemoryStore OK") memStore.Close() } // TestKeyMarshalling teste la sérialisation des clés RSA func TestKeyMarshalling(t *testing.T) { // Créer une clé RSA de test privateKey, err := rsa.GenerateKey(rand.Reader, 2048) if err != nil { t.Fatalf("Erreur génération clé: %v", err) } // Test marshalling privée clé marshalledKey, err := marshalPrivateKey(privateKey) if err != nil { t.Fatalf("Erreur marshalling clé: %v", err) } // Test unmarshalling clé privée unmarshalledKey, err := unmarshalPrivateKey(marshalledKey) if err != nil { t.Fatalf("Erreur unmarshalling clé: %v", err) } _, ok := unmarshalledKey.(*rsa.PrivateKey) if !ok { t.Fatalf("Type assertion failed, expected *rsa.PrivateKey") } t.Log("✓ Sérialisation/désérialisation des clés RSA OK") }