AI Implementation feature(823): Landing Page and Login/Register Modal (#11)
This commit was merged in pull request #11.
This commit is contained in:
@@ -52,16 +52,30 @@ beforeAll(async () => {
|
||||
expect(cookies?.some((c) => c.startsWith('csrf='))).toBe(true);
|
||||
});
|
||||
|
||||
async function primeCsrfAndLogin(agent: any): Promise<void> {
|
||||
await agent.get('/api/v1/auth/csrf');
|
||||
const cookies: any = agent.jar.getCookies(CookieAccessInfo.All);
|
||||
const csrf = cookies.find((c: any) => c.name === 'csrf');
|
||||
await agent.post('/api/v1/auth/login')
|
||||
.set('X-CSRF-Token', csrf.value)
|
||||
.send({ username: 'admin', password: 'Sup3rSecret!Pass' })
|
||||
.expect(201);
|
||||
}
|
||||
|
||||
it('login returns an access token and sets the rt refresh cookie', async () => {
|
||||
const server = app.getHttpServer();
|
||||
const agent = request.agent(server);
|
||||
|
||||
await agent.get('/api/v1/auth/csrf');
|
||||
const cookies: any = agent.jar.getCookies(CookieAccessInfo.All);
|
||||
const csrf = cookies.find((c: any) => c.name === 'csrf');
|
||||
const res = await agent.post('/api/v1/auth/login')
|
||||
.set('X-CSRF-Token', csrf.value)
|
||||
.send({ username: 'admin', password: 'Sup3rSecret!Pass' })
|
||||
.expect(201);
|
||||
expect(res.body.accessToken).toBeDefined();
|
||||
const cookies = res.headers['set-cookie'] as unknown as string[];
|
||||
const rt = cookies.find((c) => c.startsWith('rt='));
|
||||
const setCookies = res.headers['set-cookie'] as unknown as string[];
|
||||
const rt = setCookies.find((c) => c.startsWith('rt='));
|
||||
expect(rt).toBeDefined();
|
||||
expect(rt).toMatch(/HttpOnly/);
|
||||
});
|
||||
@@ -70,9 +84,7 @@ beforeAll(async () => {
|
||||
const server = app.getHttpServer();
|
||||
const agent = request.agent(server);
|
||||
|
||||
await agent.post('/api/v1/auth/login')
|
||||
.send({ username: 'admin', password: 'Sup3rSecret!Pass' })
|
||||
.expect(201);
|
||||
await primeCsrfAndLogin(agent);
|
||||
|
||||
const cookies: any = agent.jar.getCookies(CookieAccessInfo.All);
|
||||
const rt = cookies.find((c: any) => c.name === 'rt');
|
||||
@@ -93,9 +105,7 @@ beforeAll(async () => {
|
||||
const server = app.getHttpServer();
|
||||
const agent = request.agent(server);
|
||||
|
||||
await agent.post('/api/v1/auth/login')
|
||||
.send({ username: 'admin', password: 'Sup3rSecret!Pass' })
|
||||
.expect(201);
|
||||
await primeCsrfAndLogin(agent);
|
||||
|
||||
const cookies: any = agent.jar.getCookies(CookieAccessInfo.All);
|
||||
const rt = cookies.find((c: any) => c.name === 'rt');
|
||||
|
||||
Reference in New Issue
Block a user