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
|
package main
import (
_ "embed"
"os"
"testing"
"go.jolheiser.com/go-spectre/testdata"
)
// These are the exact same tests as spectre_test.go
// These are here just to make sure the CLI is giving the same outputs
func TestCLI(t *testing.T) {
cases, err := testdata.Cases()
if err != nil {
t.Log(err)
t.FailNow()
}
tmp := t.TempDir()
for _, tc := range cases {
t.Run(tc.ID, func(t *testing.T) {
args := []string{
"--username", tc.UserName,
"--secret", tc.UserSecret,
"--secret-file", "",
"--template", tc.ResultType,
"--counter", tc.KeyCounter,
"--scope", tc.KeyPurpose,
"--print",
tc.SiteName,
}
pw, err := maine(args)
if err != nil {
t.Log(err)
t.FailNow()
}
if pw != tc.Result {
t.Log("passwords did not match")
t.Fail()
}
// Test with secret-file as well
sf, err := os.CreateTemp(tmp, "spectre*")
if err != nil {
t.Log(err)
t.FailNow()
}
defer sf.Close()
if _, err := sf.WriteString(tc.UserSecret); err != nil {
t.Log(err)
t.FailNow()
}
args[3] = "" // --secret
args[5] = sf.Name() // --secret-file
pw, err = maine(args)
if err != nil {
t.Log(err)
t.FailNow()
}
if pw != tc.Result {
t.Log("passwords did not match")
t.Fail()
}
})
}
}
|