mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-15 02:43:09 -06:00
Fix AS registration tests
This commit is contained in:
parent
1e5ed0c159
commit
3eab106f87
|
|
@ -369,7 +369,6 @@ func UsernameMatchesExclusiveNamespaces(
|
||||||
// two requirements are met, no error will be returned.
|
// two requirements are met, no error will be returned.
|
||||||
func validateApplicationService(
|
func validateApplicationService(
|
||||||
cfg *config.Dendrite,
|
cfg *config.Dendrite,
|
||||||
req *http.Request,
|
|
||||||
username string,
|
username string,
|
||||||
accessToken string,
|
accessToken string,
|
||||||
) (string, *util.JSONResponse) {
|
) (string, *util.JSONResponse) {
|
||||||
|
|
@ -558,7 +557,7 @@ func handleRegistrationFlow(
|
||||||
// Check application service register user request is valid.
|
// Check application service register user request is valid.
|
||||||
// The application service's ID is returned if so.
|
// The application service's ID is returned if so.
|
||||||
appserviceID, err := validateApplicationService(
|
appserviceID, err := validateApplicationService(
|
||||||
cfg, req, r.Username, accessToken,
|
cfg, r.Username, accessToken,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return *err
|
return *err
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,6 @@
|
||||||
package routing
|
package routing
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
|
||||||
"net/url"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
|
@ -186,47 +184,26 @@ func TestValidationOfApplicationServices(t *testing.T) {
|
||||||
fakeConfig.Derived.ApplicationServices = []config.ApplicationService{fakeApplicationService}
|
fakeConfig.Derived.ApplicationServices = []config.ApplicationService{fakeApplicationService}
|
||||||
|
|
||||||
// Access token is correct, user_id omitted so we are acting as SenderLocalpart
|
// Access token is correct, user_id omitted so we are acting as SenderLocalpart
|
||||||
URL, _ := url.Parse("http://localhost/register?access_token=1234")
|
asID, resp := validateApplicationService(&fakeConfig, fakeSenderLocalpart, "1234")
|
||||||
fakeHTTPRequest := http.Request{
|
|
||||||
Method: "POST",
|
|
||||||
URL: URL,
|
|
||||||
}
|
|
||||||
asID, resp := validateApplicationService(&fakeConfig, &fakeHTTPRequest, fakeSenderLocalpart)
|
|
||||||
if resp != nil || asID != fakeID {
|
if resp != nil || asID != fakeID {
|
||||||
t.Errorf("appservice should have validated and returned correct ID: %s", resp.JSON)
|
t.Errorf("appservice should have validated and returned correct ID: %s", resp.JSON)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Access token is incorrect, user_id omitted so we are acting as SenderLocalpart
|
// Access token is incorrect, user_id omitted so we are acting as SenderLocalpart
|
||||||
URL, _ = url.Parse("http://localhost/register?access_token=xxxx")
|
asID, resp = validateApplicationService(&fakeConfig, fakeSenderLocalpart, "xxxx")
|
||||||
fakeHTTPRequest = http.Request{
|
|
||||||
Method: "POST",
|
|
||||||
URL: URL,
|
|
||||||
}
|
|
||||||
asID, resp = validateApplicationService(&fakeConfig, &fakeHTTPRequest, fakeSenderLocalpart)
|
|
||||||
if resp == nil || asID == fakeID {
|
if resp == nil || asID == fakeID {
|
||||||
t.Errorf("access_token should have been marked as invalid")
|
t.Errorf("access_token should have been marked as invalid")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Access token is correct, acting as valid user_id
|
// Access token is correct, acting as valid user_id
|
||||||
URL, _ = url.Parse("http://localhost/register?access_token=1234&user_id=@_appservice_bob:localhost")
|
asID, resp = validateApplicationService(&fakeConfig, "_appservice_bob", "1234")
|
||||||
fakeHTTPRequest = http.Request{
|
|
||||||
Method: "POST",
|
|
||||||
URL: URL,
|
|
||||||
}
|
|
||||||
asID, resp = validateApplicationService(&fakeConfig, &fakeHTTPRequest, "_appservice_bob")
|
|
||||||
if resp != nil || asID != fakeID {
|
if resp != nil || asID != fakeID {
|
||||||
t.Errorf("access_token and user_id should've been valid: %s", resp.JSON)
|
t.Errorf("access_token and user_id should've been valid: %s", resp.JSON)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Access token is correct, acting as invalid user_id
|
// Access token is correct, acting as invalid user_id
|
||||||
URL, _ = url.Parse("http://localhost/register?access_token=1234&user_id=@_something_else:localhost")
|
asID, resp = validateApplicationService(&fakeConfig, "_something_else", "1234")
|
||||||
fakeHTTPRequest = http.Request{
|
|
||||||
Method: "POST",
|
|
||||||
URL: URL,
|
|
||||||
}
|
|
||||||
asID, resp = validateApplicationService(&fakeConfig, &fakeHTTPRequest, "_something_else")
|
|
||||||
if resp == nil || asID == fakeID {
|
if resp == nil || asID == fakeID {
|
||||||
t.Errorf("user_id should not have been valid: %s",
|
t.Errorf("user_id should not have been valid: @_something_else:localhost")
|
||||||
fakeHTTPRequest.URL.Query().Get("user_id"))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue