-
Notifications
You must be signed in to change notification settings - Fork 6
/
login_test.go
65 lines (57 loc) · 1.48 KB
/
login_test.go
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
package main
import (
"github.com/corbym/gocrest/is"
"github.com/corbym/gocrest/then"
"os"
"path/filepath"
"strings"
"testing"
)
func TestGetSeedValueFromLogin(t *testing.T) {
tests := []struct {
model string
fileName string
expectedSeed string
}{
{
model: "GS305EP",
fileName: "login.cgi.html",
expectedSeed: "1761741982",
},
{
model: "GS308EPP",
fileName: "login.cgi.html",
expectedSeed: "1387882569",
},
{
model: "GS316EP",
fileName: "login.html",
expectedSeed: "885340480",
},
}
for _, test := range tests {
t.Run(test.model, func(t *testing.T) {
html := loadTestFile(test.model, test.fileName)
randomVal, err := findSeedValueInLoginHtml(strings.NewReader(html))
then.AssertThat(t, randomVal, is.EqualTo(test.expectedSeed))
then.AssertThat(t, err, is.Nil())
})
}
}
func TestEncryptPassword(t *testing.T) {
val := encryptPassword("foobar", "12345678")
then.AssertThat(t, val, is.EqualTo("d1f4394e3e212ab4f06e08c54477a237"))
}
func TestFindGambitTokenInResponseHtml(t *testing.T) {
html := loadTestFile(string(GS316EP), "redirect.html")
gambit := findGambitTokenInResponseHtml(strings.NewReader(html))
then.AssertThat(t, gambit, is.EqualTo("chpbfghbcadbaamekjof"))
}
func loadTestFile(model string, fileName string) string {
fullFileName := filepath.Join("test-data", model, fileName)
bytes, err := os.ReadFile(fullFileName)
if err != nil {
panic(err)
}
return string(bytes)
}