Home

go-spectre @906de830722452c510b2093450625b4d5d276d6f - refs - log -
-
https://git.jolheiser.com/go-spectre.git
Go implementation for spectre/masterpassword
go-spectre / testdata / testdata.go
- raw
 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
package testdata

import (
	_ "embed"
	"encoding/xml"
)

func Cases() ([]*TestCase, error) {
	var tests TestCases
	if err := xml.Unmarshal(testsXML, &tests); err != nil {
		return nil, err
	}
	defaultCase := tests.Cases[0]
	cases := make([]*TestCase, 0, len(tests.Cases[1:]))
	for _, tc := range tests.Cases[1:] {
		tc = &TestCase{
			ID:         tc.ID,
			UserName:   def(defaultCase.UserName, tc.UserName),
			UserSecret: def(defaultCase.UserSecret, tc.UserSecret),
			SiteName:   def(defaultCase.SiteName, tc.SiteName),
			ResultType: def(defaultCase.ResultType, tc.ResultType),
			KeyCounter: def(defaultCase.KeyCounter, tc.KeyCounter),
			KeyPurpose: def(defaultCase.KeyPurpose, tc.KeyPurpose),
			Result:     tc.Result,
		}
		cases = append(cases, tc)
	}
	return cases, nil
}

//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
}