test: some work on integration tests (fake)

This commit is contained in:
James Houlahan
2020-04-09 13:49:07 +02:00
parent fec5f2d3c3
commit ed8595fa5b
6 changed files with 25 additions and 15 deletions

View File

@ -208,15 +208,12 @@ func (c *client) sendAuth(auth *Auth) {
c.log.Debug("Client is sending auth to ClientManager") c.log.Debug("Client is sending auth to ClientManager")
if auth != nil { if auth != nil {
// UID is only provided in the initial /auth, not during /auth/refresh c.uid = auth.UID()
if auth.UID() != "" {
c.uid = auth.UID()
}
c.accessToken = auth.accessToken c.accessToken = auth.accessToken
} }
go func() { go func() {
c.cm.getClientAuthChannel() <- ClientAuth{ c.cm.GetClientAuthChannel() <- ClientAuth{
UserID: c.userID, UserID: c.userID,
Auth: auth, Auth: auth,
} }
@ -459,6 +456,12 @@ func (c *client) AuthRefresh(uidAndRefreshToken string) (auth *Auth, err error)
auth = res.getAuth() auth = res.getAuth()
// Responses from /auth/refresh are not guaranteed to return the UID if it has not changed.
// But we want to always return it.
if auth.uid == "" {
auth.uid = c.uid
}
c.sendAuth(auth) c.sendAuth(auth)
return auth, err return auth, err

View File

@ -249,8 +249,8 @@ func (cm *ClientManager) GetAuthUpdateChannel() chan ClientAuth {
return cm.bridgeAuths return cm.bridgeAuths
} }
// getClientAuthChannel returns a channel on which clients should send auths. // GetClientAuthChannel returns a channel on which clients should send auths.
func (cm *ClientManager) getClientAuthChannel() chan ClientAuth { func (cm *ClientManager) GetClientAuthChannel() chan ClientAuth {
return cm.clientAuths return cm.clientAuths
} }

View File

@ -29,7 +29,7 @@ test-stage:
TEST_ENV=live go test -tags=$(TAGS) -- $(FEATURES) TEST_ENV=live go test -tags=$(TAGS) -- $(FEATURES)
test-debug: test-debug:
TEST_ENV=fake dlv test -- $(FEATURES) TEST_ENV=fake TEST_ACCOUNTS=accounts/fake.json dlv test -- $(FEATURES)
test-live-debug: test-live-debug:
TEST_ENV=live dlv test -- $(FEATURES) TEST_ENV=live dlv test -- $(FEATURES)

View File

@ -65,9 +65,12 @@ func (api *FakePMAPI) Auth(username, password string, authInfo *pmapi.AuthInfo)
auth := &pmapi.Auth{ auth := &pmapi.Auth{
TwoFA: user.get2FAInfo(), TwoFA: user.get2FAInfo(),
RefreshToken: session.refreshToken, RefreshToken: session.refreshToken,
ExpiresIn: 86400,
} }
auth.DANGEROUSLYSetUID(session.uid)
api.sendAuth(auth) api.sendAuth(auth)
return auth, nil return auth, nil
} }
@ -135,7 +138,10 @@ func (api *FakePMAPI) AuthRefresh(token string) (*pmapi.Auth, error) {
auth := &pmapi.Auth{ auth := &pmapi.Auth{
RefreshToken: session.refreshToken, RefreshToken: session.refreshToken,
ExpiresIn: 86400,
} }
auth.DANGEROUSLYSetUID(session.uid)
api.sendAuth(auth) api.sendAuth(auth)
return auth, nil return auth, nil

View File

@ -32,6 +32,7 @@ type Controller struct {
labelIDGenerator idGenerator labelIDGenerator idGenerator
messageIDGenerator idGenerator messageIDGenerator idGenerator
tokenGenerator idGenerator tokenGenerator idGenerator
clientManager *pmapi.ClientManager
// State controlled by test. // State controlled by test.
noInternetConnection bool noInternetConnection bool
@ -52,6 +53,7 @@ func NewController(cm *pmapi.ClientManager) *Controller {
labelIDGenerator: 100, // We cannot use system label IDs. labelIDGenerator: 100, // We cannot use system label IDs.
messageIDGenerator: 0, messageIDGenerator: 0,
tokenGenerator: 1000, // No specific reason; 1000 simply feels right. tokenGenerator: 1000, // No specific reason; 1000 simply feels right.
clientManager: cm,
noInternetConnection: false, noInternetConnection: false,
usersByUsername: map[string]*fakeUser{}, usersByUsername: map[string]*fakeUser{},

View File

@ -103,14 +103,13 @@ func (api *FakePMAPI) checkInternetAndRecordCall(method method, path string, req
return nil return nil
} }
// TODO: This should be sent back to the ClientManager properly!
func (api *FakePMAPI) sendAuth(auth *pmapi.Auth) { func (api *FakePMAPI) sendAuth(auth *pmapi.Auth) {
if auth != nil { go func() {
auth.DANGEROUSLYSetUID(api.uid) api.controller.clientManager.GetClientAuthChannel() <- pmapi.ClientAuth{
} UserID: api.user.ID,
if api.auths != nil { Auth: auth,
api.auths <- auth }
} }()
} }
func (api *FakePMAPI) setUser(username string) error { func (api *FakePMAPI) setUser(username string) error {