Skip to content

Open-source event management and ticket selling platform — perfect for concerts, conferences, and everything in between 🎟️ If you find this project helpful, please consider giving us a star ⭐️

1.5 KB
Raw Blame
import { expect, type Page } from '@playwright/test';

export interface IdentityClaims {
  email?: string;
  email_verified?: boolean;
  given_name?: string;
  family_name?: string;
}

export class SsoPage {
  constructor(private readonly page: Page) {}

  providerButton() {
    return this.page.getByTestId('sso-provider-button-oidc');
  }

  async signInAtProvider(subject: string, claims: IdentityClaims): Promise<void> {
    await this.page.waitForURL(/\/default\/authorize/);
    await this.page.locator('input[name=username]').fill(subject);
    await this.page.locator('textarea[name=claims]').fill(JSON.stringify(claims));
    await this.page.locator('input[type=submit]').click();
    await this.page.waitForURL(/\/sso\/callback/);
  }

  async completeSignup(): Promise<void> {
    await expect(this.page.getByRole('heading', { name: 'One last step' })).toBeVisible();
    await this.page.getByTestId('sso-complete-signup-submit').click();
  }
}

export const providerIsConfigured = async (page: Page): Promise<boolean> => {
  const response = await page.request.get('/api/auth/sso/providers');
  if (!response.ok()) {
    throw new Error(`Listing the sign-in providers failed with HTTP ${response.status()}`);
  }
  const body = await response.json();
  const configured = body.data.providers.some((provider: { key: string }) => provider.key === 'oidc');
  if (!configured && process.env.CI) {
    throw new Error('No OIDC provider is configured on this stack; set SSO_OIDC_* for the e2e backend');
  }
  return configured;
};