44 "fmt"
55 "os"
66 "runtime"
7+ "strconv"
78 "strings"
89 "testing"
910
@@ -31,7 +32,7 @@ func TestMain(m *testing.M) {
3132
3233func TestGetPOSTData1 (t * testing.T ) {
3334 validate := "s_entity=54cd&s_command=AUTH%3Dgwrgwqg%25%26%5C44t3%2A%0ACOMMAND%3DModifyDomain"
34- enc := cl .GetPOSTData (map [string ]interface {} {
35+ enc := cl .GetPOSTData (map [string ]string {
3536 "COMMAND" : "ModifyDomain" ,
3637 "AUTH" : "gwrgwqg%&\\ 44t3*" ,
3738 })
@@ -48,6 +49,56 @@ func TestDisableDebugMode(t *testing.T) {
4849 cl .DisableDebugMode ()
4950}
5051
52+ func TestRequestFlattenCommand (t * testing.T ) {
53+ cl .SetCredentials ("test.user" , "test.passw0rd" )
54+ cl .UseOTESystem ()
55+ r := cl .Request (map [string ]interface {}{
56+ "COMMAND" : "CheckDomains" ,
57+ "DOMAiN" : []string {"example.com" , "example.net" },
58+ })
59+ if ! r .IsSuccess () || r .GetCode () != 200 || r .GetDescription () != "Command completed successfully" {
60+ t .Error ("TestRequestFlattenCommand: Expected response to succeed." )
61+ }
62+ cmd := r .GetCommand ()
63+ val1 , exists1 := cmd ["DOMAIN0" ]
64+ val2 , exists2 := cmd ["DOMAIN1" ]
65+ _ , exists3 := cmd ["DOMAIN" ]
66+ _ , exists4 := cmd ["DOMAiN" ]
67+ if ! exists1 || ! exists2 || exists3 || exists4 {
68+ t .Error ("TestRequestFlattenCommand: DOMAIN parameter flattening not working (keys)." )
69+ }
70+ if val1 != "example.com" || val2 != "example.net" {
71+ t .Error ("TestRequestFlattenCommand: DOMAIN parameter flattening not working (vals)." )
72+ }
73+ }
74+
75+ func TestAutoIDNConvertCommand (t * testing.T ) {
76+ cl .SetCredentials ("test.user" , "test.passw0rd" )
77+ cl .UseOTESystem ()
78+ r := cl .Request (map [string ]interface {}{
79+ "COMMAND" : "CheckDomains" ,
80+ "DOMAiN" : []string {"example.com" , "dömäin.example" , "example.net" },
81+ })
82+ if ! r .IsSuccess () || r .GetCode () != 200 || r .GetDescription () != "Command completed successfully" {
83+ t .Error ("TestRequestFlattenCommand: Expected response to succeed." + strconv .Itoa (r .GetCode ()) + r .GetDescription ())
84+ }
85+ cmd := r .GetCommand ()
86+ val1 , exists1 := cmd ["DOMAIN0" ]
87+ val2 , exists2 := cmd ["DOMAIN1" ]
88+ val3 , exists3 := cmd ["DOMAIN2" ]
89+ _ , exists4 := cmd ["DOMAIN" ]
90+ _ , exists5 := cmd ["DOMAiN" ]
91+ if ! exists1 || ! exists2 || ! exists3 || exists4 || exists5 {
92+ t .Error ("TestRequestFlattenCommand: DOMAIN parameter flattening not working (keys)." )
93+ }
94+ if val1 != "example.com" || val2 != "xn--dmin-moa0i.example" || val3 != "example.net" {
95+ t .Error ("TestRequestFlattenCommand: DOMAIN parameter flattening not working (vals)." )
96+ }
97+ // reset to defaults for following tests
98+ cl .SetCredentials ("" , "" )
99+ cl .UseLIVESystem ()
100+ }
101+
51102func TestGetSession1 (t * testing.T ) {
52103 cl .Logout ()
53104 session , err := cl .GetSession ()
@@ -105,7 +156,7 @@ func TestSetURL(t *testing.T) {
105156
106157func TestSetOTP1 (t * testing.T ) {
107158 cl .SetOTP ("12345678" )
108- tmp := cl .GetPOSTData (map [string ]interface {} {
159+ tmp := cl .GetPOSTData (map [string ]string {
109160 "COMMAND" : "StatusAccount" ,
110161 })
111162 if strings .Compare (tmp , "s_entity=54cd&s_otp=12345678&s_command=COMMAND%3DStatusAccount" ) != 0 {
@@ -115,7 +166,7 @@ func TestSetOTP1(t *testing.T) {
115166
116167func TestSetOTP2 (t * testing.T ) {
117168 cl .SetOTP ("" )
118- tmp := cl .GetPOSTData (map [string ]interface {} {
169+ tmp := cl .GetPOSTData (map [string ]string {
119170 "COMMAND" : "StatusAccount" ,
120171 })
121172 if strings .Compare (tmp , "s_entity=54cd&s_command=COMMAND%3DStatusAccount" ) != 0 {
@@ -125,7 +176,7 @@ func TestSetOTP2(t *testing.T) {
125176
126177func TestSetSession1 (t * testing.T ) {
127178 cl .SetSession ("12345678" )
128- tmp := cl .GetPOSTData (map [string ]interface {} {
179+ tmp := cl .GetPOSTData (map [string ]string {
129180 "COMMAND" : "StatusAccount" ,
130181 })
131182 if strings .Compare (tmp , "s_entity=54cd&s_session=12345678&s_command=COMMAND%3DStatusAccount" ) != 0 {
@@ -137,7 +188,7 @@ func TestSetSession2(t *testing.T) {
137188 cl .SetRoleCredentials ("myaccountid" , "myrole" , "mypassword" )
138189 cl .SetOTP ("12345678" )
139190 cl .SetSession ("12345678" )
140- tmp := cl .GetPOSTData (map [string ]interface {} {
191+ tmp := cl .GetPOSTData (map [string ]string {
141192 "COMMAND" : "StatusAccount" ,
142193 })
143194 if strings .Compare (tmp , "s_entity=54cd&s_session=12345678&s_command=COMMAND%3DStatusAccount" ) != 0 {
@@ -147,7 +198,7 @@ func TestSetSession2(t *testing.T) {
147198
148199func TestSetSession3 (t * testing.T ) {
149200 cl .SetSession ("" )
150- tmp := cl .GetPOSTData (map [string ]interface {} {
201+ tmp := cl .GetPOSTData (map [string ]string {
151202 "COMMAND" : "StatusAccount" ,
152203 })
153204 if strings .Compare (tmp , "s_entity=54cd&s_command=COMMAND%3DStatusAccount" ) != 0 {
@@ -161,7 +212,7 @@ func TestSaveReuseSession(t *testing.T) {
161212 cl .SaveSession (sessionobj )
162213 cl2 := NewAPIClient ()
163214 cl2 .ReuseSession (sessionobj )
164- tmp := cl2 .GetPOSTData (map [string ]interface {} {
215+ tmp := cl2 .GetPOSTData (map [string ]string {
165216 "COMMAND" : "StatusAccount" ,
166217 })
167218 if strings .Compare (tmp , "s_entity=54cd&s_session=12345678&s_command=COMMAND%3DStatusAccount" ) != 0 {
@@ -172,7 +223,7 @@ func TestSaveReuseSession(t *testing.T) {
172223
173224func TestSetRemoteIPAddress1 (t * testing.T ) {
174225 cl .SetRemoteIPAddress ("10.10.10.10" )
175- tmp := cl .GetPOSTData (map [string ]interface {} {
226+ tmp := cl .GetPOSTData (map [string ]string {
176227 "COMMAND" : "StatusAccount" ,
177228 })
178229 if strings .Compare (tmp , "s_entity=54cd&s_remoteaddr=10.10.10.10&s_command=COMMAND%3DStatusAccount" ) != 0 {
@@ -182,7 +233,7 @@ func TestSetRemoteIPAddress1(t *testing.T) {
182233
183234func TestSetRemoteIPAddress2 (t * testing.T ) {
184235 cl .SetRemoteIPAddress ("" )
185- tmp := cl .GetPOSTData (map [string ]interface {} {
236+ tmp := cl .GetPOSTData (map [string ]string {
186237 "COMMAND" : "StatusAccount" ,
187238 })
188239 if strings .Compare (tmp , "s_entity=54cd&s_command=COMMAND%3DStatusAccount" ) != 0 {
@@ -192,7 +243,7 @@ func TestSetRemoteIPAddress2(t *testing.T) {
192243
193244func TestSetCredentials1 (t * testing.T ) {
194245 cl .SetCredentials ("myaccountid" , "mypassword" )
195- tmp := cl .GetPOSTData (map [string ]interface {} {
246+ tmp := cl .GetPOSTData (map [string ]string {
196247 "COMMAND" : "StatusAccount" ,
197248 })
198249 if strings .Compare (tmp , "s_entity=54cd&s_login=myaccountid&s_pw=mypassword&s_command=COMMAND%3DStatusAccount" ) != 0 {
@@ -202,7 +253,7 @@ func TestSetCredentials1(t *testing.T) {
202253
203254func TestSetCredentials2 (t * testing.T ) {
204255 cl .SetCredentials ("" , "" )
205- tmp := cl .GetPOSTData (map [string ]interface {} {
256+ tmp := cl .GetPOSTData (map [string ]string {
206257 "COMMAND" : "StatusAccount" ,
207258 })
208259 if strings .Compare (tmp , "s_entity=54cd&s_command=COMMAND%3DStatusAccount" ) != 0 {
@@ -212,7 +263,7 @@ func TestSetCredentials2(t *testing.T) {
212263
213264func TestSetRoleCredentials1 (t * testing.T ) {
214265 cl .SetRoleCredentials ("myaccountid" , "myroleid" , "mypassword" )
215- tmp := cl .GetPOSTData (map [string ]interface {} {
266+ tmp := cl .GetPOSTData (map [string ]string {
216267 "COMMAND" : "StatusAccount" ,
217268 })
218269 if strings .Compare (tmp , "s_entity=54cd&s_login=myaccountid%21myroleid&s_pw=mypassword&s_command=COMMAND%3DStatusAccount" ) != 0 {
@@ -222,7 +273,7 @@ func TestSetRoleCredentials1(t *testing.T) {
222273
223274func TestSetRoleCredentials2 (t * testing.T ) {
224275 cl .SetRoleCredentials ("" , "" , "" )
225- tmp := cl .GetPOSTData (map [string ]interface {} {
276+ tmp := cl .GetPOSTData (map [string ]string {
226277 "COMMAND" : "StatusAccount" ,
227278 })
228279 if strings .Compare (tmp , "s_entity=54cd&s_command=COMMAND%3DStatusAccount" ) != 0 {
0 commit comments