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 main
import (
_ "embed"
"encoding/xml"
"fmt"
"testing"
)
// 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) {
var tests TestCases
if err := xml.Unmarshal(testsXML, &tests); err != nil {
t.Log("could not load test data")
t.FailNow()
}
dc := tests.Cases[0]
for _, tc := range tests.Cases[1:] {
t.Run(tc.ID, func(t *testing.T) {
user := def(dc.UserName, tc.UserName)
secret := def(dc.UserSecret, tc.UserSecret)
siteName := def(dc.SiteName, tc.SiteName)
template := def(dc.ResultType, tc.ResultType)
counter := def(dc.KeyCounter, tc.KeyCounter)
scope := def(dc.KeyPurpose, tc.KeyPurpose)
args := []string{
"--username", user,
"--secret", secret,
"--template", template,
"--counter", counter,
"--scope", scope,
siteName,
}
fmt.Println(args)
pw, err := doMain(args)
if err != nil {
t.Log(err)
t.FailNow()
}
if pw != tc.Result {
t.Log("passwords did not match")
t.Fail()
}
})
}
}
//go:embed spectre_tests.xml
var testsXML []byte
type TestCases struct {
Cases []TestCase `xml:"case"`
}
type TestCase struct {
ID string `xml:"id,attr"`
UserName string `xml:"userName"`
UserSecret string `xml:"userSecret"`
SiteName string `xml:"siteName"`
ResultType string `xml:"resultType"`
KeyCounter string `xml:"keyCounter"`
KeyPurpose string `xml:"keyPurpose"`
Result string `xml:"result"`
}
func def(def, alt string) string {
if alt != "" {
return alt
}
return def
}
|