diff --git a/4-Infrastructure/k3s-flake/tests/audiobookshelf-verify.spec.ts b/4-Infrastructure/k3s-flake/tests/audiobookshelf-verify.spec.ts new file mode 100644 index 00000000..d3ed9620 --- /dev/null +++ b/4-Infrastructure/k3s-flake/tests/audiobookshelf-verify.spec.ts @@ -0,0 +1,61 @@ +import { test, expect } from '@playwright/test'; + +test('Verify Audiobookshelf accessible via SSO', async ({ page }) => { + page.on('console', msg => console.log(`Browser Console [${msg.type()}]:`, msg.text())); + page.on('requestfailed', req => console.log('Request Failed:', req.url(), req.failure()?.errorText)); + page.on('pageerror', err => console.log('Page Error:', err.message)); + + console.log('Navigating to Audiobookshelf via domain...'); + await page.goto('https://audiobooks.researchstack.info/'); + await page.waitForTimeout(5000); + + console.log('Current URL:', page.url()); + + // Click on "Login with Authentik" if we see it on the Audiobookshelf login page + const ssoBtn = page.locator('button:has-text("Login with Authentik")').first(); + if (await ssoBtn.isVisible({ timeout: 5000 }).catch(() => false)) { + console.log('Login with Authentik button visible. Clicking...'); + await ssoBtn.click(); + await page.waitForTimeout(5000); + console.log('URL after clicking SSO button:', page.url()); + } + + // Check if we are on the Authentik login page and need credentials + const usernameInput = page.locator('input[name="username"], input[type="text"]').first(); + if (await usernameInput.isVisible({ timeout: 5000 }).catch(() => false)) { + console.log('Authentik login detected. Entering credentials...'); + await usernameInput.fill('allaun'); + + const submitUsername = page.locator('button[type="submit"], input[type="submit"]').first(); + await submitUsername.click(); + await page.waitForTimeout(3000); + + const passwordInput = page.locator('input[name="password"], input[type="password"]').first(); + await passwordInput.fill('Silverkitten14'); + + const submitPassword = page.locator('button[type="submit"], input[type="submit"]').first(); + await submitPassword.click(); + await page.waitForTimeout(8000); + console.log('URL after credentials submission:', page.url()); + } + + // Handle consent screen if it appears + if (page.url().includes('consent') || page.url().includes('authorize') || page.url().includes('application/o/authorize')) { + console.log('Consent/Authorization screen detected. Clicking continue...'); + const continueBtn = page.locator('button:has-text("Continue"), input[type="submit"], button[type="submit"]').first(); + if (await continueBtn.isVisible({ timeout: 5000 }).catch(() => false)) { + await continueBtn.click(); + await page.waitForTimeout(8000); + console.log('URL after consent:', page.url()); + } + } + + console.log('Final Page Title:', await page.title()); + console.log('Final URL:', page.url()); + await page.screenshot({ path: '/tmp/audiobookshelf-verify-final.png' }); + + // Assert that we have landed on the Audiobookshelf main dashboard + // Audiobookshelf uses "Audiobookshelf" in the page title + const title = await page.title(); + expect(title.toLowerCase()).toContain('audiobookshelf'); +});