|
8 | 8 | "fmt" |
9 | 9 | "io/ioutil" |
10 | 10 | "net/http" |
| 11 | + "net/url" |
11 | 12 | "testing" |
12 | 13 |
|
13 | 14 | "github.com/tidwall/gjson" |
@@ -254,6 +255,52 @@ func TestRegistration(t *testing.T) { |
254 | 255 | match.JSONKeyPresent("access_token"), |
255 | 256 | }}) |
256 | 257 | }) |
| 258 | + // Test that /_matrix/client/v3/register/available returns available for unregistered user |
| 259 | + t.Run("GET /register/available returns available for unregistered user name", func(t *testing.T) { |
| 260 | + t.Parallel() |
| 261 | + testUserName := "username_should_be_available" |
| 262 | + res := unauthedClient.DoFunc(t, "GET", []string{"_matrix", "client", "v3", "register", "available"}, client.WithQueries(url.Values{ |
| 263 | + "username": []string{testUserName}, |
| 264 | + })) |
| 265 | + must.MatchResponse(t, res, match.HTTPResponse{ |
| 266 | + StatusCode: 200, |
| 267 | + JSON: []match.JSON{ |
| 268 | + match.JSONKeyEqual("available", true), |
| 269 | + }, |
| 270 | + }) |
| 271 | + }) |
| 272 | + // Test that /_matrix/client/v3/register/available returns M_USER_IN_USE for registered user |
| 273 | + t.Run("GET /register/available returns M_USER_IN_USE for registered user name", func(t *testing.T) { |
| 274 | + t.Parallel() |
| 275 | + testUserName := "username_not_available" |
| 276 | + // Don't need the return value here, just need a user to be registered to test against |
| 277 | + _ = deployment.NewUser(t, testUserName, "hs1") |
| 278 | + res := unauthedClient.DoFunc(t, "GET", []string{"_matrix", "client", "v3", "register", "available"}, client.WithQueries(url.Values{ |
| 279 | + "username": []string{testUserName}, |
| 280 | + })) |
| 281 | + must.MatchResponse(t, res, match.HTTPResponse{ |
| 282 | + StatusCode: 400, |
| 283 | + JSON: []match.JSON{ |
| 284 | + match.JSONKeyEqual("errcode", "M_USER_IN_USE"), |
| 285 | + match.JSONKeyPresent("error"), |
| 286 | + }, |
| 287 | + }) |
| 288 | + }) |
| 289 | + // Test that /_matrix/client/v3/register/available returns M_USER_IN_USE for invalid user |
| 290 | + t.Run("GET /register/available returns M_INVALID_USERNAME for invalid user name", func(t *testing.T) { |
| 291 | + t.Parallel() |
| 292 | + testUserName := "username,should_not_be_valid" |
| 293 | + res := unauthedClient.DoFunc(t, "GET", []string{"_matrix", "client", "v3", "register", "available"}, client.WithQueries(url.Values{ |
| 294 | + "username": []string{testUserName}, |
| 295 | + })) |
| 296 | + must.MatchResponse(t, res, match.HTTPResponse{ |
| 297 | + StatusCode: 400, |
| 298 | + JSON: []match.JSON{ |
| 299 | + match.JSONKeyEqual("errcode", "M_INVALID_USERNAME"), |
| 300 | + match.JSONKeyPresent("error"), |
| 301 | + }, |
| 302 | + }) |
| 303 | + }) |
257 | 304 | }) |
258 | 305 | } |
259 | 306 |
|
|
0 commit comments