Skip to content

Commit

Permalink
Merge branch 'dev' into fix/fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
TeddyRoncin authored Oct 17, 2023
2 parents 108148b + 0ee6af2 commit bcc01c9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/controllers/discord/oauth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as Sentry from '@sentry/node';
import env from '../../utils/env';
import database from '../../services/database';
import { fetchUser } from '../../operations/user';
import { ActionFeedback, DiscordFeedbackCode } from '../../types';
import { DiscordFeedbackCode } from '../../types';
import { decrypt } from '../../utils/helpers';
import { isLoginAllowed } from '../../middlewares/settings';
import type { DiscordAuthorization } from './discordApi';
Expand All @@ -16,7 +16,7 @@ const redirect = (response: Response, statusCode: DiscordFeedbackCode) => {
response
.status(302)
.set({
Location: `${env.front.website}/dashboard/account?action=${ActionFeedback.DISCORD_OAUTH}&state=${statusCode}`,
Location: `${env.front.website}/oauth/discord/${statusCode}`,
})
.end();
};
Expand Down
25 changes: 11 additions & 14 deletions tests/discord/oauth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,10 @@ describe('GET /discord/oauth', () => {
error_description: 'Description of this error here',
})
.expect(302)
.expect('Location', `${env.front.website}/dashboard/account?action=oauth&state=4`));
.expect('Location', `${env.front.website}/oauth/discord/4`));

it('should fail because no query params were provided', () =>
request(app)
.get('/discord/oauth')
.expect(302)
.expect('Location', `${env.front.website}/dashboard/account?action=oauth&state=5`));
request(app).get('/discord/oauth').expect(302).expect('Location', `${env.front.website}/oauth/discord/5`));

it('should fail because query params were incomplete', () =>
request(app)
Expand All @@ -46,7 +43,7 @@ describe('GET /discord/oauth', () => {
code: registerOauthCode(),
})
.expect(302)
.expect('Location', `${env.front.website}/dashboard/account?action=oauth&state=5`));
.expect('Location', `${env.front.website}/oauth/discord/5`));

it('should fail because the state used matches no user id', () =>
request(app)
Expand All @@ -56,7 +53,7 @@ describe('GET /discord/oauth', () => {
state: encrypt(user.id).toString('base64').slice(1),
})
.expect(302)
.expect('Location', `${env.front.website}/dashboard/account?action=oauth&state=5`));
.expect('Location', `${env.front.website}/oauth/discord/5`));

it('should fail with an unknown error', async () => {
const stub = sandbox.stub(sentryOperations, 'setExtra').throws('Stub!');
Expand All @@ -67,7 +64,7 @@ describe('GET /discord/oauth', () => {
state: encrypt(user.id).toString('base64'),
})
.expect(302)
.expect('Location', `${env.front.website}/dashboard/account?action=oauth&state=6`);
.expect('Location', `${env.front.website}/oauth/discord/6`);
return stub.restore();
});

Expand All @@ -79,7 +76,7 @@ describe('GET /discord/oauth', () => {
state: encrypt(user.id.slice(1)).toString('base64'),
})
.expect(302)
.expect('Location', `${env.front.website}/dashboard/account?action=oauth&state=5`));
.expect('Location', `${env.front.website}/oauth/discord/5`));

it('should fail when oauth is cancelled', () =>
request(app)
Expand All @@ -89,7 +86,7 @@ describe('GET /discord/oauth', () => {
state: encrypt(user.id).toString('base64'),
})
.expect(302)
.expect('Location', `${env.front.website}/dashboard/account?action=oauth&state=4`));
.expect('Location', `${env.front.website}/oauth/discord/4`));

it('should indicate the discord account was not linked already', async () => {
await updateAdminUser(user.id, { discordId: null });
Expand All @@ -101,7 +98,7 @@ describe('GET /discord/oauth', () => {
state: encrypt(user.id).toString('base64'),
})
.expect(302)
.expect('Location', `${env.front.website}/dashboard/account?action=oauth&state=0`);
.expect('Location', `${env.front.website}/oauth/discord/0`);
});

it('should indicate the linked account is still the same', () =>
Expand All @@ -112,7 +109,7 @@ describe('GET /discord/oauth', () => {
state: encrypt(user.id).toString('base64'),
})
.expect(302)
.expect('Location', `${env.front.website}/dashboard/account?action=oauth&state=2`));
.expect('Location', `${env.front.website}/oauth/discord/2`));

it('should indicate the linked account has been updated', () => {
discordId = generateFakeDiscordId();
Expand All @@ -123,7 +120,7 @@ describe('GET /discord/oauth', () => {
state: encrypt(user.id).toString('base64'),
})
.expect(302)
.expect('Location', `${env.front.website}/dashboard/account?action=oauth&state=1`);
.expect('Location', `${env.front.website}/oauth/discord/1`);
});

it('should fail if discord account is already bound to another account', async () => {
Expand All @@ -135,6 +132,6 @@ describe('GET /discord/oauth', () => {
state: encrypt(otherUser.id).toString('base64'),
})
.expect(302)
.expect('Location', `${env.front.website}/dashboard/account?action=oauth&state=3`);
.expect('Location', `${env.front.website}/oauth/discord/3`);
});
});

0 comments on commit bcc01c9

Please sign in to comment.