Remove unused scope methods

This commit is contained in:
Pavel Škoda
2020-09-07 18:52:41 +02:00
committed by Michal Horejsek
parent f73aeec97f
commit 2e439e17cf
15 changed files with 30 additions and 51 deletions

View File

@ -4,6 +4,8 @@ Changelog [format](http://keepachangelog.com/en/1.0.0/)
## Unreleased ## Unreleased
* GODT-511 User agent format changed. * GODT-511 User agent format changed.
### Removed
* GODT-519 Unused AUTH scope parsing methods
## [IE 0.2.x] Congo ## [IE 0.2.x] Congo

View File

@ -79,7 +79,7 @@ func (f *frontendCLI) loginAccount(c *ishell.Context) { // nolint[funlen]
return return
} }
_, err = client.Auth2FA(twoFactor, auth) err = client.Auth2FA(twoFactor, auth)
if err != nil { if err != nil {
f.processAPIError(err) f.processAPIError(err)
return return

View File

@ -126,7 +126,7 @@ func (f *frontendCLI) loginAccount(c *ishell.Context) { // nolint[funlen]
return return
} }
_, err = client.Auth2FA(twoFactor, auth) err = client.Auth2FA(twoFactor, auth)
if err != nil { if err != nil {
f.processAPIError(err) f.processAPIError(err)
return return

View File

@ -208,7 +208,7 @@ func (a *Accounts) Auth2FA(twoFacAuth string) int {
if a.auth == nil || a.authClient == nil { if a.auth == nil || a.authClient == nil {
err = fmt.Errorf("missing authentication in auth2FA %p %p", a.auth, a.authClient) err = fmt.Errorf("missing authentication in auth2FA %p %p", a.auth, a.authClient)
} else { } else {
_, err = a.authClient.Auth2FA(twoFacAuth, a.auth) err = a.authClient.Auth2FA(twoFacAuth, a.auth)
} }
if a.showLoginError(err, "auth2FA") { if a.showLoginError(err, "auth2FA") {

View File

@ -164,7 +164,7 @@ func (s *FrontendQt) auth2FA(twoFacAuth string) int {
if s.auth == nil || s.authClient == nil { if s.auth == nil || s.authClient == nil {
err = fmt.Errorf("missing authentication in auth2FA %p %p", s.auth, s.authClient) err = fmt.Errorf("missing authentication in auth2FA %p %p", s.auth, s.authClient)
} else { } else {
_, err = s.authClient.Auth2FA(twoFacAuth, s.auth) err = s.authClient.Auth2FA(twoFacAuth, s.auth)
} }
if s.showLoginError(err, "auth2FA") { if s.showLoginError(err, "auth2FA") {

View File

@ -108,7 +108,6 @@ type AuthReq struct {
type Auth struct { type Auth struct {
accessToken string // Read from AuthRes. accessToken string // Read from AuthRes.
ExpiresIn int ExpiresIn int
Scope string
uid string // Read from AuthRes. uid string // Read from AuthRes.
RefreshToken string RefreshToken string
EventID string EventID string
@ -174,20 +173,8 @@ type Auth2FAReq struct {
// U2F U2FRequest // U2F U2FRequest
} }
type Auth2FA struct {
Scope string
}
type Auth2FARes struct { type Auth2FARes struct {
Res Res
Scope string
}
func (res *Auth2FARes) getAuth2FA() *Auth2FA {
return &Auth2FA{
Scope: res.Scope,
}
} }
type AuthRefreshReq struct { 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. // Auth2FA will authenticate a user into full scope.
// `Auth` struct contains method `HasTwoFactor` deciding whether this has to be done. // `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{ auth2FAReq := &Auth2FAReq{
TwoFactorCode: twoFactorCode, TwoFactorCode: twoFactorCode,
} }
req, err := c.NewJSONRequest("POST", "/auth/2fa", auth2FAReq) req, err := c.NewJSONRequest("POST", "/auth/2fa", auth2FAReq)
if err != nil { if err != nil {
return nil, err return err
} }
var auth2FARes Auth2FARes var auth2FARes Auth2FARes
if err := c.DoJSON(req, &auth2FARes); err != nil { if err := c.DoJSON(req, &auth2FARes); err != nil {
return nil, err return err
} }
if err := auth2FARes.Err(); err != nil { if err := auth2FARes.Err(); err != nil {
switch auth2FARes.StatusCode { switch auth2FARes.StatusCode {
case http.StatusUnauthorized: case http.StatusUnauthorized:
return nil, ErrBad2FACode return ErrBad2FACode
case http.StatusUnprocessableEntity: case http.StatusUnprocessableEntity:
return nil, ErrBad2FACodeTryAgain return ErrBad2FACodeTryAgain
default: default:
return nil, err return err
} }
} }
return auth2FARes.getAuth2FA(), nil return nil
} }
// AuthRefresh will refresh an expired access token. // AuthRefresh will refresh an expired access token.

View File

@ -64,16 +64,11 @@ var testAuth = &Auth{
EventID: "NcKPtU5eMNPMrDkIMbEJrgMtC9yQ7Xc5ZBT-tB3UtV1rZ324RWfCIdBI758q0UnsfywS8CkNenIQlWLIX_dUng==", EventID: "NcKPtU5eMNPMrDkIMbEJrgMtC9yQ7Xc5ZBT-tB3UtV1rZ324RWfCIdBI758q0UnsfywS8CkNenIQlWLIX_dUng==",
ExpiresIn: 86400, ExpiresIn: 86400,
RefreshToken: "feb3159ac63fb05119bcf4480d939278aa746926", RefreshToken: "feb3159ac63fb05119bcf4480d939278aa746926",
Scope: "full mail payments reset keys",
accessToken: testAccessToken, accessToken: testAccessToken,
uid: testUID, uid: testUID,
} }
var testAuth2FA = &Auth2FA{
Scope: "full mail payments reset keys",
}
var testAuthRefreshReq = AuthRefreshReq{ var testAuthRefreshReq = AuthRefreshReq{
ResponseType: "token", ResponseType: "token",
GrantType: "refresh_token", GrantType: "refresh_token",
@ -160,10 +155,8 @@ func TestClient_Auth2FA(t *testing.T) {
c.uid = testUID c.uid = testUID
c.accessToken = testAccessToken c.accessToken = testAccessToken
auth2FA, err := c.Auth2FA(testAuth2FAReq.TwoFactorCode, testAuth) err := c.Auth2FA(testAuth2FAReq.TwoFactorCode, testAuth)
Ok(t, err) Ok(t, err)
Equals(t, testAuth2FA, auth2FA)
} }
func TestClient_Auth2FA_Fail(t *testing.T) { func TestClient_Auth2FA_Fail(t *testing.T) {
@ -182,7 +175,7 @@ func TestClient_Auth2FA_Fail(t *testing.T) {
c.uid = testUID c.uid = testUID
c.accessToken = testAccessToken c.accessToken = testAccessToken
_, err := c.Auth2FA(testAuth2FAReq.TwoFactorCode, testAuth) err := c.Auth2FA(testAuth2FAReq.TwoFactorCode, testAuth)
Equals(t, ErrBad2FACode, err) Equals(t, ErrBad2FACode, err)
} }
@ -202,7 +195,7 @@ func TestClient_Auth2FA_Retry(t *testing.T) {
c.uid = testUID c.uid = testUID
c.accessToken = testAccessToken c.accessToken = testAccessToken
_, err := c.Auth2FA(testAuth2FAReq.TwoFactorCode, testAuth) err := c.Auth2FA(testAuth2FAReq.TwoFactorCode, testAuth)
Equals(t, ErrBad2FACodeTryAgain, err) Equals(t, ErrBad2FACodeTryAgain, err)
} }

View File

@ -28,7 +28,7 @@ type Client interface {
Auth(username, password string, info *AuthInfo) (*Auth, error) Auth(username, password string, info *AuthInfo) (*Auth, error)
AuthInfo(username string) (*AuthInfo, error) AuthInfo(username string) (*AuthInfo, error)
AuthRefresh(token string) (*Auth, error) AuthRefresh(token string) (*Auth, error)
Auth2FA(twoFactorCode string, auth *Auth) (*Auth2FA, error) Auth2FA(twoFactorCode string, auth *Auth) error
AuthSalt() (salt string, err error) AuthSalt() (salt string, err error)
Logout() Logout()
DeleteAuth() error DeleteAuth() error

View File

@ -65,12 +65,11 @@ func (mr *MockClientMockRecorder) Auth(arg0, arg1, arg2 interface{}) *gomock.Cal
} }
// Auth2FA mocks base method // 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() m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Auth2FA", arg0, arg1) ret := m.ctrl.Call(m, "Auth2FA", arg0, arg1)
ret0, _ := ret[0].(*pmapi.Auth2FA) ret0, _ := ret[0].(error)
ret1, _ := ret[1].(error) return ret0
return ret0, ret1
} }
// Auth2FA indicates an expected call of Auth2FA // Auth2FA indicates an expected call of Auth2FA

View File

@ -1,4 +1,4 @@
{ {
"Code": 1000, "Code": 1000,
"Scope": "full mail payments reset keys" "Scopes": ["full", "mail", "payments", "reset", "keys"]
} }

View File

@ -3,7 +3,7 @@
"AccessToken": "de0423049b44243afeec7d9c1d99be7b46da1e8a", "AccessToken": "de0423049b44243afeec7d9c1d99be7b46da1e8a",
"ExpiresIn": 86400, "ExpiresIn": 86400,
"TokenType": "Bearer", "TokenType": "Bearer",
"Scope": "full mail payments reset keys", "Scopes": ["full", "mail", "payments", "reset", "keys"],
"UID": "729ad6012421d67ad26950dc898bebe3a6e3caa2", "UID": "729ad6012421d67ad26950dc898bebe3a6e3caa2",
"RefreshToken": "a49b98256745bb497bec20e9b55f5de16f01fb52", "RefreshToken": "a49b98256745bb497bec20e9b55f5de16f01fb52",
"EventID": "NcKPtU5eMNPMrDkIMbEJrgMtC9yQ7Xc5ZBT-tB3UtV1rZ324RWfCIdBI758q0UnsfywS8CkNenIQlWLIX_dUng==", "EventID": "NcKPtU5eMNPMrDkIMbEJrgMtC9yQ7Xc5ZBT-tB3UtV1rZ324RWfCIdBI758q0UnsfywS8CkNenIQlWLIX_dUng==",

View File

@ -5,6 +5,6 @@
"TokenType": "Bearer", "TokenType": "Bearer",
"Uid": "729ad6012421d67ad26950dc898bebe3a6e3caa2", "Uid": "729ad6012421d67ad26950dc898bebe3a6e3caa2",
"UID": "729ad6012421d67ad26950dc898bebe3a6e3caa2", "UID": "729ad6012421d67ad26950dc898bebe3a6e3caa2",
"Scope": "full mail payments reset keys", "Scopes": ["full", "mail", "payments", "reset", "keys"],
"RefreshToken": "b894b4c4f20003f12d486900d8b88c7d68e67235" "RefreshToken": "b894b4c4f20003f12d486900d8b88c7d68e67235"
} }

View File

@ -3,6 +3,6 @@
"AccessToken": "de0423049b44243afeec7d9c1d99be7b46da1e8a", "AccessToken": "de0423049b44243afeec7d9c1d99be7b46da1e8a",
"ExpiresIn": 360000, "ExpiresIn": 360000,
"TokenType": "Bearer", "TokenType": "Bearer",
"Scope": "full mail payments reset keys", "Scopes": ["full", "mail", "payments", "reset", "keys"],
"RefreshToken": "b894b4c4f20003f12d486900d8b88c7d68e67235" "RefreshToken": "b894b4c4f20003f12d486900d8b88c7d68e67235"
} }

View File

@ -45,7 +45,7 @@ func (ctx *TestContext) LoginUser(username, password, mailboxPassword string) (e
} }
if auth.HasTwoFactor() { 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") return errors.Wrap(err, "failed to login with 2FA")
} }
} }

View File

@ -74,27 +74,25 @@ func (api *FakePMAPI) Auth(username, password string, authInfo *pmapi.AuthInfo)
return auth, nil 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{ if err := api.checkInternetAndRecordCall(POST, "/auth/2fa", &pmapi.Auth2FAReq{
TwoFactorCode: twoFactorCode, TwoFactorCode: twoFactorCode,
}); err != nil { }); err != nil {
return nil, err return err
} }
if api.uid == "" { if api.uid == "" {
return nil, pmapi.ErrInvalidToken return pmapi.ErrInvalidToken
} }
session, ok := api.controller.sessionsByUID[api.uid] session, ok := api.controller.sessionsByUID[api.uid]
if !ok { if !ok {
return nil, pmapi.ErrInvalidToken return pmapi.ErrInvalidToken
} }
session.hasFullScope = true session.hasFullScope = true
return &pmapi.Auth2FA{ return nil
Scope: "full",
}, nil
} }
func (api *FakePMAPI) AuthRefresh(token string) (*pmapi.Auth, error) { func (api *FakePMAPI) AuthRefresh(token string) (*pmapi.Auth, error) {