-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] ✨ Ajoute une stratégie de contrôle plus strict pour l'accès…
- Loading branch information
Showing
5 changed files
with
115 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 80 additions & 4 deletions
84
api/tests/parcoursup/unit/application/certification-route_test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,99 @@ | ||
import { certificationController } from '../../../../src/parcoursup/application/certification-controller.js'; | ||
import * as moduleUnderTest from '../../../../src/parcoursup/application/certification-route.js'; | ||
import { securityPreHandlers } from '../../../../src/shared/application/security-pre-handlers.js'; | ||
import { expect, HttpTestServer, sinon } from '../../../test-helper.js'; | ||
import { | ||
expect, | ||
generateValidRequestAuthorizationHeaderForApplication, | ||
HttpTestServer, | ||
sinon, | ||
} from '../../../test-helper.js'; | ||
|
||
describe('Parcoursup | Unit | Application | Routes | Certification', function () { | ||
describe('GET /parcoursup/students/{ine}/certification', function () { | ||
it('should return 200', async function () { | ||
//given | ||
sinon.stub(securityPreHandlers, 'checkAdminMemberHasRoleSuperAdmin').returns(true); | ||
sinon.stub(certificationController, 'getCertificationResult').callsFake((request, h) => h.response().code(200)); | ||
|
||
const httpTestServer = new HttpTestServer(); | ||
httpTestServer.setupAuthentication(); | ||
await httpTestServer.register(moduleUnderTest); | ||
|
||
const PARCOURSUP_CLIENT_ID = 'parcoursupClientId'; | ||
const PARCOURSUP_SCOPE = 'parcoursup'; | ||
const PARCOURSUP_SOURCE = 'parcoursup'; | ||
|
||
const method = 'GET'; | ||
const url = '/api/parcoursup/students/123456789OK/certification'; | ||
const headers = { | ||
authorization: generateValidRequestAuthorizationHeaderForApplication( | ||
PARCOURSUP_CLIENT_ID, | ||
PARCOURSUP_SOURCE, | ||
PARCOURSUP_SCOPE, | ||
), | ||
}; | ||
|
||
// when | ||
const response = await httpTestServer.request('GET', '/api/parcoursup/students/123456789OK/certification'); | ||
const response = await httpTestServer.request(method, url, null, null, headers); | ||
|
||
// then | ||
expect(response.statusCode).to.equal(200); | ||
}); | ||
|
||
context('with the wrong scope', function () { | ||
it('should return 403', async function () { | ||
//given | ||
const httpTestServer = new HttpTestServer(); | ||
httpTestServer.setupAuthentication(); | ||
await httpTestServer.register(moduleUnderTest); | ||
|
||
const PARCOURSUP_CLIENT_ID = 'parcoursupClientId'; | ||
const PARCOURSUP_SCOPE = 'a-wrong-scope'; | ||
const PARCOURSUP_SOURCE = 'parcoursup'; | ||
|
||
const method = 'GET'; | ||
const url = '/api/parcoursup/students/123456789OK/certification'; | ||
const headers = { | ||
authorization: generateValidRequestAuthorizationHeaderForApplication( | ||
PARCOURSUP_CLIENT_ID, | ||
PARCOURSUP_SOURCE, | ||
PARCOURSUP_SCOPE, | ||
), | ||
}; | ||
|
||
// when | ||
const response = await httpTestServer.request(method, url, null, null, headers); | ||
|
||
// then | ||
expect(response.statusCode).to.equal(403); | ||
}); | ||
}); | ||
|
||
context('with the wrong clientId', function () { | ||
it('should return 401', async function () { | ||
//given | ||
const httpTestServer = new HttpTestServer(); | ||
httpTestServer.setupAuthentication(); | ||
await httpTestServer.register(moduleUnderTest); | ||
|
||
const PARCOURSUP_CLIENT_ID = 'wrongClientId'; | ||
const PARCOURSUP_SCOPE = 'parcoursup'; | ||
const PARCOURSUP_SOURCE = 'parcoursup'; | ||
|
||
const method = 'GET'; | ||
const url = '/api/parcoursup/students/123456789OK/certification'; | ||
const headers = { | ||
authorization: generateValidRequestAuthorizationHeaderForApplication( | ||
PARCOURSUP_CLIENT_ID, | ||
PARCOURSUP_SOURCE, | ||
PARCOURSUP_SCOPE, | ||
), | ||
}; | ||
|
||
// when | ||
const response = await httpTestServer.request(method, url, null, null, headers); | ||
|
||
// then | ||
expect(response.statusCode).to.equal(401); | ||
}); | ||
}); | ||
}); | ||
}); |