@@ -0,0 +1,55 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPBKDF2SHA256Vector(t *testing.T) {
|
||||
got := hex.EncodeToString(pbkdf2SHA256([]byte("password"), []byte("salt"), 2, 32))
|
||||
const want = "ae4d0c95af6b46d32d0adff928f06dd02a303f8ef3c251dfd6e2d85a95474c43"
|
||||
if got != want {
|
||||
t.Fatalf("pbkdf2 mismatch: got %s want %s", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBrowserIdentityExportImportRoundTrip(t *testing.T) {
|
||||
id, _, err := generateIdentity()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
path := filepath.Join(t.TempDir(), "identity-export.json")
|
||||
if err := exportBrowserIdentity(path, "correct horse battery staple", id); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got, err := readIdentityImport(path, "correct horse battery staple")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got.PublicJWK.X != id.PublicJWK.X || got.PublicJWK.Y != id.PublicJWK.Y || got.PrivateJWK.D != id.PrivateJWK.D {
|
||||
t.Fatal("identity changed during export/import")
|
||||
}
|
||||
if _, err := os.Stat(path); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRawIdentityImport(t *testing.T) {
|
||||
id, _, err := generateIdentity()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
path := filepath.Join(t.TempDir(), "identity.json")
|
||||
if err := saveIdentity(path, id); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got, err := readIdentityImport(path, "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got.PrivateJWK.D != id.PrivateJWK.D {
|
||||
t.Fatal("raw identity import mismatch")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user