forked from tazjin/watchblob
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
99 lines (85 loc) · 2.1 KB
/
main_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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package main
import (
"encoding/xml"
"reflect"
"testing"
)
func TestUnmarshalChallengeRespones(t *testing.T) {
var testXml string = `
<?xml version="1.0" encoding="UTF-8"?>
<resp>
<action>sslvpn_logon</action>
<logon_status>4</logon_status>
<auth-domain-list>
<auth-domain>
<name>RADIUS</name>
</auth-domain>
</auth-domain-list>
<logon_id>441</logon_id>
<chaStr>Enter Your 6 Digit Passcode </chaStr>
</resp>`
var r WatchguardResponse
xml.Unmarshal([]byte(testXml), &r)
expected := WatchguardResponse{
Action: "sslvpn_logon",
LogonStatus: 4,
LogonId: 441,
Challenge: "Enter Your 6 Digit Passcode ",
AuthDomains: AuthDomains{AuthDomain: []AuthDomain{{Name: "RADIUS"}}},
}
assertEqual(t, expected, r)
}
func TestUnmarshalLoginError(t *testing.T) {
var testXml string = `
<?xml version="1.0" encoding="UTF-8"?>
<resp>
<action>sslvpn_logon</action>
<logon_status>2</logon_status>
<auth-domain-list>
<auth-domain>
<name>RADIUS</name>
</auth-domain>
</auth-domain-list>
<errStr>501</errStr>
</resp>`
var r WatchguardResponse
xml.Unmarshal([]byte(testXml), &r)
expected := WatchguardResponse{
Action: "sslvpn_logon",
LogonStatus: 2,
Error: "501",
AuthDomains: AuthDomains{AuthDomain: []AuthDomain{{Name: "RADIUS"}}},
}
assertEqual(t, expected, r)
}
func TestUnmarshalLoginSuccess(t *testing.T) {
var testXml string = `
<?xml version="1.0" encoding="UTF-8"?>
<resp>
<action>sslvpn_logon</action>
<logon_status>1</logon_status>
<auth-domain-list>
<auth-domain>
<name>RADIUS</name>
</auth-domain>
</auth-domain-list>
</resp>
`
var r WatchguardResponse
xml.Unmarshal([]byte(testXml), &r)
expected := WatchguardResponse{
Action: "sslvpn_logon",
LogonStatus: 1,
AuthDomains: AuthDomains{AuthDomain: []AuthDomain{{Name: "RADIUS"}}},
}
assertEqual(t, expected, r)
}
func assertEqual(t *testing.T, expected interface{}, result interface{}) {
if !reflect.DeepEqual(expected, result) {
t.Errorf(
"Unmarshaled values did not match.\nExpected: %v\nResult: %v\n",
expected, result,
)
t.Fail()
}
}