fix: Wait for login UI to appear in authRequireGuestsToLogin test
This commit is contained in:
parent
430aab638b
commit
c89979ddb2
File diff suppressed because one or more lines are too long
|
|
@ -30,8 +30,21 @@ describe('config: authRequireGuestsToLogin', function () {
|
||||||
|
|
||||||
// Navigate directly to login to avoid SPA timing issues
|
// Navigate directly to login to avoid SPA timing issues
|
||||||
await webdriver.get(runner.baseUrl() + '/login')
|
await webdriver.get(runner.baseUrl() + '/login')
|
||||||
// Wait for login form to be present
|
// Wait for Init to load and then for login UI to appear (local or OAuth)
|
||||||
await webdriver.wait(until.elementLocated(By.css('form.local-login-form, button.login-button, input[name="username"]')), 20000)
|
await webdriver.wait(async () => {
|
||||||
|
const hasInit = await webdriver.executeScript('return !!window.initResponse')
|
||||||
|
if (!hasInit) return false
|
||||||
|
|
||||||
|
const hasLocal = await webdriver.executeScript('return !!(window.initResponse && window.initResponse.authLocalLogin)')
|
||||||
|
if (hasLocal) {
|
||||||
|
const els = await webdriver.findElements(By.css('form.local-login-form, button.login-button, input[name="username"]'))
|
||||||
|
if (els.length > 0) return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// If local login not enabled, ensure OAuth or disabled message renders
|
||||||
|
const alt = await webdriver.findElements(By.css('.login-oauth2, .login-disabled'))
|
||||||
|
return alt.length > 0
|
||||||
|
}, 5000)
|
||||||
|
|
||||||
// Verify we're on the login page
|
// Verify we're on the login page
|
||||||
const currentUrlAtLogin = await webdriver.getCurrentUrl()
|
const currentUrlAtLogin = await webdriver.getCurrentUrl()
|
||||||
|
|
|
||||||
|
|
@ -1,44 +0,0 @@
|
||||||
package httpservers
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
|
|
||||||
// apiv1 "github.com/OliveTin/OliveTin/gen/olivetin/api/v1"
|
|
||||||
|
|
||||||
config "github.com/OliveTin/OliveTin/internal/config"
|
|
||||||
)
|
|
||||||
|
|
||||||
func parseHttpHeaderForAuth(cfg *config.Config, req *http.Request) (string, string) {
|
|
||||||
username, ok := req.Header[cfg.AuthHttpHeaderUsername]
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
log.Warnf("Config has AuthHttpHeaderUsername set to %v, but it was not found", cfg.AuthHttpHeaderUsername)
|
|
||||||
|
|
||||||
return "", ""
|
|
||||||
}
|
|
||||||
|
|
||||||
if cfg.AuthHttpHeaderUserGroup != "" {
|
|
||||||
usergroup, ok := req.Header[cfg.AuthHttpHeaderUserGroup]
|
|
||||||
|
|
||||||
if ok {
|
|
||||||
log.Debugf("HTTP Header Auth found a username and usergroup")
|
|
||||||
|
|
||||||
return username[0], usergroup[0]
|
|
||||||
} else {
|
|
||||||
log.Warnf("Config has AuthHttpHeaderUserGroup set to %v, but it was not found", cfg.AuthHttpHeaderUserGroup)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Debugf("HTTP Header Auth found a username, but usergroup is not being used")
|
|
||||||
|
|
||||||
return username[0], ""
|
|
||||||
}
|
|
||||||
|
|
||||||
//gocyclo:ignore
|
|
||||||
func parseJwtHeader(cfg *config.Config, req *http.Request) (string, string) {
|
|
||||||
// JWTs in the Authorization header are usually prefixed with "Bearer " which is not part of the JWT token.
|
|
||||||
return parseJwt(cfg, strings.TrimPrefix(req.Header.Get(cfg.AuthJwtHeader), "Bearer "))
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue