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

Commit

Permalink
Merge branch 'main' into EVG-19946
Browse files Browse the repository at this point in the history
  • Loading branch information
minnakt committed Sep 12, 2023
2 parents 46ae0f3 + 8d276ba commit 32cd128
Show file tree
Hide file tree
Showing 56 changed files with 2,972 additions and 1,338 deletions.
1 change: 1 addition & 0 deletions .evergreen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ functions:
script: |
echo "Generating .env-cmdrc.json"
REACT_APP_BUGSNAG_API_KEY=${REACT_APP_BUGSNAG_API_KEY} \
REACT_APP_SENTRY_AUTH_TOKEN=${REACT_APP_SENTRY_AUTH_TOKEN} \
REACT_APP_SENTRY_DSN=${REACT_APP_SENTRY_DSN} \
REACT_APP_NEW_RELIC_ACCOUNT_ID=${REACT_APP_NEW_RELIC_ACCOUNT_ID} \
REACT_APP_NEW_RELIC_AGENT_ID=${REACT_APP_NEW_RELIC_AGENT_ID} \
Expand Down
20 changes: 14 additions & 6 deletions cypress/integration/auth.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
describe("Auth", () => {
it("Unauthenticated user is redirected to login page after visiting a private route", () => {
cy.clearCookie("mci-token");
cy.logout();
cy.visit("/version/123123");
cy.url().should("include", "/login");
cy.location("pathname").should("equal", "/login");
});

it("Redirects user to My Patches page after logging in", () => {
cy.clearCookie("mci-token");
cy.logout();
cy.visit("/");
cy.enterLoginCredentials();
cy.url().should("include", "/user/admin/patches");
cy.location("pathname").should("equal", "/user/admin/patches");
});

it("Can log out via the dropdown", () => {
cy.visit("/");
cy.location("pathname").should("equal", "/user/admin/patches");
cy.dataCy("user-dropdown-link").click();
cy.dataCy("log-out").click();
cy.location("pathname").should("equal", "/login");
});

it("Automatically authenticates user if they are logged in", () => {
cy.visit("/version/123123");
cy.url().should("include", "/version/123123");
cy.location("pathname").should("equal", "/version/123123");
});

it("Redirects user to their patches page if they are already logged in and visit login page", () => {
cy.visit("/login");
cy.url().should("include", "/user/admin/patches");
cy.location("pathname").should("equal", "/user/admin/patches");
});
});
60 changes: 60 additions & 0 deletions cypress/integration/distroSettings/host_section.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { save } from "./utils";

