Skip to content

Commit

Permalink
chore: add some headless test
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolk committed Jul 21, 2023
1 parent 80961c8 commit 77db636
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions packages/amplify-e2e-tests/src/__tests__/auth/user-groups.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ import {
addAuthWithDefault,
addAuthWithGroups,
amplifyPushAuth,
amplifyPushNonInteractive,
createNewProjectDir,
deleteProject,
deleteProjectDir,
getIdentityPoolRoles,
getProjectMeta,
initJSProjectWithProfile,
updateAuthAddUserGroups,
updateHeadlessAuth,
} from '@aws-amplify/amplify-e2e-core';
import { UpdateAuthRequest } from 'amplify-headless-interface';

const defaultsSettings = {
name: 'authTest',
Expand Down Expand Up @@ -102,5 +105,54 @@ describe('user group tests', () => {
expect(identityPoolRoles.RoleMappings[roleMapKeyWebClientId].Type).toEqual('Token');
});
});

describe('...updating headless to add a user pool group', () => {
it('...assigns authenticated roles for users added to user group', async () => {
await initJSProjectWithProfile(projRoot, defaultsSettings);
await addAuthWithDefault(projRoot);
await amplifyPushNonInteractive(projRoot);
const updateAuthRequest: UpdateAuthRequest = {
version: 2,
serviceModification: {
serviceName: 'Cognito',
userPoolModification: {
autoVerifiedAttributes: [
{
type: 'EMAIL',
},
],
userPoolGroups: [
{
groupName: 'Admins',
},
{
groupName: 'Users',
},
],
},
includeIdentityPool: true,
identityPoolModification: {},
},
};

await updateHeadlessAuth(projRoot, updateAuthRequest);
await amplifyPushNonInteractive(projRoot);

const meta = getProjectMeta(projRoot);
const region = meta.providers.awscloudformation.Region;
const { AppClientID, AppClientIDWeb, IdentityPoolId, UserPoolId } = Object.keys(meta.auth)
.map((key) => meta.auth[key])
.find((auth) => auth.service === 'Cognito').output;

const identityPoolRoles = await getIdentityPoolRoles(IdentityPoolId, region);
const roleMapKeyClientId = `cognito-idp.${region}.amazonaws.com/${UserPoolId}:${AppClientID}`;
const roleMapKeyWebClientId = `cognito-idp.${region}.amazonaws.com/${UserPoolId}:${AppClientIDWeb}`;

expect(identityPoolRoles.RoleMappings[roleMapKeyClientId].AmbiguousRoleResolution).toEqual('AuthenticatedRole');
expect(identityPoolRoles.RoleMappings[roleMapKeyClientId].Type).toEqual('Token');
expect(identityPoolRoles.RoleMappings[roleMapKeyWebClientId].AmbiguousRoleResolution).toEqual('AuthenticatedRole');
expect(identityPoolRoles.RoleMappings[roleMapKeyWebClientId].Type).toEqual('Token');
});
});
});
});

0 comments on commit 77db636

Please sign in to comment.