mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 17:33:03 -05:00
* feat(cognito): implement identity provider configuration CRUD CreateIdentityProvider, DescribeIdentityProvider, ListIdentityProviders, UpdateIdentityProvider and DeleteIdentityProvider were unsupported, so infrastructure tooling could not manage a user pool's federated providers. Stores provider configuration alongside the other user pool sub-resources and matches the response and update semantics measured against the live API: - IdpIdentifiers is echoed by create and update only when the request supplied the member, whatever the stored value; describe always returns it - AttributeMapping defaults to username -> sub when the member is absent at create, while an explicitly empty map is stored as given - members a request omits are preserved rather than cleared - a duplicate provider name raises DuplicateProviderException - ListIdentityProviders returns name/type/date summaries, never ProviderDetails Federated sign-in itself is out of scope: Floci has no /oauth2/authorize or /oauth2/idpresponse endpoint, so providers are stored configuration only. * test(cognito): match identity provider exceptions on the SDK error name `rejects.toThrow(/re/)` matches the error message, but the JS SDK maps the wire `__type` onto `error.name` and puts the AWS text in `message`, so the duplicate provider assertion never matched. Assert the name, and pin the enum text with an explicit message matcher. * fix(cognito): delete a pool's identity providers with the pool, and update a copy Two review findings, both reproduced first. DeleteUserPool left provider records behind. A pool recreated on a pinned id (`floci:override-id`) then inherited the dead pool's providers, ProviderDetails client_secret included. Pool deletion now removes them the way it already removes groups. UpdateIdentityProvider mutated the instance the store handed back, so two concurrent updates could interleave into a state matching neither request. It now writes a copy, which makes the losing update simply lose — what AWS does. * fix(cognito): serialise identity provider mutations UpdateIdentityProvider is a read-modify-write: it copies the stored provider, applies only the members the request supplied and writes the whole record back. Two overlapping updates copied the same base, so the later write restored the other's omitted members to their stale values and silently dropped an update. Live Cognito merges omitted members rather than clearing them, and applies that merge atomically, so both updates survive there. One lock now guards every mutating path, since create (check-then-put) and delete (check-then-act) carry the same race, matching the existing identityLinkLock idiom. The regression test runs two writers touching different optional members across 25 rounds; it fails on the first round with the lock reverted. * fix(cognito): guard the pool deletion provider cascade with the same lock DeleteUserPool clears a pool's identity providers outside identityProviderLock, so a create or update interleaving with the cascade could reinstate a provider for a pool that is going away. It now takes the same lock as the mutations it races, closing the last unguarded path in that set. * fix(cognito): recheck the pool under the lock when creating a provider CreateIdentityProvider validated the pool before taking identityProviderLock and never rechecked it, so a DeleteUserPool whose cascade ran in between left the create writing a provider for a pool that no longer exists. It now reasserts the pool inside the lock, immediately before the duplicate check and the write. UpdateIdentityProvider needs no equivalent: the cascade deletes the provider, so its own lookup throws ResourceNotFoundException. The outer validation stays where it is to keep error ordering unchanged for ordinary single-request calls.
186 lines
6.1 KiB
TypeScript
186 lines
6.1 KiB
TypeScript
/**
|
|
* Cognito identity provider configuration compatibility tests.
|
|
*
|
|
* The response shapes asserted here were measured against the live Cognito API:
|
|
* `IdpIdentifiers` is echoed by CreateIdentityProvider and UpdateIdentityProvider
|
|
* only when the request supplied the member, whatever the stored value, while
|
|
* DescribeIdentityProvider always returns it. Members a request omits are
|
|
* preserved rather than cleared.
|
|
*/
|
|
|
|
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
|
|
import {
|
|
CognitoIdentityProviderClient,
|
|
CreateUserPoolCommand,
|
|
DeleteUserPoolCommand,
|
|
CreateIdentityProviderCommand,
|
|
DescribeIdentityProviderCommand,
|
|
ListIdentityProvidersCommand,
|
|
UpdateIdentityProviderCommand,
|
|
DeleteIdentityProviderCommand,
|
|
IdentityProviderTypeType,
|
|
} from '@aws-sdk/client-cognito-identity-provider';
|
|
import { makeClient, uniqueName } from './setup';
|
|
|
|
const OIDC_DETAILS = {
|
|
client_id: 'node-compat-client',
|
|
client_secret: 'node-compat-secret',
|
|
attributes_request_method: 'GET',
|
|
oidc_issuer: 'https://issuer.example.com',
|
|
authorize_scopes: 'openid',
|
|
};
|
|
|
|
describe('Cognito identity providers', () => {
|
|
let cognito: CognitoIdentityProviderClient;
|
|
let poolId: string;
|
|
|
|
beforeAll(async () => {
|
|
cognito = makeClient(CognitoIdentityProviderClient);
|
|
const pool = await cognito.send(
|
|
new CreateUserPoolCommand({ PoolName: uniqueName('idp-pool') })
|
|
);
|
|
poolId = pool.UserPool!.Id!;
|
|
});
|
|
|
|
afterAll(async () => {
|
|
if (poolId) {
|
|
await cognito.send(new DeleteUserPoolCommand({ UserPoolId: poolId }));
|
|
}
|
|
});
|
|
|
|
it('defaults AttributeMapping and omits IdpIdentifiers on create', async () => {
|
|
const created = await cognito.send(
|
|
new CreateIdentityProviderCommand({
|
|
UserPoolId: poolId,
|
|
ProviderName: 'NodeOidc',
|
|
ProviderType: IdentityProviderTypeType.OIDC,
|
|
ProviderDetails: { ...OIDC_DETAILS },
|
|
})
|
|
);
|
|
|
|
expect(created.IdentityProvider!.AttributeMapping).toEqual({ username: 'sub' });
|
|
expect(created.IdentityProvider!.IdpIdentifiers).toBeUndefined();
|
|
|
|
const described = await cognito.send(
|
|
new DescribeIdentityProviderCommand({ UserPoolId: poolId, ProviderName: 'NodeOidc' })
|
|
);
|
|
expect(described.IdentityProvider!.IdpIdentifiers).toEqual([]);
|
|
expect(described.IdentityProvider!.ProviderDetails!.client_id).toBe('node-compat-client');
|
|
|
|
await cognito.send(
|
|
new DeleteIdentityProviderCommand({ UserPoolId: poolId, ProviderName: 'NodeOidc' })
|
|
);
|
|
});
|
|
|
|
it('preserves members the update request omits', async () => {
|
|
await cognito.send(
|
|
new CreateIdentityProviderCommand({
|
|
UserPoolId: poolId,
|
|
ProviderName: 'NodeOidcAliased',
|
|
ProviderType: IdentityProviderTypeType.OIDC,
|
|
ProviderDetails: { ...OIDC_DETAILS },
|
|
AttributeMapping: { email: 'email', username: 'sub' },
|
|
IdpIdentifiers: ['node-alias'],
|
|
})
|
|
);
|
|
|
|
const updated = await cognito.send(
|
|
new UpdateIdentityProviderCommand({
|
|
UserPoolId: poolId,
|
|
ProviderName: 'NodeOidcAliased',
|
|
ProviderDetails: { ...OIDC_DETAILS },
|
|
})
|
|
);
|
|
expect(updated.IdentityProvider!.IdpIdentifiers).toBeUndefined();
|
|
|
|
const described = await cognito.send(
|
|
new DescribeIdentityProviderCommand({
|
|
UserPoolId: poolId,
|
|
ProviderName: 'NodeOidcAliased',
|
|
})
|
|
);
|
|
expect(described.IdentityProvider!.IdpIdentifiers).toEqual(['node-alias']);
|
|
expect(described.IdentityProvider!.AttributeMapping).toEqual({
|
|
email: 'email',
|
|
username: 'sub',
|
|
});
|
|
|
|
await cognito.send(
|
|
new DeleteIdentityProviderCommand({
|
|
UserPoolId: poolId,
|
|
ProviderName: 'NodeOidcAliased',
|
|
})
|
|
);
|
|
});
|
|
|
|
it('lists providers as summaries without provider details', async () => {
|
|
await cognito.send(
|
|
new CreateIdentityProviderCommand({
|
|
UserPoolId: poolId,
|
|
ProviderName: 'NodeOidcListed',
|
|
ProviderType: IdentityProviderTypeType.OIDC,
|
|
ProviderDetails: { ...OIDC_DETAILS },
|
|
})
|
|
);
|
|
|
|
const listed = await cognito.send(new ListIdentityProvidersCommand({ UserPoolId: poolId }));
|
|
|
|
expect(listed.Providers).toHaveLength(1);
|
|
expect(listed.Providers![0].ProviderName).toBe('NodeOidcListed');
|
|
expect(listed.Providers![0].ProviderType).toBe('OIDC');
|
|
expect(listed.Providers![0].CreationDate).toBeInstanceOf(Date);
|
|
expect(listed.Providers![0]).not.toHaveProperty('ProviderDetails');
|
|
|
|
await cognito.send(
|
|
new DeleteIdentityProviderCommand({ UserPoolId: poolId, ProviderName: 'NodeOidcListed' })
|
|
);
|
|
const empty = await cognito.send(new ListIdentityProvidersCommand({ UserPoolId: poolId }));
|
|
expect(empty.Providers).toEqual([]);
|
|
});
|
|
|
|
it('rejects a duplicate provider name and an unknown provider type', async () => {
|
|
await cognito.send(
|
|
new CreateIdentityProviderCommand({
|
|
UserPoolId: poolId,
|
|
ProviderName: 'NodeOidcDuplicate',
|
|
ProviderType: IdentityProviderTypeType.OIDC,
|
|
ProviderDetails: { ...OIDC_DETAILS },
|
|
})
|
|
);
|
|
|
|
// The SDK maps the wire `__type` onto `error.name` and puts the AWS text in
|
|
// `message`, so the exception has to be matched on the name.
|
|
await expect(
|
|
cognito.send(
|
|
new CreateIdentityProviderCommand({
|
|
UserPoolId: poolId,
|
|
ProviderName: 'NodeOidcDuplicate',
|
|
ProviderType: IdentityProviderTypeType.OIDC,
|
|
ProviderDetails: { ...OIDC_DETAILS },
|
|
})
|
|
)
|
|
).rejects.toMatchObject({ name: 'DuplicateProviderException' });
|
|
|
|
await expect(
|
|
cognito.send(
|
|
new CreateIdentityProviderCommand({
|
|
UserPoolId: poolId,
|
|
ProviderName: 'NodeBogus',
|
|
ProviderType: 'NotARealType' as IdentityProviderTypeType,
|
|
ProviderDetails: { client_id: 'x' },
|
|
})
|
|
)
|
|
).rejects.toMatchObject({
|
|
name: 'InvalidParameterException',
|
|
message: expect.stringContaining('Member must satisfy enum value set'),
|
|
});
|
|
|
|
await cognito.send(
|
|
new DeleteIdentityProviderCommand({
|
|
UserPoolId: poolId,
|
|
ProviderName: 'NodeOidcDuplicate',
|
|
})
|
|
);
|
|
});
|
|
});
|