fix: Test authRequireGuestsToLogin redirect
This commit is contained in:
parent
c89979ddb2
commit
7a1c4d3efa
|
|
@ -26,7 +26,7 @@ If you are looking for OliveTin's AI policy, you can find it in `AI.md`.
|
|||
### Test Notes and Gotchas
|
||||
- The top-level Makefile does not expose `unittests`; use `cd service && make unittests`.
|
||||
- Connect RPC API must be mounted correctly; in tests, create the handler via `GetNewHandler(ex)` and serve under `/api/`.
|
||||
- Frontend “ready” state: the app sets `document.body` attribute `initial-marshal-complete="true"` when loaded. Integration helpers wait for this before selecting elements.
|
||||
- Frontend “ready” state: the app sets `document.body` attribute `loaded-dashboard="<name>"` when loading a dashboard. Integration helpers that test dashboard functionality wait for this before selecting elements. Certain conditions enforcing login will mean that this attribute is not set until a user is logged in.
|
||||
- Modern UI uses Vue components:
|
||||
- Action buttons are rendered as `.action-button button`.
|
||||
- Logs and Diagnostics are Vue router links available via `/logs` and `/diagnostics`.
|
||||
|
|
|
|||
|
|
@ -21,49 +21,17 @@ describe('config: authRequireGuestsToLogin', function () {
|
|||
takeScreenshotOnFailure(this.currentTest, webdriver);
|
||||
});
|
||||
|
||||
it('Guest is redirected to login, then can login and access dashboard', async function () {
|
||||
it('Guest is redirected to login', async function () {
|
||||
// Don't use getRootAndWait here because we want to test the redirect, and getRootAndWait waits for the dashboard to load
|
||||
|
||||
await webdriver.get(runner.baseUrl())
|
||||
await webdriver.wait(until.titleContains('OliveTin'), 10000)
|
||||
const title = await webdriver.getTitle()
|
||||
expect(title).to.contain('OliveTin')
|
||||
console.log('✓ Server started successfully with authRequireGuestsToLogin enabled')
|
||||
|
||||
// Navigate directly to login to avoid SPA timing issues
|
||||
await webdriver.get(runner.baseUrl() + '/login')
|
||||
// Wait for Init to load and then for login UI to appear (local or OAuth)
|
||||
await webdriver.wait(async () => {
|
||||
const hasInit = await webdriver.executeScript('return !!window.initResponse')
|
||||
if (!hasInit) return false
|
||||
await webdriver.wait(until.urlContains('/login'), 10000)
|
||||
|
||||
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
|
||||
}
|
||||
// Verify login UI elements are present
|
||||
const loginElements = await webdriver.findElements(By.css('form.local-login-form, .login-oauth2, .login-disabled'))
|
||||
expect(loginElements.length).to.be.greaterThan(0)
|
||||
|
||||
// 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
|
||||
const currentUrlAtLogin = await webdriver.getCurrentUrl()
|
||||
expect(currentUrlAtLogin).to.include('/login')
|
||||
console.log('✓ Guest user redirected to login page:', currentUrlAtLogin)
|
||||
|
||||
// Verify the login page loaded
|
||||
await webdriver.wait(until.titleContains('OliveTin'), 5000)
|
||||
const pageTitle = await webdriver.getTitle()
|
||||
expect(pageTitle).to.contain('OliveTin')
|
||||
|
||||
// Check that login page elements are present
|
||||
const body = await webdriver.findElement(By.tagName('body'))
|
||||
const bodyText = await body.getText()
|
||||
|
||||
// Should have login-related content (either local login or OAuth, or both)
|
||||
const hasLoginContent = bodyText.toLowerCase().includes('login') ||
|
||||
await webdriver.findElements(By.css('input[name="username"], input[type="text"]')).then(el => el.length > 0)
|
||||
expect(hasLoginContent).to.be.true
|
||||
console.log('✓ Login page loaded correctly')
|
||||
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue