Skip to content

Commit

Permalink
chore(repo): Test that handshake is throw if suffixed client_uat is n…
Browse files Browse the repository at this point in the history
…ot found (#3752)
  • Loading branch information
nikosdouvlis authored Jul 17, 2024
1 parent 2f0f36e commit 1066eaa
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
4 changes: 2 additions & 2 deletions integration/testUtils/appPageObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const createAppPageObject = (testArgs: { page: Page }, app: Application)
// do not fail the test if interstitial is returned (401)
}
},
goToRelative: async (path: string, opts: { searchParams?: URLSearchParams; timeout?: number } = {}) => {
goToRelative: (path: string, opts: { searchParams?: URLSearchParams; timeout?: number } = {}) => {
let url: URL;

try {
Expand All @@ -35,7 +35,7 @@ export const createAppPageObject = (testArgs: { page: Page }, app: Application)
if (opts.searchParams) {
url.search = opts.searchParams.toString();
}
await page.goto(url.toString(), { timeout: opts.timeout ?? 10000 });
return page.goto(url.toString(), { timeout: opts.timeout ?? 10000 });
},
waitForClerkJsLoaded: async () => {
return page.waitForFunction(() => {
Expand Down
10 changes: 9 additions & 1 deletion integration/testUtils/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createClerkClient as backendCreateClerkClient } from '@clerk/backend';
import type { Browser, BrowserContext, Page } from '@playwright/test';
import type { Browser, BrowserContext, Page, Response } from '@playwright/test';
import { expect } from '@playwright/test';

import type { Application } from '../models/application';
import { createAppPageObject } from './appPageObject';
Expand All @@ -24,6 +25,13 @@ const createClerkClient = (app: Application) => {

const createExpectPageObject = ({ page }: TestArgs) => {
return {
toBeHandshake: async (res: Response) => {
// Travel the redirect chain until we find the handshake header
// TODO: Loop through the redirects until we find a handshake header, or timeout trying
const redirect = await res.request().redirectedFrom().redirectedFrom().redirectedFrom().response();
expect(redirect.status()).toBe(307);
expect(redirect.headers()['x-clerk-auth-status']).toContain('handshake');
},
toBeSignedOut: () => {
return page.waitForFunction(() => {
return !window.Clerk?.user;
Expand Down
7 changes: 4 additions & 3 deletions integration/testUtils/signInPageObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ export const createSignInComponentPageObject = (testArgs: TestArgs) => {
const self = {
...common(testArgs),
goTo: async (opts?: { searchParams?: URLSearchParams; headlessSelector?: string; timeout?: number }) => {
await page.goToRelative('/sign-in', opts);
const navRes = await page.goToRelative('/sign-in', opts);

if (typeof opts?.headlessSelector !== 'undefined') {
return self.waitForMounted(opts.headlessSelector);
await self.waitForMounted(opts.headlessSelector);
} else {
return self.waitForMounted();
await self.waitForMounted();
}
return navRes;
},
waitForMounted: (selector = '.cl-signIn-root') => {
return page.waitForSelector(selector, { state: 'attached' });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,9 @@ test.describe('root and subdomain production apps @sessions', () => {
// The client_uat cookie should always be set on etld+1
expect(tab0Cookies.get('__client_uat_*').domain).toEqual('.' + hosts[0]);

await u[1].page.goto(`https://${hosts[1]}`);
u[1].po.expect.toBeHandshake(await u[1].page.goto(`https://${hosts[1]}`));
await u[1].po.expect.toBeSignedOut();
expect((await u[1].page.evaluate(() => fetch('/api/me').then(r => r.json()))).userId).toBe(null);

await u[1].po.signIn.goTo();
await u[1].po.signIn.signInWithEmailAndInstantPassword(fakeUsers[1]);
Expand Down

0 comments on commit 1066eaa

Please sign in to comment.