1
0
mirror of https://github.com/aclindsa/ofxgo.git synced 2024-10-30 05:20:05 -04:00
ofxgo/signon_test.go

122 lines
3.1 KiB
Go
Raw Normal View History

package ofxgo
2017-04-08 08:58:09 -04:00
import (
"testing"
)
func TestMarshalInvalidSignons(t *testing.T) {
var client = BasicClient{
2017-04-12 21:40:42 -04:00
AppID: "OFXGO",
2017-04-08 08:58:09 -04:00
AppVer: "0001",
SpecVersion: OfxVersion203,
2017-04-08 08:58:09 -04:00
}
var request Request
2017-04-12 21:40:42 -04:00
request.Signon.UserID = "myusername"
2017-04-08 08:58:09 -04:00
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)
}
2017-04-12 21:40:42 -04:00
request.Signon.UserID = ""
2017-04-08 08:58:09 -04:00
_, err = request.Marshal()
if err == nil {
2017-04-12 21:40:42 -04:00
t.Fatalf("Expected error due to unspecified UserID\n")
2017-04-08 08:58:09 -04:00
}
2017-04-12 21:40:42 -04:00
request.Signon.UserID = "lakhgdlsakhgdlkahdglkhsadlkghaslkdghsalkdghalsdhg"
2017-04-08 08:58:09 -04:00
if err == nil {
2017-04-12 21:40:42 -04:00
t.Fatalf("Expected error due to UserID too long\n")
2017-04-08 08:58:09 -04:00
}
2017-04-12 21:40:42 -04:00
request.Signon.UserID = "myusername"
2017-04-08 08:58:09 -04:00
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"
2017-04-12 21:40:42 -04:00
request.Signon.AppID = ""
2017-04-08 08:58:09 -04:00
_, err = request.Marshal()
if err == nil {
2017-04-12 21:40:42 -04:00
t.Fatalf("Expected error due to missing AppID\n")
2017-04-08 08:58:09 -04:00
}
request.SetClientFields(&client)
_, err = request.Marshal()
if err != nil {
2017-04-12 21:40:42 -04:00
t.Fatalf("Client expected to set empty AppID: %s\n", err)
2017-04-08 08:58:09 -04:00
}
2017-04-12 21:40:42 -04:00
client.AppID = "ALKHGDH"
2017-04-08 08:58:09 -04:00
request.SetClientFields(&client)
_, err = request.Marshal()
if err == nil {
2017-04-12 21:40:42 -04:00
t.Fatalf("Expected error due to AppID too long\n")
2017-04-08 08:58:09 -04:00
}
2017-04-12 21:40:42 -04:00
client.AppID = "OFXGO"
2017-04-08 08:58:09 -04:00
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)
}
}