-
Notifications
You must be signed in to change notification settings - Fork 327
/
Copy pathnon-secure-context.test.ts
64 lines (54 loc) · 2.14 KB
/
non-secure-context.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* This test ensures that Clerk can still operate in a non-secure context.
* Especially useful for developing in local environments using custom domains pointing to localhost
* but without using self-signed certificates.
*
* No special requirements are needed for this test to run, as we will not use TLS.
*
* The test will:
* 1. Use a dev instance created from clerkstage.dev
* 2. Create and run a single app
* 3. Start a local server that proxies requests to the app running locally
* 4. Perform a simple sign-in flow
*/
import type { Server } from 'node:http';
import { test } from '@playwright/test';
import { createProxyServer } from '../scripts/proxyServer';
import type { FakeUser } from '../testUtils';
import { createTestUtils, testAgainstRunningApps } from '../testUtils';
// This NEEDS to be a domain that points to localhost
// and is not listed in the HSTS preload list
// For more info, refer to https://hstspreload.org/
// and https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security
const APP_HOST = 'lclclerk.com:8880';
testAgainstRunningApps({ withPattern: ['next.appRouter.withEmailCodes'] })(
'localhost non-secure context @generic',
({ app }) => {
test.describe.configure({ mode: 'serial' });
let fakeUser: FakeUser;
let server: Server;
test.beforeAll(async () => {
server = createProxyServer({
targets: {
[APP_HOST]: app.serverUrl,
},
});
const u = createTestUtils({ app });
fakeUser = u.services.users.createFakeUser();
await u.services.users.createBapiUser(fakeUser);
});
test.afterAll(async () => {
await Promise.all([await fakeUser.deleteIfExists(), await app.teardown()]);
server.close();
});
test('sign-in flow', async ({ page }) => {
const u = createTestUtils({ app, page });
await u.page.goto(`http://${APP_HOST}`, { timeout: 50000 });
await u.po.signIn.goTo();
await u.po.signIn.signInWithEmailAndInstantPassword(fakeUser);
await u.po.expect.toBeSignedIn();
await page.evaluate(() => window.Clerk.signOut());
await u.po.expect.toBeSignedOut();
});
},
);