Skip to content

Commit e740745

Browse files
authored
Add /register/available tests (#625)
1 parent 328f5be commit e740745

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

tests/csapi/apidoc_register_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"fmt"
99
"io/ioutil"
1010
"net/http"
11+
"net/url"
1112
"testing"
1213

1314
"github.com/tidwall/gjson"
@@ -254,6 +255,52 @@ func TestRegistration(t *testing.T) {
254255
match.JSONKeyPresent("access_token"),
255256
}})
256257
})
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+
})
257304
})
258305
}
259306

0 commit comments

Comments
 (0)