diff --git a/pkg/api/login.go b/pkg/api/login.go index d2818d7a5b6..25952330744 100644 --- a/pkg/api/login.go +++ b/pkg/api/login.go @@ -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} diff --git a/pkg/api/login_test.go b/pkg/api/login_test.go index a84668bfda8..c1925b9314a 100644 --- a/pkg/api/login_test.go +++ b/pkg/api/login_test.go @@ -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)