From 28e98d99fc97816178e6954f20d69a962426360d Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Fri, 27 Jul 2018 18:22:51 +0100 Subject: [PATCH] Reduce cyclo complexity --- .../dendrite/clientapi/routing/register.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/github.com/matrix-org/dendrite/clientapi/routing/register.go b/src/github.com/matrix-org/dendrite/clientapi/routing/register.go index a8693449..927deb04 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/routing/register.go +++ b/src/github.com/matrix-org/dendrite/clientapi/routing/register.go @@ -497,8 +497,7 @@ func Register( // Application services can register users with no auth type, but require // access token. Differentiate from users who are initially hitting register // without an auth type - if r.Auth.Type == "" && req.URL.Query().Get("access_token") == "" && - req.Header.Get("Authorization") == "" { + if initialUserInteractiveRequest(req, r) { return util.JSONResponse{ Code: http.StatusUnauthorized, JSON: newUserInteractiveResponse(sessionID, @@ -782,6 +781,17 @@ func completeRegistration( } } +// initialUserInteractiveRequest returns true or false based on whether the +// request should have User Interactive Authentication Flows returned. This is +// the case if a user is requesting registration first without specifying a +// registration type. This method also differentiates between application +// services and users, as application services can register with no type and an +// access token, either included as part of the query parameters or an +// Authorization header +func initialUserInteractiveRequest(req *http.Request, r registerRequest) bool { + return r.Auth.Type == "" && req.URL.Query().Get("access_token") == "" && req.Header.Get("Authorization") == "" +} + // Used for shared secret registration. // Checks if the username, password and isAdmin flag matches the given mac. func isValidMacLogin(