Skip to content

Commit de99c42

Browse files
feat: protect pass creation
1 parent 7fb0ed6 commit de99c42

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/infrastructure/PassInterface.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ export class PassInterface {
6565
},
6666
},
6767
{
68-
method: 'GET',
68+
method: 'POST',
6969
path: '/pass',
7070
options: {
71+
pre: [{ method: (request, h) => { return this.authService.validateFromPass(request, h); } }],
7172
handler: async (request, h) => {
7273
return this.passController.create(request, h);
7374
},

tests/acceptance/passes_tests.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,13 @@ describe('Acceptance | Endpoints | Passes', function () {
229229
});
230230

231231
it('should return pass', async function () {
232+
const token = await generateAuthorizationToken();
232233
await knex('reservations').insert({ code: '12345', start_at: new Date('2024-01-10'), court: '10', activity: 'Badminton', status: 'reserved', updated_at: new Date('2024-01-02') });
233234

234235
const response = await server.inject({
235-
method: 'GET',
236+
method: 'POST',
236237
url: '/pass',
238+
headers: { authorization: token },
237239
});
238240

239241
expect(response.statusCode).to.equal(201);
@@ -243,9 +245,12 @@ describe('Acceptance | Endpoints | Passes', function () {
243245

244246
context('when next event does not exist', function () {
245247
it('should return 503', async function () {
248+
const token = await generateAuthorizationToken();
249+
246250
const response = await server.inject({
247-
method: 'GET',
251+
method: 'POST',
248252
url: '/pass',
253+
headers: { authorization: token },
249254
});
250255

251256
expect(response.statusCode).to.equal(503);

0 commit comments

Comments
 (0)