GODT-1524: Logout issues with macOS.

This commit is contained in:
Jakub
2022-03-14 16:37:42 +01:00
parent 2d5ea669a5
commit 6671dd38ea
26 changed files with 411 additions and 135 deletions

View File

@ -46,6 +46,7 @@ type PMAPIController interface {
LockEvents(username string)
UnlockEvents(username string)
RemoveUserMessageWithoutEvent(username, messageID string) error
RevokeSession(username string) error
}
func newPMAPIController(listener listener.Listener) (PMAPIController, pmapi.Manager) {

View File

@ -250,3 +250,10 @@ func (ctl *Controller) RemoveUserMessageWithoutEvent(username string, messageID
return errors.New("message not found")
}
func (ctl *Controller) RevokeSession(username string) error {
for _, session := range ctl.sessionsByUID {
session.uid = "revoked"
}
return nil
}

View File

@ -74,12 +74,12 @@ func (ctl *Controller) createSession(username string, hasFullScope bool) *fakeSe
func (ctl *Controller) refreshSessionIfAuthorized(uid, ref string) (*fakeSession, error) {
session, ok := ctl.sessionsByUID[uid]
if !ok {
return nil, pmapi.ErrUnauthorized
if !ok || session.uid != uid {
return nil, pmapi.ErrAuthFailed{OriginalError: errors.New("bad uid")}
}
if ref != session.ref {
return nil, pmapi.ErrUnauthorized
return nil, pmapi.ErrAuthFailed{OriginalError: errors.New("bad refresh token")}
}
session.ref = ctl.tokenGenerator.next("ref")

View File

@ -133,14 +133,32 @@ func (api *FakePMAPI) authRefresh() error {
session, err := api.controller.refreshSessionIfAuthorized(api.uid, api.ref)
if err != nil {
if pmapi.IsFailedAuth(err) {
go api.handleAuth(nil)
}
return err
}
api.ref = session.ref
api.acc = session.acc
go api.handleAuth(&pmapi.AuthRefresh{
UID: api.uid,
AccessToken: api.acc,
RefreshToken: api.ref,
ExpiresIn: 7200,
Scopes: []string{"full", "self", "user", "mail"},
})
return nil
}
func (api *FakePMAPI) handleAuth(auth *pmapi.AuthRefresh) {
for _, handle := range api.authHandlers {
handle(auth)
}
}
func (api *FakePMAPI) setUser(username string) error {
api.username = username
api.log = api.log.WithField("username", username)

View File

@ -69,7 +69,7 @@ func (m *fakePMAPIManager) NewClientWithRefresh(_ context.Context, uid, ref stri
session, err := m.controller.refreshSessionIfAuthorized(uid, ref)
if err != nil {
return nil, nil, pmapi.ErrUnauthorized
return nil, nil, err
}
user, ok := m.controller.usersByUsername[session.username]

View File

@ -82,6 +82,10 @@ func (api *FakePMAPI) UpdateUser(context.Context) (*pmapi.User, error) {
return nil, err
}
if err := api.checkAndRecordCall(GET, "/addresses", nil); err != nil {
return nil, err
}
return api.user, nil
}

View File

@ -0,0 +1,17 @@
Feature: Session deleted on API
@ignore-live
Scenario: Session revoked after start
Given there is connected user "user"
When session was revoked for "user"
And the event loop of "user" loops once
Then "user" is disconnected
@ignore-live
Scenario: Starting with revoked session
Given there is user "user" which just logged in
And session was revoked for "user"
When bridge starts
Then "user" is disconnected

View File

@ -60,3 +60,7 @@ func (ctl *Controller) GetAuthClient(username string) pmapi.Client {
}
return client
}
func (ctl *Controller) RevokeSession(username string) error {
return errors.New("revoke live session not implemented")
}

View File

@ -29,6 +29,7 @@ func UsersActionsFeatureContext(s *godog.ScenarioContext) {
s.Step(`^user deletes "([^"]*)"$`, userDeletesUser)
s.Step(`^user deletes "([^"]*)" with cache$`, userDeletesUserWithCache)
s.Step(`^"([^"]*)" swaps address "([^"]*)" with address "([^"]*)"$`, swapsAddressWithAddress)
s.Step(`^session was revoked for "([^"]*)"$`, sessionRevoked)
}
func userLogsIn(bddUserID string) error {
@ -123,3 +124,8 @@ func swapsAddressWithAddress(bddUserID, bddAddressID1, bddAddressID2 string) err
return ctx.GetPMAPIController().ReorderAddresses(account.User(), addressIDs)
}
func sessionRevoked(bddUserID string) error {
account := ctx.GetTestAccount(bddUserID)
return ctx.GetPMAPIController().RevokeSession(account.Username())
}