Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add /register/available tests #625

Merged
merged 2 commits into from
Mar 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions tests/csapi/apidoc_register_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"io/ioutil"
"net/http"
"net/url"
"testing"

"github.com/tidwall/gjson"
Expand Down Expand Up @@ -254,6 +255,52 @@ func TestRegistration(t *testing.T) {
match.JSONKeyPresent("access_token"),
}})
})
// Test that /_matrix/client/v3/register/available returns available for unregistered user
t.Run("GET /register/available returns available for unregistered user name", func(t *testing.T) {
t.Parallel()
testUserName := "username_should_be_available"
res := unauthedClient.DoFunc(t, "GET", []string{"_matrix", "client", "v3", "register", "available"}, client.WithQueries(url.Values{
"username": []string{testUserName},
}))
must.MatchResponse(t, res, match.HTTPResponse{
StatusCode: 200,
JSON: []match.JSON{
match.JSONKeyEqual("available", true),
},
})
})
// Test that /_matrix/client/v3/register/available returns M_USER_IN_USE for registered user
t.Run("GET /register/available returns M_USER_IN_USE for registered user name", func(t *testing.T) {
t.Parallel()
testUserName := "username_not_available"
// Don't need the return value here, just need a user to be registered to test against
_ = deployment.NewUser(t, testUserName, "hs1")
res := unauthedClient.DoFunc(t, "GET", []string{"_matrix", "client", "v3", "register", "available"}, client.WithQueries(url.Values{
"username": []string{testUserName},
}))
must.MatchResponse(t, res, match.HTTPResponse{
StatusCode: 400,
JSON: []match.JSON{
match.JSONKeyEqual("errcode", "M_USER_IN_USE"),
match.JSONKeyPresent("error"),
},
})
})
// Test that /_matrix/client/v3/register/available returns M_USER_IN_USE for invalid user
t.Run("GET /register/available returns M_INVALID_USERNAME for invalid user name", func(t *testing.T) {
t.Parallel()
testUserName := "username,should_not_be_valid"
res := unauthedClient.DoFunc(t, "GET", []string{"_matrix", "client", "v3", "register", "available"}, client.WithQueries(url.Values{
"username": []string{testUserName},
}))
must.MatchResponse(t, res, match.HTTPResponse{
StatusCode: 400,
JSON: []match.JSON{
match.JSONKeyEqual("errcode", "M_INVALID_USERNAME"),
match.JSONKeyPresent("error"),
},
})
})
})
}

Expand Down