diff --git a/api/tests/identity-access-management/integration/domain/services/oidc-authentication-service-registry.test.js b/api/tests/identity-access-management/integration/domain/services/oidc-authentication-service-registry.test.js index 5ac5ec8cb6b..f26d16aa02f 100644 --- a/api/tests/identity-access-management/integration/domain/services/oidc-authentication-service-registry.test.js +++ b/api/tests/identity-access-management/integration/domain/services/oidc-authentication-service-registry.test.js @@ -11,7 +11,7 @@ import { catchErrSync, databaseBuilder, expect, sinon } from '../../../../test-h describe('Integration | Identity Access Management | Domain | Service | oidc-authentication-service-registry', function () { let oidcAuthenticationServiceRegistry; - beforeEach(async function () { + before(async function () { const genericOidcProviderProperties = { enabled: true, accessTokenLifespan: '7d', @@ -154,87 +154,53 @@ describe('Integration | Identity Access Management | Domain | Service | oidc-aut }); }); - // describe('#getOidcProviderServiceByCode', function () { - // describe('when the audience is admin', function () { - // it('returns a ready OIDC provider for Pix Admin', async function () { - // // given - // const oidcProviderForPixApp = { - // code: 'PROVIDER_FOR_APP', - // isReady: true, - // }; - // const oidcProviderForPixAdmin = { - // code: 'PROVIDER_FOR_ADMIN', - // isReadyForPixAdmin: true, - // }; - - // await oidcAuthenticationServiceRegistry.loadOidcProviderServices([ - // oidcProviderForPixApp, - // oidcProviderForPixAdmin, - // ]); + describe('#getOidcProviderServiceByCode', function () { + it('returns a ready OIDC Provider for Pix App', async function () { + // given + await oidcAuthenticationServiceRegistry.loadOidcProviderServices(); - // // when - // const service = oidcAuthenticationServiceRegistry.getOidcProviderServiceByCode({ - // identityProviderCode: 'PROVIDER_FOR_ADMIN', - // audience: PIX_ADMIN.AUDIENCE, - // }); + // when + const service = oidcAuthenticationServiceRegistry.getOidcProviderServiceByCode({ + identityProviderCode: 'OIDC_EXAMPLE', + }); - // // then - // expect(service.code).to.equal('PROVIDER_FOR_ADMIN'); - // }); - // }); + // then + expect(service.code).to.equal('OIDC_EXAMPLE'); + }); - // describe('when audience is not provided', function () { - // it('returns a ready OIDC Provider for Pix App', async function () { - // // given - // const identityProviderCode = 'FIRST'; - // const firstOidcProviderService = { - // code: identityProviderCode, - // isReady: true, - // }; - // const secondOidcProviderService = { - // code: 'SECOND', - // }; - - // await oidcAuthenticationServiceRegistry.loadOidcProviderServices([ - // firstOidcProviderService, - // secondOidcProviderService, - // ]); + describe('when the audience is admin', function () { + it('returns a ready OIDC provider for Pix Admin', async function () { + // given + await oidcAuthenticationServiceRegistry.loadOidcProviderServices(); - // // when - // const service = oidcAuthenticationServiceRegistry.getOidcProviderServiceByCode({ identityProviderCode }); + // when + const service = oidcAuthenticationServiceRegistry.getOidcProviderServiceByCode({ + identityProviderCode: 'OIDC_EXAMPLE_FOR_PIX_ADMIN', + audience: PIX_ADMIN.AUDIENCE, + }); - // // then - // expect(service.code).to.equal('FIRST'); - // }); - // }); + // then + expect(service.code).to.equal('OIDC_EXAMPLE_FOR_PIX_ADMIN'); + }); + }); - // it('throws an error when identity provider is not supported', async function () { - // // given - // const identityProviderCode = 'UNSUPPORTED_OIDC_PROVIDER'; - // const firstOidcProviderService = { - // code: 'FIRST', - // isReady: true, - // }; - // const secondOidcProviderService = { - // code: 'SECOND', - // }; - - // await oidcAuthenticationServiceRegistry.loadOidcProviderServices([ - // firstOidcProviderService, - // secondOidcProviderService, - // ]); - - // // when - // const error = catchErrSync( - // oidcAuthenticationServiceRegistry.getOidcProviderServiceByCode, - // oidcAuthenticationServiceRegistry, - // )({ identityProviderCode }); - - // // then - // expect(error).to.be.an.instanceOf(InvalidIdentityProviderError); - // expect(error.message).to.equal(`Identity provider ${identityProviderCode} is not supported.`); - // }); - // }); + describe('when identity provider is not supported', function () { + it('throws an error ', async function () { + // given + await oidcAuthenticationServiceRegistry.loadOidcProviderServices(); + + // when + const error = catchErrSync( + oidcAuthenticationServiceRegistry.getOidcProviderServiceByCode, + oidcAuthenticationServiceRegistry, + )({ identityProviderCode: 'OIDC_EXAMPLE_UNSUPPORTED' }); + + // then + expect(error).to.be.an.instanceOf(InvalidIdentityProviderError); + expect(error.message).to.equal(`Identity provider OIDC_EXAMPLE_UNSUPPORTED is not supported.`); + }); + }); + }); // describe('#loadOidcProviderServices', function () { // describe('when oidc provider services are already loaded', function () { @@ -320,60 +286,4 @@ describe('Integration | Identity Access Management | Domain | Service | oidc-aut // }); // }); // }); - - // describe('#configureReadyOidcProviderServiceByCode', function () { - // context('when oidc provider service does not exist', function () { - // it('returns undefined', async function () { - // // when - // const result = await oidcAuthenticationServiceRegistry.configureReadyOidcProviderServiceByCode('OIDC'); - - // // then - // expect(result).to.be.undefined; - // }); - // }); - - // context('when oidc provider service exists and loaded', function () { - // it('configures openid client for ready oidc provider service and returns true', async function () { - // // given - // const createClient = sinon.stub().resolves(); - // const oidcProviderServices = [ - // { - // code: 'OIDC', - // isReady: true, - // createClient, - // }, - // ]; - // await oidcAuthenticationServiceRegistry.loadOidcProviderServices(oidcProviderServices); - - // // when - // const result = await oidcAuthenticationServiceRegistry.configureReadyOidcProviderServiceByCode( - // oidcProviderServices[0].code, - // ); - - // // then - // expect(result).to.be.true; - // expect(createClient).to.have.been.calledOnce; - // }); - - // context('when there is already a client instantiated', function () { - // it('returns undefined', async function () { - // // given - // const oidcProviderServices = [ - // { - // code: 'OIDC', - // isReady: true, - // client: {}, - // }, - // ]; - // await oidcAuthenticationServiceRegistry.loadOidcProviderServices(oidcProviderServices); - - // // when - // const result = await oidcAuthenticationServiceRegistry.configureReadyOidcProviderServiceByCode('OIDC'); - - // // then - // expect(result).to.be.undefined; - // }); - // }); - // }); - // }); }); diff --git a/api/tests/identity-access-management/unit/domain/services/oidc-authentication-service-registry_test.js b/api/tests/identity-access-management/unit/domain/services/oidc-authentication-service-registry_test.js index 9dc2d336693..32d4f2ddbb1 100644 --- a/api/tests/identity-access-management/unit/domain/services/oidc-authentication-service-registry_test.js +++ b/api/tests/identity-access-management/unit/domain/services/oidc-authentication-service-registry_test.js @@ -15,166 +15,6 @@ describe('Unit | Identity Access Management | Domain | Services | oidc-authentic oidcAuthenticationServiceRegistry = new OidcAuthenticationServiceRegistry(); }); - describe('#getAllOidcProviderServices', function () { - it('returns all OIDC Providers', async function () { - // given - const firstOidcProviderService = { - code: 'FIRST', - }; - const secondOidcProviderService = { - code: 'SECOND', - }; - - await oidcAuthenticationServiceRegistry.loadOidcProviderServices([ - firstOidcProviderService, - secondOidcProviderService, - ]); - - // when - const services = oidcAuthenticationServiceRegistry.getAllOidcProviderServices(); - - // then - const serviceCodes = services.map((service) => service.code); - expect(serviceCodes.length).to.equal(2); - expect(serviceCodes).to.contain('FIRST'); - expect(serviceCodes).to.contain('SECOND'); - }); - }); - - describe('#getReadyOidcProviderServices', function () { - it('returns ready OIDC Providers', async function () { - // given - const firstOidcProviderService = { - code: 'FIRST', - }; - const secondOidcProviderService = { - code: 'SECOND', - isReady: true, - }; - - await oidcAuthenticationServiceRegistry.loadOidcProviderServices([ - firstOidcProviderService, - secondOidcProviderService, - ]); - - // when - const services = oidcAuthenticationServiceRegistry.getReadyOidcProviderServices(); - - // then - const serviceCodes = services.map((service) => service.code); - expect(serviceCodes.length).to.equal(1); - expect(serviceCodes).to.contain('SECOND'); - }); - }); - - describe('#getReadyOidcProviderServicesForPixAdmin', function () { - it('returns ready OIDC Providers for Pix Admin', async function () { - // given - const firstOidcProviderService = { - code: 'FIRST', - isReadyForPixAdmin: true, - }; - const secondOidcProviderService = { - code: 'SECOND', - }; - - await oidcAuthenticationServiceRegistry.loadOidcProviderServices([ - firstOidcProviderService, - secondOidcProviderService, - ]); - - // when - const services = oidcAuthenticationServiceRegistry.getReadyOidcProviderServicesForPixAdmin(); - - // then - const serviceCodes = services.map((service) => service.code); - expect(serviceCodes.length).to.equal(1); - expect(serviceCodes).to.contain('FIRST'); - }); - }); - - describe('#getOidcProviderServiceByCode', function () { - describe('when the audience is admin', function () { - it('returns a ready OIDC provider for Pix Admin', async function () { - // given - const oidcProviderForPixApp = { - code: 'PROVIDER_FOR_APP', - isReady: true, - }; - const oidcProviderForPixAdmin = { - code: 'PROVIDER_FOR_ADMIN', - isReadyForPixAdmin: true, - }; - - await oidcAuthenticationServiceRegistry.loadOidcProviderServices([ - oidcProviderForPixApp, - oidcProviderForPixAdmin, - ]); - - // when - const service = oidcAuthenticationServiceRegistry.getOidcProviderServiceByCode({ - identityProviderCode: 'PROVIDER_FOR_ADMIN', - audience: PIX_ADMIN.AUDIENCE, - }); - - // then - expect(service.code).to.equal('PROVIDER_FOR_ADMIN'); - }); - }); - - describe('when audience is not provided', function () { - it('returns a ready OIDC Provider for Pix App', async function () { - // given - const identityProviderCode = 'FIRST'; - const firstOidcProviderService = { - code: identityProviderCode, - isReady: true, - }; - const secondOidcProviderService = { - code: 'SECOND', - }; - - await oidcAuthenticationServiceRegistry.loadOidcProviderServices([ - firstOidcProviderService, - secondOidcProviderService, - ]); - - // when - const service = oidcAuthenticationServiceRegistry.getOidcProviderServiceByCode({ identityProviderCode }); - - // then - expect(service.code).to.equal('FIRST'); - }); - }); - - it('throws an error when identity provider is not supported', async function () { - // given - const identityProviderCode = 'UNSUPPORTED_OIDC_PROVIDER'; - const firstOidcProviderService = { - code: 'FIRST', - isReady: true, - }; - const secondOidcProviderService = { - code: 'SECOND', - }; - - await oidcAuthenticationServiceRegistry.loadOidcProviderServices([ - firstOidcProviderService, - secondOidcProviderService, - ]); - - // when - const error = catchErrSync( - oidcAuthenticationServiceRegistry.getOidcProviderServiceByCode, - oidcAuthenticationServiceRegistry, - )({ identityProviderCode }); - - // then - expect(error).to.be.an.instanceOf(InvalidIdentityProviderError); - expect(error.message).to.equal(`Identity provider ${identityProviderCode} is not supported.`); - }); - }); - describe('#loadOidcProviderServices', function () { describe('when oidc provider services are already loaded', function () { it('returns undefined', async function () {