diff --git a/Changelog.md b/Changelog.md index 31d91413..838935bc 100644 --- a/Changelog.md +++ b/Changelog.md @@ -4,6 +4,8 @@ Changelog [format](http://keepachangelog.com/en/1.0.0/) ## Unreleased * GODT-511 User agent format changed. +### Removed +* GODT-519 Unused AUTH scope parsing methods ## [IE 0.2.x] Congo diff --git a/internal/frontend/cli-ie/accounts.go b/internal/frontend/cli-ie/accounts.go index b0d25130..6398b359 100644 --- a/internal/frontend/cli-ie/accounts.go +++ b/internal/frontend/cli-ie/accounts.go @@ -79,7 +79,7 @@ func (f *frontendCLI) loginAccount(c *ishell.Context) { // nolint[funlen] return } - _, err = client.Auth2FA(twoFactor, auth) + err = client.Auth2FA(twoFactor, auth) if err != nil { f.processAPIError(err) return diff --git a/internal/frontend/cli/accounts.go b/internal/frontend/cli/accounts.go index a2f815a0..dfe7be96 100644 --- a/internal/frontend/cli/accounts.go +++ b/internal/frontend/cli/accounts.go @@ -126,7 +126,7 @@ func (f *frontendCLI) loginAccount(c *ishell.Context) { // nolint[funlen] return } - _, err = client.Auth2FA(twoFactor, auth) + err = client.Auth2FA(twoFactor, auth) if err != nil { f.processAPIError(err) return diff --git a/internal/frontend/qt-common/accounts.go b/internal/frontend/qt-common/accounts.go index e731456f..50ca7a30 100644 --- a/internal/frontend/qt-common/accounts.go +++ b/internal/frontend/qt-common/accounts.go @@ -208,7 +208,7 @@ func (a *Accounts) Auth2FA(twoFacAuth string) int { if a.auth == nil || a.authClient == nil { err = fmt.Errorf("missing authentication in auth2FA %p %p", a.auth, a.authClient) } else { - _, err = a.authClient.Auth2FA(twoFacAuth, a.auth) + err = a.authClient.Auth2FA(twoFacAuth, a.auth) } if a.showLoginError(err, "auth2FA") { diff --git a/internal/frontend/qt/accounts.go b/internal/frontend/qt/accounts.go index 21f2118e..9038a6ab 100644 --- a/internal/frontend/qt/accounts.go +++ b/internal/frontend/qt/accounts.go @@ -164,7 +164,7 @@ func (s *FrontendQt) auth2FA(twoFacAuth string) int { if s.auth == nil || s.authClient == nil { err = fmt.Errorf("missing authentication in auth2FA %p %p", s.auth, s.authClient) } else { - _, err = s.authClient.Auth2FA(twoFacAuth, s.auth) + err = s.authClient.Auth2FA(twoFacAuth, s.auth) } if s.showLoginError(err, "auth2FA") { diff --git a/pkg/pmapi/auth.go b/pkg/pmapi/auth.go index 6232c6d9..e7f71545 100644 --- a/pkg/pmapi/auth.go +++ b/pkg/pmapi/auth.go @@ -108,7 +108,6 @@ type AuthReq struct { type Auth struct { accessToken string // Read from AuthRes. ExpiresIn int - Scope string uid string // Read from AuthRes. RefreshToken string EventID string @@ -174,20 +173,8 @@ type Auth2FAReq struct { // U2F U2FRequest } -type Auth2FA struct { - Scope string -} - type Auth2FARes struct { Res - - Scope string -} - -func (res *Auth2FARes) getAuth2FA() *Auth2FA { - return &Auth2FA{ - Scope: res.Scope, - } } type AuthRefreshReq struct { @@ -326,33 +313,33 @@ func (c *client) Auth(username, password string, info *AuthInfo) (auth *Auth, er // Auth2FA will authenticate a user into full scope. // `Auth` struct contains method `HasTwoFactor` deciding whether this has to be done. -func (c *client) Auth2FA(twoFactorCode string, auth *Auth) (*Auth2FA, error) { +func (c *client) Auth2FA(twoFactorCode string, auth *Auth) error { auth2FAReq := &Auth2FAReq{ TwoFactorCode: twoFactorCode, } req, err := c.NewJSONRequest("POST", "/auth/2fa", auth2FAReq) if err != nil { - return nil, err + return err } var auth2FARes Auth2FARes if err := c.DoJSON(req, &auth2FARes); err != nil { - return nil, err + return err } if err := auth2FARes.Err(); err != nil { switch auth2FARes.StatusCode { case http.StatusUnauthorized: - return nil, ErrBad2FACode + return ErrBad2FACode case http.StatusUnprocessableEntity: - return nil, ErrBad2FACodeTryAgain + return ErrBad2FACodeTryAgain default: - return nil, err + return err } } - return auth2FARes.getAuth2FA(), nil + return nil } // AuthRefresh will refresh an expired access token. diff --git a/pkg/pmapi/auth_test.go b/pkg/pmapi/auth_test.go index a6ff8b0f..a73b77a8 100644 --- a/pkg/pmapi/auth_test.go +++ b/pkg/pmapi/auth_test.go @@ -64,16 +64,11 @@ var testAuth = &Auth{ EventID: "NcKPtU5eMNPMrDkIMbEJrgMtC9yQ7Xc5ZBT-tB3UtV1rZ324RWfCIdBI758q0UnsfywS8CkNenIQlWLIX_dUng==", ExpiresIn: 86400, RefreshToken: "feb3159ac63fb05119bcf4480d939278aa746926", - Scope: "full mail payments reset keys", accessToken: testAccessToken, uid: testUID, } -var testAuth2FA = &Auth2FA{ - Scope: "full mail payments reset keys", -} - var testAuthRefreshReq = AuthRefreshReq{ ResponseType: "token", GrantType: "refresh_token", @@ -160,10 +155,8 @@ func TestClient_Auth2FA(t *testing.T) { c.uid = testUID c.accessToken = testAccessToken - auth2FA, err := c.Auth2FA(testAuth2FAReq.TwoFactorCode, testAuth) + err := c.Auth2FA(testAuth2FAReq.TwoFactorCode, testAuth) Ok(t, err) - - Equals(t, testAuth2FA, auth2FA) } func TestClient_Auth2FA_Fail(t *testing.T) { @@ -182,7 +175,7 @@ func TestClient_Auth2FA_Fail(t *testing.T) { c.uid = testUID c.accessToken = testAccessToken - _, err := c.Auth2FA(testAuth2FAReq.TwoFactorCode, testAuth) + err := c.Auth2FA(testAuth2FAReq.TwoFactorCode, testAuth) Equals(t, ErrBad2FACode, err) } @@ -202,7 +195,7 @@ func TestClient_Auth2FA_Retry(t *testing.T) { c.uid = testUID c.accessToken = testAccessToken - _, err := c.Auth2FA(testAuth2FAReq.TwoFactorCode, testAuth) + err := c.Auth2FA(testAuth2FAReq.TwoFactorCode, testAuth) Equals(t, ErrBad2FACodeTryAgain, err) } diff --git a/pkg/pmapi/client_types.go b/pkg/pmapi/client_types.go index 168c9936..51bb92d5 100644 --- a/pkg/pmapi/client_types.go +++ b/pkg/pmapi/client_types.go @@ -28,7 +28,7 @@ type Client interface { Auth(username, password string, info *AuthInfo) (*Auth, error) AuthInfo(username string) (*AuthInfo, error) AuthRefresh(token string) (*Auth, error) - Auth2FA(twoFactorCode string, auth *Auth) (*Auth2FA, error) + Auth2FA(twoFactorCode string, auth *Auth) error AuthSalt() (salt string, err error) Logout() DeleteAuth() error diff --git a/pkg/pmapi/mocks/mocks.go b/pkg/pmapi/mocks/mocks.go index 6c30a7cc..1e37cc2a 100644 --- a/pkg/pmapi/mocks/mocks.go +++ b/pkg/pmapi/mocks/mocks.go @@ -65,12 +65,11 @@ func (mr *MockClientMockRecorder) Auth(arg0, arg1, arg2 interface{}) *gomock.Cal } // Auth2FA mocks base method -func (m *MockClient) Auth2FA(arg0 string, arg1 *pmapi.Auth) (*pmapi.Auth2FA, error) { +func (m *MockClient) Auth2FA(arg0 string, arg1 *pmapi.Auth) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Auth2FA", arg0, arg1) - ret0, _ := ret[0].(*pmapi.Auth2FA) - ret1, _ := ret[1].(error) - return ret0, ret1 + ret0, _ := ret[0].(error) + return ret0 } // Auth2FA indicates an expected call of Auth2FA diff --git a/pkg/pmapi/testdata/routes/auth/2fa/post_response.json b/pkg/pmapi/testdata/routes/auth/2fa/post_response.json index e58daf78..354bb31c 100644 --- a/pkg/pmapi/testdata/routes/auth/2fa/post_response.json +++ b/pkg/pmapi/testdata/routes/auth/2fa/post_response.json @@ -1,4 +1,4 @@ { "Code": 1000, - "Scope": "full mail payments reset keys" + "Scopes": ["full", "mail", "payments", "reset", "keys"] } \ No newline at end of file diff --git a/pkg/pmapi/testdata/routes/auth/post_response.json b/pkg/pmapi/testdata/routes/auth/post_response.json index 71c9fb6d..e64aad83 100644 --- a/pkg/pmapi/testdata/routes/auth/post_response.json +++ b/pkg/pmapi/testdata/routes/auth/post_response.json @@ -3,7 +3,7 @@ "AccessToken": "de0423049b44243afeec7d9c1d99be7b46da1e8a", "ExpiresIn": 86400, "TokenType": "Bearer", - "Scope": "full mail payments reset keys", + "Scopes": ["full", "mail", "payments", "reset", "keys"], "UID": "729ad6012421d67ad26950dc898bebe3a6e3caa2", "RefreshToken": "a49b98256745bb497bec20e9b55f5de16f01fb52", "EventID": "NcKPtU5eMNPMrDkIMbEJrgMtC9yQ7Xc5ZBT-tB3UtV1rZ324RWfCIdBI758q0UnsfywS8CkNenIQlWLIX_dUng==", diff --git a/pkg/pmapi/testdata/routes/auth/refresh/post_resp_has_uid.json b/pkg/pmapi/testdata/routes/auth/refresh/post_resp_has_uid.json index dfe67223..6d79c4ec 100644 --- a/pkg/pmapi/testdata/routes/auth/refresh/post_resp_has_uid.json +++ b/pkg/pmapi/testdata/routes/auth/refresh/post_resp_has_uid.json @@ -5,6 +5,6 @@ "TokenType": "Bearer", "Uid": "729ad6012421d67ad26950dc898bebe3a6e3caa2", "UID": "729ad6012421d67ad26950dc898bebe3a6e3caa2", - "Scope": "full mail payments reset keys", + "Scopes": ["full", "mail", "payments", "reset", "keys"], "RefreshToken": "b894b4c4f20003f12d486900d8b88c7d68e67235" } diff --git a/pkg/pmapi/testdata/routes/auth/refresh/post_response.json b/pkg/pmapi/testdata/routes/auth/refresh/post_response.json index cf7a0fac..7430374d 100644 --- a/pkg/pmapi/testdata/routes/auth/refresh/post_response.json +++ b/pkg/pmapi/testdata/routes/auth/refresh/post_response.json @@ -3,6 +3,6 @@ "AccessToken": "de0423049b44243afeec7d9c1d99be7b46da1e8a", "ExpiresIn": 360000, "TokenType": "Bearer", - "Scope": "full mail payments reset keys", + "Scopes": ["full", "mail", "payments", "reset", "keys"], "RefreshToken": "b894b4c4f20003f12d486900d8b88c7d68e67235" } \ No newline at end of file diff --git a/test/context/users.go b/test/context/users.go index 934fd213..c6f1e86c 100644 --- a/test/context/users.go +++ b/test/context/users.go @@ -45,7 +45,7 @@ func (ctx *TestContext) LoginUser(username, password, mailboxPassword string) (e } if auth.HasTwoFactor() { - if _, err := client.Auth2FA("2fa code", auth); err != nil { + if err := client.Auth2FA("2fa code", auth); err != nil { return errors.Wrap(err, "failed to login with 2FA") } } diff --git a/test/fakeapi/auth.go b/test/fakeapi/auth.go index ce25495a..6af31866 100644 --- a/test/fakeapi/auth.go +++ b/test/fakeapi/auth.go @@ -74,27 +74,25 @@ func (api *FakePMAPI) Auth(username, password string, authInfo *pmapi.AuthInfo) return auth, nil } -func (api *FakePMAPI) Auth2FA(twoFactorCode string, auth *pmapi.Auth) (*pmapi.Auth2FA, error) { +func (api *FakePMAPI) Auth2FA(twoFactorCode string, auth *pmapi.Auth) error { if err := api.checkInternetAndRecordCall(POST, "/auth/2fa", &pmapi.Auth2FAReq{ TwoFactorCode: twoFactorCode, }); err != nil { - return nil, err + return err } if api.uid == "" { - return nil, pmapi.ErrInvalidToken + return pmapi.ErrInvalidToken } session, ok := api.controller.sessionsByUID[api.uid] if !ok { - return nil, pmapi.ErrInvalidToken + return pmapi.ErrInvalidToken } session.hasFullScope = true - return &pmapi.Auth2FA{ - Scope: "full", - }, nil + return nil } func (api *FakePMAPI) AuthRefresh(token string) (*pmapi.Auth, error) {