77 lines
1.6 KiB
Go
77 lines
1.6 KiB
Go
|
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
|
||
|
}
|