Skip to content

Commit 4f1bb16

Browse files
committed
[test] device registration for an existed account
1 parent 8877ab0 commit 4f1bb16

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

test/e2e/mobile_test.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package e2e
22

33
import (
4+
"encoding/base64"
45
"encoding/json"
56
"testing"
67
"time"
@@ -19,6 +20,7 @@ var (
1920

2021
type mobileRegisterResponse struct {
2122
Token string `json:"token"`
23+
Login string `json:"login"`
2224
Password string `json:"password"`
2325
}
2426

@@ -203,3 +205,69 @@ func TestPublicDevicePasswordChange(t *testing.T) {
203205
})
204206
}
205207
}
208+
209+
func TestPublicDeviceRegisterWithCredentials(t *testing.T) {
210+
// won't work with registration rate limits
211+
t.SkipNow()
212+
213+
firstDevice := mobileDeviceRegister(t, publicClient)
214+
215+
cases := []struct {
216+
name string
217+
headers map[string]string
218+
expectedStatusCode int
219+
expectedLogin string
220+
expectedPassword string
221+
}{
222+
{
223+
name: "Valid Credentials",
224+
headers: map[string]string{
225+
"Authorization": "Basic " + base64.StdEncoding.EncodeToString([]byte(firstDevice.Login+":"+firstDevice.Password)),
226+
},
227+
expectedStatusCode: 201,
228+
expectedLogin: "",
229+
expectedPassword: "",
230+
},
231+
{
232+
name: "Invalid Credentials",
233+
headers: map[string]string{
234+
"Authorization": "Basic " + base64.StdEncoding.EncodeToString([]byte("a:1")),
235+
},
236+
expectedStatusCode: 401,
237+
},
238+
}
239+
240+
for _, c := range cases {
241+
t.Run(c.name, func(t *testing.T) {
242+
res, err := publicClient.R().
243+
SetHeader("Content-Type", "application/json").
244+
SetBody(`{"name": "Public Device Name", "pushToken": "token"}`).
245+
SetHeaders(c.headers).
246+
Post("device")
247+
if err != nil {
248+
t.Fatal(err)
249+
}
250+
251+
if res.StatusCode() != c.expectedStatusCode {
252+
t.Fatal(res.StatusCode(), res.String())
253+
}
254+
255+
if !res.IsSuccess() {
256+
return
257+
}
258+
259+
var resp mobileRegisterResponse
260+
if err := json.Unmarshal(res.Body(), &resp); err != nil {
261+
t.Fatal(err)
262+
}
263+
264+
if resp.Login != c.expectedLogin {
265+
t.Fatalf("expected login %s, got %s", c.expectedLogin, resp.Login)
266+
}
267+
268+
if resp.Password != c.expectedPassword {
269+
t.Fatalf("expected password %s, got %s", c.expectedPassword, resp.Password)
270+
}
271+
})
272+
}
273+
}

0 commit comments

Comments
 (0)