|
1 | 1 | package e2e |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "encoding/base64" |
4 | 5 | "encoding/json" |
5 | 6 | "testing" |
6 | 7 | "time" |
|
19 | 20 |
|
20 | 21 | type mobileRegisterResponse struct { |
21 | 22 | Token string `json:"token"` |
| 23 | + Login string `json:"login"` |
22 | 24 | Password string `json:"password"` |
23 | 25 | } |
24 | 26 |
|
@@ -203,3 +205,69 @@ func TestPublicDevicePasswordChange(t *testing.T) { |
203 | 205 | }) |
204 | 206 | } |
205 | 207 | } |
| 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