mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 09:05:45 -06:00
OAuth: Able to skip auto login (#28357)
* OAuth: able to skip auto login * OAuth: tests for internal login param * OAuth: rename internal -> disableAutoLogin * OAuth: update log message * OAuth: fix tests
This commit is contained in:
parent
af17f9fd9b
commit
d13c6b4c5a
@ -81,6 +81,13 @@ func (hs *HTTPServer) LoginView(c *models.ReqContext) {
|
||||
return
|
||||
}
|
||||
|
||||
urlParams := c.Req.URL.Query()
|
||||
if _, disableAutoLogin := urlParams["disableAutoLogin"]; disableAutoLogin {
|
||||
hs.log.Debug("Auto login manually disabled")
|
||||
c.HTML(200, getViewIndex(), viewData)
|
||||
return
|
||||
}
|
||||
|
||||
enabledOAuths := make(map[string]interface{})
|
||||
for key, oauth := range setting.OAuthService.OAuthInfos {
|
||||
enabledOAuths[key] = map[string]string{"name": oauth.Name}
|
||||
|
@ -500,6 +500,41 @@ func TestLoginOAuthRedirect(t *testing.T) {
|
||||
assert.Equal(t, location[0], "/login/github")
|
||||
}
|
||||
|
||||
func TestLoginInternal(t *testing.T) {
|
||||
mockSetIndexViewData()
|
||||
defer resetSetIndexViewData()
|
||||
|
||||
mockViewIndex()
|
||||
defer resetViewIndex()
|
||||
sc := setupScenarioContext("/login")
|
||||
hs := &HTTPServer{
|
||||
Cfg: setting.NewCfg(),
|
||||
License: &licensing.OSSLicensingService{},
|
||||
log: log.New("test"),
|
||||
}
|
||||
|
||||
sc.defaultHandler = Wrap(func(c *models.ReqContext) {
|
||||
c.Req.URL.RawQuery = "disableAutoLogin=true"
|
||||
hs.LoginView(c)
|
||||
})
|
||||
|
||||
setting.OAuthService = &setting.OAuther{}
|
||||
setting.OAuthService.OAuthInfos = make(map[string]*setting.OAuthInfo)
|
||||
setting.OAuthService.OAuthInfos["github"] = &setting.OAuthInfo{
|
||||
ClientId: "fake",
|
||||
ClientSecret: "fakefake",
|
||||
Enabled: true,
|
||||
AllowSignup: true,
|
||||
Name: "github",
|
||||
}
|
||||
setting.OAuthAutoLogin = true
|
||||
sc.m.Get(sc.url, sc.defaultHandler)
|
||||
sc.fakeReqNoAssertions("GET", sc.url).exec()
|
||||
|
||||
// Shouldn't redirect to the OAuth login URL
|
||||
assert.Equal(t, sc.resp.Code, 200)
|
||||
}
|
||||
|
||||
func TestAuthProxyLoginEnableLoginTokenDisabled(t *testing.T) {
|
||||
sc := setupAuthProxyLoginTest(false)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user