describe("host section", () => {
describe("using legacy ssh", () => {
beforeEach(() => {
cy.visit("/distro/localhost/settings/host");
});

it("shows the correct fields when distro has static provider", () => {
cy.dataCy("authorized-keys-input").should("exist");
cy.dataCy("minimum-hosts-input").should("not.exist");
cy.dataCy("maximum-hosts-input").should("not.exist");
cy.dataCy("idle-time-input").should("not.exist");
cy.dataCy("future-fraction-input").should("not.exist");
});

it("errors when selecting an incompatible host communication method", () => {
cy.selectLGOption("Host Communication Method", "RPC");
save();
cy.validateToast(
"error",
"validating changes for distro 'localhost': 'ERROR: bootstrapping hosts using legacy SSH is incompatible with non-legacy host communication'"
);
cy.selectLGOption("Host Communication Method", "Legacy SSH");
});

it("updates host fields", () => {
cy.selectLGOption("Agent Architecture", "Linux ARM 64-bit");
cy.getInputByLabel("Working Directory").clear();
cy.getInputByLabel("Working Directory").type("/usr/local/bin");
cy.getInputByLabel("SSH User").clear();
cy.getInputByLabel("SSH User").type("sudo");
cy.contains("button", "Add SSH option").click();
cy.getInputByLabel("SSH Option").type("BatchMode=yes");
cy.selectLGOption("Host Allocator Rounding Rule", "Round down");
cy.selectLGOption("Host Allocator Feedback Rule", "No feedback");
cy.selectLGOption(
"Host Overallocation Rule",
"Terminate hosts when overallocated"
);

save();
cy.validateToast("success");

// Reset fields
cy.selectLGOption("Agent Architecture", "Linux 64-bit");
cy.getInputByLabel("Working Directory").clear();
cy.getInputByLabel("Working Directory").type("/home/ubuntu/smoke");
cy.getInputByLabel("SSH User").clear();
cy.getInputByLabel("SSH User").type("ubuntu");
cy.dataCy("delete-item-button").click();
cy.selectLGOption("Host Allocator Rounding Rule", "Default");
cy.selectLGOption("Host Allocator Feedback Rule", "Default");
cy.selectLGOption("Host Overallocation Rule", "Default");

save();
cy.validateToast("success");
});
});
});
2 changes: 1 addition & 1 deletion cypress/integration/job_logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe("Job logs page", () => {
cy.get("th")
.should("have.length", 1)
.then((th) => {
cy.wrap(th).should("have.attr", "aria-sort", "none");
cy.wrap(th).should("not.have.attr", "aria-sort");
});

cy.dataCy("complete-test-logs-link")
Expand Down
13 changes: 9 additions & 4 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const LOGIN_COOKIE = "mci-token";
const loginURL = "http://localhost:9090/login";
const user = {
username: "admin",
password: "password",
Expand Down Expand Up @@ -61,13 +59,20 @@ Cypress.Commands.add("getInputByLabel", (label: string) => {

/* login */
Cypress.Commands.add("login", () => {
cy.getCookie(LOGIN_COOKIE).then((c) => {
cy.getCookie("mci-token").then((c) => {
if (!c) {
cy.request("POST", loginURL, { ...user });
cy.request("POST", "http://localhost:9090/login", { ...user });
}
});
});

/* logout */
Cypress.Commands.add("logout", () => {
cy.origin("http://localhost:9090", () => {
cy.request({ url: "/logout", followRedirect: false });
});
});

/* toggleTableFilter */
Cypress.Commands.add("toggleTableFilter", (colNum: number) => {
cy.get(`.ant-table-thead > tr > :nth-child(${colNum})`)
Expand Down
5 changes: 5 additions & 0 deletions cypress/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ declare global {
* @example cy.login()
*/
login(): void;
/**
* Custom command to log out of the application.
* @example cy.logout()
*/
logout(): void;
/**
* Custom command to open an antd table filter associated with the
* the supplied column number
Expand Down
3 changes: 0 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,5 @@ module.exports = {
"jest-watch-typeahead/testname",
],
globalSetup: "<rootDir>/global-setup.js",
globals: {
APP_VERSION: JSON.stringify(process.env.npm_package_version),
},
testTimeout: 30000,
};
25 changes: 13 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "spruce",
"version": "3.0.132",
"version": "3.0.135",
"private": true,
"scripts": {
"bootstrap-logkeeper": "./scripts/bootstrap-logkeeper.sh",
Expand Down Expand Up @@ -77,7 +77,7 @@
"@leafygreen-ui/inline-definition": "6.0.0",
"@leafygreen-ui/interaction-ring": "7.0.2",
"@leafygreen-ui/leafygreen-provider": "3.1.0",
"@leafygreen-ui/loading-indicator": "2.0.0",
"@leafygreen-ui/loading-indicator": "2.0.5",
"@leafygreen-ui/marketing-modal": "^4.0.5",
"@leafygreen-ui/menu": "20.0.1",
"@leafygreen-ui/modal": "14.0.1",
Expand All @@ -88,11 +88,11 @@
"@leafygreen-ui/radio-box-group": "12.0.1",
"@leafygreen-ui/radio-group": "10.1.1",
"@leafygreen-ui/search-input": "2.0.8",
"@leafygreen-ui/segmented-control": "7.0.2",
"@leafygreen-ui/segmented-control": "8.2.6",
"@leafygreen-ui/select": "10.2.0",
"@leafygreen-ui/side-nav": "13.0.2",
"@leafygreen-ui/table": "10.0.1",
"@leafygreen-ui/table/new": "npm:@leafygreen-ui/[email protected].0",
"@leafygreen-ui/table/new": "npm:@leafygreen-ui/[email protected].10",
"@leafygreen-ui/tabs": "11.0.4",
"@leafygreen-ui/text-area": "8.0.4",
"@leafygreen-ui/text-input": "12.1.0",
Expand Down Expand Up @@ -142,13 +142,14 @@
"@graphql-codegen/typescript-operations": "4.0.1",
"@graphql-eslint/eslint-plugin": "3.18.0",
"@originjs/vite-plugin-commonjs": "1.0.3",
"@storybook/addon-actions": "7.0.21",
"@storybook/addon-essentials": "7.0.21",
"@storybook/addon-interactions": "7.0.21",
"@storybook/addon-links": "7.0.21",
"@storybook/addon-storyshots": "7.0.21",
"@storybook/react": "7.0.21",
"@storybook/react-vite": "7.0.21",
"@sentry/vite-plugin": "2.6.2",
"@storybook/addon-actions": "7.4.0",
"@storybook/addon-essentials": "7.4.0",
"@storybook/addon-interactions": "7.4.0",
"@storybook/addon-links": "7.4.0",
"@storybook/addon-storyshots": "7.4.0",
"@storybook/react": "7.4.0",
"@storybook/react-vite": "7.4.0",
"@storybook/testing-library": "0.2.0",
"@styled/typescript-styled-plugin": "1.0.0",
"@testing-library/jest-dom": "6.1.2",
Expand Down Expand Up @@ -208,7 +209,7 @@
"rollup-plugin-visualizer": "^5.9.2",
"serve-handler": "^6.1.5",
"simple-git": "3.19.1",
"storybook": "7.0.21",
"storybook": "7.4.0",
"storybook-addon-apollo-client": "^4.1.4",
"ts-node": "10.9.1",
"typescript": "5.0.3",
Expand Down
1 change: 1 addition & 0 deletions scripts/setup-credentials.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const production = {
REACT_APP_SPRUCE_URL: "https://spruce.mongodb.com",
REACT_APP_RELEASE_STAGE: "production",
REACT_APP_BUGSNAG_API_KEY: process.env.REACT_APP_BUGSNAG_API_KEY,
REACT_APP_SENTRY_AUTH_TOKEN: process.env.REACT_APP_SENTRY_AUTH_TOKEN,
REACT_APP_SENTRY_DSN: process.env.REACT_APP_SENTRY_DSN,
REACT_APP_NEW_RELIC_ACCOUNT_ID: process.env.REACT_APP_NEW_RELIC_ACCOUNT_ID,
REACT_APP_NEW_RELIC_AGENT_ID: process.env.REACT_APP_NEW_RELIC_AGENT_ID,
Expand Down
1 change: 0 additions & 1 deletion src/components/ErrorHandling/Sentry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const initializeSentry = () => {
dsn: getSentryDSN(),
debug: !isProduction(),
normalizeDepth: 5,
release: APP_VERSION,
environment: releaseStage,
});
} catch (e) {
Expand Down
3 changes: 0 additions & 3 deletions src/components/ErrorHandling/initialize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ describe("should initialize error handlers according to release stage", () => {
dsn: "fake-sentry-key",
debug: false,
normalizeDepth: 5,
release: APP_VERSION,
environment: "production",
});
});
Expand All @@ -71,7 +70,6 @@ describe("should initialize error handlers according to release stage", () => {
dsn: "fake-sentry-key",
debug: true,
normalizeDepth: 5,
release: APP_VERSION,
environment: "beta",
});
});
Expand All @@ -95,7 +93,6 @@ describe("should initialize error handlers according to release stage", () => {
dsn: "fake-sentry-key",
debug: true,
normalizeDepth: 5,
release: APP_VERSION,
environment: "staging",
});
});
Expand Down
7 changes: 7 additions & 0 deletions src/components/Header/UserDropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useQuery } from "@apollo/client";
import { useNavbarAnalytics } from "analytics";
import { PreferencesTabRoutes, getPreferencesRoute } from "constants/routes";
import { useAuthDispatchContext } from "context/auth";
import { UserQuery } from "gql/generated/types";
import { GET_USER } from "gql/queries";
import { NavDropdown } from "./NavDropdown";
Expand All @@ -10,6 +11,7 @@ export const UserDropdown = () => {
const { user } = data || {};
const { displayName } = user || {};

const { logoutAndRedirect } = useAuthDispatchContext();
const { sendEvent } = useNavbarAnalytics();

const menuItems = [
Expand All @@ -23,6 +25,11 @@ export const UserDropdown = () => {
to: getPreferencesRoute(PreferencesTabRoutes.Notifications),
onClick: () => sendEvent({ name: "Click Notifications Link" }),
},
{
"data-cy": "log-out",
text: "Log out",
onClick: () => logoutAndRedirect(),
},
];

return (
Expand Down
Loading

0 comments on commit 32cd128

Please sign in to comment.