Skip to content

Commit

Permalink
feat(api): Add isVisible to usecase
Browse files Browse the repository at this point in the history
  • Loading branch information
theotime2005 committed Feb 5, 2025
1 parent 453638c commit 69114ed
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* @param {boolean} params.shouldCloseSession
* @param {string} params.slug
* @param {string} params.source
* @param {boolean} params.isVisible
* @param {OidcProviderRepository} params.oidcProviderRepository
* @param {CryptoService} params.cryptoService
* @returns {Promise<void>}
Expand All @@ -47,6 +48,7 @@ const addOidcProvider = async function ({
shouldCloseSession,
slug,
source,
isVisible = true,
oidcProviderRepository,
cryptoService,
addOidcProviderValidator,
Expand All @@ -71,6 +73,7 @@ const addOidcProvider = async function ({
shouldCloseSession,
slug,
source,
isVisible,
});

const encryptedClientSecret = await cryptoService.encrypt(clientSecret);
Expand All @@ -95,6 +98,7 @@ const addOidcProvider = async function ({
shouldCloseSession,
slug,
source,
isVisible,
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const schema = Joi.object({
shouldCloseSession: Joi.boolean().optional().default(false),
slug: Joi.string().required(),
source: Joi.string().optional(),
isVisible: Joi.boolean().optional().default(true),
});

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ describe('Unit | Identity Access Management | Domain | UseCases | add-oidc-provi
shouldCloseSession: true,
slug: 'oidc-example-net',
source: 'oidcexamplenet',
isVisible: true,
};

// when
Expand Down Expand Up @@ -77,6 +78,90 @@ describe('Unit | Identity Access Management | Domain | UseCases | add-oidc-provi
shouldCloseSession: true,
slug: 'oidc-example-net',
source: 'oidcexamplenet',
isVisible: true,
});
expect(cryptoService.encrypt).to.have.been.calledWithExactly('secret');
expect(oidcProviderRepository.create).to.have.been.calledWithExactly(expectedOidcProviderProperties);
});

it('creates an OIDC Provider in the oidc-provider-repository and visibility to false', async function () {
// given
const oidcProviderRepository = {
create: sinon.stub(),
};
const cryptoService = {
encrypt: sinon.stub().resolves('#%@!!!!!!!!!!!!!'),
};
const addOidcProviderValidator = {
validate: sinon.stub(),
};
const oidcProviderProperties = {
accessTokenLifespan: '7d',
clientId: 'client',
clientSecret: 'secret',
shouldCloseSession: true,
identityProvider: 'OIDC_EXAMPLE_NET',
openidConfigurationUrl: 'https://oidc.example.net/.well-known/openid-configuration',
organizationName: 'OIDC Example',
redirectUri: 'https://app.dev.pix.org/connexion/oidc-example-net',
scope: 'openid profile',
slug: 'oidc-example-net',
source: 'oidcexamplenet',
isVisible: false,
};
const expectedOidcProviderProperties = {
accessTokenLifespan: '7d',
additionalRequiredProperties: undefined,
claimMapping: undefined,
claimsToStore: undefined,
clientId: 'client',
enabled: undefined,
enabledForPixAdmin: undefined,
encryptedClientSecret: '#%@!!!!!!!!!!!!!',
extraAuthorizationUrlParameters: undefined,
identityProvider: 'OIDC_EXAMPLE_NET',
openidClientExtraMetadata: undefined,
openidConfigurationUrl: 'https://oidc.example.net/.well-known/openid-configuration',
organizationName: 'OIDC Example',
postLogoutRedirectUri: undefined,
redirectUri: 'https://app.dev.pix.org/connexion/oidc-example-net',
scope: 'openid profile',
shouldCloseSession: true,
slug: 'oidc-example-net',
source: 'oidcexamplenet',
isVisible: false,
};

// when
await addOidcProvider({
...oidcProviderProperties,
oidcProviderRepository,
cryptoService,
addOidcProviderValidator,
});

// then
expect(addOidcProviderValidator.validate).to.have.been.calledWith({
accessTokenLifespan: '7d',
additionalRequiredProperties: undefined,
claimMapping: undefined,
claimsToStore: undefined,
clientId: 'client',
clientSecret: 'secret',
enabled: undefined,
enabledForPixAdmin: undefined,
extraAuthorizationUrlParameters: undefined,
identityProvider: 'OIDC_EXAMPLE_NET',
openidClientExtraMetadata: undefined,
openidConfigurationUrl: 'https://oidc.example.net/.well-known/openid-configuration',
organizationName: 'OIDC Example',
postLogoutRedirectUri: undefined,
redirectUri: 'https://app.dev.pix.org/connexion/oidc-example-net',
scope: 'openid profile',
shouldCloseSession: true,
slug: 'oidc-example-net',
source: 'oidcexamplenet',
isVisible: false,
});
expect(cryptoService.encrypt).to.have.been.calledWithExactly('secret');
expect(oidcProviderRepository.create).to.have.been.calledWithExactly(expectedOidcProviderProperties);
Expand Down

0 comments on commit 69114ed

Please sign in to comment.