mirror of
https://github.com/grafana/grafana.git
synced 2025-09-28 07:33:56 +08:00
Always return most recently used auth_module from GetAuthInfo
This commit is contained in:
@ -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
|
||||||
}
|
}
|
||||||
|
@ -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")
|
||||||
|
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user