From b25902c159d22567cf463555f6b56909d0aed1dc Mon Sep 17 00:00:00 2001 From: LEGO Technix <109212476+lego-technix@users.noreply.github.com> Date: Thu, 23 Jan 2025 14:54:25 +0100 Subject: [PATCH 1/9] refactor(api): rewrite some functions exit-first style --- api/lib/infrastructure/authentication.js | 26 ++++++++++++------------ 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/api/lib/infrastructure/authentication.js b/api/lib/infrastructure/authentication.js index 23b4afaa5f5..ba177dde928 100644 --- a/api/lib/infrastructure/authentication.js +++ b/api/lib/infrastructure/authentication.js @@ -60,7 +60,6 @@ function validateUser(decoded) { function validateClientApplication(decoded) { const application = find(config.apimRegisterApplicationsCredentials, { clientId: decoded.client_id }); - if (!application) { return { isValid: false, errorCode: 401 }; } @@ -73,27 +72,28 @@ function validateClientApplication(decoded) { } async function _checkIsAuthenticated(request, h, { key, validate }) { - if (!request.headers.authorization) { + const authorizationHeader = request.headers.authorization; + if (!authorizationHeader) { return boom.unauthorized(null, 'jwt'); } - const authorizationHeader = request.headers.authorization; const accessToken = tokenService.extractTokenFromAuthChain(authorizationHeader); - if (!accessToken) { return boom.unauthorized(); } const decodedAccessToken = tokenService.getDecodedToken(accessToken, key); - if (decodedAccessToken) { - const { isValid, credentials, errorCode } = validate(decodedAccessToken, request, h); - if (isValid) { - return h.authenticated({ credentials }); - } - - if (errorCode === 403) { - return boom.forbidden(); - } + if (!decodedAccessToken) { + return boom.unauthorized(); + } + + const { isValid, credentials, errorCode } = validate(decodedAccessToken, request, h); + if (isValid) { + return h.authenticated({ credentials }); + } + + if (errorCode === 403) { + return boom.forbidden(); } return boom.unauthorized(); From 31616916753b02ed4ba3d2ce41b528efac0dd3ae Mon Sep 17 00:00:00 2001 From: LEGO Technix <109212476+lego-technix@users.noreply.github.com> Date: Thu, 23 Jan 2025 14:26:16 +0100 Subject: [PATCH 2/9] test(api): add new generateAuthenticatedUserRequestHeaders helper --- api/tests/test-helper.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/api/tests/test-helper.js b/api/tests/test-helper.js index 4dc55f35452..e5165c7b566 100644 --- a/api/tests/test-helper.js +++ b/api/tests/test-helper.js @@ -115,6 +115,25 @@ function toStream(data, encoding = 'utf8') { }); } +function generateAuthenticatedUserRequestHeaders({ + userId = 1234, + source = 'pix', + audience = 'https://app.pix.org', + acceptLanguage, +} = {}) { + const url = new URL(audience); + const protoHeader = url.protocol.slice(0, -1); + const hostHeader = url.hostname; + const accessToken = tokenService.createAccessTokenFromUser({ userId, source, audience }).accessToken; + + return { + authorization: `Bearer ${accessToken}`, + 'x-forwarded-proto': protoHeader, + 'x-forwarded-host': hostHeader, + ...(acceptLanguage && { 'accept-language': acceptLanguage }), + }; +} + function generateValidRequestAuthorizationHeader(userId = 1234, source = 'pix', audience = 'http://app.pix.org') { const accessToken = tokenService.createAccessTokenFromUser({ userId, source, audience }).accessToken; return `Bearer ${accessToken}`; @@ -328,6 +347,7 @@ export { domainBuilder, EMPTY_BLANK_AND_NULL, expect, + generateAuthenticatedUserRequestHeaders, generateIdTokenForExternalUser, generateValidRequestAuthorizationHeader, generateValidRequestAuthorizationHeaderForApplication, From aa0d21d552c7038d6223eb44b7eb1d3a2794241b Mon Sep 17 00:00:00 2001 From: LEGO Technix <109212476+lego-technix@users.noreply.github.com> Date: Thu, 23 Jan 2025 15:12:22 +0100 Subject: [PATCH 3/9] feat(api): validate audience for user Access Tokens --- api/lib/infrastructure/authentication.js | 10 + .../infrastructure/authentication_test.js | 209 ++++++++++++++++++ 2 files changed, 219 insertions(+) create mode 100644 api/tests/unit/infrastructure/authentication_test.js diff --git a/api/lib/infrastructure/authentication.js b/api/lib/infrastructure/authentication.js index ba177dde928..cd4ac21f616 100644 --- a/api/lib/infrastructure/authentication.js +++ b/api/lib/infrastructure/authentication.js @@ -1,6 +1,7 @@ import boom from '@hapi/boom'; import lodash from 'lodash'; +import { getForwardedOrigin } from '../../src/identity-access-management/infrastructure/utils/network.js'; import { config } from '../../src/shared/config.js'; import { tokenService } from '../../src/shared/domain/services/token-service.js'; @@ -87,6 +88,15 @@ async function _checkIsAuthenticated(request, h, { key, validate }) { return boom.unauthorized(); } + // Only tokens including user_id are User Access Tokens. + // This is why applications Access Tokens are not subject to audience validation for now. + if (decodedAccessToken.user_id && config.featureToggles.isUserTokenAudConfinementEnabled) { + const audience = getForwardedOrigin(request.headers); + if (decodedAccessToken.aud !== audience) { + return boom.unauthorized(); + } + } + const { isValid, credentials, errorCode } = validate(decodedAccessToken, request, h); if (isValid) { return h.authenticated({ credentials }); diff --git a/api/tests/unit/infrastructure/authentication_test.js b/api/tests/unit/infrastructure/authentication_test.js new file mode 100644 index 00000000000..623c3c51d48 --- /dev/null +++ b/api/tests/unit/infrastructure/authentication_test.js @@ -0,0 +1,209 @@ +import { authentication } from '../../../lib/infrastructure/authentication.js'; +import { tokenService } from '../../../src/shared/domain/services/token-service.js'; +import { expect, sinon } from '../../test-helper.js'; + +describe('Unit | Infrastructure | Authentication', function () { + beforeEach(function () { + sinon.stub(tokenService, 'extractTokenFromAuthChain'); + sinon.stub(tokenService, 'getDecodedToken'); + }); + + describe('when there is no authorization header in the request', function () { + it('should throw an error', async function () { + // given + const request = { headers: {} }; + const h = { authenticated: sinon.stub() }; + + // when + const { authenticate } = authentication.scheme(undefined, { + key: 'dummy-secret', + validate: sinon.stub(), + }); + const response = await authenticate(request, h); + + // then + expect(response.output.payload).to.include({ + statusCode: 401, + error: 'Unauthorized', + message: 'Unauthorized', + }); + }); + }); + + describe('when there is an authorization header in the request', function () { + describe('when there is no access token in the authorization header', function () { + it('should throw an error', async function () { + // given + const request = { headers: { authorization: 'Bearer' } }; + const h = { authenticated: sinon.stub() }; + tokenService.extractTokenFromAuthChain.withArgs('Bearer').returns(null); + + // when + const { authenticate } = authentication.scheme(undefined, { + key: 'dummy-secret', + validate: sinon.stub(), + }); + const response = await authenticate(request, h); + + // then + expect(response.output.payload).to.include({ + statusCode: 401, + error: 'Unauthorized', + message: 'Unauthorized', + }); + }); + }); + + describe('when access token can not be decoded', function () { + it('should throw an error', async function () { + // given + const request = { + headers: { authorization: 'Bearer token', 'x-forwarded-proto': 'https', 'x-forwarded-host': 'app.pix.fr' }, + }; + const h = { authenticated: sinon.stub() }; + tokenService.extractTokenFromAuthChain.withArgs('Bearer token').returns('token'); + tokenService.getDecodedToken.withArgs('token', 'dummy-secret').returns(false); + + // when + const { authenticate } = authentication.scheme(undefined, { + key: 'dummy-secret', + validate: sinon.stub(), + }); + const response = await authenticate(request, h); + + // then + expect(response.output.payload).to.include({ + statusCode: 401, + error: 'Unauthorized', + message: 'Unauthorized', + }); + }); + }); + + describe('when isUserTokenAudConfinementEnabled is enabled', function () { + describe('when there is a user Id', function () { + describe('when the audience is different from the forwarded origin', function () { + it('should throw an error', async function () { + // given + const request = { + headers: { + authorization: 'Bearer token', + 'x-forwarded-proto': 'https', + 'x-forwarded-host': 'app.pix.fr', + }, + }; + const h = { authenticated: sinon.stub() }; + tokenService.extractTokenFromAuthChain.withArgs('Bearer token').returns('token'); + tokenService.getDecodedToken.withArgs('token', 'dummy-secret').returns({ + user_id: 'user_id', + aud: 'https://wrong.audience.fr', + }); + + // when + const { authenticate } = authentication.scheme(undefined, { + key: 'dummy-secret', + validate: sinon.stub(), + }); + const response = await authenticate(request, h); + + // then + expect(response.output.payload).to.include({ + statusCode: 401, + error: 'Unauthorized', + message: 'Unauthorized', + }); + }); + }); + + describe('when there is no forwarded origin in the request', function () { + it('should throw an error', async function () { + // given + const request = { + headers: { + authorization: 'Bearer token', + }, + }; + + const h = { authenticated: sinon.stub() }; + tokenService.extractTokenFromAuthChain.withArgs('Bearer token').returns('token'); + tokenService.getDecodedToken.withArgs('token', 'dummy-secret').returns({ + user_id: 'user_id', + aud: 'https://app.pix.fr', + }); + + // when + const { authenticate } = authentication.scheme(undefined, { + key: 'dummy-secret', + validate: sinon.stub(), + }); + const response = await authenticate(request, h); + + // then + expect(response.output.payload).to.include({ + statusCode: 401, + error: 'Unauthorized', + message: 'Unauthorized', + }); + }); + }); + + describe('when the audience is the same than the forwarded origin', function () { + it('should not throw an error', async function () { + // given + const request = { + headers: { + authorization: 'Bearer token', + 'x-forwarded-proto': 'https', + 'x-forwarded-host': 'app.pix.fr', + }, + }; + const h = { authenticated: sinon.stub() }; + tokenService.extractTokenFromAuthChain.withArgs('Bearer token').returns('token'); + tokenService.getDecodedToken.withArgs('token', 'dummy-secret').returns({ + user_id: 'user_id', + aud: 'https://app.pix.fr', + }); + + // when + const { authenticate } = authentication.scheme(undefined, { + key: 'dummy-secret', + validate: sinon.stub().returns({ isValid: true, credentials: {}, errorCode: null }), + }); + await authenticate(request, h); + + // then + expect(h.authenticated).to.have.been.calledWithExactly({ credentials: {} }); + }); + }); + }); + + describe('when there is no user Id', function () { + it('should not throw an error', async function () { + // given + const request = { + headers: { + authorization: 'Bearer token', + 'x-forwarded-proto': 'https', + 'x-forwarded-host': 'app.pix.fr', + }, + }; + const h = { authenticated: sinon.stub() }; + tokenService.extractTokenFromAuthChain.withArgs('Bearer token').returns('token'); + tokenService.getDecodedToken.withArgs('token', 'dummy-secret').returns({ + aud: 'https://app.pix.fr', + }); + + // when + const { authenticate } = authentication.scheme(undefined, { + key: 'dummy-secret', + validate: sinon.stub().returns({ isValid: true, credentials: {}, errorCode: null }), + }); + await authenticate(request, h); + + // then + expect(h.authenticated).to.have.been.calledWithExactly({ credentials: {} }); + }); + }); + }); + }); +}); From 691333bfc6c8bc04444f2db7f5ce23090fce2ddd Mon Sep 17 00:00:00 2001 From: LEGO Technix <109212476+lego-technix@users.noreply.github.com> Date: Thu, 23 Jan 2025 16:37:54 +0100 Subject: [PATCH 4/9] test(api): in unit tests use new generateAuthenticatedUserRequestHeaders helper to have a valid authentication through a user Access Tokens now with audience --- .../application/country-controller_test.js | 4 +- .../organization-learners-route_test.js | 4 +- .../organization-place-route_test.js | 70 ++++++++++++------- ...ment-controller-get-next-challenge_test.js | 17 ++--- .../courses/course-controller_test.js | 4 +- .../utils/request-response-utils_test.js | 4 +- .../certification-course-controller_test.js | 4 +- .../unit/application/frameworks/index_test.js | 6 +- .../organization-controller_test.js | 6 +- 9 files changed, 63 insertions(+), 56 deletions(-) diff --git a/api/tests/certification/enrolment/unit/application/country-controller_test.js b/api/tests/certification/enrolment/unit/application/country-controller_test.js index fc477b2a7c4..44e1495a111 100644 --- a/api/tests/certification/enrolment/unit/application/country-controller_test.js +++ b/api/tests/certification/enrolment/unit/application/country-controller_test.js @@ -3,7 +3,7 @@ import { usecases } from '../../../../../src/certification/enrolment/domain/usec import { domainBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, hFake, sinon, } from '../../../../test-helper.js'; @@ -45,7 +45,7 @@ describe('Certification | Enrolment | Unit | Application | country-controller', const request = { params: { id: 'course_id' }, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), pre: { userId }, }; diff --git a/api/tests/prescription/learner-management/unit/application/organization-learners-route_test.js b/api/tests/prescription/learner-management/unit/application/organization-learners-route_test.js index f745cc2d641..d76d97ced19 100644 --- a/api/tests/prescription/learner-management/unit/application/organization-learners-route_test.js +++ b/api/tests/prescription/learner-management/unit/application/organization-learners-route_test.js @@ -1,7 +1,7 @@ import { organizationLearnersController } from '../../../../../src/prescription/learner-management/application/organization-learners-controller.js'; import * as moduleUnderTest from '../../../../../src/prescription/learner-management/application/organization-learners-route.js'; import { securityPreHandlers } from '../../../../../src/shared/application/security-pre-handlers.js'; -import { expect, generateValidRequestAuthorizationHeader, HttpTestServer, sinon } from '../../../../test-helper.js'; +import { expect, generateAuthenticatedUserRequestHeaders, HttpTestServer, sinon } from '../../../../test-helper.js'; describe('Unit | Prescription | learner management | Application | Router | organization-learner-router', function () { describe('DELETE /api/admin/organization-learners/{id}/association', function () { @@ -86,7 +86,7 @@ describe('Unit | Prescription | learner management | Application | Router | orga beforeEach(async function () { method = 'POST'; url = '/api/organization-learners/reconcile'; - headers = { authorization: generateValidRequestAuthorizationHeader(666) }; + headers = generateAuthenticatedUserRequestHeaders({ userId: 666 }); reconcileCommonOrganizationLearnerStub = sinon .stub(organizationLearnersController, 'reconcileCommonOrganizationLearner') diff --git a/api/tests/prescription/organization-place/unit/application/organization-place-route_test.js b/api/tests/prescription/organization-place/unit/application/organization-place-route_test.js index 2fdde91afe0..28fcd188d59 100644 --- a/api/tests/prescription/organization-place/unit/application/organization-place-route_test.js +++ b/api/tests/prescription/organization-place/unit/application/organization-place-route_test.js @@ -7,7 +7,7 @@ import { usecases } from '../../../../../src/prescription/organization-place/dom import { securityPreHandlers } from '../../../../../src/shared/application/security-pre-handlers.js'; import { ORGANIZATION_FEATURE } from '../../../../../src/shared/domain/constants.js'; import { EntityValidationError } from '../../../../../src/shared/domain/errors.js'; -import { expect, generateValidRequestAuthorizationHeader, sinon } from '../../../../test-helper.js'; +import { expect, generateAuthenticatedUserRequestHeaders, sinon } from '../../../../test-helper.js'; import { HttpTestServer } from '../../../../tooling/server/http-test-server.js'; describe('Unit | Router | organization-place-route', function () { @@ -51,9 +51,7 @@ describe('Unit | Router | organization-place-route', function () { const url = `/api/admin/organizations/${idNotNumeric}/places`; // when - const response = await httpTestServer.request(method, url, null, null, { - authorization: generateValidRequestAuthorizationHeader(), - }); + const response = await httpTestServer.request(method, url, null, null, generateAuthenticatedUserRequestHeaders()); // then expect(response.statusCode).to.equal(400); @@ -68,9 +66,7 @@ describe('Unit | Router | organization-place-route', function () { const url = '/api/admin/organizations/1/places'; // when - const response = await httpTestServer.request(method, url, null, null, { - authorization: generateValidRequestAuthorizationHeader(), - }); + const response = await httpTestServer.request(method, url, null, null, generateAuthenticatedUserRequestHeaders()); // then expect(response.statusCode).to.equal(200); @@ -103,9 +99,13 @@ describe('Unit | Router | organization-place-route', function () { }; // when - const response = await httpTestServer.request(method, url, payload, null, { - authorization: generateValidRequestAuthorizationHeader(), - }); + const response = await httpTestServer.request( + method, + url, + payload, + null, + generateAuthenticatedUserRequestHeaders(), + ); // then expect(response.statusCode).to.equal(201); @@ -133,9 +133,13 @@ describe('Unit | Router | organization-place-route', function () { }; // when - const response = await httpTestServer.request(method, url, payload, null, { - authorization: generateValidRequestAuthorizationHeader(), - }); + const response = await httpTestServer.request( + method, + url, + payload, + null, + generateAuthenticatedUserRequestHeaders(), + ); // then expect(response.statusCode).to.equal(403); @@ -156,9 +160,13 @@ describe('Unit | Router | organization-place-route', function () { }; // when - const response = await httpTestServer.request(method, url, payload, null, { - authorization: generateValidRequestAuthorizationHeader(), - }); + const response = await httpTestServer.request( + method, + url, + payload, + null, + generateAuthenticatedUserRequestHeaders(), + ); // then expect(response.statusCode).to.equal(422); @@ -178,9 +186,13 @@ describe('Unit | Router | organization-place-route', function () { organizationPlaceController.getOrganizationPlacesStatistics.callsFake((_, h) => h.response('ok').code(200)); // when - const response = await httpTestServer.request(method, url, payload, null, { - authorization: generateValidRequestAuthorizationHeader(), - }); + const response = await httpTestServer.request( + method, + url, + payload, + null, + generateAuthenticatedUserRequestHeaders(), + ); // then expect(organizationPlaceController.getOrganizationPlacesStatistics).to.have.been.calledOnce; @@ -197,9 +209,13 @@ describe('Unit | Router | organization-place-route', function () { checkOrganizationHasPlacesFeature.resolves(true); // when - const response = await httpTestServer.request(method, url, payload, null, { - authorization: generateValidRequestAuthorizationHeader(), - }); + const response = await httpTestServer.request( + method, + url, + payload, + null, + generateAuthenticatedUserRequestHeaders(), + ); // then expect(response.statusCode).to.equal(403); @@ -215,9 +231,13 @@ describe('Unit | Router | organization-place-route', function () { checkOrganizationHasPlacesFeature.callsFake(respondWithError); // when - const response = await httpTestServer.request(method, url, payload, null, { - authorization: generateValidRequestAuthorizationHeader(), - }); + const response = await httpTestServer.request( + method, + url, + payload, + null, + generateAuthenticatedUserRequestHeaders(), + ); // then expect(response.statusCode).to.equal(403); diff --git a/api/tests/shared/unit/application/assessments/assessment-controller-get-next-challenge_test.js b/api/tests/shared/unit/application/assessments/assessment-controller-get-next-challenge_test.js index ece032cc5fa..3874969df04 100644 --- a/api/tests/shared/unit/application/assessments/assessment-controller-get-next-challenge_test.js +++ b/api/tests/shared/unit/application/assessments/assessment-controller-get-next-challenge_test.js @@ -3,7 +3,7 @@ import { assessmentController } from '../../../../../src/shared/application/asse import { LOCALE } from '../../../../../src/shared/domain/constants.js'; import { AssessmentEndedError } from '../../../../../src/shared/domain/errors.js'; import { Assessment } from '../../../../../src/shared/domain/models/Assessment.js'; -import { domainBuilder, expect, generateValidRequestAuthorizationHeader, sinon } from '../../../../test-helper.js'; +import { domainBuilder, expect, generateAuthenticatedUserRequestHeaders, sinon } from '../../../../test-helper.js'; const { FRENCH_FRANCE, FRENCH_SPOKEN } = LOCALE; @@ -225,10 +225,7 @@ describe('Unit | Controller | assessment-controller-get-next-challenge', functio const locale = FRENCH_SPOKEN; const request = { params: { id: 1 }, - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - 'accept-language': locale, - }, + headers: generateAuthenticatedUserRequestHeaders({ userId, acceptLanguage: locale }), }; // when await assessmentController.getNextChallenge(request, null, dependencies); @@ -259,10 +256,7 @@ describe('Unit | Controller | assessment-controller-get-next-challenge', functio const locale = FRENCH_SPOKEN; const request = { params: { id: 1 }, - headers: { - authorization: generateValidRequestAuthorizationHeader(1), - 'accept-language': locale, - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: 1, locale }), }; // when @@ -299,10 +293,7 @@ describe('Unit | Controller | assessment-controller-get-next-challenge', functio const locale = FRENCH_SPOKEN; const request = { params: { id: 1 }, - headers: { - authorization: generateValidRequestAuthorizationHeader(1), - 'accept-language': locale, - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: 1, locale }), }; // when diff --git a/api/tests/shared/unit/application/courses/course-controller_test.js b/api/tests/shared/unit/application/courses/course-controller_test.js index 39c7adfff44..6bad0b13fe7 100644 --- a/api/tests/shared/unit/application/courses/course-controller_test.js +++ b/api/tests/shared/unit/application/courses/course-controller_test.js @@ -1,6 +1,6 @@ import { courseController } from '../../../../../src/shared/application/courses/course-controller.js'; import { Course } from '../../../../../src/shared/domain/models/Course.js'; -import { expect, generateValidRequestAuthorizationHeader, hFake, sinon } from '../../../../test-helper.js'; +import { expect, generateAuthenticatedUserRequestHeaders, hFake, sinon } from '../../../../test-helper.js'; describe('Unit | Controller | course-controller', function () { let courseServiceStub; @@ -25,7 +25,7 @@ describe('Unit | Controller | course-controller', function () { courseSerializerStub.serialize.callsFake(() => course); const request = { params: { id: 'course_id' }, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), pre: { userId }, }; diff --git a/api/tests/shared/unit/infrastructure/utils/request-response-utils_test.js b/api/tests/shared/unit/infrastructure/utils/request-response-utils_test.js index 6a2f5e8639f..c773ff3f77c 100644 --- a/api/tests/shared/unit/infrastructure/utils/request-response-utils_test.js +++ b/api/tests/shared/unit/infrastructure/utils/request-response-utils_test.js @@ -4,7 +4,7 @@ import { extractLocaleFromRequest, extractUserIdFromRequest, } from '../../../../../src/shared/infrastructure/utils/request-response-utils.js'; -import { expect, generateValidRequestAuthorizationHeader } from '../../../../test-helper.js'; +import { expect, generateAuthenticatedUserRequestHeaders } from '../../../../test-helper.js'; const { ENGLISH_SPOKEN, FRENCH_FRANCE, FRENCH_SPOKEN } = LOCALE; @@ -14,7 +14,7 @@ describe('Unit | Utils | Request Utils', function () { // given const userId = 4; const request = { - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when const result = extractUserIdFromRequest(request); diff --git a/api/tests/unit/application/certification-courses/certification-course-controller_test.js b/api/tests/unit/application/certification-courses/certification-course-controller_test.js index 10b0c84a17c..81539cdbd80 100644 --- a/api/tests/unit/application/certification-courses/certification-course-controller_test.js +++ b/api/tests/unit/application/certification-courses/certification-course-controller_test.js @@ -2,7 +2,7 @@ import { certificationCourseController } from '../../../../src/certification/eva import { usecases } from '../../../../src/certification/evaluation/domain/usecases/index.js'; import { CertificationCourse } from '../../../../src/certification/shared/domain/models/CertificationCourse.js'; import { usecases as certificationSharedUsecases } from '../../../../src/certification/shared/domain/usecases/index.js'; -import { expect, generateValidRequestAuthorizationHeader, hFake, sinon } from '../../../test-helper.js'; +import { expect, generateAuthenticatedUserRequestHeaders, hFake, sinon } from '../../../test-helper.js'; describe('Unit | Controller | certification-course-controller', function () { let certificationCourseSerializer; @@ -92,7 +92,7 @@ describe('Unit | Controller | certification-course-controller', function () { certificationCourseSerializer.serialize.withArgs(certificationCourse).resolves(certificationCourse); const request = { params: { id: certificationCourseId }, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), auth: { credentials: { userId } }, }; diff --git a/api/tests/unit/application/frameworks/index_test.js b/api/tests/unit/application/frameworks/index_test.js index 520ac23377f..5d960194465 100644 --- a/api/tests/unit/application/frameworks/index_test.js +++ b/api/tests/unit/application/frameworks/index_test.js @@ -1,7 +1,7 @@ import { frameworksController } from '../../../../lib/application/frameworks/frameworks-controller.js'; import * as moduleUnderTest from '../../../../lib/application/frameworks/index.js'; import { securityPreHandlers } from '../../../../src/shared/application/security-pre-handlers.js'; -import { expect, generateValidRequestAuthorizationHeader, HttpTestServer, sinon } from '../../../test-helper.js'; +import { expect, generateAuthenticatedUserRequestHeaders, HttpTestServer, sinon } from '../../../test-helper.js'; describe('Unit | Application | Frameworks | Routes', function () { describe('GET /api/admin/frameworks', function () { @@ -120,9 +120,7 @@ describe('Unit | Application | Frameworks | Routes', function () { const httpTestServer = new HttpTestServer(); httpTestServer.setupAuthentication(); await httpTestServer.register(moduleUnderTest); - const headers = { - authorization: generateValidRequestAuthorizationHeader(), - }; + const headers = generateAuthenticatedUserRequestHeaders(); // when const { statusCode } = await httpTestServer.request(method, url, null, null, headers); diff --git a/api/tests/unit/application/organizations/organization-controller_test.js b/api/tests/unit/application/organizations/organization-controller_test.js index d6c74e1c9ab..57ceb8f95c8 100644 --- a/api/tests/unit/application/organizations/organization-controller_test.js +++ b/api/tests/unit/application/organizations/organization-controller_test.js @@ -1,7 +1,7 @@ import { organizationController } from '../../../../lib/application/organizations/organization-controller.js'; import { usecases } from '../../../../lib/domain/usecases/index.js'; import { Organization } from '../../../../src/shared/domain/models/index.js'; -import { expect, generateValidRequestAuthorizationHeader, hFake, sinon } from '../../../test-helper.js'; +import { expect, generateAuthenticatedUserRequestHeaders, hFake, sinon } from '../../../test-helper.js'; describe('Unit | Application | Organizations | organization-controller', function () { describe('#findPaginatedFilteredOrganizations', function () { @@ -132,9 +132,7 @@ describe('Unit | Application | Organizations | organization-controller', functio const organizationId = 1234; const userId = 10; const request = { - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), params: { id: organizationId }, }; From c6ea7f2807261c542f5207cfc6d8d2bc0ee17093 Mon Sep 17 00:00:00 2001 From: LEGO Technix <109212476+lego-technix@users.noreply.github.com> Date: Thu, 23 Jan 2025 16:54:53 +0100 Subject: [PATCH 5/9] test(api): in integration tests use new generateAuthenticatedUserRequestHeaders helper to have a valid authentication through a user Access Tokens now with audience --- .../anonymization.admin.route.test.js | 8 +-- .../application/user/user.route.test.js | 18 ++---- .../infrastructure/plugins/pino_test.js | 6 +- .../organization-administration.route.test.js | 30 +++------- .../campaign-administration-route_test.js | 14 ++--- .../campaign-results-route_test.js | 18 ++---- .../organization-learners-route_test.js | 44 +++++---------- ...sup-organization-management-routes_test.js | 6 +- .../organization-place-controller_test.js | 6 +- .../organization-place-route_test.js | 56 ++++++++++++------- .../admin-target-profile-route_test.js | 6 +- .../application/target-profile-route_test.js | 10 +--- .../application/security-pre-handlers_test.js | 26 ++++----- 13 files changed, 100 insertions(+), 148 deletions(-) diff --git a/api/tests/identity-access-management/integration/application/anonymization.admin.route.test.js b/api/tests/identity-access-management/integration/application/anonymization.admin.route.test.js index 24f69c31f69..a62d1a3abce 100644 --- a/api/tests/identity-access-management/integration/application/anonymization.admin.route.test.js +++ b/api/tests/identity-access-management/integration/application/anonymization.admin.route.test.js @@ -3,7 +3,7 @@ import { identityAccessManagementRoutes } from '../../../../src/identity-access- import { databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, HttpTestServer, } from '../../../test-helper.js'; @@ -31,7 +31,7 @@ describe('Integration | Identity Access Management | Application | Route | Anony data: {}, }, null, - { authorization: generateValidRequestAuthorizationHeader(user.id) }, + generateAuthenticatedUserRequestHeaders({ userId: user.id }), ); // then @@ -51,7 +51,7 @@ describe('Integration | Identity Access Management | Application | Route | Anony const options = { method: 'POST', - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), url: '/api/admin/anonymize/gar', payload: input, }; @@ -76,7 +76,7 @@ describe('Integration | Identity Access Management | Application | Route | Anony const options = { method: 'POST', - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), url: '/api/admin/anonymize/gar', payload: input, }; diff --git a/api/tests/identity-access-management/integration/application/user/user.route.test.js b/api/tests/identity-access-management/integration/application/user/user.route.test.js index 93893c5b33c..52a2e158543 100644 --- a/api/tests/identity-access-management/integration/application/user/user.route.test.js +++ b/api/tests/identity-access-management/integration/application/user/user.route.test.js @@ -5,7 +5,7 @@ import * as i18nPlugin from '../../../../../src/shared/infrastructure/plugins/i1 import { databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, HttpTestServer, sinon, } from '../../../../test-helper.js'; @@ -121,9 +121,7 @@ describe('Integration | Identity Access Management | Application | Route | User' const userId = databaseBuilder.factory.buildUser().id; const url = '/api/users/me'; - const headers = { - authorization: generateValidRequestAuthorizationHeader(userId), - }; + const headers = generateAuthenticatedUserRequestHeaders({ userId }); // when const response = await httpTestServer.request('DELETE', url, null, null, headers); @@ -138,9 +136,7 @@ describe('Integration | Identity Access Management | Application | Route | User' it('returns controller success response HTTP code', async function () { // given const userId = databaseBuilder.factory.buildUser().id; - const headers = { - authorization: generateValidRequestAuthorizationHeader(userId), - }; + const headers = generateAuthenticatedUserRequestHeaders({ userId }); sinon.stub(userController, 'getCertificationPointOfContact').callsFake((request, h) => h.response().code(200)); // when @@ -161,9 +157,7 @@ describe('Integration | Identity Access Management | Application | Route | User' it('should return 400 - Bad request when challengeType is not valid', async function () { // given const userId = databaseBuilder.factory.buildUser().id; - const headers = { - authorization: generateValidRequestAuthorizationHeader(userId), - }; + const headers = generateAuthenticatedUserRequestHeaders({ userId }); const url = `/api/users/${userId}/has-seen-challenge-tooltip/invalid`; // when @@ -176,9 +170,7 @@ describe('Integration | Identity Access Management | Application | Route | User' it('should return 200 when challengeType is valid', async function () { // given const userId = databaseBuilder.factory.buildUser().id; - const headers = { - authorization: generateValidRequestAuthorizationHeader(userId), - }; + const headers = generateAuthenticatedUserRequestHeaders({ userId }); const url = `/api/users/${userId}/has-seen-challenge-tooltip/other`; // when diff --git a/api/tests/integration/infrastructure/plugins/pino_test.js b/api/tests/integration/infrastructure/plugins/pino_test.js index 7f876b57cc8..dda95545266 100644 --- a/api/tests/integration/infrastructure/plugins/pino_test.js +++ b/api/tests/integration/infrastructure/plugins/pino_test.js @@ -5,7 +5,7 @@ import pino from 'pino'; import { config } from '../../../../src/shared/config.js'; import { monitoringTools } from '../../../../src/shared/infrastructure/monitoring-tools.js'; import * as pinoPlugin from '../../../../src/shared/infrastructure/plugins/pino.js'; -import { expect, generateValidRequestAuthorizationHeader, HttpTestServer, sinon } from '../../../test-helper.js'; +import { expect, generateAuthenticatedUserRequestHeaders, HttpTestServer, sinon } from '../../../test-helper.js'; describe('Integration | Infrastructure | plugins | pino', function () { let httpTestServer; @@ -134,9 +134,7 @@ describe('Integration | Infrastructure | plugins | pino', function () { const method = 'GET'; const url = '/'; - const headers = { - authorization: generateValidRequestAuthorizationHeader(), - }; + const headers = generateAuthenticatedUserRequestHeaders(); // when const response = await httpTestServer.request(method, url, null, null, headers); diff --git a/api/tests/organizational-entities/integration/application/organization-administration.route.test.js b/api/tests/organizational-entities/integration/application/organization-administration.route.test.js index 3777c2df8d1..0d086dba3ff 100644 --- a/api/tests/organizational-entities/integration/application/organization-administration.route.test.js +++ b/api/tests/organizational-entities/integration/application/organization-administration.route.test.js @@ -4,7 +4,7 @@ import { logo3Mb } from '../../../integration/application/organizations-administ import { databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, HttpTestServer, sinon, } from '../../../test-helper.js'; @@ -40,9 +40,7 @@ describe('Integration | Organizational Entities | Application | Route | Organiza const wrongUrl = '/api/admin/organizations/coucou'; const simpleUserId = databaseBuilder.factory.buildUser().id; await databaseBuilder.commit(); - headers = { - authorization: generateValidRequestAuthorizationHeader(simpleUserId), - }; + headers = generateAuthenticatedUserRequestHeaders({ userId: simpleUserId }); // when const response = await httpTestServer.request(method, wrongUrl, null, null, headers); @@ -55,9 +53,7 @@ describe('Integration | Organizational Entities | Application | Route | Organiza // given const simpleUserId = databaseBuilder.factory.buildUser().id; await databaseBuilder.commit(); - headers = { - authorization: generateValidRequestAuthorizationHeader(simpleUserId), - }; + headers = generateAuthenticatedUserRequestHeaders({ userId: simpleUserId }); // when const response = await httpTestServer.request(method, url, null, null, headers); @@ -70,9 +66,7 @@ describe('Integration | Organizational Entities | Application | Route | Organiza // given const certifUserId = databaseBuilder.factory.buildUser.withRole({ role: 'CERTIF' }).id; await databaseBuilder.commit(); - headers = { - authorization: generateValidRequestAuthorizationHeader(certifUserId), - }; + headers = generateAuthenticatedUserRequestHeaders({ userId: certifUserId }); // when const response = await httpTestServer.request(method, url, null, null, headers); @@ -85,9 +79,7 @@ describe('Integration | Organizational Entities | Application | Route | Organiza // given const supportUserId = databaseBuilder.factory.buildUser.withRole({ role: 'SUPPORT' }).id; await databaseBuilder.commit(); - headers = { - authorization: generateValidRequestAuthorizationHeader(supportUserId), - }; + headers = generateAuthenticatedUserRequestHeaders({ userId: supportUserId }); // when await httpTestServer.request(method, url, null, null, headers); @@ -100,9 +92,7 @@ describe('Integration | Organizational Entities | Application | Route | Organiza // given const adminUserId = databaseBuilder.factory.buildUser.withRole({ role: 'SUPER_ADMIN' }).id; await databaseBuilder.commit(); - headers = { - authorization: generateValidRequestAuthorizationHeader(adminUserId), - }; + headers = generateAuthenticatedUserRequestHeaders({ userId: adminUserId }); // when await httpTestServer.request(method, url, null, null, headers); @@ -115,9 +105,7 @@ describe('Integration | Organizational Entities | Application | Route | Organiza // given const metierUserId = databaseBuilder.factory.buildUser.withRole({ role: 'METIER' }).id; await databaseBuilder.commit(); - headers = { - authorization: generateValidRequestAuthorizationHeader(metierUserId), - }; + headers = generateAuthenticatedUserRequestHeaders({ userId: metierUserId }); // when await httpTestServer.request(method, url, null, null, headers); @@ -130,9 +118,7 @@ describe('Integration | Organizational Entities | Application | Route | Organiza // given const metierUserId = databaseBuilder.factory.buildUser.withRole({ role: 'METIER' }).id; await databaseBuilder.commit(); - headers = { - authorization: generateValidRequestAuthorizationHeader(metierUserId), - }; + headers = generateAuthenticatedUserRequestHeaders({ userId: metierUserId }); const payload = { data: { diff --git a/api/tests/prescription/campaign/integration/application/campaign-administration-route_test.js b/api/tests/prescription/campaign/integration/application/campaign-administration-route_test.js index 9c2979e5901..4ef5a7b3e02 100644 --- a/api/tests/prescription/campaign/integration/application/campaign-administration-route_test.js +++ b/api/tests/prescription/campaign/integration/application/campaign-administration-route_test.js @@ -7,7 +7,7 @@ import { ObjectValidationError } from '../../../../../src/shared/domain/errors.j import { databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, HttpTestServer, sinon, } from '../../../../test-helper.js'; @@ -40,9 +40,7 @@ describe('Integration | Application | Route | campaign administration router', f httpTestServer = new HttpTestServer(); await httpTestServer.register(moduleUnderTest); - const headers = { - authorization: generateValidRequestAuthorizationHeader(simpleUserId), - }; + const headers = generateAuthenticatedUserRequestHeaders({ userId: simpleUserId }); const payload = { firstCampaignId: 2, @@ -66,9 +64,7 @@ describe('Integration | Application | Route | campaign administration router', f httpTestServer = new HttpTestServer(); await httpTestServer.register(moduleUnderTest); - const headers = { - authorization: generateValidRequestAuthorizationHeader(simpleUserId), - }; + const headers = generateAuthenticatedUserRequestHeaders({ userId: simpleUserId }); const payload = { campaignCode: 'CAMPAIGN', @@ -106,9 +102,7 @@ describe('Integration | Application | Route | campaign administration router', f httpTestServer.setupDeserialization(); await httpTestServer.register(moduleUnderTest); - const headers = { - authorization: generateValidRequestAuthorizationHeader(userId), - }; + const headers = generateAuthenticatedUserRequestHeaders({ userId }); // when const response = await httpTestServer.request(method, url, payload, null, headers); diff --git a/api/tests/prescription/campaign/integration/application/campaign-results-route_test.js b/api/tests/prescription/campaign/integration/application/campaign-results-route_test.js index aa7e2d0e10d..1796ba30cd7 100644 --- a/api/tests/prescription/campaign/integration/application/campaign-results-route_test.js +++ b/api/tests/prescription/campaign/integration/application/campaign-results-route_test.js @@ -3,7 +3,7 @@ import * as moduleUnderTest from '../../../../../src/prescription/campaign/appli import { databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, HttpTestServer, sinon, } from '../../../../test-helper.js'; @@ -43,9 +43,7 @@ describe('Integration | Application | campaign-results-route', function () { const simpleUserId = databaseBuilder.factory.buildUser().id; await databaseBuilder.commit(); - headers = { - authorization: generateValidRequestAuthorizationHeader(simpleUserId), - }; + headers = generateAuthenticatedUserRequestHeaders({ userId: simpleUserId }); // when const response = await httpTestServer.request(method, url, null, null, headers); @@ -60,9 +58,7 @@ describe('Integration | Application | campaign-results-route', function () { const userId = databaseBuilder.factory.buildUser().id; databaseBuilder.factory.buildMembership({ organizationId, userId, organizationRole: 'MEMBER' }); await databaseBuilder.commit(); - headers = { - authorization: generateValidRequestAuthorizationHeader(userId), - }; + headers = generateAuthenticatedUserRequestHeaders({ userId }); // when const response = await httpTestServer.request(method, wrongUrl, null, null, headers); @@ -106,9 +102,7 @@ describe('Integration | Application | campaign-results-route', function () { const simpleUserId = databaseBuilder.factory.buildUser().id; await databaseBuilder.commit(); - headers = { - authorization: generateValidRequestAuthorizationHeader(simpleUserId), - }; + headers = generateAuthenticatedUserRequestHeaders({ userId: simpleUserId }); // when const response = await httpTestServer.request(method, url, null, null, headers); @@ -123,9 +117,7 @@ describe('Integration | Application | campaign-results-route', function () { const userId = databaseBuilder.factory.buildUser().id; databaseBuilder.factory.buildMembership({ organizationId, userId, organizationRole: 'MEMBER' }); await databaseBuilder.commit(); - headers = { - authorization: generateValidRequestAuthorizationHeader(userId), - }; + headers = generateAuthenticatedUserRequestHeaders({ userId }); // when const response = await httpTestServer.request(method, wrongUrl, null, null, headers); diff --git a/api/tests/prescription/learner-management/integration/application/organization-learners-route_test.js b/api/tests/prescription/learner-management/integration/application/organization-learners-route_test.js index 3eb5bcce94e..89621fecd30 100644 --- a/api/tests/prescription/learner-management/integration/application/organization-learners-route_test.js +++ b/api/tests/prescription/learner-management/integration/application/organization-learners-route_test.js @@ -4,7 +4,7 @@ import { ORGANIZATION_FEATURE } from '../../../../../src/shared/domain/constants import { databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, HttpTestServer, sinon, } from '../../../../test-helper.js'; @@ -43,12 +43,10 @@ describe('Integration | Application | Organization Learners Management | Routes' const simpleUserId = databaseBuilder.factory.buildUser().id; databaseBuilder.factory.buildMembership({ organizationId, userId: simpleUserId, organizationRole: 'MEMBER' }); await databaseBuilder.commit(); - headers = { - authorization: generateValidRequestAuthorizationHeader(simpleUserId), - }; - payload = { - listLearners: [123], - }; + (headers = generateAuthenticatedUserRequestHeaders({ userId: simpleUserId })), + (payload = { + listLearners: [123], + }); // when const response = await httpTestServer.request(method, url, payload, null, headers); @@ -63,9 +61,7 @@ describe('Integration | Application | Organization Learners Management | Routes' const adminUser = databaseBuilder.factory.buildUser().id; databaseBuilder.factory.buildMembership({ organizationId, userId: adminUser, organizationRole: 'ADMIN' }); await databaseBuilder.commit(); - headers = { - authorization: generateValidRequestAuthorizationHeader(adminUser), - }; + headers = generateAuthenticatedUserRequestHeaders({ userId: adminUser }); payload = { listLearners: [123], }; @@ -83,9 +79,7 @@ describe('Integration | Application | Organization Learners Management | Routes' const adminUser = databaseBuilder.factory.buildUser().id; databaseBuilder.factory.buildMembership({ organizationId, userId: adminUser, organizationRole: 'ADMIN' }); await databaseBuilder.commit(); - headers = { - authorization: generateValidRequestAuthorizationHeader(adminUser), - }; + headers = generateAuthenticatedUserRequestHeaders({ userId: adminUser }); payload = { listLearners: [123], }; @@ -103,9 +97,7 @@ describe('Integration | Application | Organization Learners Management | Routes' const adminUser = databaseBuilder.factory.buildUser().id; databaseBuilder.factory.buildMembership({ organizationId, userId: adminUser, organizationRole: 'ADMIN' }); await databaseBuilder.commit(); - headers = { - authorization: generateValidRequestAuthorizationHeader(adminUser), - }; + headers = generateAuthenticatedUserRequestHeaders({ userId: adminUser }); payload = { listLearners: ['VIVEDIABLO'], }; @@ -137,9 +129,7 @@ describe('Integration | Application | Organization Learners Management | Routes' const wrongUrl = `/api/organizations/noop/import-organization-learners`; const user = databaseBuilder.factory.buildUser().id; await databaseBuilder.commit(); - headers = { - authorization: generateValidRequestAuthorizationHeader(user), - }; + headers = generateAuthenticatedUserRequestHeaders({ userId: user }); payload = buffer; // when @@ -169,9 +159,7 @@ describe('Integration | Application | Organization Learners Management | Routes' const simpleUserId = databaseBuilder.factory.buildUser().id; databaseBuilder.factory.buildMembership({ organizationId, userId: simpleUserId, organizationRole: 'MEMBER' }); await databaseBuilder.commit(); - headers = { - authorization: generateValidRequestAuthorizationHeader(simpleUserId), - }; + headers = generateAuthenticatedUserRequestHeaders({ userId: simpleUserId }); payload = buffer; // when @@ -187,9 +175,7 @@ describe('Integration | Application | Organization Learners Management | Routes' const adminUser = databaseBuilder.factory.buildUser().id; databaseBuilder.factory.buildMembership({ organizationId, userId: adminUser, organizationRole: 'ADMIN' }); await databaseBuilder.commit(); - headers = { - authorization: generateValidRequestAuthorizationHeader(adminUser), - }; + headers = generateAuthenticatedUserRequestHeaders({ userId: adminUser }); payload = buffer; // when @@ -211,9 +197,7 @@ describe('Integration | Application | Organization Learners Management | Routes' databaseBuilder.factory.buildOrganizationFeature({ featureId, organizationId }); await databaseBuilder.commit(); - headers = { - authorization: generateValidRequestAuthorizationHeader(adminUser), - }; + headers = generateAuthenticatedUserRequestHeaders({ userId: adminUser }); payload = buffer; // when @@ -233,9 +217,7 @@ describe('Integration | Application | Organization Learners Management | Routes' databaseBuilder.factory.buildOrganizationFeature({ featureId, organizationId }); await databaseBuilder.commit(); - headers = { - authorization: generateValidRequestAuthorizationHeader(adminUser), - }; + headers = generateAuthenticatedUserRequestHeaders({ userId: adminUser }); payload = buffer; // when diff --git a/api/tests/prescription/learner-management/integration/application/sup-organization-management-routes_test.js b/api/tests/prescription/learner-management/integration/application/sup-organization-management-routes_test.js index c9b5233c387..10710587f59 100644 --- a/api/tests/prescription/learner-management/integration/application/sup-organization-management-routes_test.js +++ b/api/tests/prescription/learner-management/integration/application/sup-organization-management-routes_test.js @@ -1,7 +1,7 @@ import { supOrganizationManagementController } from '../../../../../src/prescription/learner-management/application/sup-organization-management-controller.js'; import * as moduleUnderTest from '../../../../../src/prescription/learner-management/application/sup-organization-management-route.js'; import { securityPreHandlers } from '../../../../../src/shared/application/security-pre-handlers.js'; -import { expect, generateValidRequestAuthorizationHeader, HttpTestServer, sinon } from '../../../../test-helper.js'; +import { expect, generateAuthenticatedUserRequestHeaders, HttpTestServer, sinon } from '../../../../test-helper.js'; describe('Integration | Application | Route | sup-organization-learners', function () { let httpTestServer; @@ -28,9 +28,7 @@ describe('Integration | Application | Route | sup-organization-learners', functi let headers; beforeEach(function () { - headers = { - authorization: generateValidRequestAuthorizationHeader(userId), - }; + headers = generateAuthenticatedUserRequestHeaders({ userId }); }); context('when the user is authenticated', function () { diff --git a/api/tests/prescription/organization-place/integration/application/organization-place-controller_test.js b/api/tests/prescription/organization-place/integration/application/organization-place-controller_test.js index bfa6b6830fa..964c7bbb09a 100644 --- a/api/tests/prescription/organization-place/integration/application/organization-place-controller_test.js +++ b/api/tests/prescription/organization-place/integration/application/organization-place-controller_test.js @@ -4,7 +4,7 @@ import { securityPreHandlers } from '../../../../../src/shared/application/secur import { domainBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, HttpTestServer, sinon, } from '../../../../test-helper.js'; @@ -57,9 +57,7 @@ describe('Integration | Application | organization-place-controller', function ( `/api/admin/organizations/${organizationId}/places`, null, null, - { - authorization: generateValidRequestAuthorizationHeader(), - }, + generateAuthenticatedUserRequestHeaders(), ); // then diff --git a/api/tests/prescription/organization-place/integration/application/organization-place-route_test.js b/api/tests/prescription/organization-place/integration/application/organization-place-route_test.js index acb94aba9f3..8151117b4da 100644 --- a/api/tests/prescription/organization-place/integration/application/organization-place-route_test.js +++ b/api/tests/prescription/organization-place/integration/application/organization-place-route_test.js @@ -2,7 +2,7 @@ import { organizationPlaceController } from '../../../../../src/prescription/org import * as moduleUnderTest from '../../../../../src/prescription/organization-place/application/organization-place-route.js'; import { securityPreHandlers } from '../../../../../src/shared/application/security-pre-handlers.js'; import { ORGANIZATION_FEATURE } from '../../../../../src/shared/domain/constants.js'; -import { expect, generateValidRequestAuthorizationHeader, HttpTestServer, sinon } from '../../../../test-helper.js'; +import { expect, generateAuthenticatedUserRequestHeaders, HttpTestServer, sinon } from '../../../../test-helper.js'; describe('Integration | Application | organization-place-route', function () { describe('GET /api/admin/organizations/:id/places', function () { @@ -21,9 +21,7 @@ describe('Integration | Application | organization-place-route', function () { await httpTestServer.register(moduleUnderTest); // when - const response = await httpTestServer.request(method, url, null, null, { - authorization: generateValidRequestAuthorizationHeader(), - }); + const response = await httpTestServer.request(method, url, null, null, generateAuthenticatedUserRequestHeaders()); // then expect(response.statusCode).to.equal(200); @@ -51,9 +49,13 @@ describe('Integration | Application | organization-place-route', function () { await httpTestServer.register(moduleUnderTest); // when - const response = await httpTestServer.request(method, url, null, null, { - authorization: generateValidRequestAuthorizationHeader(), - }); + const response = await httpTestServer.request( + method, + url, + null, + null, + generateAuthenticatedUserRequestHeaders(), + ); // then expect(organizationPlaceController.findOrganizationPlacesLot).to.not.have.been.called; @@ -97,9 +99,13 @@ describe('Integration | Application | organization-place-route', function () { await httpTestServer.register(moduleUnderTest); // when - const response = await httpTestServer.request(method, url, payload, null, { - authorization: generateValidRequestAuthorizationHeader(), - }); + const response = await httpTestServer.request( + method, + url, + payload, + null, + generateAuthenticatedUserRequestHeaders(), + ); // then expect(organizationPlaceController.getOrganizationPlacesLots).to.have.been.calledOnce; @@ -114,9 +120,13 @@ describe('Integration | Application | organization-place-route', function () { checkOrganizationHasPlacesFeature.resolves(true); // when - const response = await httpTestServer.request(method, url, payload, null, { - authorization: generateValidRequestAuthorizationHeader(), - }); + const response = await httpTestServer.request( + method, + url, + payload, + null, + generateAuthenticatedUserRequestHeaders(), + ); // then expect(organizationPlaceController.getOrganizationPlacesLots).to.not.have.been.called; @@ -129,9 +139,13 @@ describe('Integration | Application | organization-place-route', function () { checkOrganizationHasPlacesFeature.callsFake((request, h) => h.response({ errors: new Error('forbidden') })); // when - const response = await httpTestServer.request(method, url, payload, null, { - authorization: generateValidRequestAuthorizationHeader(), - }); + const response = await httpTestServer.request( + method, + url, + payload, + null, + generateAuthenticatedUserRequestHeaders(), + ); // then expect(organizationPlaceController.getOrganizationPlacesLots).to.not.have.been.called; @@ -145,9 +159,13 @@ describe('Integration | Application | organization-place-route', function () { checkOrganizationHasPlacesFeature.resolves(true); // when - const response = await httpTestServer.request(method, url, payload, null, { - authorization: generateValidRequestAuthorizationHeader(), - }); + const response = await httpTestServer.request( + method, + url, + payload, + null, + generateAuthenticatedUserRequestHeaders(), + ); // then expect(organizationPlaceController.getOrganizationPlacesLots).to.not.have.been.called; diff --git a/api/tests/prescription/target-profile/integration/application/admin-target-profile-route_test.js b/api/tests/prescription/target-profile/integration/application/admin-target-profile-route_test.js index ec4fe234650..da4c79ba3a2 100644 --- a/api/tests/prescription/target-profile/integration/application/admin-target-profile-route_test.js +++ b/api/tests/prescription/target-profile/integration/application/admin-target-profile-route_test.js @@ -3,16 +3,14 @@ import * as moduleUnderTest from '../../../../../src/prescription/target-profile import { databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, HttpTestServer, sinon, } from '../../../../test-helper.js'; describe('Integration | Application | target-profiles-management | Routes ', function () { describe('DELETE /api/admin/target-profiles/{targetProfileId}/detach-organizations', function () { - const getHeaders = (userId) => ({ - authorization: generateValidRequestAuthorizationHeader(userId), - }); + const getHeaders = (userId) => generateAuthenticatedUserRequestHeaders({ userId }); let httpTestServer; let targetProfileId, organizationId; let method, url, payload; diff --git a/api/tests/prescription/target-profile/integration/application/target-profile-route_test.js b/api/tests/prescription/target-profile/integration/application/target-profile-route_test.js index 6769802fcd0..62289498cf4 100644 --- a/api/tests/prescription/target-profile/integration/application/target-profile-route_test.js +++ b/api/tests/prescription/target-profile/integration/application/target-profile-route_test.js @@ -3,7 +3,7 @@ import * as moduleUnderTest from '../../../../../src/prescription/target-profile import { databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, HttpTestServer, sinon, } from '../../../../test-helper.js'; @@ -40,9 +40,7 @@ describe('Integration | Application | target-profile-route', function () { const lambdaUser = databaseBuilder.factory.buildUser().id; url = `/api/organizations/${organizationId}/target-profiles`; // given - headers = { - authorization: generateValidRequestAuthorizationHeader(lambdaUser), - }; + headers = generateAuthenticatedUserRequestHeaders({ userId: lambdaUser }); // when const response = await httpTestServer.request(method, url, null, null, headers); @@ -57,9 +55,7 @@ describe('Integration | Application | target-profile-route', function () { const adminUser = databaseBuilder.factory.buildUser().id; databaseBuilder.factory.buildMembership({ organizationId, userId: adminUser, organizationRole: 'ADMIN' }); await databaseBuilder.commit(); - headers = { - authorization: generateValidRequestAuthorizationHeader(adminUser), - }; + headers = generateAuthenticatedUserRequestHeaders({ userId: adminUser }); payload = { listLearners: [123], }; diff --git a/api/tests/shared/integration/application/security-pre-handlers_test.js b/api/tests/shared/integration/application/security-pre-handlers_test.js index f5e96d2aae3..c96c6b9b961 100644 --- a/api/tests/shared/integration/application/security-pre-handlers_test.js +++ b/api/tests/shared/integration/application/security-pre-handlers_test.js @@ -5,7 +5,7 @@ import { ORGANIZATION_FEATURE } from '../../../../src/shared/domain/constants.js import { databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, HttpTestServer, sinon, } from '../../../test-helper.js'; @@ -53,7 +53,7 @@ describe('Integration | Application | SecurityPreHandlers', function () { const options = { method: 'GET', url: '/api/admin/users', - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; const response = await httpServerTest.requestObject(options); @@ -68,7 +68,7 @@ describe('Integration | Application | SecurityPreHandlers', function () { const options = { method: 'GET', url: '/api/admin/users', - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; const response = await httpServerTest.requestObject(options); @@ -83,7 +83,7 @@ describe('Integration | Application | SecurityPreHandlers', function () { const response = await httpServerTest.requestObject({ method: 'GET', url: '/api/admin/users', - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }); expect(response.statusCode).to.equal(403); }); @@ -96,7 +96,7 @@ describe('Integration | Application | SecurityPreHandlers', function () { const options = { method: 'GET', url: '/api/admin/users', - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; const response = await httpServerTest.requestObject(options); @@ -152,7 +152,7 @@ describe('Integration | Application | SecurityPreHandlers', function () { const options = { method: 'GET', url: `/check/${organizationId}`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; const response = await httpServerTest.requestObject(options); @@ -170,7 +170,7 @@ describe('Integration | Application | SecurityPreHandlers', function () { const options = { method: 'GET', url: `/checkwithId/${organizationId}`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; const response = await httpServerTest.requestObject(options); @@ -187,7 +187,7 @@ describe('Integration | Application | SecurityPreHandlers', function () { const options = { method: 'GET', url: `/check/${organizationId}`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; const response = await httpServerTest.requestObject(options); @@ -232,7 +232,7 @@ describe('Integration | Application | SecurityPreHandlers', function () { const options = { method: 'GET', url: '/framework/tubes', - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; const response = await httpServerTest.requestObject(options); @@ -249,7 +249,7 @@ describe('Integration | Application | SecurityPreHandlers', function () { const options = { method: 'GET', url: '/framework/tubes', - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; const response = await httpServerTest.requestObject(options); @@ -294,7 +294,7 @@ describe('Integration | Application | SecurityPreHandlers', function () { const options = { method: 'GET', url: `/framework/${certificationCenterId}`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; const response = await httpServerTest.requestObject(options); @@ -317,7 +317,7 @@ describe('Integration | Application | SecurityPreHandlers', function () { const options = { method: 'GET', url: `/framework/${certificationCenterId}`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; const response = await httpServerTest.requestObject(options); @@ -340,7 +340,7 @@ describe('Integration | Application | SecurityPreHandlers', function () { const options = { method: 'GET', url: `/framework/${certificationCenterId}`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; const response = await httpServerTest.requestObject(options); From d5e6899ac0fb65283f143760daa073c2f31d54be Mon Sep 17 00:00:00 2001 From: LEGO Technix <109212476+lego-technix@users.noreply.github.com> Date: Sat, 25 Jan 2025 18:32:38 +0100 Subject: [PATCH 6/9] test(api): in acceptance tests use new generateAuthenticatedUserRequestHeaders helper to have a valid authentication through a user Access Tokens now with audience --- .../campaign-participation-controller_test.js | 4 +- .../campaigns/campaign-controller_test.js | 6 +- .../campaign-management-controller_test.js | 4 +- .../index_test.js | 10 +-- ...ation-center-membership-controller_test.js | 38 +++-------- .../certification-center-controller_test.js | 28 +++----- .../countries/countries-controller_test.js | 6 +- .../courses/course-controller_test.js | 14 ++-- .../frameworks/frameworks-controller_test.js | 10 +-- .../memberships/membership-controller_test.js | 12 ++-- .../organization-controller_test.js | 36 +++++----- .../scenario-simulator-controller_test.js | 14 ++-- ...co-organization-learner-controller_test.js | 8 +-- ...ler-delete-certification-candidate_test.js | 6 +- ...r-get-jury-certification-summaries_test.js | 6 +- ...-controller-get-supervisor-kit-PDF_test.js | 4 +- .../session/session-controller_test.js | 8 +-- ...up-organization-learner-controller_test.js | 10 ++- .../application/target-profiles/index_test.js | 4 +- ...cation-centers-for-admin-route-get_test.js | 6 +- ...-organizations-for-admin-route-get_test.js | 6 +- ...r-has-seen-assessment-instructions_test.js | 6 +- ...ginated-user-recommended-trainings_test.js | 5 +- .../users/users-controller-find-users_test.js | 6 +- ...troller-get-user-profile-for-admin_test.js | 6 +- .../users-controller-get-user-profile_test.js | 6 +- .../users-controller-reset-scorecard_test.js | 8 +-- .../attach-target-profile-controller_test.js | 4 +- ...lementary-certification-controller_test.js | 6 +- .../complementary-certification-route_test.js | 14 ++-- .../application/sco-whitelist-route_test.js | 14 ++-- .../attendance-sheet-controller_test.js | 4 +- ...oller-post-certification-candidate_test.js | 10 +-- .../certification-candidate-route_test.js | 14 ++-- .../certification-center-controller_test.js | 6 +- ...ertification-centers-get-divisions_test.js | 6 +- .../application/enrolment-route_test.js | 12 ++-- .../session-mass-import-route_test.js | 22 ++----- .../application/session-route_test.js | 22 +++---- .../application/subscription-route_test.js | 4 +- .../acceptance/application/user-route_test.js | 4 +- .../acceptance/answer-route_test.js | 4 +- .../certification-attestation-route_test.js | 8 +-- .../certification-course-controller_test.js | 11 ++-- .../certification-courses/index_test.js | 12 +--- .../application/certification-route_test.js | 10 +-- .../application/companion-alert-route_test.js | 6 +- ...ash-assessment-configuration-route_test.js | 32 ++------- .../certification-reports-route_test.js | 6 +- .../certification-results-route_test.js | 8 +-- .../application/livret-scolaire-route_test.js | 4 +- .../application/organization-route_test.js | 4 +- ...oring-and-capacity-simulator-route_test.js | 20 ++---- .../scoring-configuration-route_test.js | 38 ++--------- .../application/cancellation-route_test.js | 6 +- .../certification-candidate-route_test.js | 8 +-- .../certification-course-route_test.js | 20 +++--- .../certification-details-route_test.js | 6 +- ...tification-issue-report-controller_test.js | 10 +-- .../certification-officer-route_test.js | 10 +-- .../certification-report-route_test.js | 8 +-- .../application/companion-alert-route_test.js | 6 +- ...fication-course-results-controller_test.js | 4 +- .../application/finalize-route_test.js | 32 +++------ .../finalized-session-controller_test.js | 8 +-- .../jury-certification-route_test.js | 6 +- .../application/jury-comment-route_test.js | 10 +-- ...ontroller-publish-session-in-batch_test.js | 4 +- .../session-for-supervising-route_test.js | 4 +- .../session-live-alert-route_test.js | 24 ++++--- .../session-publication-route_test.js | 10 +-- .../application/session-route_test.js | 14 ++-- .../supervise-controller-supervise_test.js | 4 +- .../application/unfinalize-route_test.js | 6 +- ...pdate-cpf-import-status-controller_test.js | 6 +- .../passages/passage-controller_test.js | 6 +- .../trainings/training-controller_test.js | 26 +++----- .../tutorial-evaluations-controller_test.js | 10 +-- .../user-tutorials-controller_test.js | 14 ++-- .../answers/answer-controller-find_test.js | 12 ++-- .../answer-controller-get-correction_test.js | 16 ++--- .../answers/answer-controller-get_test.js | 8 +-- .../answers/answer-controller-save_test.js | 12 ++-- .../answers/answer-controller-update_test.js | 4 +- .../autonomous-course-controller_test.js | 20 ++---- .../badge-criteria-controller_test.js | 6 +- .../application/badges/index_test.js | 8 +-- .../competence-evaluation-controller_test.js | 26 ++------ .../progression-controller_test.js | 10 +-- .../scorecards/scorecard-controller_test.js | 13 ++-- .../smart-random-simulator-controller_test.js | 10 +-- .../stage-collection-controller_test.js | 10 +-- .../stages/stage-controller_test.js | 6 +- ...r-user-has-seen-new-dashboard-info_test.js | 6 +- .../anonymization.admin.route.test.js | 4 +- .../oidc-provider.admin.route.test.js | 6 +- .../application/oidc-provider.route.test.js | 4 +- .../application/user/user.admin.route.test.js | 36 ++++------ .../application/user/user.route.test.js | 66 +++++++------------ .../learning-content-controller_test.js | 6 +- .../certification-center.admin.route.test.js | 18 +++-- .../organization.admin.route.test.js | 40 +++++------ .../application/tag/tag.admin.route.test.js | 14 ++-- ...admin-campaign-participation-route_test.js | 4 +- .../campaign-participation-route_test.js | 26 ++++---- .../learner-participation-route_test.js | 14 ++-- .../application/pole-emploi-route_test.js | 4 +- .../campaign-administration-route_test.js | 37 ++++------- .../application/campaign-detail-route_test.js | 26 ++++---- .../campaign-results-route_test.js | 20 +++--- .../application/campaign-route_test.js | 12 ++-- .../application/campaign-stats-route_test.js | 14 ++-- ...r-import-sco-organization-learners_test.js | 14 ++-- .../organization-import-route_test.js | 18 ++--- .../organization-learners-route_test.js | 20 ++---- .../sco-organization-management-route_test.js | 6 +- .../sup-organization-management-route_test.js | 36 ++++------ .../organization-learner-features_test.js | 10 +-- .../learner-activity-controller_test.js | 4 +- .../organization-learner-controller_test.js | 6 +- .../organization-learner-route_test.js | 6 +- .../acceptance/learner-list-route_test.js | 6 +- ...tration-organization-learner-route_test.js | 4 +- .../acceptance/sco-learner-list-route_test.js | 16 ++--- .../acceptance/sup-learner-list-route_test.js | 18 ++--- .../create-organization-places-lot_test.js | 6 +- .../delete-organization-places-lot_test.js | 14 ++-- .../find-organization-places_test.js | 10 +-- .../get-organization-places-capacity_test.js | 10 +-- .../get-organization-places-lots_test.js | 6 +- ...get-organization-places-statistics_test.js | 6 +- .../admin-target-profile-route_test.js | 40 ++++++----- .../application/target-profile-route_test.js | 8 +-- .../application/attestation-route_test.js | 4 +- .../share-profile-reward-route_test.js | 6 +- .../application/quest-route_test.js | 4 +- ...oller-auto-validate-next-challenge_test.js | 6 +- ...ent-controller-complete-assessment_test.js | 14 ++-- ...roller-find-competence-evaluations_test.js | 6 +- ...t-controller-get-last-challenge-id_test.js | 10 +-- ...-challenge-for-campaign-assessment_test.js | 4 +- ...t-next-challenge-for-certification_test.js | 8 +-- ...hallenge-for-competence-evaluation_test.js | 10 +-- ...er-get-next-challenge-locale-management.js | 7 +- .../assessment-controller-get_test.js | 37 +++-------- ...ssment-controller-pause-assessment_test.js | 6 +- .../assessment-controller-post_test.js | 4 +- ...roller-update-last-challenge-state_test.js | 14 ++-- .../badges/badge-controller_test.js | 8 +-- .../application/security-pre-handlers_test.js | 34 +++++----- .../admin-member/admin-member.route.test.js | 26 ++------ ...tion-center-invitation.admin.route.test.js | 12 ++-- ...tification-center-invitation.route.test.js | 22 ++----- ...tion-center-membership.admin.route.test.js | 14 ++-- ...tification-center-membership.route.test.js | 6 +- .../membership/membership.admin.route.test.js | 14 ++-- .../membership/membership.route.test.js | 12 ++-- ...rganization-invitation.admin.route.test.js | 14 ++-- .../organization-invitation.route.test.js | 14 ++-- ...prescriber-informations.controller.test.js | 6 +- .../user-orga-settings.controller.test.js | 4 +- 161 files changed, 759 insertions(+), 1193 deletions(-) diff --git a/api/tests/acceptance/application/campaign-participations/campaign-participation-controller_test.js b/api/tests/acceptance/application/campaign-participations/campaign-participation-controller_test.js index 89088fbfa31..b895b4489b5 100644 --- a/api/tests/acceptance/application/campaign-participations/campaign-participation-controller_test.js +++ b/api/tests/acceptance/application/campaign-participations/campaign-participation-controller_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, } from '../../../test-helper.js'; describe('Acceptance | API | Campaign Participations', function () { @@ -29,7 +29,7 @@ describe('Acceptance | API | Campaign Participations', function () { const options = { method: 'GET', url: `/api/campaign-participations/${campaignParticipation.id}/trainings`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; // when diff --git a/api/tests/acceptance/application/campaigns/campaign-controller_test.js b/api/tests/acceptance/application/campaigns/campaign-controller_test.js index 9c436b77238..e6ddc837968 100644 --- a/api/tests/acceptance/application/campaigns/campaign-controller_test.js +++ b/api/tests/acceptance/application/campaigns/campaign-controller_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, } from '../../../test-helper.js'; describe('Acceptance | API | Campaign Controller', function () { @@ -25,7 +25,7 @@ describe('Acceptance | API | Campaign Controller', function () { const response = await server.inject({ method: 'PATCH', url: `/api/campaigns/${campaign.id}`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload: { data: { type: 'campaigns', @@ -59,7 +59,7 @@ describe('Acceptance | API | Campaign Controller', function () { const response = await server.inject({ method: 'PATCH', url: `/api/campaigns/${campaign.id}`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload: { data: { type: 'campaigns', diff --git a/api/tests/acceptance/application/campaigns/campaign-management-controller_test.js b/api/tests/acceptance/application/campaigns/campaign-management-controller_test.js index 6f136328940..540fc11a816 100644 --- a/api/tests/acceptance/application/campaigns/campaign-management-controller_test.js +++ b/api/tests/acceptance/application/campaigns/campaign-management-controller_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, } from '../../../test-helper.js'; describe('Acceptance | API | Campaign Management Controller', function () { @@ -23,7 +23,7 @@ describe('Acceptance | API | Campaign Management Controller', function () { const response = await server.inject({ method: 'GET', url: `/api/admin/campaigns/${campaign.id}`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }); // then diff --git a/api/tests/acceptance/application/certification-center-invitations/index_test.js b/api/tests/acceptance/application/certification-center-invitations/index_test.js index 52e605c9516..6560e31d1cf 100644 --- a/api/tests/acceptance/application/certification-center-invitations/index_test.js +++ b/api/tests/acceptance/application/certification-center-invitations/index_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, knex, } from '../../../test-helper.js'; @@ -45,9 +45,7 @@ describe('Acceptance | API | Certification center invitations', function () { const response = await server.inject({ method: 'PATCH', url: `/api/certification-center-invitations/${certificationCenterInvitation.id}`, - headers: { - authorization: generateValidRequestAuthorizationHeader(adminUser.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: adminUser.id }), }); // then @@ -98,9 +96,7 @@ describe('Acceptance | API | Certification center invitations', function () { const response = await server.inject({ method: 'PATCH', url: `/api/certification-center-invitations/${certificationCenterInvitation.id}`, - headers: { - authorization: generateValidRequestAuthorizationHeader(user.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }); // then diff --git a/api/tests/acceptance/application/certification-center-memberships/certification-center-membership-controller_test.js b/api/tests/acceptance/application/certification-center-memberships/certification-center-membership-controller_test.js index 3b669cdbbd9..d88751b5691 100644 --- a/api/tests/acceptance/application/certification-center-memberships/certification-center-membership-controller_test.js +++ b/api/tests/acceptance/application/certification-center-memberships/certification-center-membership-controller_test.js @@ -4,7 +4,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, insertUserWithRoleSuperAdmin, } from '../../../test-helper.js'; @@ -40,9 +40,7 @@ describe('Acceptance | API | Certification Center Membership', function () { const request = { method: 'DELETE', url: `/api/admin/certification-center-memberships/${certificationCenterMembership.id}`, - headers: { - authorization: generateValidRequestAuthorizationHeader(pixAgentWithCertifRole.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: pixAgentWithCertifRole.id }), }; await databaseBuilder.commit(); @@ -64,9 +62,7 @@ describe('Acceptance | API | Certification Center Membership', function () { const request = { method: 'DELETE', url: `/api/admin/certification-center-memberships/${certificationCenterMembership.id}`, - headers: { - authorization: generateValidRequestAuthorizationHeader(userWithoutRole.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: userWithoutRole.id }), }; await databaseBuilder.commit(); @@ -87,9 +83,7 @@ describe('Acceptance | API | Certification Center Membership', function () { const request = { method: 'DELETE', url: `/api/admin/certification-center-memberships/${nonexistentCertificationCenterMembershipId}`, - headers: { - authorization: generateValidRequestAuthorizationHeader(pixAgentWithAdminRole.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: pixAgentWithAdminRole.id }), }; await databaseBuilder.commit(); @@ -141,9 +135,7 @@ describe('Acceptance | API | Certification Center Membership', function () { }, }, }, - headers: { - authorization: generateValidRequestAuthorizationHeader(certifCenterAdminUser.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: certifCenterAdminUser.id }), }; await databaseBuilder.commit(); @@ -190,9 +182,7 @@ describe('Acceptance | API | Certification Center Membership', function () { }, }, }, - headers: { - authorization: generateValidRequestAuthorizationHeader(certifCenterMemberUser.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: certifCenterMemberUser.id }), }; await databaseBuilder.commit(); @@ -231,9 +221,7 @@ describe('Acceptance | API | Certification Center Membership', function () { }, }, }, - headers: { - authorization: generateValidRequestAuthorizationHeader(certifCenterAdminUser.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: certifCenterAdminUser.id }), }; await databaseBuilder.commit(); @@ -267,9 +255,7 @@ describe('Acceptance | API | Certification Center Membership', function () { }, }, }, - headers: { - authorization: generateValidRequestAuthorizationHeader(certifCenterAdminUser.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: certifCenterAdminUser.id }), }; await databaseBuilder.commit(); @@ -309,9 +295,7 @@ describe('Acceptance | API | Certification Center Membership', function () { const request = { method: 'DELETE', url: `/api/certification-center-memberships/${certificationCenterMembership.id}`, - headers: { - authorization: generateValidRequestAuthorizationHeader(pixCertifAdminUser.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: pixCertifAdminUser.id }), }; await databaseBuilder.commit(); @@ -333,9 +317,7 @@ describe('Acceptance | API | Certification Center Membership', function () { const request = { method: 'DELETE', url: `/api/certification-center-memberships/${certificationCenterMembership.id}`, - headers: { - authorization: generateValidRequestAuthorizationHeader(userWithoutRole.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: userWithoutRole.id }), }; await databaseBuilder.commit(); diff --git a/api/tests/acceptance/application/certification-centers/certification-center-controller_test.js b/api/tests/acceptance/application/certification-centers/certification-center-controller_test.js index 37638673e9c..daefbd59636 100644 --- a/api/tests/acceptance/application/certification-centers/certification-center-controller_test.js +++ b/api/tests/acceptance/application/certification-centers/certification-center-controller_test.js @@ -4,7 +4,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, insertUserWithRoleSuperAdmin, knex, } from '../../../test-helper.js'; @@ -37,7 +37,7 @@ describe('Acceptance | API | Certification Center', function () { const request = { method: 'GET', url: '/api/certification-centers/' + certificationCenter.id + '/divisions', - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; // when @@ -63,9 +63,7 @@ describe('Acceptance | API | Certification Center', function () { // when const response = await server.inject({ - headers: { - authorization: generateValidRequestAuthorizationHeader(), - }, + headers: generateAuthenticatedUserRequestHeaders(), method: 'GET', url: `/api/admin/certification-centers/${certificationCenter.id}/certification-center-memberships`, }); @@ -91,9 +89,7 @@ describe('Acceptance | API | Certification Center', function () { // when const response = await server.inject({ - headers: { - authorization: generateValidRequestAuthorizationHeader(), - }, + headers: generateAuthenticatedUserRequestHeaders(), method: 'GET', url: `/api/admin/certification-centers/${certificationCenter.id}/certification-center-memberships`, }); @@ -172,9 +168,7 @@ describe('Acceptance | API | Certification Center', function () { databaseBuilder.factory.buildCoreSubscription({ certificationCandidateId: candidate.id }); await databaseBuilder.commit(); const request = { - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), method: 'GET', url: `/api/certification-centers/${certificationCenterId}/session-summaries?page[number]=1&page[size]=10`, }; @@ -214,9 +208,7 @@ describe('Acceptance | API | Certification Center', function () { databaseBuilder.factory.buildUser({ email }); request = { - headers: { - authorization: generateValidRequestAuthorizationHeader(), - }, + headers: generateAuthenticatedUserRequestHeaders(), method: 'POST', url: `/api/admin/certification-centers/${certificationCenterId}/certification-center-memberships`, payload: { email }, @@ -236,7 +228,7 @@ describe('Acceptance | API | Certification Center', function () { context('when user is not SuperAdmin', function () { it('should return 403 HTTP status code ', async function () { // given - request.headers.authorization = generateValidRequestAuthorizationHeader(1111); + request.headers = generateAuthenticatedUserRequestHeaders({ userId: 1111 }); // when const response = await server.inject(request); @@ -339,7 +331,7 @@ describe('Acceptance | API | Certification Center', function () { method: 'POST', url: `/api/certif/certification-centers/${certificationCenterId}/update-referer`, payload, - headers: { authorization: generateValidRequestAuthorizationHeader(certificationCenterMemberId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: certificationCenterMemberId }), }; // when @@ -382,7 +374,7 @@ describe('Acceptance | API | Certification Center', function () { method: 'POST', url: `/api/certification-centers/${certificationCenterId}/session`, payload, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when @@ -433,7 +425,7 @@ describe('Acceptance | API | Certification Center', function () { method: 'POST', url: `/api/certification-centers/${certificationCenterId}/session`, payload, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when diff --git a/api/tests/acceptance/application/countries/countries-controller_test.js b/api/tests/acceptance/application/countries/countries-controller_test.js index de679d3d6e9..3ed31e533c1 100644 --- a/api/tests/acceptance/application/countries/countries-controller_test.js +++ b/api/tests/acceptance/application/countries/countries-controller_test.js @@ -1,4 +1,4 @@ -import { createServer, expect, generateValidRequestAuthorizationHeader } from '../../../test-helper.js'; +import { createServer, expect, generateAuthenticatedUserRequestHeaders } from '../../../test-helper.js'; describe('Acceptance | API | countries-controller', function () { let server; @@ -13,9 +13,7 @@ describe('Acceptance | API | countries-controller', function () { const options = { method: 'GET', url: '/api/countries', - headers: { - authorization: generateValidRequestAuthorizationHeader({ userId: 12345 }), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: 12345 }), }; // when diff --git a/api/tests/acceptance/application/courses/course-controller_test.js b/api/tests/acceptance/application/courses/course-controller_test.js index 1398ffa03c6..da528412166 100644 --- a/api/tests/acceptance/application/courses/course-controller_test.js +++ b/api/tests/acceptance/application/courses/course-controller_test.js @@ -1,7 +1,7 @@ import { createServer, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, learningContentBuilder, mockLearningContent, nock, @@ -71,9 +71,7 @@ describe('Acceptance | API | Courses', function () { const options = { method: 'GET', url: '/api/courses/rec_active_course_id', - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; const response = await server.inject(options); @@ -92,9 +90,7 @@ describe('Acceptance | API | Courses', function () { const options = { method: 'GET', url: '/api/courses/rec_inactive_course_id', - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; const response = await server.inject(options); @@ -110,9 +106,7 @@ describe('Acceptance | API | Courses', function () { const options = { method: 'GET', url: '/api/courses/COUCOUCOUCOCUOC', - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; const response = await server.inject(options); diff --git a/api/tests/acceptance/application/frameworks/frameworks-controller_test.js b/api/tests/acceptance/application/frameworks/frameworks-controller_test.js index 800ca99c477..9411a87a639 100644 --- a/api/tests/acceptance/application/frameworks/frameworks-controller_test.js +++ b/api/tests/acceptance/application/frameworks/frameworks-controller_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, mockLearningContent, } from '../../../test-helper.js'; @@ -201,9 +201,7 @@ describe('Acceptance | Controller | frameworks-controller', function () { const options = { method: 'GET', url: `/api/frameworks/pix/areas-for-user`, - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; const expectedResult = { @@ -446,9 +444,7 @@ describe('Acceptance | Controller | frameworks-controller', function () { const options = { method: 'GET', url: `/api/admin/frameworks/fmk1/areas`, - headers: { - authorization: generateValidRequestAuthorizationHeader(user.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; // when diff --git a/api/tests/acceptance/application/memberships/membership-controller_test.js b/api/tests/acceptance/application/memberships/membership-controller_test.js index c93860665bd..b741fa7e682 100644 --- a/api/tests/acceptance/application/memberships/membership-controller_test.js +++ b/api/tests/acceptance/application/memberships/membership-controller_test.js @@ -3,7 +3,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, } from '../../../test-helper.js'; describe('Acceptance | Controller | membership-controller', function () { @@ -54,9 +54,7 @@ describe('Acceptance | Controller | membership-controller', function () { }, }, }, - headers: { - authorization: generateValidRequestAuthorizationHeader(organizationAdminUserId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: organizationAdminUserId }), }; }); @@ -76,7 +74,7 @@ describe('Acceptance | Controller | membership-controller', function () { it('should respond with a 403 if user does not have the role Admin in organization', async function () { // given const notOrganizationAdminUserId = databaseBuilder.factory.buildUser().id; - options.headers.authorization = generateValidRequestAuthorizationHeader(notOrganizationAdminUserId); + options.headers = generateAuthenticatedUserRequestHeaders({ userId: notOrganizationAdminUserId }); // when const response = await server.inject(options); @@ -124,9 +122,7 @@ describe('Acceptance | Controller | membership-controller', function () { payload: { organizationId, }, - headers: { - authorization: generateValidRequestAuthorizationHeader(organizationAdminUserId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: organizationAdminUserId }), }; // when diff --git a/api/tests/acceptance/application/organizations/organization-controller_test.js b/api/tests/acceptance/application/organizations/organization-controller_test.js index 12e5a55450d..2fae369a671 100644 --- a/api/tests/acceptance/application/organizations/organization-controller_test.js +++ b/api/tests/acceptance/application/organizations/organization-controller_test.js @@ -8,7 +8,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, insertUserWithRoleSuperAdmin, knex, sinon, @@ -45,7 +45,7 @@ describe('Acceptance | Application | organization-controller', function () { method: 'POST', url: '/api/admin/organizations', payload, - headers: { authorization: generateValidRequestAuthorizationHeader() }, + headers: generateAuthenticatedUserRequestHeaders(), }; }); @@ -70,7 +70,7 @@ describe('Acceptance | Application | organization-controller', function () { }, }, }, - headers: { authorization: generateValidRequestAuthorizationHeader(superAdminUserId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: superAdminUserId }), }); // then @@ -131,7 +131,7 @@ describe('Acceptance | Application | organization-controller', function () { it('should respond with a 403 - forbidden access - if user has not role Super Admin', function () { // given const nonSuperAdminUserId = 9999; - options.headers.authorization = generateValidRequestAuthorizationHeader(nonSuperAdminUserId); + options.headers = generateAuthenticatedUserRequestHeaders({ userId: nonSuperAdminUserId }); // when const promise = server.inject(options); @@ -165,9 +165,7 @@ describe('Acceptance | Application | organization-controller', function () { const response = await server.inject({ method: 'POST', url: `/api/admin/organizations/import-csv`, - headers: { - authorization: generateValidRequestAuthorizationHeader(superAdminUserId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: superAdminUserId }), payload: buffer, }); @@ -235,7 +233,7 @@ describe('Acceptance | Application | organization-controller', function () { method: 'GET', url: '/api/admin/organizations', payload: {}, - headers: { authorization: generateValidRequestAuthorizationHeader(userSuperAdmin.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: userSuperAdmin.id }), }; return databaseBuilder.commit(); @@ -256,7 +254,7 @@ describe('Acceptance | Application | organization-controller', function () { it('should respond with a 403 - forbidden access - if user has not role Super Admin', async function () { // given const nonSuperAdminUserId = 9999; - options.headers.authorization = generateValidRequestAuthorizationHeader(nonSuperAdminUserId); + options.headers = generateAuthenticatedUserRequestHeaders({ userId: nonSuperAdminUserId }); // when const response = await server.inject(options); @@ -360,9 +358,7 @@ describe('Acceptance | Application | organization-controller', function () { options = { method: 'GET', url: `/api/organizations/${organizationId}/campaigns`, - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; }); @@ -388,9 +384,7 @@ describe('Acceptance | Application | organization-controller', function () { options = { method: 'GET', url: `/api/organizations/${organizationId}/campaigns`, - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when @@ -545,7 +539,7 @@ describe('Acceptance | Application | organization-controller', function () { const response = await server.inject({ method: 'GET', url: `/api/organizations/${organizationId}/member-identities`, - headers: { authorization: generateValidRequestAuthorizationHeader(member1.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: member1.id }), }); // then @@ -613,7 +607,7 @@ describe('Acceptance | Application | organization-controller', function () { const response = await server.inject({ method: 'PATCH', url: `/api/organizations/${organizationId}/resend-invitation`, - headers: { authorization: generateValidRequestAuthorizationHeader(adminUserId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: adminUserId }), payload: { data: { type: 'organization-invitations', @@ -676,7 +670,7 @@ describe('Acceptance | Application | organization-controller', function () { const response = await server.inject({ method: 'POST', url: `/api/admin/organizations/${organizationId}/archive`, - headers: { authorization: generateValidRequestAuthorizationHeader(adminUser.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: adminUser.id }), }); // then @@ -698,7 +692,7 @@ describe('Acceptance | Application | organization-controller', function () { const request = { method: 'GET', url: '/api/admin/organizations/986532/children', - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when @@ -721,7 +715,7 @@ describe('Acceptance | Application | organization-controller', function () { const request = { method: 'GET', url: `/api/admin/organizations/${organizationId}/children`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when @@ -750,7 +744,7 @@ describe('Acceptance | Application | organization-controller', function () { const request = { method: 'GET', url: `/api/admin/organizations/${parentOrganizationId}/children`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when const response = await server.inject(request); diff --git a/api/tests/acceptance/application/scenario-simulator/scenario-simulator-controller_test.js b/api/tests/acceptance/application/scenario-simulator/scenario-simulator-controller_test.js index fdaf2b8ce46..92f457d3037 100644 --- a/api/tests/acceptance/application/scenario-simulator/scenario-simulator-controller_test.js +++ b/api/tests/acceptance/application/scenario-simulator/scenario-simulator-controller_test.js @@ -3,7 +3,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, mockLearningContent, parseJsonStream, } from '../../../test-helper.js'; @@ -14,7 +14,7 @@ const { describe('Acceptance | Controller | scenario-simulator-controller', function () { let server; - let adminAuthorization; + let adminAuthorizationHeaders; let validPayload; beforeEach(async function () { @@ -27,7 +27,7 @@ describe('Acceptance | Controller | scenario-simulator-controller', function () createdAt: new Date('2022-02-01'), }); - adminAuthorization = generateValidRequestAuthorizationHeader(adminId); + adminAuthorizationHeaders = generateAuthenticatedUserRequestHeaders({ userId: adminId }); await databaseBuilder.commit(); validPayload = { @@ -149,7 +149,7 @@ describe('Acceptance | Controller | scenario-simulator-controller', function () it('should return a report with the same number of simulation scenario reports as the number of challenges in the configuration', async function () { // given - options.headers.authorization = adminAuthorization; + options.headers = adminAuthorizationHeaders; options.payload = validPayload; // when @@ -172,7 +172,7 @@ describe('Acceptance | Controller | scenario-simulator-controller', function () describe('when there is no connected user', function () { it('should return status code 401', async function () { // given - options.headers.authorization = undefined; + options.headers = {}; // when const response = await server.inject(options); @@ -186,7 +186,7 @@ describe('Acceptance | Controller | scenario-simulator-controller', function () it('should return status code 403', async function () { // given const { id: userId } = databaseBuilder.factory.buildUser(); - options.headers.authorization = generateValidRequestAuthorizationHeader(userId); + options.headers = generateAuthenticatedUserRequestHeaders({ userId }); await databaseBuilder.commit(); options.payload = validPayload; @@ -201,7 +201,7 @@ describe('Acceptance | Controller | scenario-simulator-controller', function () describe('when request payload is invalid', function () { it('should return status code 400', async function () { // given - options.headers.authorization = adminAuthorization; + options.headers = adminAuthorizationHeaders; options.payload = { wrongField: [], }; diff --git a/api/tests/acceptance/application/sco-organization-learners/sco-organization-learner-controller_test.js b/api/tests/acceptance/application/sco-organization-learners/sco-organization-learner-controller_test.js index e17c7356d26..3a27275c8d2 100644 --- a/api/tests/acceptance/application/sco-organization-learners/sco-organization-learner-controller_test.js +++ b/api/tests/acceptance/application/sco-organization-learners/sco-organization-learner-controller_test.js @@ -3,8 +3,8 @@ import { createServer, databaseBuilder, expect, + generateAuthenticatedUserRequestHeaders, generateIdTokenForExternalUser, - generateValidRequestAuthorizationHeader, knex, } from '../../../test-helper.js'; @@ -337,7 +337,7 @@ describe('Acceptance | Controller | sco-organization-learners', function () { const response = await server.inject({ method: 'POST', url: '/api/sco-organization-learners/password-update', - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload: { data: { attributes: { @@ -377,7 +377,7 @@ describe('Acceptance | Controller | sco-organization-learners', function () { options = { method: 'POST', url: '/api/sco-organization-learners/username-password-generation', - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload: { data: { attributes: { @@ -538,7 +538,7 @@ describe('Acceptance | Controller | sco-organization-learners', function () { const { headers, payload, statusCode } = await server.inject({ method: 'POST', url: '/api/sco-organization-learners/batch-username-password-generate', - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload: { data: { attributes: { diff --git a/api/tests/acceptance/application/session/session-controller-delete-certification-candidate_test.js b/api/tests/acceptance/application/session/session-controller-delete-certification-candidate_test.js index c965af4503c..b1db9f18daf 100644 --- a/api/tests/acceptance/application/session/session-controller-delete-certification-candidate_test.js +++ b/api/tests/acceptance/application/session/session-controller-delete-certification-candidate_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, } from '../../../test-helper.js'; describe('Acceptance | Controller | session-controller-delete-certification-candidate', function () { @@ -26,9 +26,7 @@ describe('Acceptance | Controller | session-controller-delete-certification-cand options = { method: 'DELETE', - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; return databaseBuilder.commit(); }); diff --git a/api/tests/acceptance/application/session/session-controller-get-jury-certification-summaries_test.js b/api/tests/acceptance/application/session/session-controller-get-jury-certification-summaries_test.js index 4a07f05d57a..d5334a6360f 100644 --- a/api/tests/acceptance/application/session/session-controller-get-jury-certification-summaries_test.js +++ b/api/tests/acceptance/application/session/session-controller-get-jury-certification-summaries_test.js @@ -3,7 +3,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, } from '../../../test-helper.js'; describe('Acceptance | Controller | session-controller-get-jury-certification-summaries', function () { @@ -36,7 +36,7 @@ describe('Acceptance | Controller | session-controller-get-jury-certification-su method: 'GET', url: `/api/admin/sessions/${sessionId}/jury-certification-summaries`, payload: {}, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }); // then @@ -126,7 +126,7 @@ describe('Acceptance | Controller | session-controller-get-jury-certification-su method: 'GET', url: `/api/admin/sessions/${sessionId}/jury-certification-summaries`, payload: {}, - headers: { authorization: generateValidRequestAuthorizationHeader(superAdminId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: superAdminId }), }; return databaseBuilder.commit(); diff --git a/api/tests/acceptance/application/session/session-controller-get-supervisor-kit-PDF_test.js b/api/tests/acceptance/application/session/session-controller-get-supervisor-kit-PDF_test.js index 3d68444f839..7af30e33337 100644 --- a/api/tests/acceptance/application/session/session-controller-get-supervisor-kit-PDF_test.js +++ b/api/tests/acceptance/application/session/session-controller-get-supervisor-kit-PDF_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, } from '../../../test-helper.js'; describe('Acceptance | Controller | session-controller-get-supervisor-kit-pdf', function () { @@ -40,7 +40,7 @@ describe('Acceptance | Controller | session-controller-get-supervisor-kit-pdf', method: 'GET', url: `/api/sessions/${sessionIdAllowed}/supervisor-kit`, payload: {}, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; // when const promise = server.inject(options); diff --git a/api/tests/acceptance/application/session/session-controller_test.js b/api/tests/acceptance/application/session/session-controller_test.js index 3d039d133e5..d09f4c762ce 100644 --- a/api/tests/acceptance/application/session/session-controller_test.js +++ b/api/tests/acceptance/application/session/session-controller_test.js @@ -4,7 +4,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, } from '../../../test-helper.js'; describe('Acceptance | Controller | session-controller', function () { @@ -37,7 +37,7 @@ describe('Acceptance | Controller | session-controller', function () { method: 'GET', url: `/api/sessions/${sessionId}/certification-candidates`, payload: {}, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }); // then @@ -122,7 +122,7 @@ describe('Acceptance | Controller | session-controller', function () { method: 'GET', url: `/api/sessions/${sessionId}/certification-candidates`, payload: {}, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }); // then @@ -135,7 +135,7 @@ describe('Acceptance | Controller | session-controller', function () { method: 'GET', url: `/api/sessions/${sessionId}/certification-candidates`, payload: {}, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }); // then diff --git a/api/tests/acceptance/application/sup-organization-learners/sup-organization-learner-controller_test.js b/api/tests/acceptance/application/sup-organization-learners/sup-organization-learner-controller_test.js index 4d3a3a6caad..1082536ac13 100644 --- a/api/tests/acceptance/application/sup-organization-learners/sup-organization-learner-controller_test.js +++ b/api/tests/acceptance/application/sup-organization-learners/sup-organization-learner-controller_test.js @@ -3,7 +3,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, } from '../../../test-helper.js'; describe('Acceptance | Controller | sup-organization-learners', function () { @@ -17,13 +17,13 @@ describe('Acceptance | Controller | sup-organization-learners', function () { let organizationId; const studentNumber = '54321'; let organizationLearnerId; - let authorizationToken; + let headers; beforeEach(async function () { organizationId = databaseBuilder.factory.buildOrganization({ isManagingStudents: true, type: 'SUP' }).id; const user = databaseBuilder.factory.buildUser(); - authorizationToken = generateValidRequestAuthorizationHeader(user.id); + headers = generateAuthenticatedUserRequestHeaders({ userId: user.id }); organizationLearnerId = databaseBuilder.factory.buildOrganizationLearner({ organizationId }).id; databaseBuilder.factory.buildMembership({ organizationId, @@ -38,9 +38,7 @@ describe('Acceptance | Controller | sup-organization-learners', function () { const options = { method: 'PATCH', url: `/api/organizations/${organizationId}/sup-organization-learners/${organizationLearnerId}`, - headers: { - authorization: authorizationToken, - }, + headers, payload: { data: { attributes: { diff --git a/api/tests/acceptance/application/target-profiles/index_test.js b/api/tests/acceptance/application/target-profiles/index_test.js index 997aeae719a..141059af14e 100644 --- a/api/tests/acceptance/application/target-profiles/index_test.js +++ b/api/tests/acceptance/application/target-profiles/index_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, } from '../../../test-helper.js'; describe('Acceptance | Route | target-profiles', function () { @@ -30,7 +30,7 @@ describe('Acceptance | Route | target-profiles', function () { const options = { method: 'GET', url: `/api/admin/target-profiles/${targetProfileId}/training-summaries`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; // when diff --git a/api/tests/acceptance/application/users/find-user-certification-centers-for-admin-route-get_test.js b/api/tests/acceptance/application/users/find-user-certification-centers-for-admin-route-get_test.js index f2c1c1335fd..8c1ee0c382d 100644 --- a/api/tests/acceptance/application/users/find-user-certification-centers-for-admin-route-get_test.js +++ b/api/tests/acceptance/application/users/find-user-certification-centers-for-admin-route-get_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, } from '../../../test-helper.js'; describe('Acceptance | Route | Users', function () { @@ -31,9 +31,7 @@ describe('Acceptance | Route | Users', function () { const response = await server.inject({ method: 'GET', url: `/api/admin/users/${userId}/certification-center-memberships`, - headers: { - authorization: generateValidRequestAuthorizationHeader(adminUser.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: adminUser.id }), }); // then diff --git a/api/tests/acceptance/application/users/find-user-organizations-for-admin-route-get_test.js b/api/tests/acceptance/application/users/find-user-organizations-for-admin-route-get_test.js index 20504ef5095..9d62551d98a 100644 --- a/api/tests/acceptance/application/users/find-user-organizations-for-admin-route-get_test.js +++ b/api/tests/acceptance/application/users/find-user-organizations-for-admin-route-get_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, } from '../../../test-helper.js'; describe('Acceptance | Route | Users', function () { @@ -29,9 +29,7 @@ describe('Acceptance | Route | Users', function () { const options = { method: 'GET', url: `/api/admin/users/${userId}/organizations`, - headers: { - authorization: generateValidRequestAuthorizationHeader(admin.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: admin.id }), }; // when diff --git a/api/tests/acceptance/application/users/remember-user-has-seen-assessment-instructions_test.js b/api/tests/acceptance/application/users/remember-user-has-seen-assessment-instructions_test.js index 9893e61a495..8bb44b6d37d 100644 --- a/api/tests/acceptance/application/users/remember-user-has-seen-assessment-instructions_test.js +++ b/api/tests/acceptance/application/users/remember-user-has-seen-assessment-instructions_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, } from '../../../test-helper.js'; describe('Acceptance | Controller | users-controller-remember-user-has-seen-assessment-instructions', function () { @@ -18,7 +18,7 @@ describe('Acceptance | Controller | users-controller-remember-user-has-seen-asse options = { method: 'PATCH', url: `/api/users/${user.id}/remember-user-has-seen-assessment-instructions`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; return databaseBuilder.commit(); @@ -39,7 +39,7 @@ describe('Acceptance | Controller | users-controller-remember-user-has-seen-asse it('should respond with a 403 - forbidden access - if requested user is not the same as authenticated user', async function () { // given const otherUserId = 9999; - options.headers.authorization = generateValidRequestAuthorizationHeader(otherUserId); + options.headers = generateAuthenticatedUserRequestHeaders({ userId: otherUserId }); // when const response = await server.inject(options); diff --git a/api/tests/acceptance/application/users/users-controller-find-paginated-user-recommended-trainings_test.js b/api/tests/acceptance/application/users/users-controller-find-paginated-user-recommended-trainings_test.js index be0dbc7954c..136487745e5 100644 --- a/api/tests/acceptance/application/users/users-controller-find-paginated-user-recommended-trainings_test.js +++ b/api/tests/acceptance/application/users/users-controller-find-paginated-user-recommended-trainings_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, } from '../../../test-helper.js'; describe('Acceptance | Controller | users-controller-find-paginated-user-recommended-trainings', function () { @@ -12,14 +12,13 @@ describe('Acceptance | Controller | users-controller-find-paginated-user-recomme beforeEach(async function () { userId = databaseBuilder.factory.buildUser({}).id; - const authorization = generateValidRequestAuthorizationHeader(userId); await databaseBuilder.commit(); options = { method: 'GET', url: `/api/users/${userId}/trainings`, payload: {}, - headers: { authorization }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; server = await createServer(); }); diff --git a/api/tests/acceptance/application/users/users-controller-find-users_test.js b/api/tests/acceptance/application/users/users-controller-find-users_test.js index c5bc0be9e63..e771f5adbe1 100644 --- a/api/tests/acceptance/application/users/users-controller-find-users_test.js +++ b/api/tests/acceptance/application/users/users-controller-find-users_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, } from '../../../test-helper.js'; describe('Acceptance | users-controller-find-users', function () { @@ -27,7 +27,7 @@ describe('Acceptance | users-controller-find-users', function () { options = { method: 'GET', url: '/api/admin/users', - headers: { authorization: generateValidRequestAuthorizationHeader(userSuperAdminId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: userSuperAdminId }), }; await databaseBuilder.commit(); @@ -51,7 +51,7 @@ describe('Acceptance | users-controller-find-users', function () { it('should respond with a 403 - forbidden access - if user has not role Super Admin', function () { // given const nonSuperAdminUserId = 9999; - options.headers.authorization = generateValidRequestAuthorizationHeader(nonSuperAdminUserId); + options.headers = generateAuthenticatedUserRequestHeaders({ userId: nonSuperAdminUserId }); // when const promise = server.inject(options); diff --git a/api/tests/acceptance/application/users/users-controller-get-user-profile-for-admin_test.js b/api/tests/acceptance/application/users/users-controller-get-user-profile-for-admin_test.js index 8ea03937129..c82ddabf0b3 100644 --- a/api/tests/acceptance/application/users/users-controller-get-user-profile-for-admin_test.js +++ b/api/tests/acceptance/application/users/users-controller-get-user-profile-for-admin_test.js @@ -3,7 +3,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, insertUserWithRoleSuperAdmin, mockLearningContent, } from '../../../test-helper.js'; @@ -83,7 +83,7 @@ describe('Acceptance | Controller | users-controller-get-user-profile-for-admin' it('should respond with a 403 - forbidden access - if requested user is not admin', async function () { // given - options.headers.authorization = generateValidRequestAuthorizationHeader(userId); + options.headers = generateAuthenticatedUserRequestHeaders({ userId }); // when const response = await server.inject(options); @@ -96,7 +96,7 @@ describe('Acceptance | Controller | users-controller-get-user-profile-for-admin' describe('Success case', function () { beforeEach(async function () { const superAdmin = await insertUserWithRoleSuperAdmin(); - options.headers.authorization = generateValidRequestAuthorizationHeader(superAdmin.id); + options.headers = generateAuthenticatedUserRequestHeaders({ userId: superAdmin.id }); await mockLearningContent(learningContent); diff --git a/api/tests/acceptance/application/users/users-controller-get-user-profile_test.js b/api/tests/acceptance/application/users/users-controller-get-user-profile_test.js index d103ae41962..64efa0611c6 100644 --- a/api/tests/acceptance/application/users/users-controller-get-user-profile_test.js +++ b/api/tests/acceptance/application/users/users-controller-get-user-profile_test.js @@ -3,7 +3,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, mockLearningContent, } from '../../../test-helper.js'; @@ -83,7 +83,7 @@ describe('Acceptance | Controller | users-controller-get-user-profile', function it('should respond with a 403 - forbidden access - if requested user is not the same as authenticated user', async function () { // given const otherUserId = 9999; - options.headers.authorization = generateValidRequestAuthorizationHeader(otherUserId); + options.headers = generateAuthenticatedUserRequestHeaders({ userId: otherUserId }); // when const response = await server.inject(options); @@ -95,7 +95,7 @@ describe('Acceptance | Controller | users-controller-get-user-profile', function describe('Success case', function () { beforeEach(async function () { - options.headers.authorization = generateValidRequestAuthorizationHeader(userId); + options.headers = generateAuthenticatedUserRequestHeaders({ userId }); await mockLearningContent(learningContent); diff --git a/api/tests/acceptance/application/users/users-controller-reset-scorecard_test.js b/api/tests/acceptance/application/users/users-controller-reset-scorecard_test.js index d4ed556e5d4..1727981df0d 100644 --- a/api/tests/acceptance/application/users/users-controller-reset-scorecard_test.js +++ b/api/tests/acceptance/application/users/users-controller-reset-scorecard_test.js @@ -5,7 +5,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, knex, learningContentBuilder, mockLearningContent, @@ -121,7 +121,7 @@ describe('Acceptance | Controller | users-controller-reset-scorecard', function it('should respond with a 403 - forbidden access - if requested user is not the same as authenticated user', async function () { // given const otherUserId = 9999; - options.headers.authorization = generateValidRequestAuthorizationHeader(otherUserId); + options.headers = generateAuthenticatedUserRequestHeaders({ userId: otherUserId }); // when const response = await server.inject(options); @@ -135,7 +135,7 @@ describe('Acceptance | Controller | users-controller-reset-scorecard', function const competenceEvaluationId = 111; beforeEach(async function () { - options.headers.authorization = generateValidRequestAuthorizationHeader(userId); + options.headers = generateAuthenticatedUserRequestHeaders({ userId }); databaseBuilder.factory.buildCompetenceEvaluation({ id: competenceEvaluationId, @@ -168,7 +168,7 @@ describe('Acceptance | Controller | users-controller-reset-scorecard', function const createdAt = new Date('2019-01-01'); beforeEach(async function () { - options.headers.authorization = generateValidRequestAuthorizationHeader(userId); + options.headers = generateAuthenticatedUserRequestHeaders({ userId }); sinon.useFakeTimers({ now: new Date('2019-01-10'), diff --git a/api/tests/certification/complementary-certification/acceptance/application/attach-target-profile-controller_test.js b/api/tests/certification/complementary-certification/acceptance/application/attach-target-profile-controller_test.js index d93d66a0e21..ffda302a50d 100644 --- a/api/tests/certification/complementary-certification/acceptance/application/attach-target-profile-controller_test.js +++ b/api/tests/certification/complementary-certification/acceptance/application/attach-target-profile-controller_test.js @@ -4,7 +4,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, insertUserWithRoleSuperAdmin, knex, } from '../../../../test-helper.js'; @@ -95,7 +95,7 @@ describe('Acceptance | Controller | Complementary certification | attach-target- }, }, }, - headers: { authorization: generateValidRequestAuthorizationHeader(superAdmin.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: superAdmin.id }), }; await databaseBuilder.commit(); diff --git a/api/tests/certification/complementary-certification/acceptance/application/complementary-certification-controller_test.js b/api/tests/certification/complementary-certification/acceptance/application/complementary-certification-controller_test.js index 6084f536183..29893d8f96a 100644 --- a/api/tests/certification/complementary-certification/acceptance/application/complementary-certification-controller_test.js +++ b/api/tests/certification/complementary-certification/acceptance/application/complementary-certification-controller_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, insertUserWithRoleSuperAdmin, } from '../../../../test-helper.js'; @@ -16,9 +16,7 @@ describe('Acceptance | API | complementary-certification-controller', function ( const options = { method: 'GET', url: '/api/admin/complementary-certifications/' + complementaryCertificationId + '/target-profiles', - headers: { - authorization: generateValidRequestAuthorizationHeader(superAdmin.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: superAdmin.id }), }; const attachedAt = new Date('2019-01-01'); diff --git a/api/tests/certification/configuration/acceptance/application/complementary-certification-route_test.js b/api/tests/certification/configuration/acceptance/application/complementary-certification-route_test.js index bae126f8d96..14c93c87a92 100644 --- a/api/tests/certification/configuration/acceptance/application/complementary-certification-route_test.js +++ b/api/tests/certification/configuration/acceptance/application/complementary-certification-route_test.js @@ -3,7 +3,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, insertUserWithRoleSuperAdmin, } from '../../../../test-helper.js'; @@ -21,9 +21,7 @@ describe('Certification | Configuration | Acceptance | API | complementary-certi const options = { method: 'GET', url: '/api/admin/complementary-certifications', - headers: { - authorization: generateValidRequestAuthorizationHeader(superAdmin.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: superAdmin.id }), }; databaseBuilder.factory.buildComplementaryCertification({ id: 1, @@ -73,9 +71,7 @@ describe('Certification | Configuration | Acceptance | API | complementary-certi const options = { method: 'GET', url: '/api/admin/complementary-certifications/attachable-target-profiles', - headers: { - authorization: generateValidRequestAuthorizationHeader(superAdmin.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: superAdmin.id }), }; databaseBuilder.factory.buildTargetProfile({ @@ -111,9 +107,7 @@ describe('Certification | Configuration | Acceptance | API | complementary-certi const options = { method: 'GET', url: '/api/admin/complementary-certifications/attachable-target-profiles?searchTerm=that%20way', - headers: { - authorization: generateValidRequestAuthorizationHeader(superAdmin.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: superAdmin.id }), }; databaseBuilder.factory.buildTargetProfile({ diff --git a/api/tests/certification/configuration/acceptance/application/sco-whitelist-route_test.js b/api/tests/certification/configuration/acceptance/application/sco-whitelist-route_test.js index 4a8469466b5..78851792a96 100644 --- a/api/tests/certification/configuration/acceptance/application/sco-whitelist-route_test.js +++ b/api/tests/certification/configuration/acceptance/application/sco-whitelist-route_test.js @@ -4,7 +4,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, insertUserWithRoleSuperAdmin, knex, } from '../../../../test-helper.js'; @@ -24,9 +24,7 @@ describe('Certification | Configuration | Acceptance | API | sco-whitelist-route const options = { method: 'POST', url: '/api/admin/sco-whitelist', - headers: { - authorization: generateValidRequestAuthorizationHeader(superAdmin.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: superAdmin.id }), payload: buffer, }; databaseBuilder.factory.buildCertificationCenter({ @@ -68,9 +66,7 @@ describe('Certification | Configuration | Acceptance | API | sco-whitelist-route const options = { method: 'POST', url: '/api/admin/sco-whitelist', - headers: { - authorization: generateValidRequestAuthorizationHeader(superAdmin.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: superAdmin.id }), payload: buffer, }; databaseBuilder.factory.buildCertificationCenter({ @@ -123,9 +119,7 @@ describe('Certification | Configuration | Acceptance | API | sco-whitelist-route const options = { method: 'GET', url: '/api/admin/sco-whitelist', - headers: { - authorization: generateValidRequestAuthorizationHeader(superAdmin.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: superAdmin.id }), }; databaseBuilder.factory.buildCertificationCenter({ diff --git a/api/tests/certification/enrolment/acceptance/application/attendance-sheet-controller_test.js b/api/tests/certification/enrolment/acceptance/application/attendance-sheet-controller_test.js index b7b5413275b..25310e6552e 100644 --- a/api/tests/certification/enrolment/acceptance/application/attendance-sheet-controller_test.js +++ b/api/tests/certification/enrolment/acceptance/application/attendance-sheet-controller_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, } from '../../../../test-helper.js'; describe('Acceptance | Controller | session-controller-get-attendance-sheet', function () { @@ -33,7 +33,7 @@ describe('Acceptance | Controller | session-controller-get-attendance-sheet', fu method: 'GET', url: `/api/sessions/${sessionIdAllowed}/attendance-sheet`, payload: {}, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; // when diff --git a/api/tests/certification/enrolment/acceptance/application/certification-candidate-controller-post-certification-candidate_test.js b/api/tests/certification/enrolment/acceptance/application/certification-candidate-controller-post-certification-candidate_test.js index f6c9f9abfd6..874330c8550 100644 --- a/api/tests/certification/enrolment/acceptance/application/certification-candidate-controller-post-certification-candidate_test.js +++ b/api/tests/certification/enrolment/acceptance/application/certification-candidate-controller-post-certification-candidate_test.js @@ -10,7 +10,7 @@ import { databaseBuilder, domainBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, knex, sinon, } from '../../../../test-helper.js'; @@ -123,9 +123,7 @@ describe('Acceptance | Controller | Certification | Enrolment | session-controll options = { method: 'POST', url: `/api/sessions/${sessionId}/certification-candidates`, - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload, }; @@ -249,9 +247,7 @@ describe('Acceptance | Controller | Certification | Enrolment | session-controll options = { method: 'POST', url: `/api/sessions/${sessionId}/certification-candidates`, - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload, }; diff --git a/api/tests/certification/enrolment/acceptance/application/certification-candidate-route_test.js b/api/tests/certification/enrolment/acceptance/application/certification-candidate-route_test.js index 6068ef8d491..f9b386a9784 100644 --- a/api/tests/certification/enrolment/acceptance/application/certification-candidate-route_test.js +++ b/api/tests/certification/enrolment/acceptance/application/certification-candidate-route_test.js @@ -6,7 +6,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, knex, } from '../../../../test-helper.js'; @@ -88,7 +88,7 @@ describe('Certification | Enrolment | Acceptance | Application | Routes | certif }, }, }, - headers: { authorization: generateValidRequestAuthorizationHeader(certificationCenterUserId, 'pix-certif') }, + headers: generateAuthenticatedUserRequestHeaders({ userId: certificationCenterUserId, source: 'pix-certif' }), }; // when @@ -147,7 +147,7 @@ describe('Certification | Enrolment | Acceptance | Application | Routes | certif method: 'GET', url: `/api/sessions/${sessionId}/certification-candidates`, payload: {}, - headers: { authorization: generateValidRequestAuthorizationHeader(certificationCenterUserId, 'pix-certif') }, + headers: generateAuthenticatedUserRequestHeaders({ userId: certificationCenterUserId, source: 'pix-certif' }), }; // when @@ -184,7 +184,7 @@ describe('Certification | Enrolment | Acceptance | Application | Routes | certif method: 'PATCH', url: `/api/certification-candidates/${candidateId}/validate-certification-instructions`, payload: {}, - headers: { authorization: generateValidRequestAuthorizationHeader(candidateUserId, 'pix') }, + headers: generateAuthenticatedUserRequestHeaders({ userId: candidateUserId, source: 'pix' }), }; // when @@ -234,7 +234,7 @@ describe('Certification | Enrolment | Acceptance | Application | Routes | certif method: 'GET', url: `/api/certification-candidates/${candidateId}`, payload: {}, - headers: { authorization: generateValidRequestAuthorizationHeader(candidateUserId, 'pix') }, + headers: generateAuthenticatedUserRequestHeaders({ userId: candidateUserId, source: 'pix' }), }; // when @@ -309,7 +309,7 @@ describe('Certification | Enrolment | Acceptance | Application | Routes | certif }, }, }, - headers: { authorization: generateValidRequestAuthorizationHeader(certificationCenterUserId, 'pix-certif') }, + headers: generateAuthenticatedUserRequestHeaders({ userId: certificationCenterUserId, source: 'pix-certif' }), }; // when @@ -366,7 +366,7 @@ describe('Certification | Enrolment | Acceptance | Application | Routes | certif method: 'DELETE', url: `/api/sessions/${sessionId}/certification-candidates/${candidateId}`, payload: {}, - headers: { authorization: generateValidRequestAuthorizationHeader(certificationCenterUserId, 'pix-certif') }, + headers: generateAuthenticatedUserRequestHeaders({ userId: certificationCenterUserId, source: 'pix-certif' }), }; // when diff --git a/api/tests/certification/enrolment/acceptance/application/certification-center-controller_test.js b/api/tests/certification/enrolment/acceptance/application/certification-center-controller_test.js index 8d828fb3429..5d1d00a46a1 100644 --- a/api/tests/certification/enrolment/acceptance/application/certification-center-controller_test.js +++ b/api/tests/certification/enrolment/acceptance/application/certification-center-controller_test.js @@ -4,7 +4,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, insertUserWithRoleSuperAdmin, } from '../../../../test-helper.js'; @@ -32,7 +32,7 @@ describe('Acceptance | API | Certification Center', function () { const request = { method: 'GET', url: `/api/certification-centers/${certificationCenter.id}/sessions/${session.id}/students?page[size]=10&page[number]=1`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; // when @@ -60,7 +60,7 @@ describe('Acceptance | API | Certification Center', function () { const request = { method: 'GET', url: `/api/certification-centers/${certificationCenter.id}/sessions/${session.id}/students?page[size]=10&page[number]=1`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; // when diff --git a/api/tests/certification/enrolment/acceptance/application/certification-centers-get-divisions_test.js b/api/tests/certification/enrolment/acceptance/application/certification-centers-get-divisions_test.js index 88acd8543bc..2c592c1cf18 100644 --- a/api/tests/certification/enrolment/acceptance/application/certification-centers-get-divisions_test.js +++ b/api/tests/certification/enrolment/acceptance/application/certification-centers-get-divisions_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, } from '../../../../test-helper.js'; describe('Certification | Enrolment | Acceptance | Route | Certification Centers', function () { @@ -34,9 +34,7 @@ describe('Certification | Enrolment | Acceptance | Route | Certification Centers // when const { result, statusCode } = await server.inject({ - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), method: 'GET', payload: {}, url: `/api/certification-centers/${certificationCenterId}/divisions`, diff --git a/api/tests/certification/enrolment/acceptance/application/enrolment-route_test.js b/api/tests/certification/enrolment/acceptance/application/enrolment-route_test.js index db6431500ab..5440c5e0fd5 100644 --- a/api/tests/certification/enrolment/acceptance/application/enrolment-route_test.js +++ b/api/tests/certification/enrolment/acceptance/application/enrolment-route_test.js @@ -7,7 +7,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, sinon, } from '../../../../test-helper.js'; @@ -27,7 +27,7 @@ describe('Certification | Enrolment | Acceptance | Application | Routes | enrolm options = { method: 'POST', url: '/api/sessions/1/enrol-students-to-session', - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; return databaseBuilder.commit(); }); @@ -55,7 +55,7 @@ describe('Certification | Enrolment | Acceptance | Application | Routes | enrolm options = { method: 'PUT', url: '/api/sessions/2.1/enrol-students-to-session', - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; }); @@ -111,7 +111,7 @@ describe('Certification | Enrolment | Acceptance | Application | Routes | enrolm options = { method: 'PUT', url: `/api/sessions/${sessionId}/enrol-students-to-session`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload, }; }); @@ -200,7 +200,7 @@ describe('Certification | Enrolment | Acceptance | Application | Routes | enrolm method: 'GET', url: `/api/sessions/${sessionIdAllowed}/candidates-import-sheet`, payload: {}, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; // when const response = await server.inject(options); @@ -386,7 +386,7 @@ function generateOptions({ odsFilePath, userId, sessionId }) { return { method: 'POST', url: `/api/sessions/${sessionId}/certification-candidates/import`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload: fs.createReadStream(odsFilePath), }; } diff --git a/api/tests/certification/enrolment/acceptance/application/session-mass-import-route_test.js b/api/tests/certification/enrolment/acceptance/application/session-mass-import-route_test.js index 081445385f1..2c12639f490 100644 --- a/api/tests/certification/enrolment/acceptance/application/session-mass-import-route_test.js +++ b/api/tests/certification/enrolment/acceptance/application/session-mass-import-route_test.js @@ -6,7 +6,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, knex, sinon, } from '../../../../test-helper.js'; @@ -73,9 +73,7 @@ describe('Acceptance | Controller | Session | session-mass-import-route', functi const options = { method: 'POST', url: `/api/certification-centers/${certificationCenterId}/sessions/validate-for-mass-import`, - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload: newBuffer, }; @@ -132,9 +130,7 @@ describe('Acceptance | Controller | Session | session-mass-import-route', functi const options = { method: 'POST', url: `/api/certification-centers/${certificationCenterId}/sessions/validate-for-mass-import`, - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload: newBuffer, }; @@ -202,9 +198,7 @@ describe('Acceptance | Controller | Session | session-mass-import-route', functi const options = { method: 'POST', url: `/api/certification-centers/${certificationCenterId}/sessions/confirm-for-mass-import`, - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload: { data: { attributes: { cachedValidatedSessionsKey: newCachedSessionUUID } } }, }; @@ -261,9 +255,7 @@ describe('Acceptance | Controller | Session | session-mass-import-route', functi const options = { method: 'POST', url: `/api/certification-centers/${certificationCenterId}/sessions/confirm-for-mass-import`, - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload: { data: { attributes: { cachedValidatedSessionsKey: newCachedSessionUUID } } }, }; @@ -309,9 +301,7 @@ describe('Acceptance | Controller | Session | session-mass-import-route', functi const options = { method: 'GET', url: `/api/certification-centers/${certificationCenterId}/import`, - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when diff --git a/api/tests/certification/enrolment/acceptance/application/session-route_test.js b/api/tests/certification/enrolment/acceptance/application/session-route_test.js index ff40c0a4088..24c29f5e10e 100644 --- a/api/tests/certification/enrolment/acceptance/application/session-route_test.js +++ b/api/tests/certification/enrolment/acceptance/application/session-route_test.js @@ -6,7 +6,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, knex, learningContentBuilder, mockLearningContent, @@ -43,7 +43,7 @@ describe('Certification | Enrolment | Acceptance | Routes | session-route', func }, }, }, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; return databaseBuilder.commit(); }); @@ -120,7 +120,7 @@ describe('Certification | Enrolment | Acceptance | Routes | session-route', func const options = { method: 'PATCH', url: `/api/sessions/${session.id}`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), payload, }; @@ -141,7 +141,7 @@ describe('Certification | Enrolment | Acceptance | Routes | session-route', func const options = { method: 'PATCH', url: `/api/sessions/${session.id}`, - headers: { authorization: generateValidRequestAuthorizationHeader(unauthorizedUser.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: unauthorizedUser.id }), payload, }; @@ -172,9 +172,7 @@ describe('Certification | Enrolment | Acceptance | Routes | session-route', func await databaseBuilder.commit(); const options = { - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), method: 'DELETE', url: `/api/sessions/${sessionId}`, }; @@ -208,9 +206,7 @@ describe('Certification | Enrolment | Acceptance | Routes | session-route', func await databaseBuilder.commit(); const options = { - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), method: 'GET', url: `/api/sessions/${sessionId}`, }; @@ -392,7 +388,7 @@ describe('Certification | Enrolment | Acceptance | Routes | session-route', func }, }, }, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; return databaseBuilder.commit(); @@ -516,7 +512,7 @@ describe('Certification | Enrolment | Acceptance | Routes | session-route', func }, }, }, - headers: { authorization: generateValidRequestAuthorizationHeader(onlyComplementarySubscriptionUserId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: onlyComplementarySubscriptionUserId }), }; // when @@ -576,7 +572,7 @@ describe('Certification | Enrolment | Acceptance | Routes | session-route', func }, }, }, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; return databaseBuilder.commit(); diff --git a/api/tests/certification/enrolment/acceptance/application/subscription-route_test.js b/api/tests/certification/enrolment/acceptance/application/subscription-route_test.js index 3c9ecbb4a05..18928704482 100644 --- a/api/tests/certification/enrolment/acceptance/application/subscription-route_test.js +++ b/api/tests/certification/enrolment/acceptance/application/subscription-route_test.js @@ -3,7 +3,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, learningContentBuilder, mockLearningContent, } from '../../../../test-helper.js'; @@ -97,7 +97,7 @@ describe('Certification | Enrolment | Acceptance | Application | Routes | subscr const options = { method: 'GET', url: `/api/certification-candidates/${candidate.id}/subscriptions`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId, 'pix-certif') }, + headers: generateAuthenticatedUserRequestHeaders({ userId, source: 'pix-certif' }), }; // when diff --git a/api/tests/certification/enrolment/acceptance/application/user-route_test.js b/api/tests/certification/enrolment/acceptance/application/user-route_test.js index 4d07f3a17a1..a67cb061ccf 100644 --- a/api/tests/certification/enrolment/acceptance/application/user-route_test.js +++ b/api/tests/certification/enrolment/acceptance/application/user-route_test.js @@ -3,7 +3,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, learningContentBuilder, mockLearningContent, } from '../../../../test-helper.js'; @@ -241,7 +241,7 @@ describe('Certification | Enrolment | Acceptance | Routes | User', function () { method: 'GET', url: `/api/users/${user.id}/is-certifiable`, payload: {}, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; return databaseBuilder.commit(); diff --git a/api/tests/certification/evaluation/acceptance/answer-route_test.js b/api/tests/certification/evaluation/acceptance/answer-route_test.js index 85e9ce545b5..6b804b91f02 100644 --- a/api/tests/certification/evaluation/acceptance/answer-route_test.js +++ b/api/tests/certification/evaluation/acceptance/answer-route_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, knex, mockLearningContent, } from '../../../test-helper.js'; @@ -91,7 +91,7 @@ function _setupRequestOptions({ userId, challengeId, assessmentId }) { return { method: 'POST', url: '/api/answers', - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload: { data: { type: 'answers', diff --git a/api/tests/certification/evaluation/acceptance/application/certification-attestation-route_test.js b/api/tests/certification/evaluation/acceptance/application/certification-attestation-route_test.js index cd86dcbb6af..09005c71db7 100644 --- a/api/tests/certification/evaluation/acceptance/application/certification-attestation-route_test.js +++ b/api/tests/certification/evaluation/acceptance/application/certification-attestation-route_test.js @@ -8,7 +8,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, insertUserWithRoleSuperAdmin, learningContentBuilder, mockLearningContent, @@ -124,7 +124,7 @@ describe('Certification | Results | Acceptance | Application | Routes | certific const response = await server.inject({ method: 'GET', url: '/api/attestation/1234?isFrenchDomainExtension=true&lang=fr', - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }); // then @@ -149,7 +149,7 @@ describe('Certification | Results | Acceptance | Application | Routes | certific const response = await server.inject({ method: 'GET', url: '/api/admin/sessions/4567/attestations', - headers: { authorization: generateValidRequestAuthorizationHeader(superAdmin.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: superAdmin.id }), }); // then @@ -222,7 +222,7 @@ describe('Certification | Results | Acceptance | Application | Routes | certific const options = { method: 'GET', url: `/api/organizations/${organization.id}/certification-attestations?division=aDivision&isFrenchDomainExtension=true&lang=fr`, - headers: { authorization: generateValidRequestAuthorizationHeader(adminIsManagingStudent.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: adminIsManagingStudent.id }), }; // when diff --git a/api/tests/certification/evaluation/acceptance/application/certification-courses/certification-course-controller_test.js b/api/tests/certification/evaluation/acceptance/application/certification-courses/certification-course-controller_test.js index 70c438e62c7..537287726f5 100644 --- a/api/tests/certification/evaluation/acceptance/application/certification-courses/certification-course-controller_test.js +++ b/api/tests/certification/evaluation/acceptance/application/certification-courses/certification-course-controller_test.js @@ -9,7 +9,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, knex, learningContentBuilder, } from '../../../../../test-helper.js'; @@ -78,7 +78,7 @@ describe('Acceptance | API | Certification Course', function () { describe('Resource access management', function () { it('should respond with a 403 - forbidden access - if user is not linked to the certification course', function () { // given - options.headers.authorization = generateValidRequestAuthorizationHeader(otherUserId); + options.headers = generateAuthenticatedUserRequestHeaders({ userId: otherUserId }); // when const promise = server.inject(options); @@ -92,7 +92,7 @@ describe('Acceptance | API | Certification Course', function () { it('should return the certification course', async function () { // given - options.headers.authorization = generateValidRequestAuthorizationHeader(userId); + options.headers = generateAuthenticatedUserRequestHeaders({ userId }); // when const response = await server.inject(options); @@ -496,10 +496,7 @@ function _createRequestOptions( const options = { method: 'POST', url: '/api/certification-courses', - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - 'accept-language': `${locale}`, - }, + headers: generateAuthenticatedUserRequestHeaders({ userId, acceptLanguage: locale }), payload, }; diff --git a/api/tests/certification/evaluation/acceptance/application/certification-courses/index_test.js b/api/tests/certification/evaluation/acceptance/application/certification-courses/index_test.js index 3e031e18972..952911b2c20 100644 --- a/api/tests/certification/evaluation/acceptance/application/certification-courses/index_test.js +++ b/api/tests/certification/evaluation/acceptance/application/certification-courses/index_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, knex, learningContentBuilder, mockLearningContent, @@ -237,10 +237,7 @@ describe('Acceptance | Route | Certification Courses', function () { // when await server.inject({ - headers: { - authorization: generateValidRequestAuthorizationHeader(1), - 'accept-language': 'FR', - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: 1, acceptLanguage: 'FR' }), method: 'POST', payload: { data: { @@ -277,10 +274,7 @@ describe('Acceptance | Route | Certification Courses', function () { // when const response = await server.inject({ - headers: { - authorization: generateValidRequestAuthorizationHeader(1), - 'accept-language': 'FR', - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: 1, acceptLanguage: 'FR' }), method: 'POST', payload: { data: { diff --git a/api/tests/certification/evaluation/acceptance/application/certification-route_test.js b/api/tests/certification/evaluation/acceptance/application/certification-route_test.js index 120133147f8..a2ae48d115f 100644 --- a/api/tests/certification/evaluation/acceptance/application/certification-route_test.js +++ b/api/tests/certification/evaluation/acceptance/application/certification-route_test.js @@ -6,7 +6,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, learningContentBuilder, mockLearningContent, } from '../../../../test-helper.js'; @@ -125,7 +125,7 @@ describe('Certification | Results | Acceptance | Application | Certification', f options = { method: 'GET', url: `/api/certifications/${certificationCourse.id}`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when @@ -259,7 +259,7 @@ describe('Certification | Results | Acceptance | Application | Certification', f options = { method: 'GET', url: `/api/certifications/${certificationCourse.id}`, - headers: { authorization: generateValidRequestAuthorizationHeader(unauthenticatedUserId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: unauthenticatedUserId }), }; // when @@ -375,7 +375,7 @@ describe('Certification | Results | Acceptance | Application | Certification', f options = { method: 'GET', url: '/api/certifications', - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when const response = await server.inject(options); @@ -466,7 +466,7 @@ describe('Certification | Results | Acceptance | Application | Certification', f options = { method: 'GET', url: '/api/certifications', - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when const response = await server.inject(options); diff --git a/api/tests/certification/evaluation/acceptance/application/companion-alert-route_test.js b/api/tests/certification/evaluation/acceptance/application/companion-alert-route_test.js index c2b21055704..ea5f1191d95 100644 --- a/api/tests/certification/evaluation/acceptance/application/companion-alert-route_test.js +++ b/api/tests/certification/evaluation/acceptance/application/companion-alert-route_test.js @@ -4,7 +4,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, knex, } from '../../../../test-helper.js'; @@ -25,7 +25,7 @@ describe('Certification | Evaluation | Acceptance | Application | Routes | compa options = { method: 'POST', url: `/api/assessments/${assessment.id}/companion-alert`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; return databaseBuilder.commit(); @@ -34,7 +34,7 @@ describe('Certification | Evaluation | Acceptance | Application | Routes | compa it('should respond with a 401 if requested user is not the same as the user of the assessment', async function () { // given const otherUserId = 9999; - options.headers.authorization = generateValidRequestAuthorizationHeader(otherUserId); + options.headers = generateAuthenticatedUserRequestHeaders({ userId: otherUserId }); options.payload = {}; // when diff --git a/api/tests/certification/flash-certification/acceptance/application/flash-assessment-configuration-route_test.js b/api/tests/certification/flash-certification/acceptance/application/flash-assessment-configuration-route_test.js index 506795f5ceb..c94077458dc 100644 --- a/api/tests/certification/flash-certification/acceptance/application/flash-assessment-configuration-route_test.js +++ b/api/tests/certification/flash-certification/acceptance/application/flash-assessment-configuration-route_test.js @@ -3,7 +3,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, knex, } from '../../../../test-helper.js'; @@ -32,14 +32,10 @@ describe('Acceptance | Application | flash-assessment-configuration-route', func describe('when called without a super admin role', function () { it('should return a 403', async function () { // given - const authorization = generateValidRequestAuthorizationHeader(); - const options = { method: 'GET', url: '/api/admin/flash-assessment-configuration', - headers: { - authorization, - }, + headers: generateAuthenticatedUserRequestHeaders(), }; // when const response = await server.inject(options); @@ -68,14 +64,10 @@ describe('Acceptance | Application | flash-assessment-configuration-route', func await databaseBuilder.commit(); - const authorization = generateValidRequestAuthorizationHeader(superAdmin.id); - const options = { method: 'GET', url: '/api/admin/flash-assessment-configuration', - headers: { - authorization, - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: superAdmin.id }), }; // when @@ -107,14 +99,10 @@ describe('Acceptance | Application | flash-assessment-configuration-route', func describe('when called without a super admin role', function () { it('should return a 403', async function () { // given - const authorization = generateValidRequestAuthorizationHeader(); - const options = { method: 'POST', url: '/api/admin/flash-assessment-configuration', - headers: { - authorization, - }, + headers: generateAuthenticatedUserRequestHeaders(), payload: {}, }; @@ -141,14 +129,10 @@ describe('Acceptance | Application | flash-assessment-configuration-route', func await databaseBuilder.commit(); - const authorization = generateValidRequestAuthorizationHeader(superAdmin.id); - const options = { method: 'POST', url: '/api/admin/flash-assessment-configuration', - headers: { - authorization, - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: superAdmin.id }), payload: { lol: 0.5, }, @@ -176,14 +160,10 @@ describe('Acceptance | Application | flash-assessment-configuration-route', func await databaseBuilder.commit(); - const authorization = generateValidRequestAuthorizationHeader(superAdmin.id); - const options = { method: 'POST', url: '/api/admin/flash-assessment-configuration', - headers: { - authorization, - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: superAdmin.id }), payload: { variationPercent: 0.5, }, diff --git a/api/tests/certification/results/acceptance/application/certification-reports-route_test.js b/api/tests/certification/results/acceptance/application/certification-reports-route_test.js index bc2fa852973..cbd63a2ed17 100644 --- a/api/tests/certification/results/acceptance/application/certification-reports-route_test.js +++ b/api/tests/certification/results/acceptance/application/certification-reports-route_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, } from '../../../../test-helper.js'; describe('Acceptance | Route | Course | certification-reports-route', function () { @@ -35,7 +35,7 @@ describe('Acceptance | Route | Course | certification-reports-route', function ( method: 'GET', url: `/api/sessions/${sessionId}/certification-reports`, payload: {}, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }); // then @@ -55,7 +55,7 @@ describe('Acceptance | Route | Course | certification-reports-route', function ( method: 'GET', url: `/api/sessions/${sessionId}/certification-reports`, payload: {}, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }); // then diff --git a/api/tests/certification/results/acceptance/application/certification-results-route_test.js b/api/tests/certification/results/acceptance/application/certification-results-route_test.js index 20d9aa5efbb..a02e0dd5fed 100644 --- a/api/tests/certification/results/acceptance/application/certification-results-route_test.js +++ b/api/tests/certification/results/acceptance/application/certification-results-route_test.js @@ -7,7 +7,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, insertUserWithRoleSuperAdmin, } from '../../../../test-helper.js'; @@ -48,7 +48,7 @@ describe('Certification | Results | Acceptance | Application | Routes | certific const request = { method: 'GET', url: `/api/sessions/${sessionId}/certified-clea-candidate-data`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; await databaseBuilder.commit(); @@ -217,7 +217,7 @@ describe('Certification | Results | Acceptance | Application | Routes | certific await databaseBuilder.commit(); // when - options.headers = { authorization: generateValidRequestAuthorizationHeader() }; + options.headers = generateAuthenticatedUserRequestHeaders(); const response = await server.inject(options); // then @@ -238,7 +238,7 @@ describe('Certification | Results | Acceptance | Application | Routes | certific await insertUserWithRoleSuperAdmin(); // when - options.headers = { authorization: generateValidRequestAuthorizationHeader(1111) }; + options.headers = generateAuthenticatedUserRequestHeaders({ userId: 1111 }); const response = await server.inject(options); // then diff --git a/api/tests/certification/results/acceptance/application/livret-scolaire-route_test.js b/api/tests/certification/results/acceptance/application/livret-scolaire-route_test.js index cfb77bb9945..94d012ba10c 100644 --- a/api/tests/certification/results/acceptance/application/livret-scolaire-route_test.js +++ b/api/tests/certification/results/acceptance/application/livret-scolaire-route_test.js @@ -3,7 +3,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, generateValidRequestAuthorizationHeaderForApplication, } from '../../../../test-helper.js'; import { @@ -323,7 +323,7 @@ describe('Certification | Results | Acceptance | Application | Livret Scolaire', options = { method: 'GET', url: '/api/organizations/9999/certifications', - headers: { authorization: generateValidRequestAuthorizationHeader() }, + headers: generateAuthenticatedUserRequestHeaders(), }; // when diff --git a/api/tests/certification/results/acceptance/application/organization-route_test.js b/api/tests/certification/results/acceptance/application/organization-route_test.js index 91fa57925a7..b270fa90b11 100644 --- a/api/tests/certification/results/acceptance/application/organization-route_test.js +++ b/api/tests/certification/results/acceptance/application/organization-route_test.js @@ -5,7 +5,7 @@ import { Membership } from '../../../../../src/shared/domain/models/Membership.j import { databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, insertUserWithRoleSuperAdmin, } from '../../../../test-helper.js'; @@ -74,7 +74,7 @@ describe('Certification | Results | Acceptance | Application | Routes | organiza const options = { method: 'GET', url: `/api/organizations/${organization.id}/certification-results?division=aDivision`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; // when diff --git a/api/tests/certification/scoring/acceptance/application/scoring-and-capacity-simulator-route_test.js b/api/tests/certification/scoring/acceptance/application/scoring-and-capacity-simulator-route_test.js index aa7e96441b8..21bebd238fe 100644 --- a/api/tests/certification/scoring/acceptance/application/scoring-and-capacity-simulator-route_test.js +++ b/api/tests/certification/scoring/acceptance/application/scoring-and-capacity-simulator-route_test.js @@ -3,7 +3,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, learningContentBuilder, mockLearningContent, } from '../../../../test-helper.js'; @@ -33,14 +33,10 @@ describe('Acceptance | Application | scoring-and-capacity-simulator-route', func describe('when called without a super admin role', function () { it('should return a 403', async function () { // given - const authorization = generateValidRequestAuthorizationHeader(); - const options = { method: 'POST', url: '/api/admin/simulate-score-or-capacity', - headers: { - authorization, - }, + headers: generateAuthenticatedUserRequestHeaders(), payload: { data: { capacity: 1, @@ -67,14 +63,10 @@ describe('Acceptance | Application | scoring-and-capacity-simulator-route', func await databaseBuilder.commit(); - const authorization = generateValidRequestAuthorizationHeader(superAdmin.id); - const options = { method: 'POST', url: '/api/admin/simulate-score-or-capacity', - headers: { - authorization, - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: superAdmin.id }), payload: { data: { toto: 1, @@ -492,14 +484,10 @@ describe('Acceptance | Application | scoring-and-capacity-simulator-route', func await databaseBuilder.commit(); - const authorization = generateValidRequestAuthorizationHeader(superAdmin.id); - const options = { method: 'POST', url: '/api/admin/simulate-score-or-capacity', - headers: { - authorization, - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: superAdmin.id }), payload: { data: { score: 127, diff --git a/api/tests/certification/scoring/acceptance/application/scoring-configuration-route_test.js b/api/tests/certification/scoring/acceptance/application/scoring-configuration-route_test.js index fbd47f79460..9e23f2f9460 100644 --- a/api/tests/certification/scoring/acceptance/application/scoring-configuration-route_test.js +++ b/api/tests/certification/scoring/acceptance/application/scoring-configuration-route_test.js @@ -3,7 +3,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, knex, } from '../../../../test-helper.js'; @@ -32,14 +32,10 @@ describe('Acceptance | Application | scoring-configuration-route', function () { describe('when called without a super admin role', function () { it('should return a 403', async function () { // given - const authorization = generateValidRequestAuthorizationHeader(); - const options = { method: 'POST', url: '/api/admin/competence-for-scoring-configuration', - headers: { - authorization, - }, + headers: generateAuthenticatedUserRequestHeaders(), payload: [ { competence: '1.1', @@ -74,14 +70,10 @@ describe('Acceptance | Application | scoring-configuration-route', function () { await databaseBuilder.commit(); - const authorization = generateValidRequestAuthorizationHeader(superAdmin.id); - const options = { method: 'POST', url: '/api/admin/competence-for-scoring-configuration', - headers: { - authorization, - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: superAdmin.id }), payload: { lol: 0.5, }, @@ -104,14 +96,10 @@ describe('Acceptance | Application | scoring-configuration-route', function () { await databaseBuilder.commit(); - const authorization = generateValidRequestAuthorizationHeader(superAdmin.id); - const options = { method: 'POST', url: '/api/admin/competence-for-scoring-configuration', - headers: { - authorization, - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: superAdmin.id }), payload: [ { competence: '1.1', @@ -161,14 +149,10 @@ describe('Acceptance | Application | scoring-configuration-route', function () { describe('when called without a super admin role', function () { it('should return a 403', async function () { // given - const authorization = generateValidRequestAuthorizationHeader(); - const options = { method: 'POST', url: '/api/admin/certification-scoring-configuration', - headers: { - authorization, - }, + headers: generateAuthenticatedUserRequestHeaders(), payload: [ { meshLevel: 1, @@ -198,14 +182,10 @@ describe('Acceptance | Application | scoring-configuration-route', function () { await databaseBuilder.commit(); - const authorization = generateValidRequestAuthorizationHeader(superAdmin.id); - const options = { method: 'POST', url: '/api/admin/certification-scoring-configuration', - headers: { - authorization, - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: superAdmin.id }), payload: { lol: 0.5, }, @@ -228,14 +208,10 @@ describe('Acceptance | Application | scoring-configuration-route', function () { await databaseBuilder.commit(); - const authorization = generateValidRequestAuthorizationHeader(superAdmin.id); - const options = { method: 'POST', url: '/api/admin/certification-scoring-configuration', - headers: { - authorization, - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: superAdmin.id }), payload: [ { meshLevel: 1, diff --git a/api/tests/certification/session-management/acceptance/application/cancellation-route_test.js b/api/tests/certification/session-management/acceptance/application/cancellation-route_test.js index fa0c5d328e9..fcb87e36ecb 100644 --- a/api/tests/certification/session-management/acceptance/application/cancellation-route_test.js +++ b/api/tests/certification/session-management/acceptance/application/cancellation-route_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, insertUserWithRoleSuperAdmin, } from '../../../../test-helper.js'; @@ -20,7 +20,7 @@ describe('Certification | Session-management | Acceptance | Application | Routes const options = { method: 'PATCH', url: '/api/admin/certification-courses/123/cancel', - headers: { authorization: generateValidRequestAuthorizationHeader() }, + headers: generateAuthenticatedUserRequestHeaders(), }; await insertUserWithRoleSuperAdmin(); await databaseBuilder.commit(); @@ -40,7 +40,7 @@ describe('Certification | Session-management | Acceptance | Application | Routes const options = { method: 'PATCH', url: '/api/admin/certification-courses/123/uncancel', - headers: { authorization: generateValidRequestAuthorizationHeader() }, + headers: generateAuthenticatedUserRequestHeaders(), }; await insertUserWithRoleSuperAdmin(); await databaseBuilder.commit(); diff --git a/api/tests/certification/session-management/acceptance/application/certification-candidate-route_test.js b/api/tests/certification/session-management/acceptance/application/certification-candidate-route_test.js index 2b226827599..9fb1565548f 100644 --- a/api/tests/certification/session-management/acceptance/application/certification-candidate-route_test.js +++ b/api/tests/certification/session-management/acceptance/application/certification-candidate-route_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, } from '../../../../test-helper.js'; describe('Certification | Session Management | Acceptance | Application | Routes | certification-candidate', function () { @@ -51,7 +51,7 @@ describe('Certification | Session Management | Acceptance | Application | Routes const options = { method: 'POST', url: `/api/certification-candidates/${candidate.id}/authorize-to-start`, - headers: { authorization: generateValidRequestAuthorizationHeader(supervisorUserId, 'pix-certif') }, + headers: generateAuthenticatedUserRequestHeaders({ userId: supervisorUserId, source: 'pix-certif' }), payload: { 'authorized-to-start': true }, }; @@ -105,7 +105,7 @@ describe('Certification | Session Management | Acceptance | Application | Routes const options = { method: 'POST', url: `/api/certification-candidates/${candidate.id}/authorize-to-resume`, - headers: { authorization: generateValidRequestAuthorizationHeader(supervisorUserId, 'pix-certif') }, + headers: generateAuthenticatedUserRequestHeaders({ userId: supervisorUserId, source: 'pix-certif' }), }; // when @@ -164,7 +164,7 @@ describe('Certification | Session Management | Acceptance | Application | Routes const options = { method: 'PATCH', url: `/api/certification-candidates/1001/end-assessment-by-supervisor`, - headers: { authorization: generateValidRequestAuthorizationHeader(supervisorUserId, 'pix-certif') }, + headers: generateAuthenticatedUserRequestHeaders({ userId: supervisorUserId, source: 'pix-certif' }), }; // when diff --git a/api/tests/certification/session-management/acceptance/application/certification-course-route_test.js b/api/tests/certification/session-management/acceptance/application/certification-course-route_test.js index a6d28a94203..edd1e0c9b3d 100644 --- a/api/tests/certification/session-management/acceptance/application/certification-course-route_test.js +++ b/api/tests/certification/session-management/acceptance/application/certification-course-route_test.js @@ -5,7 +5,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, insertUserWithRoleSuperAdmin, knex, } from '../../../../test-helper.js'; @@ -19,7 +19,7 @@ describe('Certification | Session Management | Acceptance | Application | Routes const server = await createServer(); const options = { - headers: { authorization: generateValidRequestAuthorizationHeader() }, + headers: generateAuthenticatedUserRequestHeaders(), method: 'PATCH', url: '/api/admin/certification-courses/1', payload: { @@ -61,7 +61,7 @@ describe('Certification | Session Management | Acceptance | Application | Routes }).id; options = { - headers: { authorization: generateValidRequestAuthorizationHeader() }, + headers: generateAuthenticatedUserRequestHeaders(), method: 'PATCH', url: `/api/admin/certification-courses/${certificationCourseId}`, payload: { @@ -151,7 +151,7 @@ describe('Certification | Session Management | Acceptance | Application | Routes const response = await server.inject({ method: 'PATCH', url: `/api/admin/certification-courses/${certificationCourse.id}/reject`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }); // then @@ -236,7 +236,7 @@ describe('Certification | Session Management | Acceptance | Application | Routes const response = await server.inject({ method: 'PATCH', url: `/api/admin/certification-courses/${certificationCourse.id}/reject`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }); // then @@ -320,7 +320,7 @@ describe('Certification | Session Management | Acceptance | Application | Routes const response = await server.inject({ method: 'PATCH', url: `/api/admin/certification-courses/${certificationCourse.id}/unreject`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }); // then @@ -372,7 +372,7 @@ describe('Certification | Session Management | Acceptance | Application | Routes options = { method: 'POST', url: `/api/admin/certification-courses/${certificationCourseId}/assessment-results`, - headers: { authorization: generateValidRequestAuthorizationHeader() }, + headers: generateAuthenticatedUserRequestHeaders(), payload: { data: { attributes: { @@ -387,7 +387,7 @@ describe('Certification | Session Management | Acceptance | Application | Routes it('should respond with a 403 - forbidden access - if user has not role Super Admin', async function () { // given const nonSuperAdminUserId = 9999; - options.headers.authorization = generateValidRequestAuthorizationHeader(nonSuperAdminUserId); + options.headers = generateAuthenticatedUserRequestHeaders({ userId: nonSuperAdminUserId }); // when const response = await server.inject(options); @@ -435,14 +435,14 @@ describe('Certification | Session Management | Acceptance | Application | Routes options = { method: 'GET', url: `/api/admin/certification-courses-v3/${certificationCourse.id}/details`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; }); it('should respond with a 403 - forbidden access - if user is not an admin member', async function () { // given const nonAdminMemberUserId = 9999; - options.headers.authorization = generateValidRequestAuthorizationHeader(nonAdminMemberUserId); + options.headers = generateAuthenticatedUserRequestHeaders({ userId: nonAdminMemberUserId }); // when const response = await server.inject(options); diff --git a/api/tests/certification/session-management/acceptance/application/certification-details-route_test.js b/api/tests/certification/session-management/acceptance/application/certification-details-route_test.js index 9a15eaf94f8..00e9fa942b0 100644 --- a/api/tests/certification/session-management/acceptance/application/certification-details-route_test.js +++ b/api/tests/certification/session-management/acceptance/application/certification-details-route_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, insertUserWithRoleSuperAdmin, learningContentBuilder, mockLearningContent, @@ -23,9 +23,7 @@ describe('Certification | Session Management | Acceptance | Application | Routes const options = { method: 'GET', url: '/api/admin/certifications/1234/details', - headers: { - authorization: generateValidRequestAuthorizationHeader(), - }, + headers: generateAuthenticatedUserRequestHeaders(), }; const learningContent = [ diff --git a/api/tests/certification/session-management/acceptance/application/certification-issue-report-controller_test.js b/api/tests/certification/session-management/acceptance/application/certification-issue-report-controller_test.js index 95535871156..8ea0e34535e 100644 --- a/api/tests/certification/session-management/acceptance/application/certification-issue-report-controller_test.js +++ b/api/tests/certification/session-management/acceptance/application/certification-issue-report-controller_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, insertUserWithRoleSuperAdmin, knex, } from '../../../../test-helper.js'; @@ -26,9 +26,7 @@ describe('Acceptance | Controller | certification-issue-report-controller', func const response = await server.inject({ method: 'DELETE', url: `/api/certification-issue-reports/${certificationIssueReportId}`, - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }); // then @@ -52,9 +50,7 @@ describe('Acceptance | Controller | certification-issue-report-controller', func const request = { method: 'PATCH', url: `/api/certification-issue-reports/${certificationIssueReportId}`, - headers: { - authorization: generateValidRequestAuthorizationHeader(superAdmin.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: superAdmin.id }), payload: { data: { resolution: 'resolved', diff --git a/api/tests/certification/session-management/acceptance/application/certification-officer-route_test.js b/api/tests/certification/session-management/acceptance/application/certification-officer-route_test.js index 7a1e04a08bf..313083f0d67 100644 --- a/api/tests/certification/session-management/acceptance/application/certification-officer-route_test.js +++ b/api/tests/certification/session-management/acceptance/application/certification-officer-route_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, } from '../../../../test-helper.js'; describe('Certification | Session Management | Acceptance | Application | Routes | certification-officer', function () { @@ -23,7 +23,7 @@ describe('Certification | Session Management | Acceptance | Application | Routes const response = await server.inject({ method: 'PATCH', url: '/api/admin/sessions/12/certification-officer-assignment', - headers: { authorization: generateValidRequestAuthorizationHeader(certificationOfficerId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: certificationOfficerId }), }); // then @@ -41,7 +41,7 @@ describe('Certification | Session Management | Acceptance | Application | Routes // when const response = await server.inject({ method: 'PATCH', - headers: { authorization: generateValidRequestAuthorizationHeader(certificationOfficerId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: certificationOfficerId }), url: '/api/admin/sessions/test/certification-officer-assignment', }); @@ -60,7 +60,7 @@ describe('Certification | Session Management | Acceptance | Application | Routes // when const response = await server.inject({ method: 'PATCH', - headers: { authorization: generateValidRequestAuthorizationHeader(certificationOfficerId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: certificationOfficerId }), url: '/api/admin/sessions/1/certification-officer-assignment', }); @@ -83,7 +83,7 @@ describe('Certification | Session Management | Acceptance | Application | Routes // when const response = await server.inject({ method: 'PATCH', - headers: { authorization: generateValidRequestAuthorizationHeader(certificationOfficerId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: certificationOfficerId }), url: `/api/admin/sessions/${sessionId}/certification-officer-assignment`, }); diff --git a/api/tests/certification/session-management/acceptance/application/certification-report-route_test.js b/api/tests/certification/session-management/acceptance/application/certification-report-route_test.js index c74f4fb7c3a..be86a0b2d60 100644 --- a/api/tests/certification/session-management/acceptance/application/certification-report-route_test.js +++ b/api/tests/certification/session-management/acceptance/application/certification-report-route_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, } from '../../../../test-helper.js'; describe('Certification | Session Management | Acceptance | Application | Routes | certification-report', function () { @@ -46,9 +46,7 @@ describe('Certification | Session Management | Acceptance | Application | Routes type: 'certification-issue-reports', }, }, - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; await databaseBuilder.commit(); @@ -70,7 +68,7 @@ describe('Certification | Session Management | Acceptance | Application | Routes method: 'POST', url: `/api/certification-reports/${certificationCourseId}/abort`, payload: { data: { reason: 'technical' } }, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when diff --git a/api/tests/certification/session-management/acceptance/application/companion-alert-route_test.js b/api/tests/certification/session-management/acceptance/application/companion-alert-route_test.js index 4ba731d3200..7fe4609458c 100644 --- a/api/tests/certification/session-management/acceptance/application/companion-alert-route_test.js +++ b/api/tests/certification/session-management/acceptance/application/companion-alert-route_test.js @@ -4,7 +4,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, knex, } from '../../../../test-helper.js'; @@ -44,7 +44,7 @@ describe('Certification | Session Management | Acceptance | Application | Routes await databaseBuilder.commit(); - const headers = { authorization: generateValidRequestAuthorizationHeader(supervisorId, 'pix-certif') }; + const headers = generateAuthenticatedUserRequestHeaders({ userId: supervisorId, source: 'pix-certif' }); const options = { headers, @@ -72,7 +72,7 @@ describe('Certification | Session Management | Acceptance | Application | Routes await databaseBuilder.commit(); - const headers = { authorization: generateValidRequestAuthorizationHeader(supervisorId, 'pix-certif') }; + const headers = generateAuthenticatedUserRequestHeaders({ userId: supervisorId, source: 'pix-certif' }); const options = { headers, diff --git a/api/tests/certification/session-management/acceptance/application/complementary-certification-course-results-controller_test.js b/api/tests/certification/session-management/acceptance/application/complementary-certification-course-results-controller_test.js index 715306d8078..03f8292d36d 100644 --- a/api/tests/certification/session-management/acceptance/application/complementary-certification-course-results-controller_test.js +++ b/api/tests/certification/session-management/acceptance/application/complementary-certification-course-results-controller_test.js @@ -3,7 +3,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, insertUserWithRoleSuperAdmin, } from '../../../../test-helper.js'; @@ -59,7 +59,7 @@ describe('Certification | Session-management | Acceptance | complementary-certif const options = { method: 'POST', url: '/api/admin/complementary-certification-course-results', - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload: { data: { attributes: { diff --git a/api/tests/certification/session-management/acceptance/application/finalize-route_test.js b/api/tests/certification/session-management/acceptance/application/finalize-route_test.js index 7a32f8da4d2..7b2653a620e 100644 --- a/api/tests/certification/session-management/acceptance/application/finalize-route_test.js +++ b/api/tests/certification/session-management/acceptance/application/finalize-route_test.js @@ -9,7 +9,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, knex, learningContentBuilder, mockLearningContent, @@ -48,7 +48,7 @@ describe('Certification | Session Management | Acceptance | Application | Route // given const userId = databaseBuilder.factory.buildUser().id; await databaseBuilder.commit(); - options.headers.authorization = generateValidRequestAuthorizationHeader(userId); + options.headers = generateAuthenticatedUserRequestHeaders({ userId }); // when const response = await server.inject(options); @@ -73,7 +73,7 @@ describe('Certification | Session Management | Acceptance | Application | Route }); await databaseBuilder.commit(); - options.headers.authorization = generateValidRequestAuthorizationHeader(userId); + options.headers = generateAuthenticatedUserRequestHeaders({ userId }); // when await server.inject(options); @@ -169,9 +169,7 @@ describe('Certification | Session Management | Acceptance | Application | Route ], }, }, - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), url: `/api/sessions/${session.id}/finalization`, }; @@ -263,9 +261,7 @@ describe('Certification | Session Management | Acceptance | Application | Route ], }, }, - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), url: `/api/sessions/${session.id}/finalization`, }; @@ -368,9 +364,7 @@ describe('Certification | Session Management | Acceptance | Application | Route ], }, }, - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), url: `/api/sessions/${session.id}/finalization`, }; @@ -400,7 +394,7 @@ describe('Certification | Session Management | Acceptance | Application | Route }); await databaseBuilder.commit(); - options.headers.authorization = generateValidRequestAuthorizationHeader(userId); + options.headers = generateAuthenticatedUserRequestHeaders({ userId }); // when await server.inject(options); @@ -480,9 +474,7 @@ describe('Certification | Session Management | Acceptance | Application | Route ], }, }, - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), url: `/api/sessions/${session.id}/finalization`, }; @@ -602,9 +594,7 @@ describe('Certification | Session Management | Acceptance | Application | Route ], }, }, - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), url: `/api/sessions/${session.id}/finalization`, }; @@ -649,9 +639,7 @@ describe('Certification | Session Management | Acceptance | Application | Route ], }, }, - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), url: `/api/sessions/${session.id}/finalization`, }; diff --git a/api/tests/certification/session-management/acceptance/application/finalized-session-controller_test.js b/api/tests/certification/session-management/acceptance/application/finalized-session-controller_test.js index 160ef802d00..9b34a7e56d2 100644 --- a/api/tests/certification/session-management/acceptance/application/finalized-session-controller_test.js +++ b/api/tests/certification/session-management/acceptance/application/finalized-session-controller_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, insertUserWithRoleSuperAdmin, } from '../../../../test-helper.js'; @@ -36,7 +36,7 @@ describe('Certification | Session-management | Acceptance | Application | finali }); context('When user is authorized', function () { beforeEach(function () { - options.headers = { authorization: generateValidRequestAuthorizationHeader() }; + options.headers = generateAuthenticatedUserRequestHeaders(); }); it('should return a 200 status code response with JSON API serialized', async function () { @@ -89,7 +89,7 @@ describe('Certification | Session-management | Acceptance | Application | finali method: 'GET', url: '/api/admin/sessions/with-required-action', payload: {}, - headers: { authorization: generateValidRequestAuthorizationHeader() }, + headers: generateAuthenticatedUserRequestHeaders(), }; // when @@ -124,7 +124,7 @@ describe('Certification | Session-management | Acceptance | Application | finali method: 'GET', url: '/api/admin/sessions/with-required-action?filter[version]=3', payload: {}, - headers: { authorization: generateValidRequestAuthorizationHeader() }, + headers: generateAuthenticatedUserRequestHeaders(), }; // when diff --git a/api/tests/certification/session-management/acceptance/application/jury-certification-route_test.js b/api/tests/certification/session-management/acceptance/application/jury-certification-route_test.js index d8ac5dab54a..84734168ef7 100644 --- a/api/tests/certification/session-management/acceptance/application/jury-certification-route_test.js +++ b/api/tests/certification/session-management/acceptance/application/jury-certification-route_test.js @@ -4,7 +4,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, insertUserWithRoleSuperAdmin, } from '../../../../test-helper.js'; @@ -117,9 +117,7 @@ describe('Certification | Session Management | Acceptance | Application | Routes const options = { method: 'GET', url: '/api/admin/certifications/123', - headers: { - authorization: generateValidRequestAuthorizationHeader(user.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; // when diff --git a/api/tests/certification/session-management/acceptance/application/jury-comment-route_test.js b/api/tests/certification/session-management/acceptance/application/jury-comment-route_test.js index e46a77217bc..dbd5cff071f 100644 --- a/api/tests/certification/session-management/acceptance/application/jury-comment-route_test.js +++ b/api/tests/certification/session-management/acceptance/application/jury-comment-route_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, insertUserWithRoleSuperAdmin, } from '../../../../test-helper.js'; @@ -22,9 +22,7 @@ describe('Certification | Session Management | Acceptance | Application | Routes }, }, }, - headers: { - authorization: generateValidRequestAuthorizationHeader(), - }, + headers: generateAuthenticatedUserRequestHeaders(), url: `/api/admin/sessions/${session.id}/comment`, }; await databaseBuilder.commit(); @@ -45,9 +43,7 @@ describe('Certification | Session Management | Acceptance | Application | Routes const session = databaseBuilder.factory.buildSession(); await databaseBuilder.commit(); const options = { - headers: { - authorization: generateValidRequestAuthorizationHeader(), - }, + headers: generateAuthenticatedUserRequestHeaders(), method: 'DELETE', url: `/api/admin/sessions/${session.id}/comment`, }; diff --git a/api/tests/certification/session-management/acceptance/application/session-controller-publish-session-in-batch_test.js b/api/tests/certification/session-management/acceptance/application/session-controller-publish-session-in-batch_test.js index 8fdef789fa9..bf842d87e3e 100644 --- a/api/tests/certification/session-management/acceptance/application/session-controller-publish-session-in-batch_test.js +++ b/api/tests/certification/session-management/acceptance/application/session-controller-publish-session-in-batch_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, } from '../../../../test-helper.js'; describe('POST /api/admin/sessions/publish-in-batch', function () { @@ -17,7 +17,7 @@ describe('POST /api/admin/sessions/publish-in-batch', function () { server = await createServer(); // given userId = databaseBuilder.factory.buildUser.withRole().id; - options.headers = { authorization: generateValidRequestAuthorizationHeader(userId) }; + options.headers = generateAuthenticatedUserRequestHeaders({ userId }); return databaseBuilder.commit(); }); diff --git a/api/tests/certification/session-management/acceptance/application/session-for-supervising-route_test.js b/api/tests/certification/session-management/acceptance/application/session-for-supervising-route_test.js index 5bd959c3929..f655e048055 100644 --- a/api/tests/certification/session-management/acceptance/application/session-for-supervising-route_test.js +++ b/api/tests/certification/session-management/acceptance/application/session-for-supervising-route_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, } from '../../../../test-helper.js'; describe('Certification | Session Management | Acceptance | Application | Routes | session-for-supervising', function () { @@ -28,7 +28,7 @@ describe('Certification | Session Management | Acceptance | Application | Routes databaseBuilder.factory.buildSupervisorAccess({ userId, sessionId: 121 }); await databaseBuilder.commit(); - const headers = { authorization: generateValidRequestAuthorizationHeader(userId, 'pix-certif') }; + const headers = generateAuthenticatedUserRequestHeaders({ userId, source: 'pix-certif' }); const options = { headers, diff --git a/api/tests/certification/session-management/acceptance/application/session-live-alert-route_test.js b/api/tests/certification/session-management/acceptance/application/session-live-alert-route_test.js index 7113585b636..a7a7db7dd89 100644 --- a/api/tests/certification/session-management/acceptance/application/session-live-alert-route_test.js +++ b/api/tests/certification/session-management/acceptance/application/session-live-alert-route_test.js @@ -3,7 +3,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, knex, } from '../../../../test-helper.js'; @@ -43,9 +43,7 @@ describe('Certification | Session | Acceptance | Application | Routes | session- await databaseBuilder.commit(); - const headers = { - authorization: generateValidRequestAuthorizationHeader(supervisorUserId, 'pix-certif'), - }; + const headers = generateAuthenticatedUserRequestHeaders({ userId: supervisorUserId, source: 'pix-certif' }); const options = { headers, method: 'PATCH', @@ -80,9 +78,10 @@ describe('Certification | Session | Acceptance | Application | Routes | session- await databaseBuilder.commit(); - const headers = { - authorization: generateValidRequestAuthorizationHeader(userNotLinkedToTheSessionId, 'pix-certif'), - }; + const headers = generateAuthenticatedUserRequestHeaders({ + userId: userNotLinkedToTheSessionId, + source: 'pix-certif', + }); const options = { headers, method: 'PATCH', @@ -131,9 +130,7 @@ describe('Certification | Session | Acceptance | Application | Routes | session- await databaseBuilder.commit(); - const headers = { - authorization: generateValidRequestAuthorizationHeader(supervisorUserId, 'pix-certif'), - }; + const headers = generateAuthenticatedUserRequestHeaders({ userId: supervisorUserId, source: 'pix-certif' }); const options = { headers, method: 'PATCH', @@ -173,9 +170,10 @@ describe('Certification | Session | Acceptance | Application | Routes | session- await databaseBuilder.commit(); - const headers = { - authorization: generateValidRequestAuthorizationHeader(userNotLinkedToTheSessionId, 'pix-certif'), - }; + const headers = generateAuthenticatedUserRequestHeaders({ + userId: userNotLinkedToTheSessionId, + source: 'pix-certif', + }); const options = { headers, method: 'PATCH', diff --git a/api/tests/certification/session-management/acceptance/application/session-publication-route_test.js b/api/tests/certification/session-management/acceptance/application/session-publication-route_test.js index 06abc8b823f..c2a34f9e668 100644 --- a/api/tests/certification/session-management/acceptance/application/session-publication-route_test.js +++ b/api/tests/certification/session-management/acceptance/application/session-publication-route_test.js @@ -3,7 +3,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, knex, sinon, } from '../../../../test-helper.js'; @@ -27,7 +27,7 @@ describe('Certification | Session-Management | Acceptance | Application | Routes it('should return a 403 error code', async function () { // given options.url = '/api/admin/sessions/1/publish'; - options.headers = { authorization: generateValidRequestAuthorizationHeader(userId) }; + options.headers = generateAuthenticatedUserRequestHeaders({ userId }); // when const response = await server.inject(options); @@ -41,7 +41,7 @@ describe('Certification | Session-Management | Acceptance | Application | Routes beforeEach(function () { // given userId = databaseBuilder.factory.buildUser.withRole().id; - options.headers = { authorization: generateValidRequestAuthorizationHeader(userId) }; + options.headers = generateAuthenticatedUserRequestHeaders({ userId }); return databaseBuilder.commit(); }); @@ -197,7 +197,7 @@ describe('Certification | Session-Management | Acceptance | Application | Routes it('should return a 403 error code', async function () { // given options.url = '/api/admin/sessions/1/unpublish'; - options.headers = { authorization: generateValidRequestAuthorizationHeader(userId) }; + options.headers = generateAuthenticatedUserRequestHeaders({ userId }); // when const response = await server.inject(options); @@ -211,7 +211,7 @@ describe('Certification | Session-Management | Acceptance | Application | Routes beforeEach(function () { // given userId = databaseBuilder.factory.buildUser.withRole().id; - options.headers = { authorization: generateValidRequestAuthorizationHeader(userId) }; + options.headers = generateAuthenticatedUserRequestHeaders({ userId }); return databaseBuilder.commit(); }); diff --git a/api/tests/certification/session-management/acceptance/application/session-route_test.js b/api/tests/certification/session-management/acceptance/application/session-route_test.js index 8332b0f1bb4..579c9f03f70 100644 --- a/api/tests/certification/session-management/acceptance/application/session-route_test.js +++ b/api/tests/certification/session-management/acceptance/application/session-route_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, insertUserWithRoleSuperAdmin, } from '../../../../test-helper.js'; @@ -29,7 +29,7 @@ describe('Certification | Session Management | Acceptance | Application | Route context('when user is Super Admin', function () { beforeEach(function () { - options.headers = { authorization: generateValidRequestAuthorizationHeader() }; + options.headers = generateAuthenticatedUserRequestHeaders(); }); it('should return a 200 status code response with JSON API serialized', async function () { @@ -107,7 +107,7 @@ describe('Certification | Session Management | Acceptance | Application | Route context('when user is not SuperAdmin', function () { beforeEach(function () { - options.headers = { authorization: generateValidRequestAuthorizationHeader(1111) }; + options.headers = generateAuthenticatedUserRequestHeaders({ userId: 1111 }); }); it('should return 403 HTTP status code ', async function () { @@ -162,7 +162,7 @@ describe('Certification | Session Management | Acceptance | Application | Route context('when user is Super Admin', function () { beforeEach(function () { - options.headers = { authorization: generateValidRequestAuthorizationHeader() }; + options.headers = generateAuthenticatedUserRequestHeaders(); }); it('should return a 200 status code response with JSON API serialized', async function () { @@ -214,7 +214,7 @@ describe('Certification | Session Management | Acceptance | Application | Route context('when user is not SuperAdmin', function () { beforeEach(function () { - options.headers = { authorization: generateValidRequestAuthorizationHeader(1111) }; + options.headers = generateAuthenticatedUserRequestHeaders({ userId: 1111 }); }); it('should return 403 HTTP status code ', async function () { @@ -256,9 +256,7 @@ describe('Certification | Session Management | Acceptance | Application | Route await databaseBuilder.commit(); const options = { - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), method: 'GET', url: `/api/sessions/${sessionId}/management`, }; diff --git a/api/tests/certification/session-management/acceptance/application/supervise-controller-supervise_test.js b/api/tests/certification/session-management/acceptance/application/supervise-controller-supervise_test.js index 1093b393268..a61b9625160 100644 --- a/api/tests/certification/session-management/acceptance/application/supervise-controller-supervise_test.js +++ b/api/tests/certification/session-management/acceptance/application/supervise-controller-supervise_test.js @@ -3,7 +3,7 @@ import { databaseBuilder, domainBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, knex, } from '../../../../test-helper.js'; @@ -26,7 +26,7 @@ describe('Acceptance | Controller | Certification | Session management | session databaseBuilder.factory.buildSession(session); await databaseBuilder.commit(); - const headers = { authorization: generateValidRequestAuthorizationHeader(3456, 'pix-certif') }; + const headers = generateAuthenticatedUserRequestHeaders({ userId: 3456, source: 'pix-certif' }); const options = { headers, diff --git a/api/tests/certification/session-management/acceptance/application/unfinalize-route_test.js b/api/tests/certification/session-management/acceptance/application/unfinalize-route_test.js index df76e8aa4cf..2cafab70b6c 100644 --- a/api/tests/certification/session-management/acceptance/application/unfinalize-route_test.js +++ b/api/tests/certification/session-management/acceptance/application/unfinalize-route_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, } from '../../../../test-helper.js'; describe('Certification | Session Management | Acceptance | Application | Controller | unfinalize', function () { @@ -18,9 +18,7 @@ describe('Certification | Session Management | Acceptance | Application | Contro const options = { method: 'PATCH', url: '/api/admin/sessions/123/unfinalize', - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when diff --git a/api/tests/certification/session-management/acceptance/application/update-cpf-import-status-controller_test.js b/api/tests/certification/session-management/acceptance/application/update-cpf-import-status-controller_test.js index e675907bc0c..4be752fd798 100644 --- a/api/tests/certification/session-management/acceptance/application/update-cpf-import-status-controller_test.js +++ b/api/tests/certification/session-management/acceptance/application/update-cpf-import-status-controller_test.js @@ -5,7 +5,7 @@ import * as url from 'node:url'; import { createServer, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, insertUserWithRoleSuperAdmin, nock, } from '../../../../test-helper.js'; @@ -48,7 +48,7 @@ describe('Acceptance | Controller | Session | update-cpf-import-status-controlle const options = { method: 'PUT', url: '/api/admin/cpf/receipts', - headers: { authorization: generateValidRequestAuthorizationHeader(superAdmin.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: superAdmin.id }), }; // when @@ -64,7 +64,7 @@ describe('Acceptance | Controller | Session | update-cpf-import-status-controlle const options = { method: 'PUT', url: '/api/admin/cpf/receipts', - headers: { authorization: generateValidRequestAuthorizationHeader(1) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: 1 }), }; // when diff --git a/api/tests/devcomp/acceptance/application/passages/passage-controller_test.js b/api/tests/devcomp/acceptance/application/passages/passage-controller_test.js index 9cc8bd84db2..49024790ebb 100644 --- a/api/tests/devcomp/acceptance/application/passages/passage-controller_test.js +++ b/api/tests/devcomp/acceptance/application/passages/passage-controller_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, knex, } from '../../../../test-helper.js'; @@ -70,9 +70,7 @@ describe('Acceptance | Controller | passage-controller', function () { }, }, }, - headers: { - authorization: generateValidRequestAuthorizationHeader(user.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }); // then diff --git a/api/tests/devcomp/acceptance/application/trainings/training-controller_test.js b/api/tests/devcomp/acceptance/application/trainings/training-controller_test.js index 40abcc63822..1c605ca2f5d 100644 --- a/api/tests/devcomp/acceptance/application/trainings/training-controller_test.js +++ b/api/tests/devcomp/acceptance/application/trainings/training-controller_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, insertUserWithRoleSuperAdmin, knex, learningContentBuilder, @@ -107,9 +107,7 @@ describe('Acceptance | Controller | training-controller', function () { const response = await server.inject({ method: 'GET', url: `/api/admin/trainings/${trainingId}`, - headers: { - authorization: generateValidRequestAuthorizationHeader(superAdmin.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: superAdmin.id }), }); // then @@ -189,7 +187,7 @@ describe('Acceptance | Controller | training-controller', function () { }, }, }, - headers: { authorization: generateValidRequestAuthorizationHeader(superAdmin.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: superAdmin.id }), }); // then @@ -223,9 +221,7 @@ describe('Acceptance | Controller | training-controller', function () { options = { method: 'PATCH', url: `/api/admin/trainings/${training.id}`, - headers: { - authorization: generateValidRequestAuthorizationHeader(superAdmin.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: superAdmin.id }), payload: { data: { type: 'trainings', @@ -292,9 +288,7 @@ describe('Acceptance | Controller | training-controller', function () { options = { method: 'GET', url: `/api/admin/training-summaries?page[number]=1&page[size]=2`, - headers: { - authorization: generateValidRequestAuthorizationHeader(superAdmin.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: superAdmin.id }), }; const expectedResponse = { @@ -387,9 +381,7 @@ describe('Acceptance | Controller | training-controller', function () { const options = { method: 'PUT', url: `/api/admin/trainings/${trainingId}/triggers`, - headers: { - authorization: generateValidRequestAuthorizationHeader(superAdmin.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: superAdmin.id }), payload: { data: { type: 'training-triggers', @@ -466,9 +458,7 @@ describe('Acceptance | Controller | training-controller', function () { const response = await server.inject({ method: 'GET', url: `/api/admin/trainings/${training.id}/target-profile-summaries`, - headers: { - authorization: generateValidRequestAuthorizationHeader(superAdmin.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: superAdmin.id }), }); // then @@ -504,7 +494,7 @@ describe('Acceptance | Controller | training-controller', function () { const options = { method: 'POST', url: `/api/admin/trainings/${trainingId}/attach-target-profiles`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload: { 'target-profile-ids': [alreadyAttachedTargetProfileId, toAttachTargetProfileId], }, diff --git a/api/tests/devcomp/acceptance/application/tutorial-evaulations/tutorial-evaluations-controller_test.js b/api/tests/devcomp/acceptance/application/tutorial-evaulations/tutorial-evaluations-controller_test.js index 7296c3681dd..dfb980cfc49 100644 --- a/api/tests/devcomp/acceptance/application/tutorial-evaulations/tutorial-evaluations-controller_test.js +++ b/api/tests/devcomp/acceptance/application/tutorial-evaulations/tutorial-evaluations-controller_test.js @@ -3,7 +3,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, mockLearningContent, } from '../../../../test-helper.js'; @@ -47,9 +47,7 @@ describe('Acceptance | Controller | tutorial-evaluations-controller', function ( options = { method: 'PUT', url: '/api/users/tutorials/tutorialId/evaluate', - headers: { - authorization: generateValidRequestAuthorizationHeader(4444), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: 4444 }), payload: { data: { type: 'tutorial-evaluations', @@ -93,9 +91,7 @@ describe('Acceptance | Controller | tutorial-evaluations-controller', function ( options = { method: 'PUT', url: '/api/users/tutorials/tutorialId/evaluate', - headers: { - authorization: generateValidRequestAuthorizationHeader(4444), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: 4444 }), payload: { data: { type: 'tutorial-evaluations', diff --git a/api/tests/devcomp/acceptance/application/user-tutorials/user-tutorials-controller_test.js b/api/tests/devcomp/acceptance/application/user-tutorials/user-tutorials-controller_test.js index 4cb69aa9857..03ecc7a56f4 100644 --- a/api/tests/devcomp/acceptance/application/user-tutorials/user-tutorials-controller_test.js +++ b/api/tests/devcomp/acceptance/application/user-tutorials/user-tutorials-controller_test.js @@ -3,7 +3,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, learningContentBuilder, mockLearningContent, } from '../../../../test-helper.js'; @@ -52,9 +52,7 @@ describe('Acceptance | Controller | user-tutorial-controller', function () { options = { method: 'PUT', url: '/api/users/tutorials/tutorialId', - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; await mockLearningContent(learningContent); @@ -147,9 +145,7 @@ describe('Acceptance | Controller | user-tutorial-controller', function () { options = { method: 'GET', url: `/api/users/${userId}/tutorials?filter[competences]=recCompetence1&filter[type]=saved`, - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; learningContentObjects = learningContentBuilder.fromAreas([ @@ -472,9 +468,7 @@ describe('Acceptance | Controller | user-tutorial-controller', function () { options = { method: 'DELETE', url: '/api/users/tutorials/tutorialId', - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; await mockLearningContent(learningContent); diff --git a/api/tests/evaluation/acceptance/application/answers/answer-controller-find_test.js b/api/tests/evaluation/acceptance/application/answers/answer-controller-find_test.js index fc49ffd2069..db7c15ee792 100644 --- a/api/tests/evaluation/acceptance/application/answers/answer-controller-find_test.js +++ b/api/tests/evaluation/acceptance/application/answers/answer-controller-find_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, } from '../../../../test-helper.js'; describe('Acceptance | Controller | answer-controller-find', function () { @@ -21,7 +21,7 @@ describe('Acceptance | Controller | answer-controller-find', function () { options = { method: 'GET', url: `/api/answers?challengeId=${challengeId}&assessmentId=salut`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; }); @@ -57,7 +57,7 @@ describe('Acceptance | Controller | answer-controller-find', function () { options = { method: 'GET', url: `/api/answers?challengeId=${challengeId}&assessmentId=${assessment.id}`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; }); @@ -107,7 +107,7 @@ describe('Acceptance | Controller | answer-controller-find', function () { options = { method: 'GET', url: `/api/answers?challengeId=${challengeId}&assessmentId=${assessment.id}`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId + 3) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: userId + 3 }), }; }); @@ -169,7 +169,7 @@ describe('Acceptance | Controller | answer-controller-find', function () { options = { method: 'GET', url: `/api/answers?assessmentId=${assessment.id}`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; }); @@ -216,7 +216,7 @@ describe('Acceptance | Controller | answer-controller-find', function () { options = { method: 'GET', url: `/api/answers?assessmentId=${assessment.id}`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId + 3) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: userId + 3 }), }; }); diff --git a/api/tests/evaluation/acceptance/application/answers/answer-controller-get-correction_test.js b/api/tests/evaluation/acceptance/application/answers/answer-controller-get-correction_test.js index c9e625614c7..a041ded380f 100644 --- a/api/tests/evaluation/acceptance/application/answers/answer-controller-get-correction_test.js +++ b/api/tests/evaluation/acceptance/application/answers/answer-controller-get-correction_test.js @@ -3,7 +3,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, mockLearningContent, } from '../../../../test-helper.js'; @@ -12,10 +12,7 @@ const { FRENCH_FRANCE } = LOCALE; const buildOptions = (answerId, userId) => ({ method: 'GET', url: `/api/answers/${answerId}/correction`, - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - 'accept-language': FRENCH_FRANCE, - }, + headers: generateAuthenticatedUserRequestHeaders({ userId, acceptLanguage: FRENCH_FRANCE }), }); const solution = 'l1:\n- chien\n- chat\n- cochon\nl2:\n- pigeon\n- poulet\n- veau\nl3:\n- canard\n- couincouin\nl4:\n- mouton'; @@ -197,10 +194,7 @@ describe('Acceptance | Controller | answer-controller-get-correction', function const options = { method: 'GET', url: `/api/answers/${answer.id}/correction`, - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - 'accept-language': FRENCH_FRANCE, - }, + headers: generateAuthenticatedUserRequestHeaders({ userId, acceptLanguage: FRENCH_FRANCE }), }; const expectedBody = { @@ -351,7 +345,7 @@ describe('Acceptance | Controller | answer-controller-get-correction', function const options = { method: 'GET', url: `/api/answers/${answer.id}/correction`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId + 3) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: userId + 3 }), }; // when @@ -366,7 +360,7 @@ describe('Acceptance | Controller | answer-controller-get-correction', function const options = { method: 'GET', url: '/api/answers/1/correction', - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when diff --git a/api/tests/evaluation/acceptance/application/answers/answer-controller-get_test.js b/api/tests/evaluation/acceptance/application/answers/answer-controller-get_test.js index aef82c4db4c..a04c60b3d86 100644 --- a/api/tests/evaluation/acceptance/application/answers/answer-controller-get_test.js +++ b/api/tests/evaluation/acceptance/application/answers/answer-controller-get_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, } from '../../../../test-helper.js'; describe('Acceptance | Controller | answer-controller-get', function () { @@ -27,7 +27,7 @@ describe('Acceptance | Controller | answer-controller-get', function () { options = { method: 'GET', url: `/api/answers/${answer.id}`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; }); @@ -70,7 +70,7 @@ describe('Acceptance | Controller | answer-controller-get', function () { options = { method: 'GET', url: '/api/answers/salut', - headers: { authorization: generateValidRequestAuthorizationHeader(userId + 1) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: userId + 1 }), }; }); @@ -98,7 +98,7 @@ describe('Acceptance | Controller | answer-controller-get', function () { options = { method: 'GET', url: `/api/answers/${answer.id}`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId + 1) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: userId + 1 }), }; }); diff --git a/api/tests/evaluation/acceptance/application/answers/answer-controller-save_test.js b/api/tests/evaluation/acceptance/application/answers/answer-controller-save_test.js index 87249ef2ff0..67da30d09e0 100644 --- a/api/tests/evaluation/acceptance/application/answers/answer-controller-save_test.js +++ b/api/tests/evaluation/acceptance/application/answers/answer-controller-save_test.js @@ -3,7 +3,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, knex, mockLearningContent, } from '../../../../test-helper.js'; @@ -82,7 +82,7 @@ describe('Acceptance | Controller | answer-controller-save', function () { postAnswersOptions = { method: 'POST', url: '/api/answers', - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload: { data: { type: 'answers', @@ -200,7 +200,7 @@ describe('Acceptance | Controller | answer-controller-save', function () { postAnswersOptions = { method: 'POST', url: '/api/answers', - headers: { authorization: generateValidRequestAuthorizationHeader(userId + 3) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: userId + 3 }), payload: { data: { type: 'answers', @@ -243,7 +243,7 @@ describe('Acceptance | Controller | answer-controller-save', function () { postAnswersOptions = { method: 'POST', url: '/api/answers', - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload: {}, }; promise = server.inject(postAnswersOptions); @@ -297,7 +297,7 @@ describe('Acceptance | Controller | answer-controller-save', function () { postAnswersOptions = { method: 'POST', url: '/api/answers', - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload: { data: { type: 'answers', @@ -375,7 +375,7 @@ describe('Acceptance | Controller | answer-controller-save', function () { postAnswersOptions = { method: 'POST', url: '/api/answers', - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload: { data: { type: 'answers', diff --git a/api/tests/evaluation/acceptance/application/answers/answer-controller-update_test.js b/api/tests/evaluation/acceptance/application/answers/answer-controller-update_test.js index b8693e6d5be..1dcfc1e8811 100644 --- a/api/tests/evaluation/acceptance/application/answers/answer-controller-update_test.js +++ b/api/tests/evaluation/acceptance/application/answers/answer-controller-update_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, } from '../../../../test-helper.js'; describe('Acceptance | Controller | answer-controller-update', function () { @@ -25,7 +25,7 @@ describe('Acceptance | Controller | answer-controller-update', function () { method: 'PATCH', url: '/api/answers/' + answer.id, payload: {}, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; }); diff --git a/api/tests/evaluation/acceptance/application/autonomous-courses/autonomous-course-controller_test.js b/api/tests/evaluation/acceptance/application/autonomous-courses/autonomous-course-controller_test.js index 95d3ce4c4ef..1f8117240ae 100644 --- a/api/tests/evaluation/acceptance/application/autonomous-courses/autonomous-course-controller_test.js +++ b/api/tests/evaluation/acceptance/application/autonomous-courses/autonomous-course-controller_test.js @@ -3,7 +3,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, insertUserWithRoleSuperAdmin, knex, learningContentBuilder, @@ -82,9 +82,7 @@ describe('Acceptance | API | Autonomous Course', function () { const options = { method: 'POST', url: '/api/admin/autonomous-courses', - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload, }; const response = await server.inject(options); @@ -165,9 +163,7 @@ describe('Acceptance | API | Autonomous Course', function () { const response = await server.inject({ method: 'GET', url: '/api/admin/autonomous-courses', - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }); // then @@ -225,9 +221,7 @@ describe('Acceptance | API | Autonomous Course', function () { const response = await server.inject({ method: 'GET', url: `/api/admin/autonomous-courses/${autonomousCourseId}`, - headers: { - authorization: generateValidRequestAuthorizationHeader(superAdmin.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: superAdmin.id }), }); // then @@ -273,9 +267,7 @@ describe('Acceptance | API | Autonomous Course', function () { const response = await server.inject({ method: 'PATCH', url: `/api/admin/autonomous-courses/${autonomousCourseId}`, - headers: { - authorization: generateValidRequestAuthorizationHeader(superAdmin.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: superAdmin.id }), payload: { data: { type: 'autonomous-courses', @@ -351,7 +343,7 @@ describe('Acceptance | API | Autonomous Course', function () { const options = { method: 'GET', url: `/api/admin/autonomous-courses/target-profiles`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; const expectedResult = [ diff --git a/api/tests/evaluation/acceptance/application/badge-criteria/badge-criteria-controller_test.js b/api/tests/evaluation/acceptance/application/badge-criteria/badge-criteria-controller_test.js index ca2b5c852ee..10d69de1408 100644 --- a/api/tests/evaluation/acceptance/application/badge-criteria/badge-criteria-controller_test.js +++ b/api/tests/evaluation/acceptance/application/badge-criteria/badge-criteria-controller_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, insertUserWithRoleSuperAdmin, knex, } from '../../../../test-helper.js'; @@ -32,9 +32,7 @@ describe('Acceptance | API | Badge Criteria', function () { const response = await server.inject({ method: 'PATCH', url: `/api/admin/badge-criteria/${initialBadgeCriterion.id}`, - headers: { - authorization: generateValidRequestAuthorizationHeader(superAdmin.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: superAdmin.id }), payload: { data: { type: 'badge-criteria', diff --git a/api/tests/evaluation/acceptance/application/badges/index_test.js b/api/tests/evaluation/acceptance/application/badges/index_test.js index 10dcb8bfe9a..8e94acb239e 100644 --- a/api/tests/evaluation/acceptance/application/badges/index_test.js +++ b/api/tests/evaluation/acceptance/application/badges/index_test.js @@ -4,7 +4,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, knex, } from '../../../../test-helper.js'; @@ -59,7 +59,7 @@ describe('Acceptance | Route | target-profiles', function () { const options = { method: 'POST', url: `/api/admin/target-profiles/${targetProfileId}/badges/`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), payload: { data: { type: 'badge-creations', @@ -142,7 +142,7 @@ describe('Acceptance | Route | target-profiles', function () { const options = { method: 'POST', url: `/api/admin/target-profiles/${targetProfileId}/badges/`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), payload: { data: { type: 'badge-creations', @@ -196,7 +196,7 @@ describe('Acceptance | Route | target-profiles', function () { const options = { method: 'POST', url: `/api/admin/target-profiles/${targetProfileId}/badges/`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), payload: { data: { type: 'badge-creations', diff --git a/api/tests/evaluation/acceptance/application/competence-evaluations/competence-evaluation-controller_test.js b/api/tests/evaluation/acceptance/application/competence-evaluations/competence-evaluation-controller_test.js index a2de4081900..fb58ce44259 100644 --- a/api/tests/evaluation/acceptance/application/competence-evaluations/competence-evaluation-controller_test.js +++ b/api/tests/evaluation/acceptance/application/competence-evaluations/competence-evaluation-controller_test.js @@ -3,7 +3,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, knex, learningContentBuilder, mockLearningContent, @@ -46,9 +46,7 @@ describe('Acceptance | API | Competence Evaluations', function () { const options = { method: 'POST', url: '/api/competence-evaluations/start-or-resume', - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload: { competenceId }, }; const response = await server.inject(options); @@ -64,9 +62,7 @@ describe('Acceptance | API | Competence Evaluations', function () { const options = { method: 'POST', url: '/api/competence-evaluations/start-or-resume', - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload: { competenceId }, }; databaseBuilder.factory.buildCompetenceEvaluation({ competenceId, userId }); @@ -88,9 +84,7 @@ describe('Acceptance | API | Competence Evaluations', function () { const options = { method: 'POST', url: '/api/competence-evaluations/start-or-resume', - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload: { competenceId: 'WRONG_ID' }, }; @@ -142,9 +136,7 @@ describe('Acceptance | API | Competence Evaluations', function () { const options = { method: 'PUT', url: '/api/competence-evaluations/improve', - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload: { competenceId }, }; @@ -183,9 +175,7 @@ describe('Acceptance | API | Competence Evaluations', function () { const options = { method: 'PUT', url: '/api/competence-evaluations/improve', - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload: { competenceId }, }; @@ -204,9 +194,7 @@ describe('Acceptance | API | Competence Evaluations', function () { const options = { method: 'PUT', url: '/api/competence-evaluations/improve', - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload: { competenceId: 'WRONG_ID' }, }; diff --git a/api/tests/evaluation/acceptance/application/progressions/progression-controller_test.js b/api/tests/evaluation/acceptance/application/progressions/progression-controller_test.js index 541d4a363fc..aa99923dabb 100644 --- a/api/tests/evaluation/acceptance/application/progressions/progression-controller_test.js +++ b/api/tests/evaluation/acceptance/application/progressions/progression-controller_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, learningContentBuilder, mockLearningContent, } from '../../../../test-helper.js'; @@ -87,9 +87,7 @@ describe('Acceptance | API | Progressions', function () { const options = { method: 'GET', url: `/api/progressions/${progressionId}`, - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when @@ -109,9 +107,7 @@ describe('Acceptance | API | Progressions', function () { const options = { method: 'GET', url: `/api/progressions/${progressionId}`, - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when diff --git a/api/tests/evaluation/acceptance/application/scorecards/scorecard-controller_test.js b/api/tests/evaluation/acceptance/application/scorecards/scorecard-controller_test.js index cb03b1da9ba..80966568407 100644 --- a/api/tests/evaluation/acceptance/application/scorecards/scorecard-controller_test.js +++ b/api/tests/evaluation/acceptance/application/scorecards/scorecard-controller_test.js @@ -4,7 +4,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, mockLearningContent, } from '../../../../test-helper.js'; @@ -133,7 +133,7 @@ describe('Acceptance | Controller | scorecard-controller', function () { context('Success case', function () { beforeEach(async function () { - options.headers.authorization = generateValidRequestAuthorizationHeader(userId); + options.headers = generateAuthenticatedUserRequestHeaders({ userId }); databaseBuilder.factory.buildKnowledgeElement({ userId, @@ -258,10 +258,7 @@ describe('Acceptance | Controller | scorecard-controller', function () { databaseBuilder.factory.buildUserSavedTutorial({ id: 10500, userId, tutorialId: tutorialWebId }); await databaseBuilder.commit(); - options.headers = { - authorization: generateValidRequestAuthorizationHeader(userId), - 'accept-language': FRENCH_SPOKEN, - }; + options.headers = generateAuthenticatedUserRequestHeaders({ userId, acceptLanguage: FRENCH_SPOKEN }); databaseBuilder.factory.buildKnowledgeElement({ userId, @@ -372,9 +369,7 @@ describe('Acceptance | Controller | scorecard-controller', function () { method: 'POST', url: `/api/users/${userId}/competences/${competenceId}/reset`, payload: {}, - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; await server.inject(options); diff --git a/api/tests/evaluation/acceptance/application/smart-random-simulator/smart-random-simulator-controller_test.js b/api/tests/evaluation/acceptance/application/smart-random-simulator/smart-random-simulator-controller_test.js index e1380a8d0b8..f220c722b71 100644 --- a/api/tests/evaluation/acceptance/application/smart-random-simulator/smart-random-simulator-controller_test.js +++ b/api/tests/evaluation/acceptance/application/smart-random-simulator/smart-random-simulator-controller_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, } from '../../../../test-helper.js'; describe('Acceptance | API | Smart Random Simulator', function () { @@ -68,9 +68,7 @@ describe('Acceptance | API | Smart Random Simulator', function () { options = { method: 'POST', url: '/api/admin/smart-random-simulator/get-next-challenge', - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload: buildPayload(), }; response = await server.inject(options); @@ -187,9 +185,7 @@ describe('Acceptance | API | Smart Random Simulator', function () { options = { method: 'POST', url: '/api/admin/smart-random-simulator/get-next-challenge', - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload: buildPayload(false), }; response = await server.inject(options); diff --git a/api/tests/evaluation/acceptance/application/stage-collections/stage-collection-controller_test.js b/api/tests/evaluation/acceptance/application/stage-collections/stage-collection-controller_test.js index f6442918c2c..d299e95df93 100644 --- a/api/tests/evaluation/acceptance/application/stage-collections/stage-collection-controller_test.js +++ b/api/tests/evaluation/acceptance/application/stage-collections/stage-collection-controller_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, learningContentBuilder, mockLearningContent, } from '../../../../test-helper.js'; @@ -31,9 +31,7 @@ describe('Acceptance | Controller | stage-collection', function () { const options = { method: 'PATCH', url: `/api/admin/stage-collections/${targetProfile.id}`, - headers: { - authorization: generateValidRequestAuthorizationHeader(user.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), payload: { data: { type: 'stage-collections', @@ -84,9 +82,7 @@ describe('Acceptance | Controller | stage-collection', function () { const options = { method: 'PATCH', url: `/api/admin/stage-collections/${targetProfile.id}`, - headers: { - authorization: generateValidRequestAuthorizationHeader(user.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), payload: { data: { type: 'stage-collections', diff --git a/api/tests/evaluation/acceptance/application/stages/stage-controller_test.js b/api/tests/evaluation/acceptance/application/stages/stage-controller_test.js index eee4cc926dd..fbd236ca2e7 100644 --- a/api/tests/evaluation/acceptance/application/stages/stage-controller_test.js +++ b/api/tests/evaluation/acceptance/application/stages/stage-controller_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, knex, learningContentBuilder, mockLearningContent, @@ -55,9 +55,7 @@ describe('Acceptance | API | Stages', function () { const options = { method: 'PATCH', url: `/api/admin/stages/${stageId}`, - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload: { data: { attributes: { diff --git a/api/tests/evaluation/acceptance/application/users/remember-user-has-seen-new-dashboard-info_test.js b/api/tests/evaluation/acceptance/application/users/remember-user-has-seen-new-dashboard-info_test.js index 4d55f85a6af..32da95e0ded 100644 --- a/api/tests/evaluation/acceptance/application/users/remember-user-has-seen-new-dashboard-info_test.js +++ b/api/tests/evaluation/acceptance/application/users/remember-user-has-seen-new-dashboard-info_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, } from '../../../../test-helper.js'; describe('Acceptance | Controller | users-controller-has-seen-new-dashboard-info', function () { @@ -18,7 +18,7 @@ describe('Acceptance | Controller | users-controller-has-seen-new-dashboard-info options = { method: 'PATCH', url: `/api/users/${user.id}/has-seen-new-dashboard-info`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; return databaseBuilder.commit(); @@ -39,7 +39,7 @@ describe('Acceptance | Controller | users-controller-has-seen-new-dashboard-info it('should respond with a 403 - forbidden access - if requested user is not the same as authenticated user', async function () { // given const otherUserId = 9999; - options.headers.authorization = generateValidRequestAuthorizationHeader(otherUserId); + options.headers = generateAuthenticatedUserRequestHeaders({ userId: otherUserId }); // when const response = await server.inject(options); diff --git a/api/tests/identity-access-management/acceptance/application/anonymization.admin.route.test.js b/api/tests/identity-access-management/acceptance/application/anonymization.admin.route.test.js index 842f5778c29..7c1598917d0 100644 --- a/api/tests/identity-access-management/acceptance/application/anonymization.admin.route.test.js +++ b/api/tests/identity-access-management/acceptance/application/anonymization.admin.route.test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, insertUserWithRoleSuperAdmin, } from '../../../test-helper.js'; @@ -45,7 +45,7 @@ describe('Acceptance | Identity Access Management | Application | Route | Admin const options = { method: 'POST', - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), url: '/api/admin/anonymize/gar', payload: input, }; diff --git a/api/tests/identity-access-management/acceptance/application/oidc-provider.admin.route.test.js b/api/tests/identity-access-management/acceptance/application/oidc-provider.admin.route.test.js index 92a4d36881a..1a77ec0f8f1 100644 --- a/api/tests/identity-access-management/acceptance/application/oidc-provider.admin.route.test.js +++ b/api/tests/identity-access-management/acceptance/application/oidc-provider.admin.route.test.js @@ -6,7 +6,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, insertUserWithRoleSuperAdmin, knex, } from '../../../test-helper.js'; @@ -43,7 +43,7 @@ describe('Acceptance | Identity Access Management | Route | Admin | oidc-provide method: 'POST', url: '/api/admin/oidc-providers/import', payload, - headers: { authorization: generateValidRequestAuthorizationHeader(superAdmin.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: superAdmin.id }), }; // when @@ -63,7 +63,7 @@ describe('Acceptance | Identity Access Management | Route | Admin | oidc-provide const options = { method: 'GET', url: '/api/admin/oidc/identity-providers', - headers: { authorization: generateValidRequestAuthorizationHeader(superAdmin.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: superAdmin.id }), }; // when diff --git a/api/tests/identity-access-management/acceptance/application/oidc-provider.route.test.js b/api/tests/identity-access-management/acceptance/application/oidc-provider.route.test.js index a559fd77e5f..10d300c164d 100644 --- a/api/tests/identity-access-management/acceptance/application/oidc-provider.route.test.js +++ b/api/tests/identity-access-management/acceptance/application/oidc-provider.route.test.js @@ -10,7 +10,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, knex, sinon, } from '../../../test-helper.js'; @@ -59,7 +59,7 @@ describe('Acceptance | Identity Access Management | Application | Route | oidc-p const options = { method: 'GET', url: '/api/oidc/redirect-logout-url?identity_provider=OIDC_EXAMPLE_NET&logout_url_uuid=86e1338f-304c-41a8-9472-89fe1b9748a1', - headers: { authorization: generateValidRequestAuthorizationHeader() }, + headers: generateAuthenticatedUserRequestHeaders(), }; // when diff --git a/api/tests/identity-access-management/acceptance/application/user/user.admin.route.test.js b/api/tests/identity-access-management/acceptance/application/user/user.admin.route.test.js index 7e01d28ce16..43f3d6082fa 100644 --- a/api/tests/identity-access-management/acceptance/application/user/user.admin.route.test.js +++ b/api/tests/identity-access-management/acceptance/application/user/user.admin.route.test.js @@ -4,7 +4,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, insertUserWithRoleSuperAdmin, knex, sinon, @@ -29,7 +29,7 @@ describe('Acceptance | Identity Access Management | Application | Route | Admin const response = await server.inject({ method: 'PUT', url: `/api/admin/users/${userId}/unblock`, - headers: { authorization: generateValidRequestAuthorizationHeader(superAdmin.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: superAdmin.id }), }); // then @@ -67,7 +67,7 @@ describe('Acceptance | Identity Access Management | Application | Route | Admin requestOptions = { method: 'GET', url: `/api/admin/users${params}`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; // when const response = await server.inject(requestOptions); @@ -90,7 +90,7 @@ describe('Acceptance | Identity Access Management | Application | Route | Admin requestOptions = { method: 'GET', url: `/api/admin/users${params}`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; // when const response = await server.inject(requestOptions); @@ -115,7 +115,7 @@ describe('Acceptance | Identity Access Management | Application | Route | Admin const options = { method: 'PATCH', url: `/api/admin/users/${user.id}`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), payload: { data: { id: user.id, @@ -176,7 +176,7 @@ describe('Acceptance | Identity Access Management | Application | Route | Admin const options = { method: 'PATCH', url: `/api/admin/users/${user.id}`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), payload: { data: { id: user.id, @@ -228,9 +228,7 @@ describe('Acceptance | Identity Access Management | Application | Route | Admin method: 'GET', url: `/api/admin/users/${user.id}`, payload: {}, - headers: { - authorization: generateValidRequestAuthorizationHeader(otherUserId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: otherUserId }), }); // then @@ -261,9 +259,7 @@ describe('Acceptance | Identity Access Management | Application | Route | Admin method: 'GET', url: `/api/admin/users/${user.id}`, payload: {}, - headers: { - authorization: generateValidRequestAuthorizationHeader(superAdmin.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: superAdmin.id }), }); // then @@ -374,7 +370,7 @@ describe('Acceptance | Identity Access Management | Application | Route | Admin method: 'POST', url: `/api/admin/users/${userId}/anonymize`, payload: {}, - headers: { authorization: generateValidRequestAuthorizationHeader(superAdmin.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: superAdmin.id }), }); }); @@ -427,9 +423,7 @@ describe('Acceptance | Identity Access Management | Application | Route | Admin const response = await server.inject({ method: 'POST', url: `/api/admin/users/${user.id}/add-pix-authentication-method`, - headers: { - authorization: generateValidRequestAuthorizationHeader(superAdmin.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: superAdmin.id }), payload: { data: { id: user.id, @@ -471,7 +465,7 @@ describe('Acceptance | Identity Access Management | Application | Route | Admin }, }, }, - headers: { authorization: generateValidRequestAuthorizationHeader(superAdmin.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: superAdmin.id }), }; return databaseBuilder.commit(); }); @@ -529,9 +523,7 @@ describe('Acceptance | Identity Access Management | Application | Route | Admin const response = await server.inject({ method: 'POST', url: `/api/admin/users/${originUserId}/authentication-methods/${authenticationMethodId}`, - headers: { - authorization: generateValidRequestAuthorizationHeader(superAdmin.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: superAdmin.id }), payload: { data: { attributes: { @@ -564,9 +556,7 @@ describe('Acceptance | Identity Access Management | Application | Route | Admin const response = await server.inject({ method: 'POST', url: `/api/admin/users/${originUserId}/authentication-methods/${authenticationMethodId}`, - headers: { - authorization: generateValidRequestAuthorizationHeader(superAdmin.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: superAdmin.id }), payload: { data: { attributes: { diff --git a/api/tests/identity-access-management/acceptance/application/user/user.route.test.js b/api/tests/identity-access-management/acceptance/application/user/user.route.test.js index f2272162fbd..1f2d5c01c86 100644 --- a/api/tests/identity-access-management/acceptance/application/user/user.route.test.js +++ b/api/tests/identity-access-management/acceptance/application/user/user.route.test.js @@ -12,7 +12,7 @@ import { databaseBuilder, domainBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, knex, sinon, } from '../../../../test-helper.js'; @@ -195,7 +195,7 @@ describe('Acceptance | Identity Access Management | Application | Route | User', options = { method: 'GET', url: '/api/users/me', - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; return databaseBuilder.commit(); @@ -274,7 +274,7 @@ describe('Acceptance | Identity Access Management | Application | Route | User', const response = await server.inject({ method: 'GET', url: '/api/users/my-account', - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }); // then @@ -306,9 +306,7 @@ describe('Acceptance | Identity Access Management | Application | Route | User', const options = { method: 'GET', url: `/api/users/${user.id}/authentication-methods`, - headers: { - authorization: generateValidRequestAuthorizationHeader(user.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; // when @@ -411,7 +409,7 @@ describe('Acceptance | Identity Access Management | Application | Route | User', options = { method: 'PATCH', url: `/api/users/${user.id}/pix-terms-of-service-acceptance`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; return databaseBuilder.commit(); @@ -432,7 +430,7 @@ describe('Acceptance | Identity Access Management | Application | Route | User', it('responds with a 403 - forbidden access - if requested user is not the same as authenticated user', async function () { // given const otherUserId = 9999; - options.headers.authorization = generateValidRequestAuthorizationHeader(otherUserId); + options.headers = generateAuthenticatedUserRequestHeaders({ userId: otherUserId }); // when const response = await server.inject(options); @@ -465,7 +463,7 @@ describe('Acceptance | Identity Access Management | Application | Route | User', options = { method: 'PATCH', url: `/api/users/${user.id}/pix-orga-terms-of-service-acceptance`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; return databaseBuilder.commit(); @@ -486,7 +484,7 @@ describe('Acceptance | Identity Access Management | Application | Route | User', it('responds with a 403 - forbidden access - if requested user is not the same as authenticated user', async function () { // given const otherUserId = 9999; - options.headers.authorization = generateValidRequestAuthorizationHeader(otherUserId); + options.headers = generateAuthenticatedUserRequestHeaders({ userId: otherUserId }); // when const response = await server.inject(options); @@ -517,7 +515,7 @@ describe('Acceptance | Identity Access Management | Application | Route | User', options = { method: 'PATCH', url: `/api/users/${user.id}/pix-certif-terms-of-service-acceptance`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; return databaseBuilder.commit(); @@ -538,7 +536,7 @@ describe('Acceptance | Identity Access Management | Application | Route | User', it('responds with a 403 - forbidden access - if requested user is not the same as authenticated user', async function () { // given const otherUserId = 9999; - options.headers.authorization = generateValidRequestAuthorizationHeader(otherUserId); + options.headers = generateAuthenticatedUserRequestHeaders({ userId: otherUserId }); // when const response = await server.inject(options); @@ -570,7 +568,7 @@ describe('Acceptance | Identity Access Management | Application | Route | User', options = { method: 'PATCH', url: `/api/users/${user.id}/lang/${newLang}`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; return databaseBuilder.commit(); @@ -591,7 +589,7 @@ describe('Acceptance | Identity Access Management | Application | Route | User', it('responds with a 403 - forbidden access - if requested user is not the same as authenticated user', async function () { // given const otherUserId = 9999; - options.headers.authorization = generateValidRequestAuthorizationHeader(otherUserId); + options.headers = generateAuthenticatedUserRequestHeaders({ userId: otherUserId }); // when const response = await server.inject(options); @@ -649,7 +647,7 @@ describe('Acceptance | Identity Access Management | Application | Route | User', const response = await server.inject({ method: 'PATCH', url: `/api/users/${user.id}/has-seen-last-data-protection-policy-information`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }); // then @@ -670,7 +668,7 @@ describe('Acceptance | Identity Access Management | Application | Route | User', options = { method: 'PATCH', url: `/api/users/${user.id}/has-seen-challenge-tooltip/${challengeType}`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; return databaseBuilder.commit(); @@ -690,7 +688,7 @@ describe('Acceptance | Identity Access Management | Application | Route | User', it('should respond with a 403 - forbidden access - if requested user is not the same as authenticated user', async function () { // given const otherUserId = 9999; - options.headers.authorization = generateValidRequestAuthorizationHeader(otherUserId); + options.headers = generateAuthenticatedUserRequestHeaders({ userId: otherUserId }); // when const response = await server.inject(options); @@ -709,7 +707,7 @@ describe('Acceptance | Identity Access Management | Application | Route | User', options = { method: 'PATCH', url: `/api/users/${user.id}/has-seen-challenge-tooltip/${challengeType}`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; await databaseBuilder.commit(); @@ -728,7 +726,7 @@ describe('Acceptance | Identity Access Management | Application | Route | User', options = { method: 'PATCH', url: `/api/users/${user.id}/has-seen-challenge-tooltip/${challengeType}`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; await databaseBuilder.commit(); @@ -797,10 +795,7 @@ describe('Acceptance | Identity Access Management | Application | Route | User', method: 'PUT', url: `/api/users/${user.id}/email/verification-code`, payload, - headers: { - authorization: generateValidRequestAuthorizationHeader(user.id), - 'accept-language': locale, - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id, acceptLanguage: locale }), }; // when @@ -837,10 +832,7 @@ describe('Acceptance | Identity Access Management | Application | Route | User', method: 'PUT', url: `/api/users/${user.id}/email/verification-code`, payload, - headers: { - authorization: generateValidRequestAuthorizationHeader(user.id), - 'accept-language': locale, - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id, acceptLanguage: locale }), }; // when @@ -879,10 +871,7 @@ describe('Acceptance | Identity Access Management | Application | Route | User', method: 'PUT', url: '/api/users/999/email/verification-code', payload, - headers: { - authorization: generateValidRequestAuthorizationHeader(user.id), - 'accept-language': locale, - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id, acceptLanguage: locale }), }; // when @@ -921,10 +910,7 @@ describe('Acceptance | Identity Access Management | Application | Route | User', method: 'PUT', url: `/api/users/${user.id}/email/verification-code`, payload, - headers: { - authorization: generateValidRequestAuthorizationHeader(user.id), - 'accept-language': locale, - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id, acceptLanguage: locale }), }; // when @@ -963,9 +949,7 @@ describe('Acceptance | Identity Access Management | Application | Route | User', method: 'POST', url: `/api/users/${user.id}/update-email`, payload, - headers: { - authorization: generateValidRequestAuthorizationHeader(user.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; // when @@ -991,9 +975,7 @@ describe('Acceptance | Identity Access Management | Application | Route | User', const options = { method: 'DELETE', url: '/api/users/me', - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when @@ -1043,7 +1025,7 @@ describe('Acceptance | Identity Access Management | Application | Route | User', const options = { method: 'GET', url: '/api/certification-point-of-contacts/me', - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when diff --git a/api/tests/learning-content/acceptance/application/learning-content-controller_test.js b/api/tests/learning-content/acceptance/application/learning-content-controller_test.js index 66d39bd1602..c1c7c8cf324 100644 --- a/api/tests/learning-content/acceptance/application/learning-content-controller_test.js +++ b/api/tests/learning-content/acceptance/application/learning-content-controller_test.js @@ -1,4 +1,4 @@ -import { createServer, expect, generateValidRequestAuthorizationHeader } from '../../../test-helper.js'; +import { createServer, expect, generateAuthenticatedUserRequestHeaders } from '../../../test-helper.js'; describe('Acceptance | Controller | lcms-controller', function () { let server; @@ -33,7 +33,7 @@ describe('Acceptance | Controller | lcms-controller', function () { const response = await server.inject({ method: 'PATCH', url: '/api/cache/challenges/recChallengeId', - headers: { authorization: generateValidRequestAuthorizationHeader(nonSuperAdminUserId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: nonSuperAdminUserId }), payload: { id: 'recChallengeId', param: 'updatedModelParam', @@ -68,7 +68,7 @@ describe('Acceptance | Controller | lcms-controller', function () { const response = await server.inject({ method: 'PATCH', url: '/api/cache', - headers: { authorization: generateValidRequestAuthorizationHeader(nonSuperAdminUserId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: nonSuperAdminUserId }), }); // then diff --git a/api/tests/organizational-entities/acceptance/application/certification-center/certification-center.admin.route.test.js b/api/tests/organizational-entities/acceptance/application/certification-center/certification-center.admin.route.test.js index bbcdb0780cc..c0da3fb5272 100644 --- a/api/tests/organizational-entities/acceptance/application/certification-center/certification-center.admin.route.test.js +++ b/api/tests/organizational-entities/acceptance/application/certification-center/certification-center.admin.route.test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, insertUserWithRoleSuperAdmin, } from '../../../../test-helper.js'; @@ -24,7 +24,7 @@ describe('Acceptance | Organization Entities | Admin | Route | Certification Cen context('when user is Super Admin', function () { beforeEach(function () { - request.headers = { authorization: generateValidRequestAuthorizationHeader() }; + request.headers = generateAuthenticatedUserRequestHeaders(); }); it('returns a list of certificationCenter, with their name and id', async function () { @@ -129,7 +129,7 @@ describe('Acceptance | Organization Entities | Admin | Route | Certification Cen context('when user is not SuperAdmin', function () { beforeEach(function () { - request.headers = { authorization: generateValidRequestAuthorizationHeader(1111) }; + request.headers = generateAuthenticatedUserRequestHeaders({ userId: 1111 }); }); it('returns a 403 HTTP status code ', async function () { @@ -171,7 +171,7 @@ describe('Acceptance | Organization Entities | Admin | Route | Certification Cen const response = await server.inject({ method: 'POST', url: '/api/admin/certification-centers', - headers: { authorization: generateValidRequestAuthorizationHeader() }, + headers: generateAuthenticatedUserRequestHeaders(), payload: { data: { type: 'certification-center', @@ -212,7 +212,7 @@ describe('Acceptance | Organization Entities | Admin | Route | Certification Cen const response = await server.inject({ method: 'POST', url: '/api/admin/certification-centers', - headers: { authorization: generateValidRequestAuthorizationHeader(111) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: 111 }), payload: { data: { type: 'certification-center', @@ -264,7 +264,7 @@ describe('Acceptance | Organization Entities | Admin | Route | Certification Cen context('when user is Super Admin', function () { beforeEach(function () { - request.headers = { authorization: generateValidRequestAuthorizationHeader() }; + request.headers = generateAuthenticatedUserRequestHeaders(); }); it('returns 200 HTTP status', async function () { @@ -337,7 +337,7 @@ describe('Acceptance | Organization Entities | Admin | Route | Certification Cen context('when user is not SuperAdmin', function () { beforeEach(function () { - request.headers = { authorization: generateValidRequestAuthorizationHeader(1111) }; + request.headers = generateAuthenticatedUserRequestHeaders({ userId: 1111 }); }); it('returns 403 HTTP status code ', async function () { @@ -370,9 +370,7 @@ describe('Acceptance | Organization Entities | Admin | Route | Certification Cen // when const { result, statusCode } = await server.inject({ - headers: { - authorization: generateValidRequestAuthorizationHeader(adminMember.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: adminMember.id }), method: 'PATCH', payload: { data: { diff --git a/api/tests/organizational-entities/acceptance/application/organization/organization.admin.route.test.js b/api/tests/organizational-entities/acceptance/application/organization/organization.admin.route.test.js index f7980400c43..9c8607d9d05 100644 --- a/api/tests/organizational-entities/acceptance/application/organization/organization.admin.route.test.js +++ b/api/tests/organizational-entities/acceptance/application/organization/organization.admin.route.test.js @@ -6,7 +6,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, insertUserWithRoleSuperAdmin, knex, } from '../../../../test-helper.js'; @@ -72,7 +72,7 @@ describe('Acceptance | Organizational Entities | Application | Route | Admin | O const response = await server.inject({ method: 'GET', url: `/api/admin/organizations/${organization.id}`, - headers: { authorization: generateValidRequestAuthorizationHeader(admin.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: admin.id }), }); // then @@ -154,7 +154,7 @@ describe('Acceptance | Organizational Entities | Application | Route | Admin | O const response = await server.inject({ method: 'GET', url: `/api/admin/organizations/999`, - headers: { authorization: generateValidRequestAuthorizationHeader(admin.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: admin.id }), }); // then @@ -193,7 +193,7 @@ describe('Acceptance | Organizational Entities | Application | Route | Admin | O const promise = server.inject({ method: 'GET', url: `/api/admin/organizations/999`, - headers: { authorization: generateValidRequestAuthorizationHeader(nonSuperAdminUserId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: nonSuperAdminUserId }), }); // then @@ -234,7 +234,7 @@ describe('Acceptance | Organizational Entities | Application | Route | Admin | O method: 'PATCH', url: `/api/admin/organizations/${organization.id}`, payload, - headers: { authorization: generateValidRequestAuthorizationHeader() }, + headers: generateAuthenticatedUserRequestHeaders(), }; // when @@ -265,7 +265,7 @@ describe('Acceptance | Organizational Entities | Application | Route | Admin | O const options = { method: 'POST', - headers: { authorization: generateValidRequestAuthorizationHeader(admin.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: admin.id }), url: '/api/admin/organizations/add-organization-features', payload: iconv.encode(input, 'UTF-8'), }; @@ -299,7 +299,7 @@ describe('Acceptance | Organizational Entities | Application | Route | Admin | O const options = { method: 'POST', url: `/api/admin/organizations/${parentOrganizationId}/attach-child-organization`, - headers: { authorization: generateValidRequestAuthorizationHeader(admin.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: admin.id }), payload: { childOrganizationId: childOrganization.id, }, @@ -338,7 +338,7 @@ describe('Acceptance | Organizational Entities | Application | Route | Admin | O const options = { method: 'POST', url: `/api/admin/organizations/${parentOrganizationId}/attach-child-organization`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload: { childOrganizationId, }, @@ -362,7 +362,7 @@ describe('Acceptance | Organizational Entities | Application | Route | Admin | O const options = { method: 'POST', url: `/api/admin/organizations/${parentOrganizationId}/attach-child-organization`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload: { childOrganizationId, }, @@ -396,7 +396,7 @@ describe('Acceptance | Organizational Entities | Application | Route | Admin | O const options = { method: 'POST', url: `/api/admin/organizations/985421/attach-child-organization`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload: { childOrganizationId, }, @@ -416,7 +416,7 @@ describe('Acceptance | Organizational Entities | Application | Route | Admin | O const options = { method: 'POST', url: `/api/admin/organizations/${parentOrganizationId}/attach-child-organization`, - headers: { authorization: generateValidRequestAuthorizationHeader(admin.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: admin.id }), payload: { childOrganizationId: 984512, }, @@ -440,7 +440,7 @@ describe('Acceptance | Organizational Entities | Application | Route | Admin | O const options = { method: 'POST', url: `/api/admin/organizations/${parentOrganizationId}/attach-child-organization`, - headers: { authorization: generateValidRequestAuthorizationHeader(admin.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: admin.id }), payload: { childOrganizationId: parentOrganizationId, }, @@ -475,7 +475,7 @@ describe('Acceptance | Organizational Entities | Application | Route | Admin | O const options = { method: 'POST', url: `/api/admin/organizations/${parentOrganizationId}/attach-child-organization`, - headers: { authorization: generateValidRequestAuthorizationHeader(admin.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: admin.id }), payload: { childOrganizationId, }, @@ -510,7 +510,7 @@ describe('Acceptance | Organizational Entities | Application | Route | Admin | O const options = { method: 'POST', url: `/api/admin/organizations/${parentOrganizationId}/attach-child-organization`, - headers: { authorization: generateValidRequestAuthorizationHeader(admin.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: admin.id }), payload: { childOrganizationId, }, @@ -542,7 +542,7 @@ describe('Acceptance | Organizational Entities | Application | Route | Admin | O const options = { method: 'POST', url: `/api/admin/organizations/${parentOrganizationId}/attach-child-organization`, - headers: { authorization: generateValidRequestAuthorizationHeader(admin.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: admin.id }), payload: { childOrganizationId, }, @@ -580,7 +580,7 @@ describe('Acceptance | Organizational Entities | Application | Route | Admin | O const options = { method: 'POST', url: `/api/admin/organizations/${parentOrganizationId}/attach-child-organization`, - headers: { authorization: generateValidRequestAuthorizationHeader(admin.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: admin.id }), payload: { childOrganizationId, }, @@ -625,7 +625,7 @@ describe('Acceptance | Organizational Entities | Application | Route | Admin | O const options = { method: 'POST', - headers: { authorization: generateValidRequestAuthorizationHeader(admin.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: admin.id }), url: '/api/admin/organizations/update-organizations', payload: iconv.encode(input, 'UTF-8'), }; @@ -652,7 +652,7 @@ describe('Acceptance | Organizational Entities | Application | Route | Admin | O const options = { method: 'POST', url: `/api/admin/organizations/update-organizations`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload: iconv.encode(input, 'UTF-8'), }; @@ -674,7 +674,7 @@ describe('Acceptance | Organizational Entities | Application | Route | Admin | O const options = { method: 'POST', url: `/api/admin/organizations/update-organizations`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload: iconv.encode(input, 'UTF-8'), }; @@ -718,7 +718,7 @@ describe('Acceptance | Organizational Entities | Application | Route | Admin | O const options = { method: 'POST', - headers: { authorization: generateValidRequestAuthorizationHeader(admin.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: admin.id }), url: '/api/admin/organizations/import-tags-csv', payload: iconv.encode(input, 'UTF-8'), }; diff --git a/api/tests/organizational-entities/acceptance/application/tag/tag.admin.route.test.js b/api/tests/organizational-entities/acceptance/application/tag/tag.admin.route.test.js index 0f375dbd52b..274b39f64ac 100644 --- a/api/tests/organizational-entities/acceptance/application/tag/tag.admin.route.test.js +++ b/api/tests/organizational-entities/acceptance/application/tag/tag.admin.route.test.js @@ -4,7 +4,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, insertUserWithRoleCertif, insertUserWithRoleSuperAdmin, } from '../../../../test-helper.js'; @@ -23,7 +23,7 @@ describe('Acceptance | Organizational Entities | Application | Route | Admin | T const options = { method: 'GET', url: '/api/admin/tags', - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; const expectedTags = [ @@ -60,7 +60,7 @@ describe('Acceptance | Organizational Entities | Application | Route | Admin | T const options = { method: 'GET', url: '/api/admin/tags', - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when @@ -93,7 +93,7 @@ describe('Acceptance | Organizational Entities | Application | Route | Admin | T }, }, }, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }); // then @@ -124,7 +124,7 @@ describe('Acceptance | Organizational Entities | Application | Route | Admin | T }, }, }, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }); // then @@ -161,7 +161,7 @@ describe('Acceptance | Organizational Entities | Application | Route | Admin | T const { statusCode, result } = await server.inject({ method: 'GET', url: `/api/admin/tags/${basedTag.id}/recently-used`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }); // then @@ -197,7 +197,7 @@ describe('Acceptance | Organizational Entities | Application | Route | Admin | T const { statusCode } = await server.inject({ method: 'GET', url: `/api/admin/tags/${basedTag.id}/recently-used`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }); // then diff --git a/api/tests/prescription/campaign-participation/acceptance/application/admin-campaign-participation-route_test.js b/api/tests/prescription/campaign-participation/acceptance/application/admin-campaign-participation-route_test.js index 58abdae55fa..afcf84bfa73 100644 --- a/api/tests/prescription/campaign-participation/acceptance/application/admin-campaign-participation-route_test.js +++ b/api/tests/prescription/campaign-participation/acceptance/application/admin-campaign-participation-route_test.js @@ -5,7 +5,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, sinon, } from '../../../../test-helper.js'; @@ -44,7 +44,7 @@ describe('Acceptance | Controller | GET /api/admin/users/{userId}/participations const response = await server.inject({ method: 'GET', url: `/api/admin/users/${user.id}/participations`, - headers: { authorization: generateValidRequestAuthorizationHeader(admin.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: admin.id }), }); // then diff --git a/api/tests/prescription/campaign-participation/acceptance/application/campaign-participation-route_test.js b/api/tests/prescription/campaign-participation/acceptance/application/campaign-participation-route_test.js index 3ad4930ec84..c034e803b71 100644 --- a/api/tests/prescription/campaign-participation/acceptance/application/campaign-participation-route_test.js +++ b/api/tests/prescription/campaign-participation/acceptance/application/campaign-participation-route_test.js @@ -7,7 +7,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, insertUserWithRoleSuperAdmin, knex, learningContentBuilder, @@ -35,7 +35,7 @@ describe('Acceptance | API | Campaign Participations', function () { options = { method: 'DELETE', url: `/api/campaigns/${campaignId}/campaign-participations/${campaignParticipationId}`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when @@ -64,7 +64,7 @@ describe('Acceptance | API | Campaign Participations', function () { const options = { method: 'GET', url: `/api/campaigns/${campaignId}/profiles-collection-participations/${campaignParticipation.id}`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; const response = await server.inject(options); @@ -85,7 +85,7 @@ describe('Acceptance | API | Campaign Participations', function () { options = { method: 'DELETE', url: `/api/admin/campaign-participations/${campaignParticipationId}`, - headers: { authorization: generateValidRequestAuthorizationHeader(superAdmin.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: superAdmin.id }), }; // when @@ -166,7 +166,7 @@ describe('Acceptance | API | Campaign Participations', function () { options = { method: 'GET', url: `/api/campaign-participations/${campaignParticipation.id}/analyses`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; const expectedCampaignParticipationAnalysis = { data: { @@ -251,7 +251,7 @@ describe('Acceptance | API | Campaign Participations', function () { const options = { method: 'GET', url: `/api/campaigns/${campaignId}/assessment-participations/${campaignParticipation.id}`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; const response = await server.inject(options); @@ -320,7 +320,7 @@ describe('Acceptance | API | Campaign Participations', function () { const options = { method: 'GET', url: `/api/campaigns/${campaignId}/assessment-participations/${campaignParticipation.id}/results`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; const response = await server.inject(options); @@ -349,7 +349,7 @@ describe('Acceptance | API | Campaign Participations', function () { const options = { method: 'GET', url: `/api/campaigns/${campaignId}/organization-learners/${organizationLearnerId}/participations`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; const response = await server.inject(options); @@ -374,7 +374,7 @@ describe('Acceptance | API | Campaign Participations', function () { const options = { method: 'PATCH', url: `/api/admin/campaign-participations/${campaignParticipation.id}`, - headers: { authorization: generateValidRequestAuthorizationHeader(superAdmin.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: superAdmin.id }), payload: { data: { id: campaignParticipation.id, @@ -409,7 +409,7 @@ describe('Acceptance | API | Campaign Participations', function () { const response = await server.inject({ method: 'GET', url: `/api/admin/campaigns/${campaign.id}/participations`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }); // then @@ -772,7 +772,7 @@ describe('Acceptance | API | Campaign Participations', function () { const response = await server.inject({ method: 'GET', url: `/api/users/${user.id}/campaigns/${campaign.id}/assessment-result`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }); // then @@ -836,7 +836,7 @@ describe('Acceptance | API | Campaign Participations', function () { options = { method: 'GET', url: `/api/users/${userId}/campaign-participation-overviews?filter[states][]=ONGOING&filter[states][]=TO_SHARE`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when @@ -862,7 +862,7 @@ describe('Acceptance | API | Campaign Participations', function () { options = { method: 'GET', url: `/api/users/${userId}/campaigns/${campaignId}/campaign-participations`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; return databaseBuilder.commit(); diff --git a/api/tests/prescription/campaign-participation/acceptance/application/learner-participation-route_test.js b/api/tests/prescription/campaign-participation/acceptance/application/learner-participation-route_test.js index 0242637d31e..2db372a977f 100644 --- a/api/tests/prescription/campaign-participation/acceptance/application/learner-participation-route_test.js +++ b/api/tests/prescription/campaign-participation/acceptance/application/learner-participation-route_test.js @@ -11,7 +11,7 @@ import { databaseBuilder, domainBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, knex, learningContentBuilder, mockLearningContent, @@ -61,7 +61,7 @@ describe('Acceptance | Routes | Campaign Participations', function () { options = { method: 'PATCH', url: `/api/campaign-participations/${campaignParticipationId}`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; }); @@ -125,7 +125,7 @@ describe('Acceptance | Routes | Campaign Participations', function () { }; beforeEach(async function () { - options.headers = { authorization: generateValidRequestAuthorizationHeader(user.id) }; + options.headers = generateAuthenticatedUserRequestHeaders({ userId: user.id }); const targetProfileId = databaseBuilder.factory.buildTargetProfile({ areKnowledgeElementsResettable: true }).id; databaseBuilder.factory.buildTargetProfileTube({ tubeId: 'tubeId1', targetProfileId }); databaseBuilder.factory.buildKnowledgeElement({ @@ -303,7 +303,7 @@ describe('Acceptance | Routes | Campaign Participations', function () { options = { method: 'PATCH', url: `/api/campaign-participations/${campaignParticipationId}/begin-improvement`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when @@ -332,7 +332,7 @@ describe('Acceptance | Routes | Campaign Participations', function () { options = { method: 'PATCH', url: `/api/campaign-participations/${campaignParticipationId}/begin-improvement`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when @@ -361,7 +361,7 @@ describe('Acceptance | Routes | Campaign Participations', function () { options = { method: 'PATCH', url: `/api/campaign-participations/${campaignParticipationId}/begin-improvement`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when @@ -447,7 +447,7 @@ describe('Acceptance | Routes | Campaign Participations', function () { options = { method: 'GET', url: `/api/users/${userId}/campaigns/${campaign.id}/profile`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; }); diff --git a/api/tests/prescription/campaign-participation/acceptance/application/pole-emploi-route_test.js b/api/tests/prescription/campaign-participation/acceptance/application/pole-emploi-route_test.js index 50de45c5948..1db8be0152d 100644 --- a/api/tests/prescription/campaign-participation/acceptance/application/pole-emploi-route_test.js +++ b/api/tests/prescription/campaign-participation/acceptance/application/pole-emploi-route_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, generateValidRequestAuthorizationHeaderForApplication, } from '../../../../test-helper.js'; @@ -144,7 +144,7 @@ describe('Acceptance | API | Pole Emploi envois', function () { options = { method: 'GET', url: '/api/pole-emploi/envois', - headers: { authorization: generateValidRequestAuthorizationHeader() }, + headers: generateAuthenticatedUserRequestHeaders(), }; // when diff --git a/api/tests/prescription/campaign/acceptance/application/campaign-administration-route_test.js b/api/tests/prescription/campaign/acceptance/application/campaign-administration-route_test.js index 167b23c7747..ea827553db9 100644 --- a/api/tests/prescription/campaign/acceptance/application/campaign-administration-route_test.js +++ b/api/tests/prescription/campaign/acceptance/application/campaign-administration-route_test.js @@ -5,7 +5,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, knex, learningContentBuilder, mockLearningContent, @@ -83,7 +83,7 @@ describe('Acceptance | API | campaign-administration-route', function () { { method: 'POST', url: '/api/campaigns', - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload, }, payload, @@ -132,7 +132,7 @@ describe('Acceptance | API | campaign-administration-route', function () { { method: 'POST', url: '/api/campaigns', - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload, }, payload, @@ -207,7 +207,7 @@ describe('Acceptance | API | campaign-administration-route', function () { { method: 'POST', url: '/api/campaigns', - headers: { authorization: generateValidRequestAuthorizationHeader(anotherUserId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: anotherUserId }), payload, }, payload, @@ -245,9 +245,7 @@ describe('Acceptance | API | campaign-administration-route', function () { const options = { method: 'POST', url: '/api/admin/campaigns', - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload: buffer, }; const response = await server.inject(options); @@ -267,9 +265,7 @@ describe('Acceptance | API | campaign-administration-route', function () { const options = { method: 'POST', url: '/api/admin/campaigns', - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; const response = await server.inject(options); @@ -294,9 +290,7 @@ describe('Acceptance | API | campaign-administration-route', function () { const options = { method: 'POST', url: '/api/admin/campaigns/swap-codes', - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload, }; @@ -316,7 +310,7 @@ describe('Acceptance | API | campaign-administration-route', function () { const response = await server.inject({ method: 'PATCH', url: `/api/admin/campaigns/${campaign.id}`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), payload: { data: { attributes: { @@ -344,7 +338,6 @@ describe('Acceptance | API | campaign-administration-route', function () { const userId = databaseBuilder.factory.buildUser.withRole({ role: ROLES.SUPER_ADMIN }).id; const campaignId = databaseBuilder.factory.buildCampaign({ code: 'ABCEFG123' }).id; await databaseBuilder.commit(); - const authorization = generateValidRequestAuthorizationHeader(userId); const payload = { campaignCode: 'GOODCODE1', }; @@ -352,7 +345,7 @@ describe('Acceptance | API | campaign-administration-route', function () { const options = { method: 'PATCH', url: `/api/admin/campaigns/${campaignId}/update-code`, - headers: { authorization }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload, }; @@ -374,7 +367,7 @@ describe('Acceptance | API | campaign-administration-route', function () { const response = await server.inject({ method: 'PUT', url: `/api/campaigns/${campaign.id}/archive`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }); // then @@ -397,7 +390,7 @@ describe('Acceptance | API | campaign-administration-route', function () { const response = await server.inject({ method: 'PUT', url: `/api/campaigns/${campaign.id}/archive`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }); // then @@ -418,7 +411,7 @@ describe('Acceptance | API | campaign-administration-route', function () { const response = await server.inject({ method: 'DELETE', url: `/api/campaigns/${campaign.id}/archive`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }); // then @@ -441,7 +434,7 @@ describe('Acceptance | API | campaign-administration-route', function () { const response = await server.inject({ method: 'DELETE', url: `/api/campaigns/${campaign.id}/archive`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }); // then @@ -466,9 +459,7 @@ describe('Acceptance | API | campaign-administration-route', function () { const options = { method: 'POST', url: `/api/admin/campaigns/archive-campaigns`, - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload: buffer, }; diff --git a/api/tests/prescription/campaign/acceptance/application/campaign-detail-route_test.js b/api/tests/prescription/campaign/acceptance/application/campaign-detail-route_test.js index e79da665683..d7802c480c3 100644 --- a/api/tests/prescription/campaign/acceptance/application/campaign-detail-route_test.js +++ b/api/tests/prescription/campaign/acceptance/application/campaign-detail-route_test.js @@ -6,7 +6,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, learningContentBuilder, mockLearningContent, } from '../../../../test-helper.js'; @@ -74,7 +74,7 @@ describe('Acceptance | API | campaign-detail-route', function () { userId, }); - options.headers.authorization = generateValidRequestAuthorizationHeader(userId); + options.headers = generateAuthenticatedUserRequestHeaders({ userId }); options.url = `/api/campaigns/${campaign.id}`; await databaseBuilder.commit(); @@ -130,7 +130,7 @@ describe('Acceptance | API | campaign-detail-route', function () { organizationRole: Membership.roles.MEMBER, }); - options.headers.authorization = generateValidRequestAuthorizationHeader(userId); + options.headers = generateAuthenticatedUserRequestHeaders({ userId }); options.url = `/api/campaigns/${campaign.id}/csv-profiles-collection-results`; await databaseBuilder.commit(); @@ -216,7 +216,7 @@ describe('Acceptance | API | campaign-detail-route', function () { organizationRole: Membership.roles.MEMBER, }); - options.headers.authorization = generateValidRequestAuthorizationHeader(userId); + options.headers = generateAuthenticatedUserRequestHeaders({ userId }); options.url = `/api/campaigns/${campaign.id}/csv-assessment-results`; await databaseBuilder.commit(); @@ -313,7 +313,7 @@ describe('Acceptance | API | campaign-detail-route', function () { const options = { method: 'GET', url: `/api/campaigns/${campaign.id}/participants-activity`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; const response = await server.inject(options); @@ -326,7 +326,7 @@ describe('Acceptance | API | campaign-detail-route', function () { const options = { method: 'GET', url: `/api/campaigns/${campaign.id}/participants-activity?page[number]=1&page[size]=1`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; const response = await server.inject(options); @@ -340,7 +340,7 @@ describe('Acceptance | API | campaign-detail-route', function () { const options = { method: 'GET', url: `/api/campaigns/${campaign.id}/participants-activity?filter[divisions][]=5eme`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; const response = await server.inject(options); @@ -355,7 +355,7 @@ describe('Acceptance | API | campaign-detail-route', function () { const options = { method: 'GET', url: `/api/campaigns/${campaign.id}/participants-activity?filter[status]=STARTED`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; const response = await server.inject(options); @@ -370,7 +370,7 @@ describe('Acceptance | API | campaign-detail-route', function () { const options = { method: 'GET', url: `/api/campaigns/${campaign.id}/participants-activity?filter[search]=Mary M`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; const response = await server.inject(options); @@ -385,7 +385,7 @@ describe('Acceptance | API | campaign-detail-route', function () { const options = { method: 'GET', url: `/api/campaigns/${campaign.id}/participants-activity?filter[groups][]=L1`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; const response = await server.inject(options); @@ -400,7 +400,7 @@ describe('Acceptance | API | campaign-detail-route', function () { const options = { method: 'GET', url: `/api/campaigns/${campaign.id}/participants-activity?filter[status]=bad`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; const response = await server.inject(options); @@ -422,7 +422,7 @@ describe('Acceptance | API | campaign-detail-route', function () { const options = { method: 'GET', url: `/api/organizations/${organizationId}/campaigns?filter[name]=&filter[status]=&filter[isOwnedByMe]=true&page[number]=1&page[size]=50`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; const response = await server.inject(options); @@ -444,7 +444,7 @@ describe('Acceptance | API | campaign-detail-route', function () { const options = { method: 'GET', url: `/api/organizations/${organizationId}/campaigns?filter[name]=&filter[status]=&filter[ownerName]=&page[number]=1&page[size]=50`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; const response = await server.inject(options); diff --git a/api/tests/prescription/campaign/acceptance/application/campaign-results-route_test.js b/api/tests/prescription/campaign/acceptance/application/campaign-results-route_test.js index 540556a026b..4b69a269e87 100644 --- a/api/tests/prescription/campaign/acceptance/application/campaign-results-route_test.js +++ b/api/tests/prescription/campaign/acceptance/application/campaign-results-route_test.js @@ -3,7 +3,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, learningContentBuilder, mockLearningContent, } from '../../../../test-helper.js'; @@ -87,7 +87,7 @@ describe('Acceptance | API | campaign-results-route', function () { const options = { method: 'GET', url: `/api/campaigns/${campaign.id}/assessment-results?page[number]=1&page[size]=10&filter[divisions][]=5eme`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; const response = await server.inject(options); @@ -102,7 +102,7 @@ describe('Acceptance | API | campaign-results-route', function () { const options = { method: 'GET', url: `/api/campaigns/${campaign.id}/assessment-results?page[number]=1&page[size]=10&filter[search]=Holly M`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; const response = await server.inject(options); @@ -189,7 +189,7 @@ describe('Acceptance | API | campaign-results-route', function () { const options = { method: 'GET', url: `/api/campaigns/${campaign.id}/profiles-collection-participations?filter[divisions][]=Division+Barry`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when const response = await server.inject(options); @@ -259,7 +259,7 @@ describe('Acceptance | API | campaign-results-route', function () { const options = { method: 'GET', url: `/api/campaigns/${campaign.id}/profiles-collection-participations?filter[divisions][]=Division+Marvin&filter[divisions][]=Division+Aretha`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when const response = await server.inject(options); @@ -320,7 +320,7 @@ describe('Acceptance | API | campaign-results-route', function () { const options = { method: 'GET', url: `/api/campaigns/${campaign.id}/profiles-collection-participations?filter[groups][]=L1`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when const response = await server.inject(options); @@ -390,7 +390,7 @@ describe('Acceptance | API | campaign-results-route', function () { const options = { method: 'GET', url: `/api/campaigns/${campaign.id}/profiles-collection-participations?filter[groups][]=L3&filter[groups][]=L2`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when const response = await server.inject(options); @@ -450,7 +450,7 @@ describe('Acceptance | API | campaign-results-route', function () { const options = { method: 'GET', url: `/api/campaigns/${campaign.id}/profiles-collection-participations?filter[search]=Marvin G`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when const response = await server.inject(options); @@ -510,7 +510,7 @@ describe('Acceptance | API | campaign-results-route', function () { const options = { method: 'GET', url: `/api/campaigns/${campaign.id}/profiles-collection-participations?filter[certificability]=eligible`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when const response = await server.inject(options); @@ -619,7 +619,7 @@ describe('Acceptance | API | campaign-results-route', function () { const request = { method: 'GET', url, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; const expectedResult = { data: { diff --git a/api/tests/prescription/campaign/acceptance/application/campaign-route_test.js b/api/tests/prescription/campaign/acceptance/application/campaign-route_test.js index 4de1b612cbf..ca17a82f37f 100644 --- a/api/tests/prescription/campaign/acceptance/application/campaign-route_test.js +++ b/api/tests/prescription/campaign/acceptance/application/campaign-route_test.js @@ -3,7 +3,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, learningContentBuilder, mockLearningContent, } from '../../../../test-helper.js'; @@ -29,7 +29,7 @@ describe('Acceptance | API | Campaign Route', function () { const options = { method: 'GET', url: `/api/campaigns/${campaign.id}/divisions`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; const response = await server.inject(options); @@ -53,7 +53,7 @@ describe('Acceptance | API | Campaign Route', function () { const options = { method: 'GET', url: `/api/campaigns/${campaign.id}/groups`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; const response = await server.inject(options); @@ -142,7 +142,7 @@ describe('Acceptance | API | Campaign Route', function () { const request = { method: 'GET', url, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; const expectedResult = { data: { @@ -284,7 +284,7 @@ describe('Acceptance | API | Campaign Route', function () { const request = { method: 'GET', url, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; const expectedResult = { data: { @@ -420,7 +420,7 @@ describe('Acceptance | API | Campaign Route', function () { const options = { method: 'GET', url: `/api/campaigns/${campaign.code}/presentation-steps`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; const response = await server.inject(options); diff --git a/api/tests/prescription/campaign/acceptance/application/campaign-stats-route_test.js b/api/tests/prescription/campaign/acceptance/application/campaign-stats-route_test.js index 919c79c55b1..13c6f7035ae 100644 --- a/api/tests/prescription/campaign/acceptance/application/campaign-stats-route_test.js +++ b/api/tests/prescription/campaign/acceptance/application/campaign-stats-route_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, learningContentBuilder, mockLearningContent, } from '../../../../test-helper.js'; @@ -64,7 +64,7 @@ describe('Acceptance | API | Campaign Stats Route', function () { const response = await server.inject({ method: 'GET', url: `/api/campaigns/${campaign.id}/stats/participations-by-stage`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }); // then @@ -93,7 +93,7 @@ describe('Acceptance | API | Campaign Stats Route', function () { const response = await server.inject({ method: 'GET', url: `/api/campaigns/${campaign.id}/stats/participations-by-stage`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }); // then @@ -113,7 +113,7 @@ describe('Acceptance | API | Campaign Stats Route', function () { const response = await server.inject({ method: 'GET', url: `/api/campaigns/${campaign.id}/stats/participations-by-status`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }); // then @@ -132,7 +132,7 @@ describe('Acceptance | API | Campaign Stats Route', function () { const response = await server.inject({ method: 'GET', url: `/api/campaigns/${campaign.id}/stats/participations-by-status`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }); // then @@ -152,7 +152,7 @@ describe('Acceptance | API | Campaign Stats Route', function () { const response = await server.inject({ method: 'GET', url: `/api/campaigns/${campaign.id}/stats/participations-by-day`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }); // then @@ -181,7 +181,7 @@ describe('Acceptance | API | Campaign Stats Route', function () { const options = { method: 'GET', url: `/api/campaigns/${campaignId}/stats/participations-by-mastery-rate`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; const { statusCode, result } = await server.inject(options); diff --git a/api/tests/prescription/learner-management/acceptance/application/organization-controller-import-sco-organization-learners_test.js b/api/tests/prescription/learner-management/acceptance/application/organization-controller-import-sco-organization-learners_test.js index 0010210fef5..aea25041dbf 100644 --- a/api/tests/prescription/learner-management/acceptance/application/organization-controller-import-sco-organization-learners_test.js +++ b/api/tests/prescription/learner-management/acceptance/application/organization-controller-import-sco-organization-learners_test.js @@ -9,7 +9,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, } from '../../../../test-helper.js'; EventEmitter.defaultMaxListeners = 60; @@ -49,9 +49,7 @@ describe('Acceptance | Application | organization-controller-import-sco-organiza options = { method: 'POST', url: `/api/organizations/${organizationId}/sco-organization-learners/import-siecle`, - headers: { - authorization: generateValidRequestAuthorizationHeader(connectedUser.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: connectedUser.id }), }; }); @@ -132,7 +130,7 @@ describe('Acceptance | Application | organization-controller-import-sco-organiza const userId = databaseBuilder.factory.buildUser.withMembership().id; await databaseBuilder.commit(); - options.headers.authorization = generateValidRequestAuthorizationHeader(userId); + options.headers = generateAuthenticatedUserRequestHeaders({ userId }); }); it('should respond with a 403 - Forbidden access', async function () { @@ -157,7 +155,7 @@ describe('Acceptance | Application | organization-controller-import-sco-organiza }).id; await databaseBuilder.commit(); - options.headers.authorization = generateValidRequestAuthorizationHeader(userId); + options.headers = generateAuthenticatedUserRequestHeaders({ userId }); options.url = `/api/organizations/${organizationId}/sco-organization-learners/import-siecle`; }); @@ -183,7 +181,7 @@ describe('Acceptance | Application | organization-controller-import-sco-organiza }).id; await databaseBuilder.commit(); - options.headers.authorization = generateValidRequestAuthorizationHeader(userId); + options.headers = generateAuthenticatedUserRequestHeaders({ userId }); options.url = `/api/organizations/${organizationId}/sco-organization-learners/import-siecle`; }); @@ -209,7 +207,7 @@ describe('Acceptance | Application | organization-controller-import-sco-organiza }).id; await databaseBuilder.commit(); - options.headers.authorization = generateValidRequestAuthorizationHeader(userId); + options.headers = generateAuthenticatedUserRequestHeaders({ userId }); options.url = `/api/organizations/${organizationId}/sco-organization-learners/import-siecle`; }); diff --git a/api/tests/prescription/learner-management/acceptance/application/organization-import-route_test.js b/api/tests/prescription/learner-management/acceptance/application/organization-import-route_test.js index 169e8b2456c..1e3dcb3e351 100644 --- a/api/tests/prescription/learner-management/acceptance/application/organization-import-route_test.js +++ b/api/tests/prescription/learner-management/acceptance/application/organization-import-route_test.js @@ -6,7 +6,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, } from '../../../../test-helper.js'; describe('Acceptance | Application | organization-import', function () { @@ -46,9 +46,7 @@ describe('Acceptance | Application | organization-import', function () { options = { method: 'GET', url: `/api/organizations/${organization.id}/import-information`, - headers: { - authorization: generateValidRequestAuthorizationHeader(connectedUser.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: connectedUser.id }), }; // when const response = await server.inject(options); @@ -78,9 +76,7 @@ describe('Acceptance | Application | organization-import', function () { options = { method: 'GET', url: `/api/organizations/${organization.id}/import-information`, - headers: { - authorization: generateValidRequestAuthorizationHeader(connectedUser.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: connectedUser.id }), }; // when const response = await server.inject(options); @@ -116,9 +112,7 @@ describe('Acceptance | Application | organization-import', function () { options = { method: 'GET', url: `/api/organizations/${organization.id}/import-information`, - headers: { - authorization: generateValidRequestAuthorizationHeader(connectedUser.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: connectedUser.id }), }; // when const response = await server.inject(options); @@ -144,9 +138,7 @@ describe('Acceptance | Application | organization-import', function () { options = { method: 'POST', url: `/api/admin/import-organization-learners-format`, - headers: { - authorization: generateValidRequestAuthorizationHeader(connectedUser.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: connectedUser.id }), payload: buffer, }; // when diff --git a/api/tests/prescription/learner-management/acceptance/application/organization-learners-route_test.js b/api/tests/prescription/learner-management/acceptance/application/organization-learners-route_test.js index effbe9489d3..ff382e405f0 100644 --- a/api/tests/prescription/learner-management/acceptance/application/organization-learners-route_test.js +++ b/api/tests/prescription/learner-management/acceptance/application/organization-learners-route_test.js @@ -6,7 +6,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, insertUserWithRoleSuperAdmin, } from '../../../../test-helper.js'; @@ -30,9 +30,7 @@ describe('Acceptance | Prescription | learner management | Application | organiz const options = { method: 'DELETE', url: `/api/admin/organization-learners/${organizationLearner.id}/association`, - headers: { - authorization: generateValidRequestAuthorizationHeader(superAdmin.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: superAdmin.id }), }; const response = await server.inject(options); @@ -57,9 +55,7 @@ describe('Acceptance | Prescription | learner management | Application | organiz options = { method: 'DELETE', url: `/api/organizations/${organizationId}/organization-learners`, - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload: { listLearners: [firstOrganizationLearnerId, secondOrganizationLearnerId], }, @@ -121,9 +117,7 @@ describe('Acceptance | Prescription | learner management | Application | organiz options = { method: 'POST', url: `/api/organizations/${organizationId}/import-organization-learners`, - headers: { - authorization: generateValidRequestAuthorizationHeader(connectedUser.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: connectedUser.id }), payload: buffer, }; // when @@ -208,9 +202,7 @@ describe('Acceptance | Prescription | learner management | Application | organiz const options = { method: 'POST', url: `/api/organization-learners/reconcile`, - headers: { - authorization: generateValidRequestAuthorizationHeader(connectedUser.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: connectedUser.id }), payload: { data: { attributes: { @@ -266,7 +258,7 @@ describe('Acceptance | Prescription | learner management | Application | organiz databaseBuilder.factory.buildOrganizationLearner({ userId: user.id, nationalStudentId }); await databaseBuilder.commit(); - options.headers.authorization = generateValidRequestAuthorizationHeader(user.id); + options.headers = generateAuthenticatedUserRequestHeaders({ userId: user.id }); options.payload.data = { attributes: { 'campaign-code': campaign.code, diff --git a/api/tests/prescription/learner-management/acceptance/application/sco-organization-management-route_test.js b/api/tests/prescription/learner-management/acceptance/application/sco-organization-management-route_test.js index cd149890916..65eef6db67a 100644 --- a/api/tests/prescription/learner-management/acceptance/application/sco-organization-management-route_test.js +++ b/api/tests/prescription/learner-management/acceptance/application/sco-organization-management-route_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, knex, } from '../../../../test-helper.js'; @@ -47,7 +47,7 @@ describe('Acceptance | Route | sco-organization-management-route', function () { context('associate user with firstName, lastName and birthdate', function () { it('should return an 200 status after having successfully associated user to organizationLearner', async function () { // given - options.headers.authorization = generateValidRequestAuthorizationHeader(user.id); + options.headers = generateAuthenticatedUserRequestHeaders({ userId: user.id }); options.payload.data = { attributes: { 'campaign-code': campaign.code, @@ -81,7 +81,7 @@ describe('Acceptance | Route | sco-organization-management-route', function () { context('When withReconciliation query param is set to false', function () { it('should not reconcile user and return a 204 No Content', async function () { // given - options.headers.authorization = generateValidRequestAuthorizationHeader(user.id); + options.headers = generateAuthenticatedUserRequestHeaders({ userId: user.id }); options.payload.data = { attributes: { 'campaign-code': campaign.code, diff --git a/api/tests/prescription/learner-management/acceptance/application/sup-organization-management-route_test.js b/api/tests/prescription/learner-management/acceptance/application/sup-organization-management-route_test.js index 44735ac0765..4c12654d4ef 100644 --- a/api/tests/prescription/learner-management/acceptance/application/sup-organization-management-route_test.js +++ b/api/tests/prescription/learner-management/acceptance/application/sup-organization-management-route_test.js @@ -1,11 +1,12 @@ import { SupOrganizationLearnerImportHeader } from '../../../../../src/prescription/learner-management/infrastructure/serializers/csv/sup-organization-learner-import-header.js'; import { Membership } from '../../../../../src/shared/domain/models/Membership.js'; +import * as tokenService from '../../../../../src/shared/domain/services/token-service.js'; import { getI18n } from '../../../../../src/shared/infrastructure/i18n/i18n.js'; import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, } from '../../../../test-helper.js'; const i18n = getI18n(); @@ -52,7 +53,7 @@ describe('Acceptance | Application | organization-controller-sup-organization-le it('should return an 204 status after updating higher organization learner', async function () { // given - options.headers.authorization = generateValidRequestAuthorizationHeader(user.id); + options.headers = generateAuthenticatedUserRequestHeaders({ userId: user.id }); options.payload.data = { attributes: { 'student-number': '12345', @@ -96,9 +97,7 @@ describe('Acceptance | Application | organization-controller-sup-organization-le const options = { method: 'POST', url: `/api/organizations/${organization.id}/sup-organization-learners/import-csv`, - headers: { - authorization: generateValidRequestAuthorizationHeader(connectedUser.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: connectedUser.id }), payload: buffer, }; @@ -112,9 +111,7 @@ describe('Acceptance | Application | organization-controller-sup-organization-le const options = { method: 'POST', url: '/api/organizations/123/sup-organization-learners/import-csv', - headers: { - authorization: generateValidRequestAuthorizationHeader(connectedUser.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: connectedUser.id }), payload: buffer, }; @@ -139,9 +136,7 @@ describe('Acceptance | Application | organization-controller-sup-organization-le const options = { method: 'POST', url: `/api/organizations/${organization.id}/sup-organization-learners/import-csv`, - headers: { - authorization: generateValidRequestAuthorizationHeader(connectedUser.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: connectedUser.id }), payload: buffer, }; @@ -167,9 +162,7 @@ describe('Acceptance | Application | organization-controller-sup-organization-le const options = { method: 'POST', url: `/api/organizations/${organization.id}/sup-organization-learners/import-csv`, - headers: { - authorization: generateValidRequestAuthorizationHeader(connectedUser.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: connectedUser.id }), payload: buffer, }; @@ -209,9 +202,7 @@ describe('Acceptance | Application | organization-controller-sup-organization-le const options = { method: 'POST', url: `/api/organizations/${organization.id}/sup-organization-learners/replace-csv`, - headers: { - authorization: generateValidRequestAuthorizationHeader(connectedUser.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: connectedUser.id }), payload: buffer, }; @@ -225,9 +216,7 @@ describe('Acceptance | Application | organization-controller-sup-organization-le const options = { method: 'POST', url: '/api/organizations/123/sup-organization-learners/replace-csv', - headers: { - authorization: generateValidRequestAuthorizationHeader(connectedUser.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: connectedUser.id }), payload: buffer, }; @@ -244,8 +233,11 @@ describe('Acceptance | Application | organization-controller-sup-organization-le beforeEach(async function () { userId = databaseBuilder.factory.buildUser().id; - const authHeader = generateValidRequestAuthorizationHeader(userId); - accessToken = authHeader.replace('Bearer ', ''); + accessToken = tokenService.createAccessTokenFromUser({ + userId, + source: 'pix', + audience: 'https://orga.pix.org', + }).accessToken; }); context("when it's a SUP organization", function () { diff --git a/api/tests/prescription/organization-learner-feature/acceptance/application/organization-learner-features_test.js b/api/tests/prescription/organization-learner-feature/acceptance/application/organization-learner-features_test.js index c1f07072652..c8a7a6d192c 100644 --- a/api/tests/prescription/organization-learner-feature/acceptance/application/organization-learner-features_test.js +++ b/api/tests/prescription/organization-learner-feature/acceptance/application/organization-learner-features_test.js @@ -4,7 +4,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, } from '../../../../test-helper.js'; describe('Acceptance | Organization learner features', function () { @@ -33,9 +33,7 @@ describe('Acceptance | Organization learner features', function () { const options = { method: 'POST', url: `/api/organizations/${organization.id}/organization-learners/${organizationLearner.id}/features/${feature.key}`, - headers: { - authorization: generateValidRequestAuthorizationHeader(notAdminUserId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: notAdminUserId }), }; const response = await server.inject(options); @@ -73,9 +71,7 @@ describe('Acceptance | Organization learner features', function () { const options = { method: 'DELETE', url: `/api/organizations/${organization.id}/organization-learners/${organizationLearner.id}/features/${feature.key}`, - headers: { - authorization: generateValidRequestAuthorizationHeader(notAdminUserId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: notAdminUserId }), }; const response = await server.inject(options); diff --git a/api/tests/prescription/organization-learner/acceptance/application/learner-activity-controller_test.js b/api/tests/prescription/organization-learner/acceptance/application/learner-activity-controller_test.js index c1a020747d7..2944ecc1598 100644 --- a/api/tests/prescription/organization-learner/acceptance/application/learner-activity-controller_test.js +++ b/api/tests/prescription/organization-learner/acceptance/application/learner-activity-controller_test.js @@ -3,7 +3,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, } from '../../../../test-helper.js'; describe('Acceptance | Controller | organization-learners-management', function () { @@ -36,7 +36,7 @@ describe('Acceptance | Controller | organization-learners-management', function const options = { method: 'GET', url: `/api/organization-learners/${organizationLearnerId}/activity`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when const response = await server.inject(options); diff --git a/api/tests/prescription/organization-learner/acceptance/application/organization-learner-controller_test.js b/api/tests/prescription/organization-learner/acceptance/application/organization-learner-controller_test.js index 7a61da2348b..70e3c103743 100644 --- a/api/tests/prescription/organization-learner/acceptance/application/organization-learner-controller_test.js +++ b/api/tests/prescription/organization-learner/acceptance/application/organization-learner-controller_test.js @@ -3,7 +3,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, } from '../../../../test-helper.js'; describe('Acceptance | Controller | organization-learner', function () { @@ -31,7 +31,7 @@ describe('Acceptance | Controller | organization-learner', function () { options = { method: 'GET', url: `/api/organization-learners/${organizationLearnerId}`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when const response = await server.inject(options); @@ -53,7 +53,7 @@ describe('Acceptance | Controller | organization-learner', function () { options = { method: 'GET', url: `/api/organization-learners/${organizationLearnerId}`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when const response = await server.inject(options); diff --git a/api/tests/prescription/organization-learner/acceptance/application/organization-learner-route_test.js b/api/tests/prescription/organization-learner/acceptance/application/organization-learner-route_test.js index b71cbbaf9fb..878cfaff0fc 100644 --- a/api/tests/prescription/organization-learner/acceptance/application/organization-learner-route_test.js +++ b/api/tests/prescription/organization-learner/acceptance/application/organization-learner-route_test.js @@ -6,7 +6,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, insertUserWithRoleSuperAdmin, nock, } from '../../../../test-helper.js'; @@ -52,7 +52,7 @@ describe('Prescription | Organization Learner | Acceptance | Application | Organ const request = { method: 'GET', url: `/api/organizations/${organizationId}/attestations/${attestation.key}?divisions[]=6emeA`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when @@ -102,7 +102,7 @@ describe('Prescription | Organization Learner | Acceptance | Application | Organ const options = { method: 'GET', url: `/api/organizations/${organizationId}/organization-learners-level-by-tubes`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when diff --git a/api/tests/prescription/organization-learner/acceptance/learner-list-route_test.js b/api/tests/prescription/organization-learner/acceptance/learner-list-route_test.js index ac1e6ea8bcf..41074ab2e49 100644 --- a/api/tests/prescription/organization-learner/acceptance/learner-list-route_test.js +++ b/api/tests/prescription/organization-learner/acceptance/learner-list-route_test.js @@ -3,7 +3,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, insertUserWithRoleSuperAdmin, } from '../../../test-helper.js'; @@ -42,7 +42,7 @@ describe('Acceptance | Application | learner-list-route', function () { const request = { method: 'GET', url: `/api/organizations/${organizationId}/participants`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when @@ -81,7 +81,7 @@ describe('Acceptance | Application | learner-list-route', function () { const request = { method: 'GET', url: '/api/organizations/' + organization.id + '/divisions', - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when diff --git a/api/tests/prescription/organization-learner/acceptance/registration-organization-learner-route_test.js b/api/tests/prescription/organization-learner/acceptance/registration-organization-learner-route_test.js index 84627277501..2ab5dbabd0b 100644 --- a/api/tests/prescription/organization-learner/acceptance/registration-organization-learner-route_test.js +++ b/api/tests/prescription/organization-learner/acceptance/registration-organization-learner-route_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, } from '../../../test-helper.js'; describe('Acceptance | Application | registration-organization-learner-route', function () { @@ -35,7 +35,7 @@ describe('Acceptance | Application | registration-organization-learner-route', f options = { method: 'GET', url: `/api/organization-learners?userId=${user.id}&campaignCode=${campaignCode}`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; }); diff --git a/api/tests/prescription/organization-learner/acceptance/sco-learner-list-route_test.js b/api/tests/prescription/organization-learner/acceptance/sco-learner-list-route_test.js index 0012a8ec04d..a32d011c869 100644 --- a/api/tests/prescription/organization-learner/acceptance/sco-learner-list-route_test.js +++ b/api/tests/prescription/organization-learner/acceptance/sco-learner-list-route_test.js @@ -3,7 +3,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, insertUserWithRoleSuperAdmin, } from '../../../test-helper.js'; @@ -33,7 +33,7 @@ describe('Acceptance | Application | sco-leaner-list-route', function () { options = { method: 'GET', url: `/api/organizations/${organization.id}/sco-participants`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; }); @@ -100,7 +100,7 @@ describe('Acceptance | Application | sco-leaner-list-route', function () { options = { method: 'GET', url: `/api/organizations/${organization.id}/sco-participants?filter[certificability][]=eligible`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; // when @@ -115,7 +115,7 @@ describe('Acceptance | Application | sco-leaner-list-route', function () { options = { method: 'GET', url: `/api/organizations/${organization.id}/sco-participants?filter[certificability][]=eligible&filter[certificability][]=not-available`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; // when @@ -131,7 +131,7 @@ describe('Acceptance | Application | sco-leaner-list-route', function () { options = { method: 'GET', url: `/api/organizations/${organization.id}/sco-participants?filter[connectionTypes][]=none`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; // when @@ -146,7 +146,7 @@ describe('Acceptance | Application | sco-leaner-list-route', function () { options = { method: 'GET', url: `/api/organizations/${organization.id}/sco-participants?filter[connectionTypes][]=none&filter[connectionTypes][]=email`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; // when @@ -174,7 +174,7 @@ describe('Acceptance | Application | sco-leaner-list-route', function () { // given const userId = databaseBuilder.factory.buildUser.withMembership().id; await databaseBuilder.commit(); - options.headers.authorization = generateValidRequestAuthorizationHeader(userId); + options.headers = generateAuthenticatedUserRequestHeaders({ userId }); // when const response = await server.inject(options); @@ -189,7 +189,7 @@ describe('Acceptance | Application | sco-leaner-list-route', function () { const userId = databaseBuilder.factory.buildUser.withMembership({ organizationId }).id; await databaseBuilder.commit(); - options.headers.authorization = generateValidRequestAuthorizationHeader(userId); + options.headers = generateAuthenticatedUserRequestHeaders({ userId }); options.url = `/api/organizations/${organizationId}/sco-participants`; // when diff --git a/api/tests/prescription/organization-learner/acceptance/sup-learner-list-route_test.js b/api/tests/prescription/organization-learner/acceptance/sup-learner-list-route_test.js index 2c0efc51224..9c341c2c1a8 100644 --- a/api/tests/prescription/organization-learner/acceptance/sup-learner-list-route_test.js +++ b/api/tests/prescription/organization-learner/acceptance/sup-learner-list-route_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, insertUserWithRoleSuperAdmin, } from '../../../test-helper.js'; @@ -28,7 +28,7 @@ describe('Acceptance | Application | sup-leaner-list-route', function () { options = { method: 'GET', url: `/api/organizations/${organization.id}/sup-participants`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; }); @@ -75,7 +75,7 @@ describe('Acceptance | Application | sup-leaner-list-route', function () { // given const userId = databaseBuilder.factory.buildUser.withMembership().id; await databaseBuilder.commit(); - options.headers.authorization = generateValidRequestAuthorizationHeader(userId); + options.headers = generateAuthenticatedUserRequestHeaders({ userId }); // when const response = await server.inject(options); @@ -90,7 +90,7 @@ describe('Acceptance | Application | sup-leaner-list-route', function () { const userId = databaseBuilder.factory.buildUser.withMembership({ organizationId }).id; await databaseBuilder.commit(); - options.headers.authorization = generateValidRequestAuthorizationHeader(userId); + options.headers = generateAuthenticatedUserRequestHeaders({ userId }); options.url = `/api/organizations/${organizationId}/sup-participants`; // when @@ -108,7 +108,7 @@ describe('Acceptance | Application | sup-leaner-list-route', function () { options = { method: 'GET', url: `/api/organizations/${organization.id}/sup-participants?filter[groups][]=L5`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; // when @@ -122,7 +122,7 @@ describe('Acceptance | Application | sup-leaner-list-route', function () { options = { method: 'GET', url: `/api/organizations/${organization.id}/sup-participants?filter[groups][]=L5&filter[groups][]=D3`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; // when @@ -138,7 +138,7 @@ describe('Acceptance | Application | sup-leaner-list-route', function () { options = { method: 'GET', url: `/api/organizations/${organization.id}/sup-participants?filter[studentNumber]=L5645745`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; // when @@ -154,7 +154,7 @@ describe('Acceptance | Application | sup-leaner-list-route', function () { options = { method: 'GET', url: `/api/organizations/${organization.id}/sup-participants?filter[certificability][]=eligible`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; // when @@ -168,7 +168,7 @@ describe('Acceptance | Application | sup-leaner-list-route', function () { options = { method: 'GET', url: `/api/organizations/${organization.id}/sup-participants?filter[certificability][]=eligible&filter[certificability][]=not-available`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; // when diff --git a/api/tests/prescription/organization-place/acceptance/application/create-organization-places-lot_test.js b/api/tests/prescription/organization-place/acceptance/application/create-organization-places-lot_test.js index 48a95e69c70..0c3e09dcd23 100644 --- a/api/tests/prescription/organization-place/acceptance/application/create-organization-places-lot_test.js +++ b/api/tests/prescription/organization-place/acceptance/application/create-organization-places-lot_test.js @@ -3,7 +3,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, insertUserWithRoleSuperAdmin, } from '../../../../test-helper.js'; @@ -19,9 +19,7 @@ describe('Acceptance | Route | Create Organization Places Lot', function () { const options = { method: 'POST', url: `/api/admin/organizations/${organizationId}/places`, - headers: { - authorization: generateValidRequestAuthorizationHeader(adminUser.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: adminUser.id }), payload: { data: { attributes: { diff --git a/api/tests/prescription/organization-place/acceptance/application/delete-organization-places-lot_test.js b/api/tests/prescription/organization-place/acceptance/application/delete-organization-places-lot_test.js index 8aeaa7ef017..6ee4f1369a5 100644 --- a/api/tests/prescription/organization-place/acceptance/application/delete-organization-places-lot_test.js +++ b/api/tests/prescription/organization-place/acceptance/application/delete-organization-places-lot_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, insertUserWithRoleSuperAdmin, } from '../../../../test-helper.js'; @@ -18,9 +18,7 @@ describe('Acceptance | Route | Delete Organizations Places Lot', function () { const options = { method: 'DELETE', url: `/api/admin/organizations/${organizationPlace.organizationId}/places/${organizationPlace.id}`, - headers: { - authorization: generateValidRequestAuthorizationHeader(adminUser.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: adminUser.id }), }; await databaseBuilder.commit(); @@ -41,9 +39,7 @@ describe('Acceptance | Route | Delete Organizations Places Lot', function () { const options = { method: 'DELETE', url: `/api/admin/organizations/${organizationPlace.organizationId}/places/123156`, - headers: { - authorization: generateValidRequestAuthorizationHeader(adminUser.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: adminUser.id }), }; await databaseBuilder.commit(); @@ -67,9 +63,7 @@ describe('Acceptance | Route | Delete Organizations Places Lot', function () { const options = { method: 'DELETE', url: `/api/admin/organizations/${organizationPlace.organizationId}/places/${organizationPlace.id}`, - headers: { - authorization: generateValidRequestAuthorizationHeader(adminUser.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: adminUser.id }), }; await databaseBuilder.commit(); diff --git a/api/tests/prescription/organization-place/acceptance/application/find-organization-places_test.js b/api/tests/prescription/organization-place/acceptance/application/find-organization-places_test.js index 523eeb226a9..c2f0fa6b381 100644 --- a/api/tests/prescription/organization-place/acceptance/application/find-organization-places_test.js +++ b/api/tests/prescription/organization-place/acceptance/application/find-organization-places_test.js @@ -3,7 +3,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, insertUserWithRoleSuperAdmin, } from '../../../../test-helper.js'; @@ -28,9 +28,7 @@ describe('Acceptance | Route | Find Organization Places', function () { const options = { method: 'GET', url: `/api/admin/organizations/${organizationId}/places`, - headers: { - authorization: generateValidRequestAuthorizationHeader(adminUser.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: adminUser.id }), }; await databaseBuilder.commit(); @@ -56,9 +54,7 @@ describe('Acceptance | Route | Find Organization Places', function () { const options = { method: 'GET', url: `/api/admin/organizations/${organizationId}/places`, - headers: { - authorization: generateValidRequestAuthorizationHeader(adminUser.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: adminUser.id }), }; await databaseBuilder.commit(); diff --git a/api/tests/prescription/organization-place/acceptance/application/get-organization-places-capacity_test.js b/api/tests/prescription/organization-place/acceptance/application/get-organization-places-capacity_test.js index be3861abc5f..2e7f150c875 100644 --- a/api/tests/prescription/organization-place/acceptance/application/get-organization-places-capacity_test.js +++ b/api/tests/prescription/organization-place/acceptance/application/get-organization-places-capacity_test.js @@ -3,7 +3,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, insertUserWithRoleSuperAdmin, } from '../../../../test-helper.js'; @@ -19,9 +19,7 @@ describe('Acceptance | Route | Get Organizations Places Capacity', function () { const options = { method: 'GET', url: `/api/admin/organizations/${organizationId}/places/capacity`, - headers: { - authorization: generateValidRequestAuthorizationHeader(adminUser.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: adminUser.id }), }; await databaseBuilder.commit(); @@ -49,9 +47,7 @@ describe('Acceptance | Route | Get Organizations Places Capacity', function () { const options = { method: 'GET', url: `/api/admin/organizations/${organizationId}/places/capacity`, - headers: { - authorization: generateValidRequestAuthorizationHeader(adminUser.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: adminUser.id }), }; await databaseBuilder.commit(); diff --git a/api/tests/prescription/organization-place/acceptance/application/get-organization-places-lots_test.js b/api/tests/prescription/organization-place/acceptance/application/get-organization-places-lots_test.js index 27b36ff234f..1554e2257db 100644 --- a/api/tests/prescription/organization-place/acceptance/application/get-organization-places-lots_test.js +++ b/api/tests/prescription/organization-place/acceptance/application/get-organization-places-lots_test.js @@ -4,7 +4,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, } from '../../../../test-helper.js'; describe('Acceptance | Route | Get Organizations Places Lots', function () { @@ -35,9 +35,7 @@ describe('Acceptance | Route | Get Organizations Places Lots', function () { const options = { method: 'GET', url: `/api/organizations/${organizationId}/places-lots`, - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when diff --git a/api/tests/prescription/organization-place/acceptance/application/get-organization-places-statistics_test.js b/api/tests/prescription/organization-place/acceptance/application/get-organization-places-statistics_test.js index fa1baf8f29a..54363d12ad2 100644 --- a/api/tests/prescription/organization-place/acceptance/application/get-organization-places-statistics_test.js +++ b/api/tests/prescription/organization-place/acceptance/application/get-organization-places-statistics_test.js @@ -5,7 +5,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, } from '../../../../test-helper.js'; describe('Acceptance | Route | Get Organizations Places Statistics', function () { @@ -37,9 +37,7 @@ describe('Acceptance | Route | Get Organizations Places Statistics', function () const options = { method: 'GET', url: `/api/organizations/${organizationId}/place-statistics`, - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when diff --git a/api/tests/prescription/target-profile/acceptance/application/admin-target-profile-route_test.js b/api/tests/prescription/target-profile/acceptance/application/admin-target-profile-route_test.js index 40c2602d6af..7a67ac278d0 100644 --- a/api/tests/prescription/target-profile/acceptance/application/admin-target-profile-route_test.js +++ b/api/tests/prescription/target-profile/acceptance/application/admin-target-profile-route_test.js @@ -3,7 +3,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, knex, learningContentBuilder, MockDate, @@ -71,7 +71,7 @@ describe('Acceptance | TargetProfile | Application | Route | admin-target-profil const options = { method: 'PATCH', url: `/api/admin/target-profiles/${targetProfile.id}`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), payload: { data: { attributes: { @@ -108,7 +108,7 @@ describe('Acceptance | TargetProfile | Application | Route | admin-target-profil const options = { method: 'PATCH', url: `/api/admin/target-profiles/${targetProfile.id}`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), payload: { data: { attributes: { @@ -218,7 +218,7 @@ describe('Acceptance | TargetProfile | Application | Route | admin-target-profil const response = await server.inject({ method: 'GET', url: `/api/admin/target-profiles/${targetProfile.id}`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }); // then @@ -249,7 +249,7 @@ describe('Acceptance | TargetProfile | Application | Route | admin-target-profil const response = await server.inject({ method: 'GET', url: `/api/admin/target-profiles/${targetProfile.id}?filter[badges]=certifiable`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }); // then @@ -392,7 +392,7 @@ describe('Acceptance | TargetProfile | Application | Route | admin-target-profil method: 'GET', url: `/api/admin/target-profiles/${targetProfileId}/content-json`, payload: {}, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; // when @@ -416,7 +416,7 @@ describe('Acceptance | TargetProfile | Application | Route | admin-target-profil method: 'GET', url: `/api/admin/target-profiles/${targetProfileId}/learning-content-pdf?language=fr`, payload: {}, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; // when @@ -443,7 +443,7 @@ describe('Acceptance | TargetProfile | Application | Route | admin-target-profil const options = { method: 'POST', url: `/api/admin/target-profiles/${targetProfileId}/attach-organizations`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), payload: { 'organization-ids': [organization1.id, organization2.id], }, @@ -482,7 +482,7 @@ describe('Acceptance | TargetProfile | Application | Route | admin-target-profil const options = { method: 'POST', url: `/api/admin/target-profiles/${targetProfileId}/copy-organizations`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload: { 'target-profile-id': existingTargetProfileId, }, @@ -526,7 +526,7 @@ describe('Acceptance | TargetProfile | Application | Route | admin-target-profil const options = { method: 'POST', url: `/api/admin/organizations/${organizationId}/attach-target-profiles`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload: { 'target-profile-ids': [alreadyAttachedTargetProfileId, toAttachTargetProfileId], }, @@ -551,7 +551,7 @@ describe('Acceptance | TargetProfile | Application | Route | admin-target-profil const options = { method: 'POST', url: `/api/admin/organizations/${organizationId}/attach-target-profiles`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload: { 'target-profile-ids': [alreadyAttachedTargetProfileId, 6000, toAttachTargetProfileId], }, @@ -588,7 +588,7 @@ describe('Acceptance | TargetProfile | Application | Route | admin-target-profil const options = { method: 'DELETE', url: `/api/admin/target-profiles/${targetProfileId}/detach-organizations`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), payload: { data: { attributes: { @@ -614,7 +614,7 @@ describe('Acceptance | TargetProfile | Application | Route | admin-target-profil const options = { method: 'PUT', url: `/api/admin/target-profiles/${targetProfile.id}/outdate`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), payload: { data: { attributes: { @@ -644,9 +644,7 @@ describe('Acceptance | TargetProfile | Application | Route | admin-target-profil const options = { method: 'PUT', url: `/api/admin/target-profiles/${targetProfile.id}/simplified-access`, - headers: { - authorization: generateValidRequestAuthorizationHeader(user.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; // when @@ -697,7 +695,7 @@ describe('Acceptance | TargetProfile | Application | Route | admin-target-profil const options = { method: 'GET', url: `/api/admin/target-profiles/${targetProfileId}/organizations`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; // when @@ -748,7 +746,7 @@ describe('Acceptance | TargetProfile | Application | Route | admin-target-profil const response = await server.inject({ method: 'POST', url: `/api/admin/target-profiles/${targetProfile.id}/copy`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }); // then @@ -806,7 +804,7 @@ describe('Acceptance | TargetProfile | Application | Route | admin-target-profil const options = { method: 'GET', url: `/api/admin/organizations/${organizationId}/target-profile-summaries`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when @@ -840,7 +838,7 @@ describe('Acceptance | TargetProfile | Application | Route | admin-target-profil const options = { method: 'GET', url: `/api/admin/target-profile-summaries`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when @@ -878,7 +876,7 @@ describe('Acceptance | TargetProfile | Application | Route | admin-target-profil const options = { method: 'POST', url: '/api/admin/target-profiles', - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), payload: { data: { attributes: { diff --git a/api/tests/prescription/target-profile/acceptance/application/target-profile-route_test.js b/api/tests/prescription/target-profile/acceptance/application/target-profile-route_test.js index 7754f8f4435..af9c0e17ccf 100644 --- a/api/tests/prescription/target-profile/acceptance/application/target-profile-route_test.js +++ b/api/tests/prescription/target-profile/acceptance/application/target-profile-route_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, insertUserWithRoleSuperAdmin, learningContentBuilder, mockLearningContent, @@ -51,7 +51,7 @@ describe('Acceptance | Route | target-profile', function () { const options = { method: 'GET', url: `/api/organizations/${linkedOrganization.id}/target-profiles`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; // when @@ -267,9 +267,7 @@ describe('Acceptance | Route | target-profile', function () { const options = { method: 'GET', url: `/api/frameworks/for-target-profile-submission`, - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when diff --git a/api/tests/profile/acceptance/application/attestation-route_test.js b/api/tests/profile/acceptance/application/attestation-route_test.js index 3ff6383a046..f9c736835dd 100644 --- a/api/tests/profile/acceptance/application/attestation-route_test.js +++ b/api/tests/profile/acceptance/application/attestation-route_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, } from '../../../test-helper.js'; describe('Profile | Acceptance | Application | Attestation Route ', function () { @@ -21,7 +21,7 @@ describe('Profile | Acceptance | Application | Attestation Route ', function () await databaseBuilder.commit(); const options = { method: 'GET', - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), url: `/api/users/${userId}/attestations/${attestationKey}`, }; diff --git a/api/tests/profile/acceptance/application/share-profile-reward-route_test.js b/api/tests/profile/acceptance/application/share-profile-reward-route_test.js index 4f86897195a..2b2e1f6eb06 100644 --- a/api/tests/profile/acceptance/application/share-profile-reward-route_test.js +++ b/api/tests/profile/acceptance/application/share-profile-reward-route_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, } from '../../../test-helper.js'; describe('Profile | Acceptance | Application | Share Profile Route ', function () { @@ -23,7 +23,7 @@ describe('Profile | Acceptance | Application | Share Profile Route ', function ( await databaseBuilder.commit(); const options = { method: 'POST', - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), url: `/api/users/${userId}/profile/share-reward`, payload: { data: { @@ -54,7 +54,7 @@ describe('Profile | Acceptance | Application | Share Profile Route ', function ( await databaseBuilder.commit(); const options = { method: 'POST', - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), url: `/api/users/${userId}/profile/share-reward`, payload: { data: { diff --git a/api/tests/quest/acceptance/application/quest-route_test.js b/api/tests/quest/acceptance/application/quest-route_test.js index d23cd4c0c3f..a23fe6e71cf 100644 --- a/api/tests/quest/acceptance/application/quest-route_test.js +++ b/api/tests/quest/acceptance/application/quest-route_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, } from '../../../test-helper.js'; describe('Quest | Acceptance | Application | Quest Route ', function () { @@ -34,7 +34,7 @@ describe('Quest | Acceptance | Application | Quest Route ', function () { await databaseBuilder.commit(); const options = { method: 'GET', - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), url: `/api/campaign-participations/${campaignParticipationId}/quest-results`, }; diff --git a/api/tests/shared/acceptance/application/assessments/assessment-controller-auto-validate-next-challenge_test.js b/api/tests/shared/acceptance/application/assessments/assessment-controller-auto-validate-next-challenge_test.js index 750456bff14..9347e575820 100644 --- a/api/tests/shared/acceptance/application/assessments/assessment-controller-auto-validate-next-challenge_test.js +++ b/api/tests/shared/acceptance/application/assessments/assessment-controller-auto-validate-next-challenge_test.js @@ -4,7 +4,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, insertUserWithRoleSuperAdmin, knex, learningContentBuilder, @@ -83,9 +83,7 @@ describe('Acceptance | API | assessment-controller-auto-validate-next-challenge' const response = await server.inject({ method: 'POST', url: `/api/admin/assessments/${assessmentId}/always-ok-validate-next-challenge`, - headers: { - authorization: `Bearer ${generateValidRequestAuthorizationHeader(userId)}`, - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }); // then diff --git a/api/tests/shared/acceptance/application/assessments/assessment-controller-complete-assessment_test.js b/api/tests/shared/acceptance/application/assessments/assessment-controller-complete-assessment_test.js index 3cd332e70fd..6fb720a53f5 100644 --- a/api/tests/shared/acceptance/application/assessments/assessment-controller-complete-assessment_test.js +++ b/api/tests/shared/acceptance/application/assessments/assessment-controller-complete-assessment_test.js @@ -8,7 +8,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, knex, learningContentBuilder, mockLearningContent, @@ -429,9 +429,7 @@ describe('Acceptance | Controller | assessment-controller-complete-assessment', options = { method: 'PATCH', url: `/api/assessments/${assessment.id}/complete-assessment`, - headers: { - authorization: generateValidRequestAuthorizationHeader(user.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; }); @@ -439,7 +437,7 @@ describe('Acceptance | Controller | assessment-controller-complete-assessment', context('when user is not the owner of the assessment', function () { it('should return a 401 HTTP status code', async function () { // given - options.headers.authorization = generateValidRequestAuthorizationHeader(user.id + 1); + options.headers = generateAuthenticatedUserRequestHeaders({ userId: user.id + 1 }); // when const response = await server.inject(options); @@ -604,7 +602,7 @@ describe('Acceptance | Controller | assessment-controller-complete-assessment', it('should complete the certification assessment', async function () { // given options.url = `/api/assessments/${certificationAssessmentId}/complete-assessment`; - options.headers.authorization = generateValidRequestAuthorizationHeader(certifiableUserId); + options.headers = generateAuthenticatedUserRequestHeaders({ userId: certifiableUserId }); // when const response = await server.inject(options); @@ -642,7 +640,7 @@ describe('Acceptance | Controller | assessment-controller-complete-assessment', await databaseBuilder.commit(); options.url = `/api/assessments/${certificationAssessment.id}/complete-assessment`; - options.headers.authorization = generateValidRequestAuthorizationHeader(certifiableUserId); + options.headers = generateAuthenticatedUserRequestHeaders({ userId: certifiableUserId }); // when const response = await server.inject(options); @@ -724,6 +722,6 @@ async function _createAndCompleteCampaignParticipation({ user, campaign, badge, await databaseBuilder.commit(); options.url = `/api/assessments/${campaignAssessment.id}/complete-assessment`; - options.headers.authorization = generateValidRequestAuthorizationHeader(user.id); + options.headers = generateAuthenticatedUserRequestHeaders({ userId: user.id }); await server.inject(options); } diff --git a/api/tests/shared/acceptance/application/assessments/assessment-controller-find-competence-evaluations_test.js b/api/tests/shared/acceptance/application/assessments/assessment-controller-find-competence-evaluations_test.js index b7c0024034a..d036d22c717 100644 --- a/api/tests/shared/acceptance/application/assessments/assessment-controller-find-competence-evaluations_test.js +++ b/api/tests/shared/acceptance/application/assessments/assessment-controller-find-competence-evaluations_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, } from '../../../../test-helper.js'; describe('Acceptance | API | assessment-controller-find-competence-evaluations', function () { @@ -22,9 +22,7 @@ describe('Acceptance | API | assessment-controller-find-competence-evaluations', const options = { method: 'GET', url: `/api/assessments/${assessmentId}/competence-evaluations`, - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when diff --git a/api/tests/shared/acceptance/application/assessments/assessment-controller-get-last-challenge-id_test.js b/api/tests/shared/acceptance/application/assessments/assessment-controller-get-last-challenge-id_test.js index cb2c43d18cc..3bc52fddb04 100644 --- a/api/tests/shared/acceptance/application/assessments/assessment-controller-get-last-challenge-id_test.js +++ b/api/tests/shared/acceptance/application/assessments/assessment-controller-get-last-challenge-id_test.js @@ -3,7 +3,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, insertUserWithRoleSuperAdmin, } from '../../../../test-helper.js'; @@ -36,9 +36,7 @@ describe('Acceptance | API | assessment-controller-get-last-challenge-id', funct options = { method: 'GET', url: `/api/assessments/${assessmentId}/last-challenge-id`, - headers: { - authorization: `Bearer ${generateValidRequestAuthorizationHeader(userId)}`, - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; }); @@ -75,9 +73,7 @@ describe('Acceptance | API | assessment-controller-get-last-challenge-id', funct options = { method: 'GET', url: `/api/assessments/${assessmentId}/last-challenge-id`, - headers: { - authorization: `Bearer ${generateValidRequestAuthorizationHeader(userId)}`, - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; const response = await server.inject(options); diff --git a/api/tests/shared/acceptance/application/assessments/assessment-controller-get-next-challenge-for-campaign-assessment_test.js b/api/tests/shared/acceptance/application/assessments/assessment-controller-get-next-challenge-for-campaign-assessment_test.js index d9e10f22e66..de62b806ef9 100644 --- a/api/tests/shared/acceptance/application/assessments/assessment-controller-get-next-challenge-for-campaign-assessment_test.js +++ b/api/tests/shared/acceptance/application/assessments/assessment-controller-get-next-challenge-for-campaign-assessment_test.js @@ -3,7 +3,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, knex, learningContentBuilder, mockLearningContent, @@ -114,7 +114,7 @@ describe('Acceptance | API | assessment-controller-get-next-challenge-for-campai const options = { method: 'GET', url: `/api/assessments/${assessmentId}/next`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; const lastQuestionDate = new Date(); diff --git a/api/tests/shared/acceptance/application/assessments/assessment-controller-get-next-challenge-for-certification_test.js b/api/tests/shared/acceptance/application/assessments/assessment-controller-get-next-challenge-for-certification_test.js index 465df907842..5f1c9a02288 100644 --- a/api/tests/shared/acceptance/application/assessments/assessment-controller-get-next-challenge-for-certification_test.js +++ b/api/tests/shared/acceptance/application/assessments/assessment-controller-get-next-challenge-for-certification_test.js @@ -5,7 +5,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, knex, learningContentBuilder, mockLearningContent, @@ -124,7 +124,7 @@ describe('Acceptance | API | assessment-controller-get-next-challenge-for-certif const options = { method: 'GET', url: `/api/assessments/${assessmentId}/next`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; const lastQuestionDate = new Date(); @@ -189,7 +189,7 @@ describe('Acceptance | API | assessment-controller-get-next-challenge-for-certif const options = { method: 'GET', url: `/api/assessments/${assessmentId}/next`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when @@ -242,7 +242,7 @@ describe('Acceptance | API | assessment-controller-get-next-challenge-for-certif const options = { method: 'GET', url: `/api/assessments/${assessmentId}/next`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when diff --git a/api/tests/shared/acceptance/application/assessments/assessment-controller-get-next-challenge-for-competence-evaluation_test.js b/api/tests/shared/acceptance/application/assessments/assessment-controller-get-next-challenge-for-competence-evaluation_test.js index 091f2c5f5bf..1d3c01ca14b 100644 --- a/api/tests/shared/acceptance/application/assessments/assessment-controller-get-next-challenge-for-competence-evaluation_test.js +++ b/api/tests/shared/acceptance/application/assessments/assessment-controller-get-next-challenge-for-competence-evaluation_test.js @@ -4,7 +4,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, knex, learningContentBuilder, mockLearningContent, @@ -123,7 +123,7 @@ describe('Acceptance | API | assessment-controller-get-next-challenge-for-compet const options = { method: 'GET', url: `/api/assessments/${assessmentId}/next`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; const lastQuestionDate = new Date(); @@ -142,7 +142,7 @@ describe('Acceptance | API | assessment-controller-get-next-challenge-for-compet const options = { method: 'GET', url: `/api/assessments/${assessmentId}/next`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when @@ -212,7 +212,7 @@ describe('Acceptance | API | assessment-controller-get-next-challenge-for-compet const options = { method: 'GET', url: `/api/assessments/${assessmentId}/next`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when @@ -230,7 +230,7 @@ describe('Acceptance | API | assessment-controller-get-next-challenge-for-compet const options = { method: 'GET', url: `/api/assessments/${assessmentId}/next`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when diff --git a/api/tests/shared/acceptance/application/assessments/assessment-controller-get-next-challenge-locale-management.js b/api/tests/shared/acceptance/application/assessments/assessment-controller-get-next-challenge-locale-management.js index 573c935eecd..f233645ab2f 100644 --- a/api/tests/shared/acceptance/application/assessments/assessment-controller-get-next-challenge-locale-management.js +++ b/api/tests/shared/acceptance/application/assessments/assessment-controller-get-next-challenge-locale-management.js @@ -4,7 +4,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, learningContentBuilder, mockLearningContent, } from '../../../../test-helper.js'; @@ -88,10 +88,7 @@ describe('Acceptance | API | assessment-controller-get-next-challenge-locale-man const options = { method: 'GET', url: `/api/assessments/${assessmentId}/next`, - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - 'accept-language': FRENCH_FRANCE, - }, + headers: generateAuthenticatedUserRequestHeaders({ userId, acceptLanguage: FRENCH_FRANCE }), }; // when diff --git a/api/tests/shared/acceptance/application/assessments/assessment-controller-get_test.js b/api/tests/shared/acceptance/application/assessments/assessment-controller-get_test.js index c87b34a0ff7..b4f23d46157 100644 --- a/api/tests/shared/acceptance/application/assessments/assessment-controller-get_test.js +++ b/api/tests/shared/acceptance/application/assessments/assessment-controller-get_test.js @@ -4,7 +4,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, learningContentBuilder, mockLearningContent, } from '../../../../test-helper.js'; @@ -43,10 +43,7 @@ describe('Acceptance | API | assessment-controller-get', function () { options = { method: 'GET', url: `/api/assessments/${assessmentId}`, - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - 'accept-language': FRENCH_SPOKEN, - }, + headers: generateAuthenticatedUserRequestHeaders({ userId, acceptLanguage: FRENCH_SPOKEN }), }; // when @@ -120,10 +117,7 @@ describe('Acceptance | API | assessment-controller-get', function () { options = { method: 'GET', url: `/api/assessments/${assessmentId}`, - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - 'accept-language': FRENCH_SPOKEN, - }, + headers: generateAuthenticatedUserRequestHeaders({ userId, acceptLanguage: FRENCH_SPOKEN }), }; // when @@ -149,10 +143,7 @@ describe('Acceptance | API | assessment-controller-get', function () { options = { method: 'GET', url: `/api/assessments/${assessmentId}`, - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - 'accept-language': FRENCH_SPOKEN, - }, + headers: generateAuthenticatedUserRequestHeaders({ userId, acceptLanguage: FRENCH_SPOKEN }), }; // when @@ -206,10 +197,7 @@ describe('Acceptance | API | assessment-controller-get', function () { }).id; await databaseBuilder.commit(); options = { - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - 'accept-language': FRENCH_SPOKEN, - }, + headers: generateAuthenticatedUserRequestHeaders({ userId, acceptLanguage: FRENCH_SPOKEN }), method: 'GET', url: `/api/assessments/${assessmentId}`, }; @@ -247,10 +235,7 @@ describe('Acceptance | API | assessment-controller-get', function () { const options = { method: 'GET', url: `/api/assessments/${assessmentId}`, - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - 'accept-language': FRENCH_SPOKEN, - }, + headers: generateAuthenticatedUserRequestHeaders({ userId, acceptLanguage: FRENCH_SPOKEN }), }; // when @@ -264,10 +249,7 @@ describe('Acceptance | API | assessment-controller-get', function () { const options = { method: 'GET', url: `/api/assessments/${assessmentId}`, - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - 'accept-language': FRENCH_SPOKEN, - }, + headers: generateAuthenticatedUserRequestHeaders({ userId, acceptLanguage: FRENCH_SPOKEN }), }; // when @@ -283,10 +265,7 @@ describe('Acceptance | API | assessment-controller-get', function () { const options = { method: 'GET', url: `/api/assessments/${assessmentId}`, - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - 'accept-language': FRENCH_SPOKEN, - }, + headers: generateAuthenticatedUserRequestHeaders({ userId, acceptLanguage: FRENCH_SPOKEN }), }; // when diff --git a/api/tests/shared/acceptance/application/assessments/assessment-controller-pause-assessment_test.js b/api/tests/shared/acceptance/application/assessments/assessment-controller-pause-assessment_test.js index 30d4ad82307..abe97acf14d 100644 --- a/api/tests/shared/acceptance/application/assessments/assessment-controller-pause-assessment_test.js +++ b/api/tests/shared/acceptance/application/assessments/assessment-controller-pause-assessment_test.js @@ -3,7 +3,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, knex, mockLearningContent, } from '../../../../test-helper.js'; @@ -46,7 +46,7 @@ describe('Acceptance | API | assessment-controller-pause-assessment', function ( options = { method: 'POST', url: `/api/assessments/${assessment.id}/alert`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), payload: { data: { attributes: { @@ -63,7 +63,7 @@ describe('Acceptance | API | assessment-controller-pause-assessment', function ( it('should respond with a 401 if requested user is not the same as the user of the assessment', async function () { // given const otherUserId = 9999; - options.headers.authorization = generateValidRequestAuthorizationHeader(otherUserId); + options.headers = generateAuthenticatedUserRequestHeaders({ userId: otherUserId }); options.payload = {}; // when diff --git a/api/tests/shared/acceptance/application/assessments/assessment-controller-post_test.js b/api/tests/shared/acceptance/application/assessments/assessment-controller-post_test.js index c974a694d2d..60c327975a4 100644 --- a/api/tests/shared/acceptance/application/assessments/assessment-controller-post_test.js +++ b/api/tests/shared/acceptance/application/assessments/assessment-controller-post_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, knex, } from '../../../../test-helper.js'; @@ -44,7 +44,7 @@ describe('Acceptance | API | Assessments POST', function () { }, }, }, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; return databaseBuilder.commit(); }); diff --git a/api/tests/shared/acceptance/application/assessments/assessment-controller-update-last-challenge-state_test.js b/api/tests/shared/acceptance/application/assessments/assessment-controller-update-last-challenge-state_test.js index 1fd72365329..7935b8ceae9 100644 --- a/api/tests/shared/acceptance/application/assessments/assessment-controller-update-last-challenge-state_test.js +++ b/api/tests/shared/acceptance/application/assessments/assessment-controller-update-last-challenge-state_test.js @@ -3,7 +3,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, knex, learningContentBuilder, mockLearningContent, @@ -81,7 +81,7 @@ describe('Acceptance | API | assessment-controller-update-last-challenge-state', options = { method: 'PATCH', url: `/api/assessments/${assessment.id}/last-challenge-state/${newState}`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; return databaseBuilder.commit(); @@ -90,7 +90,7 @@ describe('Acceptance | API | assessment-controller-update-last-challenge-state', it('should respond with a 401 if requested user is not the same as the user of the assessment', async function () { // given const otherUserId = 9999; - options.headers.authorization = generateValidRequestAuthorizationHeader(otherUserId); + options.headers = generateAuthenticatedUserRequestHeaders({ userId: otherUserId }); options.payload = {}; // when @@ -133,7 +133,7 @@ describe('Acceptance | API | assessment-controller-update-last-challenge-state', const options = { method: 'PATCH', url: `/api/assessments/${assessmentId}/last-challenge-state/${state}`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload: {}, }; @@ -159,7 +159,7 @@ describe('Acceptance | API | assessment-controller-update-last-challenge-state', const options = { method: 'PATCH', url: `/api/assessments/${assessmentId}/last-challenge-state/${state}`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload, }; @@ -200,7 +200,7 @@ describe('Acceptance | API | assessment-controller-update-last-challenge-state', const options = { method: 'PATCH', url: `/api/assessments/${assessmentId}/last-challenge-state/${state}`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload, }; @@ -241,7 +241,7 @@ describe('Acceptance | API | assessment-controller-update-last-challenge-state', const options = { method: 'PATCH', url: `/api/assessments/${assessmentId}/last-challenge-state/${state}`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload, }; diff --git a/api/tests/shared/acceptance/application/badges/badge-controller_test.js b/api/tests/shared/acceptance/application/badges/badge-controller_test.js index f9ccc097dcf..c9696a56452 100644 --- a/api/tests/shared/acceptance/application/badges/badge-controller_test.js +++ b/api/tests/shared/acceptance/application/badges/badge-controller_test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, insertUserWithRoleSuperAdmin, } from '../../../../test-helper.js'; @@ -45,7 +45,7 @@ describe('Acceptance | API | Badges', function () { options = { method: 'PATCH', url: `/api/admin/badges/${badge.id}`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), payload: { data: { type: 'badges', @@ -79,7 +79,7 @@ describe('Acceptance | API | Badges', function () { options = { method: 'DELETE', url: `/api/admin/badges/${badge.id}`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when @@ -98,7 +98,7 @@ describe('Acceptance | API | Badges', function () { options = { method: 'DELETE', url: `/api/admin/badges/${badge.id}`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when diff --git a/api/tests/shared/acceptance/application/security-pre-handlers_test.js b/api/tests/shared/acceptance/application/security-pre-handlers_test.js index 831a5497b3c..6d4fecc53e9 100644 --- a/api/tests/shared/acceptance/application/security-pre-handlers_test.js +++ b/api/tests/shared/acceptance/application/security-pre-handlers_test.js @@ -5,7 +5,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, } from '../../../test-helper.js'; describe('Acceptance | Application | SecurityPreHandlers', function () { @@ -31,7 +31,7 @@ describe('Acceptance | Application | SecurityPreHandlers', function () { const options = { method: 'PATCH', url: '/api/cache', - headers: { authorization: generateValidRequestAuthorizationHeader() }, + headers: generateAuthenticatedUserRequestHeaders(), }; // when @@ -64,7 +64,7 @@ describe('Acceptance | Application | SecurityPreHandlers', function () { const options = { method: 'GET', url: '/test_route/3', - headers: { authorization: generateValidRequestAuthorizationHeader(2) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: 2 }), }; // when @@ -85,7 +85,7 @@ describe('Acceptance | Application | SecurityPreHandlers', function () { userId = databaseBuilder.factory.buildUser().id; options = { method: 'GET', - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; await databaseBuilder.commit(); @@ -152,7 +152,7 @@ describe('Acceptance | Application | SecurityPreHandlers', function () { userId = databaseBuilder.factory.buildUser().id; organizationId = databaseBuilder.factory.buildOrganization().id; options = { - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), method: 'GET', url: `/api/organizations/${organizationId}/invitations`, }; @@ -223,7 +223,7 @@ describe('Acceptance | Application | SecurityPreHandlers', function () { const options = { method: 'GET', url: `/test_route/${organizationId}`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; const response = await server.inject(options); @@ -246,7 +246,7 @@ describe('Acceptance | Application | SecurityPreHandlers', function () { const options = { method: 'GET', url: `/test_route/${organizationId}`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; const response = await server.inject(options); @@ -280,7 +280,7 @@ describe('Acceptance | Application | SecurityPreHandlers', function () { const options = { method: 'GET', url: `/test_route/${organizationId}`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; const response = await server.inject(options); @@ -303,7 +303,7 @@ describe('Acceptance | Application | SecurityPreHandlers', function () { const options = { method: 'GET', url: `/test_route/${organizationId}`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; const response = await server.inject(options); @@ -324,7 +324,7 @@ describe('Acceptance | Application | SecurityPreHandlers', function () { options = { method: 'GET', url: `/api/organizations/${organizationId}/memberships`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; await databaseBuilder.commit(); @@ -363,7 +363,7 @@ describe('Acceptance | Application | SecurityPreHandlers', function () { certificationCenterId = databaseBuilder.factory.buildCertificationCenter().id; databaseBuilder.factory.options = { - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), method: 'GET', url: `/api/organizations/${certificationCenterId}/invitations`, }; @@ -386,7 +386,7 @@ describe('Acceptance | Application | SecurityPreHandlers', function () { options = { method: 'GET', url: `/test_route/certification-centers/admin/${certificationCenterId}`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; }); @@ -446,7 +446,7 @@ describe('Acceptance | Application | SecurityPreHandlers', function () { const options = { method: 'GET', url: `/test_route_user_is_member_of_one_organization`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; const response = await server.inject(options); @@ -469,7 +469,7 @@ describe('Acceptance | Application | SecurityPreHandlers', function () { const options = { method: 'GET', url: `/test_route_user_is_member_of_one_organization`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; const response = await server.inject(options); @@ -491,7 +491,7 @@ describe('Acceptance | Application | SecurityPreHandlers', function () { const options = { method: 'GET', url: `/test_route_user_is_member_of_one_organization`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; const response = await server.inject(options); @@ -515,7 +515,7 @@ describe('Acceptance | Application | SecurityPreHandlers', function () { await databaseBuilder.commit(); const options = { - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), method: 'POST', url: '/api/memberships/me/disable', payload: { organizationId }, @@ -542,7 +542,7 @@ describe('Acceptance | Application | SecurityPreHandlers', function () { await databaseBuilder.commit(); const options = { - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), method: 'GET', url: `/api/organizations/${organizationId}/place-statistics`, }; diff --git a/api/tests/team/acceptance/application/admin-member/admin-member.route.test.js b/api/tests/team/acceptance/application/admin-member/admin-member.route.test.js index c4c4a8d8ba1..864bc5c1d6a 100644 --- a/api/tests/team/acceptance/application/admin-member/admin-member.route.test.js +++ b/api/tests/team/acceptance/application/admin-member/admin-member.route.test.js @@ -3,7 +3,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, insertUserWithRoleSuperAdmin, } from '../../../../test-helper.js'; @@ -20,9 +20,7 @@ describe('Acceptance | Team | Route | Admin-member', function () { // when const response = await server.inject({ - headers: { - authorization: generateValidRequestAuthorizationHeader(admin.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: admin.id }), method: 'GET', url: '/api/admin/admin-members/me', }); @@ -40,9 +38,7 @@ describe('Acceptance | Team | Route | Admin-member', function () { // when const response = await server.inject({ - headers: { - authorization: generateValidRequestAuthorizationHeader(user.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), method: 'GET', url: '/api/admin/admin-members/me', }); @@ -71,9 +67,7 @@ describe('Acceptance | Team | Route | Admin-member', function () { // when const response = await server.inject({ - headers: { - authorization: generateValidRequestAuthorizationHeader(admin.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: admin.id }), method: 'GET', url: `/api/admin/admin-members`, }); @@ -105,9 +99,7 @@ describe('Acceptance | Team | Route | Admin-member', function () { // when const { statusCode, result } = await server.inject({ - headers: { - authorization: generateValidRequestAuthorizationHeader(adminMemberWithRoleSuperAdmin.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: adminMemberWithRoleSuperAdmin.id }), method: 'POST', url: '/api/admin/admin-members', payload: { @@ -143,9 +135,7 @@ describe('Acceptance | Team | Route | Admin-member', function () { // when const response = await server.inject({ - headers: { - authorization: generateValidRequestAuthorizationHeader(superAdmin.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: superAdmin.id }), method: 'PATCH', url: `/api/admin/admin-members/${pixAdminRole.id}`, payload: { @@ -177,9 +167,7 @@ describe('Acceptance | Team | Route | Admin-member', function () { // when const response = await server.inject({ - headers: { - authorization: generateValidRequestAuthorizationHeader(superAdmin.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: superAdmin.id }), method: 'PUT', url: `/api/admin/admin-members/${adminMemberToDeactivate.id}/deactivate`, }); diff --git a/api/tests/team/acceptance/application/certification-center-invitation/certification-center-invitation.admin.route.test.js b/api/tests/team/acceptance/application/certification-center-invitation/certification-center-invitation.admin.route.test.js index 656f542159d..45fd3085053 100644 --- a/api/tests/team/acceptance/application/certification-center-invitation/certification-center-invitation.admin.route.test.js +++ b/api/tests/team/acceptance/application/certification-center-invitation/certification-center-invitation.admin.route.test.js @@ -3,7 +3,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, insertUserWithRoleSuperAdmin, sinon, } from '../../../../test-helper.js'; @@ -45,7 +45,7 @@ describe('Acceptance | Team | Application | Route | Admin | Certification Center const response = await server.inject({ method: 'GET', url: `/api/admin/certification-centers/${certificationCenterId}/invitations`, - headers: { authorization: generateValidRequestAuthorizationHeader(adminUser.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: adminUser.id }), }); // then @@ -97,9 +97,7 @@ describe('Acceptance | Team | Application | Route | Admin | Certification Center // when const { result, statusCode } = await server.inject({ - headers: { - authorization: generateValidRequestAuthorizationHeader(adminMember.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: adminMember.id }), method: 'POST', payload: { data: { @@ -140,9 +138,7 @@ describe('Acceptance | Team | Application | Route | Admin | Certification Center const response = await server.inject({ method: 'DELETE', url: `/api/admin/certification-center-invitations/${certificationCenterInvitation.id}`, - headers: { - authorization: generateValidRequestAuthorizationHeader(adminMember.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: adminMember.id }), }); // then diff --git a/api/tests/team/acceptance/application/certification-center-invitation/certification-center-invitation.route.test.js b/api/tests/team/acceptance/application/certification-center-invitation/certification-center-invitation.route.test.js index 19ce69cce5e..eebe1f49374 100644 --- a/api/tests/team/acceptance/application/certification-center-invitation/certification-center-invitation.route.test.js +++ b/api/tests/team/acceptance/application/certification-center-invitation/certification-center-invitation.route.test.js @@ -3,7 +3,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, knex, } from '../../../../test-helper.js'; @@ -34,9 +34,7 @@ describe('Acceptance | Team | Application | Route | Certification Center Invitat await databaseBuilder.commit(); request = { - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), method: 'POST', url: `/api/certification-centers/${certificationCenterId}/invitations`, payload: {}, @@ -58,9 +56,7 @@ describe('Acceptance | Team | Application | Route | Certification Center Invitat await databaseBuilder.commit(); request = { - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), method: 'POST', url: `/api/certification-centers/${certificationCenterId}/invitations`, payload: { @@ -107,9 +103,7 @@ describe('Acceptance | Team | Application | Route | Certification Center Invitat await databaseBuilder.commit(); request = { - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), method: 'GET', url: `/api/certification-centers/${certificationCenterId}/invitations`, payload: { certificationCenterId }, @@ -134,9 +128,7 @@ describe('Acceptance | Team | Application | Route | Certification Center Invitat await databaseBuilder.commit(); request = { - headers: { - authorization: generateValidRequestAuthorizationHeader(userId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), method: 'GET', url: `/api/certification-centers/${certificationCenterId}/invitations`, payload: { certificationCenterId }, @@ -250,9 +242,7 @@ describe('Acceptance | Team | Application | Route | Certification Center Invitat await databaseBuilder.commit(); request = { - headers: { - authorization: generateValidRequestAuthorizationHeader(user.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), method: 'DELETE', url: `/api/certification-center-invitations/${certificationCenterInvitation.id}`, }; diff --git a/api/tests/team/acceptance/application/certification-center-membership/certification-center-membership.admin.route.test.js b/api/tests/team/acceptance/application/certification-center-membership/certification-center-membership.admin.route.test.js index 7777f989909..430c87ca7f6 100644 --- a/api/tests/team/acceptance/application/certification-center-membership/certification-center-membership.admin.route.test.js +++ b/api/tests/team/acceptance/application/certification-center-membership/certification-center-membership.admin.route.test.js @@ -4,7 +4,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, } from '../../../../test-helper.js'; describe('Acceptance | Team | Application | Admin | Routes | certification-center-membership', function () { @@ -45,9 +45,7 @@ describe('Acceptance | Team | Application | Admin | Routes | certification-cente }, }, }, - headers: { - authorization: generateValidRequestAuthorizationHeader(pixAgentWithAdminRole.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: pixAgentWithAdminRole.id }), }; await databaseBuilder.commit(); @@ -101,9 +99,7 @@ describe('Acceptance | Team | Application | Admin | Routes | certification-cente }, }, }, - headers: { - authorization: generateValidRequestAuthorizationHeader(pixAgentWithCertifRole.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: pixAgentWithCertifRole.id }), }; await databaseBuilder.commit(); @@ -160,9 +156,7 @@ describe('Acceptance | Team | Application | Admin | Routes | certification-cente }, }, }, - headers: { - authorization: generateValidRequestAuthorizationHeader(pixAgentWithSupportRole.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: pixAgentWithSupportRole.id }), }; await databaseBuilder.commit(); diff --git a/api/tests/team/acceptance/application/certification-center-membership/certification-center-membership.route.test.js b/api/tests/team/acceptance/application/certification-center-membership/certification-center-membership.route.test.js index c5a83e5b1a7..e517c5376ec 100644 --- a/api/tests/team/acceptance/application/certification-center-membership/certification-center-membership.route.test.js +++ b/api/tests/team/acceptance/application/certification-center-membership/certification-center-membership.route.test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, } from '../../../../test-helper.js'; describe('Acceptance | Team | Application | Routes | certification-center-membership ', function () { @@ -26,9 +26,7 @@ describe('Acceptance | Team | Application | Routes | certification-center-member await databaseBuilder.commit(); options = { - headers: { - authorization: generateValidRequestAuthorizationHeader(certificationCenterMember.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: certificationCenterMember.id }), method: 'GET', url: `/api/certification-centers/${certificationCenter.id}/members`, }; diff --git a/api/tests/team/acceptance/application/membership/membership.admin.route.test.js b/api/tests/team/acceptance/application/membership/membership.admin.route.test.js index 639a66053e1..d1f9a4233b9 100644 --- a/api/tests/team/acceptance/application/membership/membership.admin.route.test.js +++ b/api/tests/team/acceptance/application/membership/membership.admin.route.test.js @@ -5,7 +5,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, } from '../../../../test-helper.js'; describe('Acceptance | Team | Admin | Route | membership', function () { @@ -49,9 +49,7 @@ describe('Acceptance | Team | Admin | Route | membership', function () { }, }, }, - headers: { - authorization: generateValidRequestAuthorizationHeader(adminUserId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: adminUserId }), }; }); @@ -159,9 +157,7 @@ describe('Acceptance | Team | Admin | Route | membership', function () { }, }, }, - headers: { - authorization: generateValidRequestAuthorizationHeader(adminUserId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: adminUserId }), }; }); @@ -212,7 +208,7 @@ describe('Acceptance | Team | Admin | Route | membership', function () { }); await databaseBuilder.commit(); - options.headers.authorization = generateValidRequestAuthorizationHeader(notAdminUserId); + options.headers = generateAuthenticatedUserRequestHeaders({ userId: notAdminUserId }); // when const response = await server.inject(options); @@ -253,7 +249,7 @@ describe('Acceptance | Team | Admin | Route | membership', function () { const response = await server.inject({ method: 'GET', url: `/api/admin/organizations/${organization.id}/memberships?filter[email]=&filter[firstName]=&filter[lastName]=&filter[organizationRole]=`, - headers: { authorization: generateValidRequestAuthorizationHeader(userSuperAdmin.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: userSuperAdmin.id }), }); // then diff --git a/api/tests/team/acceptance/application/membership/membership.route.test.js b/api/tests/team/acceptance/application/membership/membership.route.test.js index 261a78dd9ac..87dd47a0f93 100644 --- a/api/tests/team/acceptance/application/membership/membership.route.test.js +++ b/api/tests/team/acceptance/application/membership/membership.route.test.js @@ -5,7 +5,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, } from '../../../../test-helper.js'; describe('Acceptance | Team | Application | Route | membership', function () { @@ -69,9 +69,7 @@ describe('Acceptance | Team | Application | Route | membership', function () { }, }, }, - headers: { - authorization: generateValidRequestAuthorizationHeader(adminUserId), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: adminUserId }), }; }); @@ -122,7 +120,7 @@ describe('Acceptance | Team | Application | Route | membership', function () { }); await databaseBuilder.commit(); - options.headers.authorization = generateValidRequestAuthorizationHeader(notAdminUserId); + options.headers = generateAuthenticatedUserRequestHeaders({ userId: notAdminUserId }); // when const response = await server.inject(options); @@ -170,7 +168,7 @@ describe('Acceptance | Team | Application | Route | membership', function () { const response = await server.inject({ method: 'GET', url: `/api/organizations/${organizationId}/memberships/?filter[email]=&filter[firstName]=&filter[lastName]=&filter[organizationRole]=`, - headers: { authorization: generateValidRequestAuthorizationHeader(adminOfTheOrganization.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: adminOfTheOrganization.id }), }); // then @@ -272,7 +270,7 @@ describe('Acceptance | Team | Application | Route | membership', function () { const response = await server.inject({ method: 'GET', url: `/api/organizations/${organizationId}/memberships`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }); // then diff --git a/api/tests/team/acceptance/application/organization-invitations/organization-invitation.admin.route.test.js b/api/tests/team/acceptance/application/organization-invitations/organization-invitation.admin.route.test.js index d2c7d4bfc80..4752b59c85a 100644 --- a/api/tests/team/acceptance/application/organization-invitations/organization-invitation.admin.route.test.js +++ b/api/tests/team/acceptance/application/organization-invitations/organization-invitation.admin.route.test.js @@ -4,7 +4,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, insertOrganizationUserWithRoleAdmin, insertUserWithRoleSuperAdmin, } from '../../../../../tests/test-helper.js'; @@ -27,7 +27,7 @@ describe('Acceptance | Team | Route | Admin | organization-invitation', function const response = await server.inject({ method: 'GET', url: `/api/admin/organizations/${organizationId}/invitations`, - headers: { authorization: generateValidRequestAuthorizationHeader(adminMember.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: adminMember.id }), }); // then @@ -64,7 +64,7 @@ describe('Acceptance | Team | Route | Admin | organization-invitation', function const response = await server.inject({ method: 'GET', url: `/api/admin/organizations/${organizationId}/invitations`, - headers: { authorization: generateValidRequestAuthorizationHeader(nonSuperAdminUserId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: nonSuperAdminUserId }), }); // then @@ -88,9 +88,7 @@ describe('Acceptance | Team | Route | Admin | organization-invitation', function const options = { method: 'DELETE', url: `/api/admin/organizations/${organization.id}/invitations/${invitation.id}`, - headers: { - authorization: generateValidRequestAuthorizationHeader(adminMember.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: adminMember.id }), }; await databaseBuilder.commit(); @@ -126,9 +124,7 @@ describe('Acceptance | Team | Route | Admin | organization-invitation', function method: 'POST', url: `/api/admin/organizations/${organization.id}/invitations`, payload, - headers: { - authorization: generateValidRequestAuthorizationHeader(superAdmin.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: superAdmin.id }), }; await databaseBuilder.commit(); diff --git a/api/tests/team/acceptance/application/organization-invitations/organization-invitation.route.test.js b/api/tests/team/acceptance/application/organization-invitations/organization-invitation.route.test.js index b48f37b4bb0..b7b16eead39 100644 --- a/api/tests/team/acceptance/application/organization-invitations/organization-invitation.route.test.js +++ b/api/tests/team/acceptance/application/organization-invitations/organization-invitation.route.test.js @@ -6,7 +6,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, insertOrganizationUserWithRoleAdmin, } from '../../../../../tests/test-helper.js'; @@ -326,7 +326,7 @@ describe('Acceptance | Team | Application | Controller | organization-invitation options = { method: 'GET', url: `/api/organizations/${organizationId}/invitations`, - headers: { authorization: generateValidRequestAuthorizationHeader(adminUserId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: adminUserId }), }; await databaseBuilder.commit(); @@ -392,7 +392,7 @@ describe('Acceptance | Team | Application | Controller | organization-invitation // given const nonSuperAdminUserId = databaseBuilder.factory.buildUser().id; await databaseBuilder.commit(); - options.headers.authorization = generateValidRequestAuthorizationHeader(nonSuperAdminUserId); + options.headers = generateAuthenticatedUserRequestHeaders({ userId: nonSuperAdminUserId }); // when const response = await server.inject(options); @@ -424,7 +424,7 @@ describe('Acceptance | Team | Application | Controller | organization-invitation options = { method: 'POST', url: `/api/organizations/${organization.id}/invitations`, - headers: { authorization: generateValidRequestAuthorizationHeader(adminUserId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: adminUserId }), payload: { data: { type: 'organization-invitations', @@ -494,7 +494,7 @@ describe('Acceptance | Team | Application | Controller | organization-invitation // given const nonAdminUserId = databaseBuilder.factory.buildUser().id; await databaseBuilder.commit(); - options.headers.authorization = generateValidRequestAuthorizationHeader(nonAdminUserId); + options.headers = generateAuthenticatedUserRequestHeaders({ userId: nonAdminUserId }); // when const response = await server.inject(options); @@ -527,9 +527,7 @@ describe('Acceptance | Team | Application | Controller | organization-invitation const options = { method: 'DELETE', url: `/api/organizations/${organization.id}/invitations/${invitation.id}`, - headers: { - authorization: generateValidRequestAuthorizationHeader(adminUser.id), - }, + headers: generateAuthenticatedUserRequestHeaders({ userId: adminUser.id }), }; await databaseBuilder.commit(); diff --git a/api/tests/team/acceptance/application/prescriber-informations.controller.test.js b/api/tests/team/acceptance/application/prescriber-informations.controller.test.js index 40dfe70fe0e..6b89af0c194 100644 --- a/api/tests/team/acceptance/application/prescriber-informations.controller.test.js +++ b/api/tests/team/acceptance/application/prescriber-informations.controller.test.js @@ -5,7 +5,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, } from '../../../test-helper.js'; describe('Acceptance | Team | Application | Controller | prescriber-informations', function () { @@ -147,7 +147,7 @@ describe('Acceptance | Team | Application | Controller | prescriber-informations options = { method: 'GET', url: `/api/prescription/prescribers/${user.id}`, - headers: { authorization: generateValidRequestAuthorizationHeader(user.id) }, + headers: generateAuthenticatedUserRequestHeaders({ userId: user.id }), }; }); @@ -166,7 +166,7 @@ describe('Acceptance | Team | Application | Controller | prescriber-informations it('should respond with a 403 - forbidden access - if requested user is not the same as authenticated user', async function () { // given const otherUserId = 9999; - options.headers.authorization = generateValidRequestAuthorizationHeader(otherUserId); + options.headers = generateAuthenticatedUserRequestHeaders({ userId: otherUserId }); // when const response = await server.inject(options); diff --git a/api/tests/team/acceptance/application/user-orga-settings.controller.test.js b/api/tests/team/acceptance/application/user-orga-settings.controller.test.js index 929d3b574fd..127bf00cb5f 100644 --- a/api/tests/team/acceptance/application/user-orga-settings.controller.test.js +++ b/api/tests/team/acceptance/application/user-orga-settings.controller.test.js @@ -2,7 +2,7 @@ import { createServer, databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, } from '../../../test-helper.js'; describe('Acceptance | Controller | user-orga-settings-controller', function () { @@ -71,7 +71,7 @@ describe('Acceptance | Controller | user-orga-settings-controller', function () context('When user is authenticated', function () { beforeEach(async function () { - options.headers = { authorization: generateValidRequestAuthorizationHeader(userId) }; + options.headers = generateAuthenticatedUserRequestHeaders({ userId }); }); it('should update and return 200 HTTP status code', async function () { From 8ceb2d18879fb44ae382e6bf0f7b181e5aad1778 Mon Sep 17 00:00:00 2001 From: P-Jeremy Date: Wed, 29 Jan 2025 14:19:12 +0100 Subject: [PATCH 7/9] test(api): use use new generateAuthenticatedUserRequestHeaders helper in Certification prehandlers tests --- .../application/pre-handlers/authorization_test.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/api/tests/certification/session-management/integration/application/pre-handlers/authorization_test.js b/api/tests/certification/session-management/integration/application/pre-handlers/authorization_test.js index 9fe999b3a4a..4ea6b9452d1 100644 --- a/api/tests/certification/session-management/integration/application/pre-handlers/authorization_test.js +++ b/api/tests/certification/session-management/integration/application/pre-handlers/authorization_test.js @@ -2,7 +2,7 @@ import { authorization } from '../../../../../../src/certification/session-manag import { databaseBuilder, expect, - generateValidRequestAuthorizationHeader, + generateAuthenticatedUserRequestHeaders, HttpTestServer, } from '../../../../../test-helper.js'; @@ -54,7 +54,7 @@ describe('Certification | Session-Management | Integration | Application | Pre-H const options = { method: 'GET', url: `/api/test/sessions/${sessionId}/supervisor-kit`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when @@ -81,7 +81,7 @@ describe('Certification | Session-Management | Integration | Application | Pre-H const options = { method: 'GET', url: `/api/test/sessions/${sessionId}/supervisor-kit`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when @@ -136,7 +136,7 @@ describe('Certification | Session-Management | Integration | Application | Pre-H const options = { method: 'GET', url: `/api/test/sessions/${sessionId}/supervisor-kit`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when @@ -160,7 +160,7 @@ describe('Certification | Session-Management | Integration | Application | Pre-H const options = { method: 'GET', url: `/api/test/sessions/${sessionId}/supervisor-kit`, - headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, + headers: generateAuthenticatedUserRequestHeaders({ userId }), }; // when From 53b41987c56c0d703fbff20f1003940115bb6f35 Mon Sep 17 00:00:00 2001 From: LEGO Technix <109212476+lego-technix@users.noreply.github.com> Date: Sun, 26 Jan 2025 11:20:35 +0100 Subject: [PATCH 8/9] test(api): remove now useless unused generateValidRequestAuthorizationHeader helper --- api/tests/test-helper.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/api/tests/test-helper.js b/api/tests/test-helper.js index e5165c7b566..7f58a1be7cb 100644 --- a/api/tests/test-helper.js +++ b/api/tests/test-helper.js @@ -134,11 +134,6 @@ function generateAuthenticatedUserRequestHeaders({ }; } -function generateValidRequestAuthorizationHeader(userId = 1234, source = 'pix', audience = 'http://app.pix.org') { - const accessToken = tokenService.createAccessTokenFromUser({ userId, source, audience }).accessToken; - return `Bearer ${accessToken}`; -} - function generateValidRequestAuthorizationHeaderForApplication(clientId = 'client-id-name', source, scope) { const application = _.find(apimRegisterApplicationsCredentials, { clientId }); if (application) { @@ -349,7 +344,6 @@ export { expect, generateAuthenticatedUserRequestHeaders, generateIdTokenForExternalUser, - generateValidRequestAuthorizationHeader, generateValidRequestAuthorizationHeaderForApplication, hFake, HttpTestServer, From ad449de4618564094db1b07f2188da4f4dcbf6e1 Mon Sep 17 00:00:00 2001 From: LEGO Technix <109212476+lego-technix@users.noreply.github.com> Date: Thu, 23 Jan 2025 14:24:48 +0100 Subject: [PATCH 9/9] test(api): enable isUserTokenAudConfinementEnabled for tests in config --- api/src/shared/config.js | 2 +- .../feature-toggles/feature-toggle-controller_test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/api/src/shared/config.js b/api/src/shared/config.js index 047208ff7b9..8f09553de0e 100644 --- a/api/src/shared/config.js +++ b/api/src/shared/config.js @@ -497,7 +497,7 @@ const configuration = (function () { config.featureToggles.isSelfAccountDeletionEnabled = false; config.featureToggles.isQuestEnabled = false; config.featureToggles.isAsyncQuestRewardingCalculationEnabled = false; - config.featureToggles.isUserTokenAudConfinementEnabled = false; + config.featureToggles.isUserTokenAudConfinementEnabled = true; config.featureToggles.isTextToSpeechButtonEnabled = false; config.featureToggles.isLegalDocumentsVersioningEnabled = false; config.featureToggles.showNewResultPage = false; diff --git a/api/tests/shared/acceptance/application/feature-toggles/feature-toggle-controller_test.js b/api/tests/shared/acceptance/application/feature-toggles/feature-toggle-controller_test.js index f931159f8fd..777b24dea2f 100644 --- a/api/tests/shared/acceptance/application/feature-toggles/feature-toggle-controller_test.js +++ b/api/tests/shared/acceptance/application/feature-toggles/feature-toggle-controller_test.js @@ -30,7 +30,7 @@ describe('Acceptance | Shared | Application | Controller | feature-toggle', func 'is-pix1d-enabled': true, 'is-pix-companion-enabled': false, 'is-quest-enabled': false, - 'is-user-token-aud-confinement-enabled': false, + 'is-user-token-aud-confinement-enabled': true, 'is-self-account-deletion-enabled': false, 'is-text-to-speech-button-enabled': false, 'is-legal-documents-versioning-enabled': false,