Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions packages/agent/src/agent/routes/security/authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import jsonwebtoken from 'jsonwebtoken';
import jwt from 'koa-jwt';

import { Context } from 'koa';
import { HttpCode, RouteType } from '../../types';
import { RouteType } from '../../types';
import BaseRoute from '../base-route';
import ForestHttpApi from '../../utils/forest-http-api';

Expand Down Expand Up @@ -44,13 +44,11 @@ export default class Authentication extends BaseRoute {
router.get('/authentication/callback', this.handleAuthenticationCallback.bind(this));

router.use(jwt({ secret: this.options.authSecret, cookie: 'forest_session_token' }));

router.post('/authentication/logout', this.handleAuthenticationLogout.bind(this));
}

public async handleAuthentication(context: Context): Promise<void> {
const renderingId = Number(context.request.body?.renderingId);
this.checkRenderingId(renderingId);
Authentication.checkRenderingId(renderingId);

const authorizationUrl = this.client.authorizationUrl({
scope: 'openid email profile',
Expand All @@ -68,7 +66,7 @@ export default class Authentication extends BaseRoute {

try {
renderingId = JSON.parse(state).renderingId;
this.checkRenderingId(renderingId);
Authentication.checkRenderingId(renderingId);
} catch {
throw new ValidationError('Failed to retrieve renderingId from query[state]');
}
Expand All @@ -87,11 +85,7 @@ export default class Authentication extends BaseRoute {
};
}

public async handleAuthenticationLogout(context: Context) {
context.response.status = HttpCode.NoContent;
}

private checkRenderingId(renderingId: number): void {
private static checkRenderingId(renderingId: number): void {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added the statickeyword.

if (Number.isNaN(renderingId)) {
throw new ValidationError('Rendering id must be a number');
}
Expand Down
14 changes: 0 additions & 14 deletions packages/agent/test/agent/routes/security/authentication.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { createMockContext } from '@shopify/jest-koa-mocks';
import openidClient, { Issuer } from 'openid-client';

import * as factories from '../../__factories__';
import { HttpCode } from '../../../../src/agent/types';
import Authentication from '../../../../src/agent/routes/security/authentication';
import ForestHttpApi from '../../../../src/agent/utils/forest-http-api';

Expand Down Expand Up @@ -121,7 +120,6 @@ describe('Authentication', () => {

expect(router.post).toHaveBeenCalledWith('/authentication', expect.any(Function));
expect(router.get).toHaveBeenCalledWith('/authentication/callback', expect.any(Function));
expect(router.post).toHaveBeenCalledWith('/authentication/logout', expect.any(Function));
});
});
});
Expand Down Expand Up @@ -240,16 +238,4 @@ describe('Authentication', () => {
});
});
});

describe('handleAuthenticationLogout', () => {
test('should return a 204', async () => {
const authentication = new Authentication(services, options);

const context = createMockContext();

await authentication.handleAuthenticationLogout(context);

expect(context.response.status).toEqual(HttpCode.NoContent);
});
});
});