|
1 | 1 | import { certificationController } from '../../../../src/parcoursup/application/certification-controller.js';
|
2 | 2 | import * as moduleUnderTest from '../../../../src/parcoursup/application/certification-route.js';
|
3 |
| -import { securityPreHandlers } from '../../../../src/shared/application/security-pre-handlers.js'; |
4 |
| -import { expect, HttpTestServer, sinon } from '../../../test-helper.js'; |
| 3 | +import { |
| 4 | + expect, |
| 5 | + generateValidRequestAuthorizationHeaderForApplication, |
| 6 | + HttpTestServer, |
| 7 | + sinon, |
| 8 | +} from '../../../test-helper.js'; |
5 | 9 |
|
6 | 10 | describe('Parcoursup | Unit | Application | Routes | Certification', function () {
|
7 | 11 | describe('GET /parcoursup/students/{ine}/certification', function () {
|
8 | 12 | it('should return 200', async function () {
|
9 | 13 | //given
|
10 |
| - sinon.stub(securityPreHandlers, 'checkAdminMemberHasRoleSuperAdmin').returns(true); |
11 | 14 | sinon.stub(certificationController, 'getCertificationResult').callsFake((request, h) => h.response().code(200));
|
12 | 15 |
|
13 | 16 | const httpTestServer = new HttpTestServer();
|
| 17 | + httpTestServer.setupAuthentication(); |
14 | 18 | await httpTestServer.register(moduleUnderTest);
|
15 | 19 |
|
| 20 | + const PARCOURSUP_CLIENT_ID = 'parcoursupClientId'; |
| 21 | + const PARCOURSUP_SCOPE = 'parcoursup'; |
| 22 | + const PARCOURSUP_SOURCE = 'parcoursup'; |
| 23 | + |
| 24 | + const method = 'GET'; |
| 25 | + const url = '/api/parcoursup/students/123456789OK/certification'; |
| 26 | + const headers = { |
| 27 | + authorization: generateValidRequestAuthorizationHeaderForApplication( |
| 28 | + PARCOURSUP_CLIENT_ID, |
| 29 | + PARCOURSUP_SOURCE, |
| 30 | + PARCOURSUP_SCOPE, |
| 31 | + ), |
| 32 | + }; |
| 33 | + |
16 | 34 | // when
|
17 |
| - const response = await httpTestServer.request('GET', '/api/parcoursup/students/123456789OK/certification'); |
| 35 | + const response = await httpTestServer.request(method, url, null, null, headers); |
18 | 36 |
|
19 | 37 | // then
|
20 | 38 | expect(response.statusCode).to.equal(200);
|
21 | 39 | });
|
| 40 | + |
| 41 | + context('with the wrong scope', function () { |
| 42 | + it('should return 403', async function () { |
| 43 | + //given |
| 44 | + const httpTestServer = new HttpTestServer(); |
| 45 | + httpTestServer.setupAuthentication(); |
| 46 | + await httpTestServer.register(moduleUnderTest); |
| 47 | + |
| 48 | + const PARCOURSUP_CLIENT_ID = 'parcoursupClientId'; |
| 49 | + const PARCOURSUP_SCOPE = 'a-wrong-scope'; |
| 50 | + const PARCOURSUP_SOURCE = 'parcoursup'; |
| 51 | + |
| 52 | + const method = 'GET'; |
| 53 | + const url = '/api/parcoursup/students/123456789OK/certification'; |
| 54 | + const headers = { |
| 55 | + authorization: generateValidRequestAuthorizationHeaderForApplication( |
| 56 | + PARCOURSUP_CLIENT_ID, |
| 57 | + PARCOURSUP_SOURCE, |
| 58 | + PARCOURSUP_SCOPE, |
| 59 | + ), |
| 60 | + }; |
| 61 | + |
| 62 | + // when |
| 63 | + const response = await httpTestServer.request(method, url, null, null, headers); |
| 64 | + |
| 65 | + // then |
| 66 | + expect(response.statusCode).to.equal(403); |
| 67 | + }); |
| 68 | + }); |
| 69 | + |
| 70 | + context('with the wrong clientId', function () { |
| 71 | + it('should return 401', async function () { |
| 72 | + //given |
| 73 | + const httpTestServer = new HttpTestServer(); |
| 74 | + httpTestServer.setupAuthentication(); |
| 75 | + await httpTestServer.register(moduleUnderTest); |
| 76 | + |
| 77 | + const PARCOURSUP_CLIENT_ID = 'wrongClientId'; |
| 78 | + const PARCOURSUP_SCOPE = 'parcoursup'; |
| 79 | + const PARCOURSUP_SOURCE = 'parcoursup'; |
| 80 | + |
| 81 | + const method = 'GET'; |
| 82 | + const url = '/api/parcoursup/students/123456789OK/certification'; |
| 83 | + const headers = { |
| 84 | + authorization: generateValidRequestAuthorizationHeaderForApplication( |
| 85 | + PARCOURSUP_CLIENT_ID, |
| 86 | + PARCOURSUP_SOURCE, |
| 87 | + PARCOURSUP_SCOPE, |
| 88 | + ), |
| 89 | + }; |
| 90 | + |
| 91 | + // when |
| 92 | + const response = await httpTestServer.request(method, url, null, null, headers); |
| 93 | + |
| 94 | + // then |
| 95 | + expect(response.statusCode).to.equal(401); |
| 96 | + }); |
| 97 | + }); |
22 | 98 | });
|
23 | 99 | });
|
0 commit comments