-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathsignon_test.go
121 lines (108 loc) · 3.1 KB
/
signon_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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package ofxgo
import (
"testing"
)
func TestMarshalInvalidSignons(t *testing.T) {
var client = BasicClient{
AppID: "OFXGO",
AppVer: "0001",
SpecVersion: OfxVersion203,
}
var request Request
request.Signon.UserID = "myusername"
request.Signon.UserPass = "Pa$$word"
request.Signon.Org = "BNK"
request.Signon.Fid = "1987"
request.SetClientFields(&client)
_, err := request.Marshal()
if err != nil {
t.Fatalf("Unexpected error marshalling signon: %s\n", err)
}
request.Signon.UserKey = "mykey"
_, err = request.Marshal()
if err == nil {
t.Fatalf("Expected error due to key and password both being specified\n")
}
request.Signon.UserPass = ""
_, err = request.Marshal()
if err != nil {
t.Fatalf("Unexpected error marshalling signon: %s\n", err)
}
request.Signon.UserID = ""
_, err = request.Marshal()
if err == nil {
t.Fatalf("Expected error due to unspecified UserID\n")
}
request.Signon.UserID = "lakhgdlsakhgdlkahdglkhsadlkghaslkdghsalkdghalsdhg"
if err == nil {
t.Fatalf("Expected error due to UserID too long\n")
}
request.Signon.UserID = "myusername"
request.Signon.UserKey = "adlfahdslkgahdweoihadf98agrha87rghasdf9hawhra2hrkwahhaguhwaoefajkei23hff"
_, err = request.Marshal()
if err == nil {
t.Fatalf("Expected error due to UserKey too long\n")
}
request.Signon.UserKey = ""
request.Signon.UserPass = "adlfahdslkgahdweoihadf98agrha87rghasdf9hawhra2hrkwahhaguhwaoefajkei23hff"
_, err = request.Marshal()
if err == nil {
t.Fatalf("Expected error due to UserPass too long\n")
}
request.Signon.UserPass = "lakhgdlkahd"
request.Signon.Language = "English"
_, err = request.Marshal()
if err == nil {
t.Fatalf("Expected error due to Language too long\n")
}
request.Signon.Language = "EN"
_, err = request.Marshal()
if err == nil {
t.Fatalf("Expected error due to Language too short\n")
}
request.Signon.Language = ""
_, err = request.Marshal()
if err != nil || request.Signon.Language != "ENG" {
t.Fatalf("Empty Language expected to default to ENG: %s\n", err)
}
request.Signon.Language = "ENG"
request.Signon.AppID = ""
_, err = request.Marshal()
if err == nil {
t.Fatalf("Expected error due to missing AppID\n")
}
request.SetClientFields(&client)
_, err = request.Marshal()
if err != nil {
t.Fatalf("Client expected to set empty AppID: %s\n", err)
}
client.AppID = "ALKHGDH"
request.SetClientFields(&client)
_, err = request.Marshal()
if err == nil {
t.Fatalf("Expected error due to AppID too long\n")
}
client.AppID = "OFXGO"
request.Signon.AppVer = ""
_, err = request.Marshal()
if err == nil {
t.Fatalf("Expected error due to missing AppVer\n")
}
request.SetClientFields(&client)
_, err = request.Marshal()
if err != nil {
t.Fatalf("Client expected to set empty AppVer: %s\n", err)
}
client.AppVer = "00002"
request.SetClientFields(&client)
_, err = request.Marshal()
if err == nil {
t.Fatalf("Expected error due to AppVer too long\n")
}
client.AppVer = "0001"
request.SetClientFields(&client)
_, err = request.Marshal()
if err != nil {
t.Fatalf("Unexpected error after resetting all fields to reasonable values: %s\n", err)
}
}