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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
package spectre_test
import (
_ "embed"
"fmt"
"strconv"
"testing"
"go.jolheiser.com/go-spectre"
"go.jolheiser.com/go-spectre/testdata"
)
func TestSpectre(t *testing.T) {
cases, err := testdata.Cases()
if err != nil {
t.Log(err)
t.FailNow()
}
for _, tc := range cases {
t.Run(tc.ID, func(t *testing.T) {
s, err := spectre.New(tc.UserName, tc.UserSecret)
if err != nil {
t.Logf("could not initialize spectre: %v", err)
t.Fail()
}
counter, err := strconv.Atoi(tc.KeyCounter)
if err != nil {
t.Log("could not convert counter")
t.Fail()
}
pass := s.Site(tc.SiteName,
spectre.WithTemplate(spectre.Template(tc.ResultType)),
spectre.WithCounter(counter),
spectre.WithScope(spectre.Scope(tc.KeyPurpose)),
)
if pass != tc.Result {
t.Log("passwords did not match")
t.Fail()
}
})
}
}
// From the website sanity check
func Example() {
s, err := spectre.New("Robert Lee Mitchell", "banana colored duckling")
if err != nil {
panic(err)
}
pw := s.Site("masterpasswordapp.com")
fmt.Println(pw)
// Output: Jejr5[RepuSosp
}
// Example with options
func Example_second() {
scoper := spectre.SimpleScoper{
Key: "com.jojodev.jolheiser",
}
s, err := spectre.New("Robert Lee Mitchell", "banana colored duckling", spectre.WithScoper(scoper))
if err != nil {
panic(err)
}
pw := s.Site("jojodev.com",
spectre.WithScope(spectre.Identification),
spectre.WithTemplate(spectre.Maximum),
spectre.WithCounter(2), // Password was leaked, so increment counter (example)
)
fmt.Println(pw)
// Output: Ig^JIcxD!*)TbefJBi6-
}
|