Skip to content
This repository has been archived by the owner on Dec 6, 2024. It is now read-only.

Commit

Permalink
fix: integ tests for auth change (#915)
Browse files Browse the repository at this point in the history
  • Loading branch information
SanketD92 authored Feb 10, 2022
1 parent b334136 commit 86c6e19
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('Get authentication config list scenarios', () => {
const admin2Session = await setup.createAdminSession();
const response = await admin2Session.resources.authentication.configs().get();

await expect(response).toEqual(
expect(response).toEqual(
expect.arrayContaining([
expect.objectContaining(admin2Session.resources.authentication.configs().defaultConfigs()),
]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('Get current user scenarios', () => {
'should return current user information for user in status %a',
async a => {
const researcher2Session = await setup.createResearcherSession();
await researcher2Session.resources.currentUser.update({ status: a, rev: 0 });
await researcher2Session.resources.currentUser.update({ status: a, rev: 1 });
await expect(researcher2Session.resources.currentUser.get()).resolves.toMatchObject({ status: a });
},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('Update current user scenarios', () => {
describe('updating current user', () => {
it('should fail for anonymous user', async () => {
const anonymousSession = await setup.createAnonymousSession();
await expect(anonymousSession.resources.currentUser.update({ rev: 0 })).rejects.toMatchObject({
await expect(anonymousSession.resources.currentUser.update({ rev: 1 })).rejects.toMatchObject({
code: errorCode.http.code.badImplementation,
});
});
Expand All @@ -41,30 +41,30 @@ describe('Update current user scenarios', () => {
const researcher2Info = await researcher2Session.resources.currentUser.get();
const researcher1Info = await researcher1Session.resources.currentUser.get();
await expect(
researcher1Session.resources.currentUser.update({ uid: researcher2Info.uid, rev: 0, status: 'pending' }),
researcher1Session.resources.currentUser.update({ uid: researcher2Info.uid, rev: 1, status: 'pending' }),
).resolves.toEqual(expect.objectContaining({ uid: researcher1Info.uid }));
});

it.each([{ isSamlAuthenticatedUser: true }, { isAdmin: true }, { userRole: 'admin' }])(
'should fail if non-admin user update restrictive field %a',
async a => {
const researcherSession = await setup.createResearcherSession();
await expect(researcherSession.resources.currentUser.update({ rev: 0, ...a })).rejects.toMatchObject({
await expect(researcherSession.resources.currentUser.update({ rev: 1, ...a })).rejects.toMatchObject({
code: errorCode.http.code.forbidden,
});
},
);

it('should not allow admin elevate to root', async () => {
const admin2Session = await setup.createAdminSession();
await expect(admin2Session.resources.currentUser.update({ rev: 0, userRole: 'root' })).rejects.toMatchObject({
await expect(admin2Session.resources.currentUser.update({ rev: 1, userRole: 'root' })).rejects.toMatchObject({
code: errorCode.http.code.notFound,
});
});

it('should not allow inactive user to become active', async () => {
const researcherSession = await setup.createResearcherSession();
await researcherSession.resources.currentUser.update({ rev: 0, status: 'inactive' });
await researcherSession.resources.currentUser.update({ rev: 1, status: 'inactive' });
await expect(researcherSession.resources.currentUser.update({ rev: 1, status: 'active' })).rejects.toMatchObject({
code: errorCode.http.code.forbidden,
});
Expand All @@ -73,9 +73,9 @@ describe('Update current user scenarios', () => {
// Note: This use-case is for federated user self-registration
it('should allow inactive user to become pending', async () => {
const researcherSession = await setup.createResearcherSession();
await researcherSession.resources.currentUser.update({ rev: 0, status: 'inactive' });
await researcherSession.resources.currentUser.update({ rev: 1, status: 'inactive' });
await expect(
researcherSession.resources.currentUser.update({ rev: 1, status: 'pending' }),
researcherSession.resources.currentUser.update({ rev: 2, status: 'pending' }),
).resolves.toMatchObject({
status: 'pending',
});
Expand All @@ -84,11 +84,11 @@ describe('Update current user scenarios', () => {
it('should update successfully', async () => {
const researcherSession = await setup.createResearcherSession();
await expect(
researcherSession.resources.currentUser.update({ rev: 0, firstName: 'John', lastName: 'Snow' }),
researcherSession.resources.currentUser.update({ rev: 1, firstName: 'John', lastName: 'Snow' }),
).resolves.toMatchObject({
firstName: 'John',
lastName: 'Snow',
rev: 1,
rev: 2,
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('Update user scenarios', () => {
it('should fail for anonymous user', async () => {
const anonymousSession = await setup.createAnonymousSession();
await expect(
anonymousSession.resources.users.user(uid).update({ rev: 0, firstName: 'John' }),
anonymousSession.resources.users.user(uid).update({ rev: 1, firstName: 'John' }),
).rejects.toMatchObject({
code: errorCode.http.code.badImplementation,
});
Expand All @@ -51,7 +51,7 @@ describe('Update user scenarios', () => {
const admin1Session = await setup.createAdminSession();
await adminSession.resources.users.deactivateUser(admin1Session.user);
await expect(
admin1Session.resources.users.user(uid).update({ rev: 0, firstName: 'John' }),
admin1Session.resources.users.user(uid).update({ rev: 1, firstName: 'John' }),
).rejects.toMatchObject({ code: errorCode.http.code.unauthorized });
});

Expand All @@ -67,7 +67,7 @@ describe('Update user scenarios', () => {
it.each(['researcher', 'guest', 'internal-guest'])('should update self successfully for %a', async a => {
const nonAdminSession = await setup.createUserSession({ userRole: a, projectId: [] });
await expect(
nonAdminSession.resources.users.user(nonAdminSession.user.uid).update({ rev: 0, firstName: 'John' }),
nonAdminSession.resources.users.user(nonAdminSession.user.uid).update({ rev: 1, firstName: 'John' }),
).resolves.toMatchObject({
uid: nonAdminSession.user.uid,
firstName: 'John',
Expand All @@ -77,13 +77,13 @@ describe('Update user scenarios', () => {
it.each(['researcher', 'guest', 'internal-guest'])('should fail if %a update restrictive fields', async a => {
const nonAdminSession = await setup.createUserSession({ userRole: a, projectId: [] });
await expect(
nonAdminSession.resources.users.user(nonAdminSession.user.uid).update({ rev: 0, isAdmin: true }),
nonAdminSession.resources.users.user(nonAdminSession.user.uid).update({ rev: 1, isAdmin: true }),
).rejects.toMatchObject({
code: errorCode.http.code.forbidden,
});
const projectId = setup.defaults.project.id;
await expect(
nonAdminSession.resources.users.user(nonAdminSession.user.uid).update({ rev: 0, projectId: [projectId] }),
nonAdminSession.resources.users.user(nonAdminSession.user.uid).update({ rev: 1, projectId: [projectId] }),
).rejects.toMatchObject({
code: errorCode.http.code.forbidden,
});
Expand All @@ -92,7 +92,7 @@ describe('Update user scenarios', () => {
it.each(['researcher', 'guest', 'internal-guest'])('should fail if %a update other user', async a => {
const nonAdminSession = await setup.createUserSession({ userRole: a, projectId: [] });
await expect(
nonAdminSession.resources.users.user(uid).update({ rev: 0, firstName: 'John' }),
nonAdminSession.resources.users.user(uid).update({ rev: 1, firstName: 'John' }),
).rejects.toMatchObject({
code: errorCode.http.code.forbidden,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ class AuthenticationProviderConfigs extends CollectionResource {
}

// ************************ Helpers methods ************************
// TODO: Return Cognito as default config
defaultConfigs() {
// return InternalAuthProviderConfig;
return {
id: `https://cognito-idp.${this.setup.defaults.awsRegion}.amazonaws.com/${this.setup.defaults.userPoolId}`,
status: 'active',
};
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
const _ = require('lodash');

const CollectionResource = require('../base/collection-resource');
const InternalAuthProviderType = require('./helpers/default-auth-provider-type-internal.json');
const CognitoAuthProviderType = require('./helpers/default-auth-provider-type-cognito.json');

class AuthenticationProviderTypes extends CollectionResource {
Expand All @@ -33,7 +32,7 @@ class AuthenticationProviderTypes extends CollectionResource {

// ************************ Helpers methods ************************
defaultTypes() {
return [InternalAuthProviderType, CognitoAuthProviderType];
return [CognitoAuthProviderType];
}
}

Expand Down

0 comments on commit 86c6e19

Please sign in to comment.