1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
package profile
import (
"os"
"path/filepath"
"testing"
)
func TestVaultRoundTrip(t *testing.T) {
value, err := Generate("pseudonym", "reader@example.org")
if err != nil {
t.Fatal(err)
}
path := filepath.Join(t.TempDir(), "profile.json.age")
if err := Save(path, value, "correct horse battery staple"); err != nil {
t.Fatal(err)
}
loaded, err := Load(path, "correct horse battery staple")
if err != nil {
t.Fatal(err)
}
if loaded.Username != value.Username || loaded.PublicKey != value.PublicKey || loaded.PrivateKey != value.PrivateKey {
t.Fatal("profile vault round-trip changed identity")
}
if _, err := Load(path, "wrong password"); err == nil {
t.Fatal("wrong password unlocked profile vault")
}
data, err := os.ReadFile(path)
if err != nil {
t.Fatal(err)
}
if len(data) == 0 || string(data) == "" {
t.Fatal("empty profile vault")
}
}
func TestPasswordMinimum(t *testing.T) {
value, err := Generate("pseudonym", "reader@example.org")
if err != nil {
t.Fatal(err)
}
if err := Save(filepath.Join(t.TempDir(), "profile.json.age"), value, "short"); err == nil {
t.Fatal("short profile password accepted")
}
}
|