Always return most recently used auth_module from GetAuthInfo

This commit is contained in:
Sean Lafferty
2019-03-13 11:29:13 -04:00
parent d922285ab8
commit f17307bb97
2 changed files with 33 additions and 1 deletions

View File

@ -119,7 +119,7 @@ func GetAuthInfo(query *m.GetAuthInfoQuery) error {
AuthModule: query.AuthModule, AuthModule: query.AuthModule,
AuthId: query.AuthId, AuthId: query.AuthId,
} }
has, err := x.Get(userAuth) has, err := x.Desc("created").Get(userAuth)
if err != nil { if err != nil {
return err return err
} }

View File

@ -169,5 +169,37 @@ func TestUserAuth(t *testing.T) {
So(getAuthQuery.Result.OAuthTokenType, ShouldEqual, token.TokenType) So(getAuthQuery.Result.OAuthTokenType, ShouldEqual, token.TokenType)
}) })
Convey("Always return the most recently used auth_module", func() {
// Find a user to set tokens on
login := "loginuser0"
// Calling GetUserByAuthInfoQuery on an existing user will populate an entry in the user_auth table
query := &m.GetUserByAuthInfoQuery{Login: login, AuthModule: "test", AuthId: "test"}
err = GetUserByAuthInfo(query)
So(err, ShouldBeNil)
So(query.Result.Login, ShouldEqual, login)
// Add a second auth module for this user
// resolution of `Created` column is 1sec, so we need a delay
time.Sleep(time.Second)
query = &m.GetUserByAuthInfoQuery{Login: login, AuthModule: "test2", AuthId: "test2"}
err = GetUserByAuthInfo(query)
So(err, ShouldBeNil)
So(query.Result.Login, ShouldEqual, login)
// Get the latest entry by not supply an authmodule or authid
getAuthQuery := &m.GetAuthInfoQuery{
UserId: query.Result.Id,
}
err = GetAuthInfo(getAuthQuery)
So(err, ShouldBeNil)
So(getAuthQuery.Result.AuthModule, ShouldEqual, "test2")
})
}) })
} }