Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Redirect non admin users to "/" if they try to access "/users" #489

Merged
merged 8 commits into from
May 17, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import React from 'react';
import { Tab, Segment, Container } from 'semantic-ui-react';
import { observer } from 'mobx-react';
import { inject, observer } from 'mobx-react';
import { withRouter } from 'react-router-dom';
import RolesList from './RolesList';
import UsersList from './UsersList';
Expand All @@ -28,14 +28,17 @@ const panes = [
// eslint-disable-next-line react/prefer-stateless-function
class User extends React.Component {
render() {
if (!this.props.userStore.cloneUser.isAdmin) {
this.props.history.push('/');
}
return (
<Container className="mt3 animated fadeIn">
<Segment basic className="p0">
<Tab panes={panes} />
<Tab panes={panes} data-testid="users-table" />
</Segment>
</Container>
);
}
}

export default withRouter(observer(User));
export default inject('userStore')(withRouter(observer(User)));
1 change: 1 addition & 0 deletions main/end-to-end-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ In this section we will discuss how you can run these tests from your desktop.
To run the E2E tests, you will need the following items:

- A Service Workbench environment setup with Service Catalog
- Username and password of an admin for the Service Workbench environment
- Username and password of a researcher for the Service Workbench environment
- A project set up for that researcher that can launch EC2 workspaces and Sagemaker workspaces
- A configured EC2 workspace
Expand Down
2 changes: 2 additions & 0 deletions main/end-to-end-tests/cypress.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"env": {
"researcherEmail": "<EMAIL ACCOUNT OF PREMADE RESEARCHER>",
"researcherPassword": "<RESEARCHER ACCOUNT PASSWORD>",
"adminEmail": "<EMAIL ACCOUNT OF PREMADE ADMIN>",
"adminPassword": "<ADMIN ACCOUNT PASSWORD>",
"isCognitoEnabled": false,
"workspaces": {
"sagemaker": {
Expand Down
2 changes: 1 addition & 1 deletion main/end-to-end-tests/cypress/integration/login.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
*/
describe('Login', () => {
it('should login as researcher successfully', () => {
cy.login();
cy.login('researcher');
});
});
14 changes: 14 additions & 0 deletions main/end-to-end-tests/cypress/integration/page-routing.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
describe('page routing', () => {
describe('should navigate to /users page correctly', () => {
it('should redirect researchers trying to access /users page', () => {
cy.login('researcher');
cy.visit('/users');
cy.get("div[data-testid='page-title'] div").contains('Dashboard');
});
it('should allow admin to access /users page', () => {
cy.login('admin');
cy.visit('/users');
cy.get("div[data-testid='users-table']");
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

describe('Launch a new sagemaker workspace', () => {
before(() => {
cy.login();
cy.login('researcher');
navigateToWorkspaces();
terminatePrexistingWorkspaces();
});
Expand Down
22 changes: 15 additions & 7 deletions main/end-to-end-tests/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,28 @@

// TODO: If an environment is configured with an Identity Provider, the login steps needs to select an
// identity provider
Cypress.Commands.add('login', () => {
const loginInfo = {
researcherEmail: Cypress.env('researcherEmail'),
researcherPassword: Cypress.env('researcherPassword'),
};
Cypress.Commands.add('login', role => {
let loginInfo = {};
if (role === 'researcher') {
loginInfo = {
email: Cypress.env('researcherEmail'),
password: Cypress.env('researcherPassword'),
};
} else if (role === 'admin') {
loginInfo = {
email: Cypress.env('adminEmail'),
password: Cypress.env('adminPassword'),
};
}
const isCognitoEnabled = Cypress.env('isCognitoEnabled');

if (isCognitoEnabled) {
cy.visit('/?internal');
} else {
cy.visit('/');
}
cy.get("div[data-testid='username'] input").type(loginInfo.researcherEmail);
cy.get("div[data-testid='password'] input").type(loginInfo.researcherPassword);
cy.get("div[data-testid='username'] input").type(loginInfo.email);
cy.get("div[data-testid='password'] input").type(loginInfo.password);
cy.get("button[data-testid='login']").click();
cy.get("div[data-testid='page-title'] div").contains('Dashboard');
});