-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2782 from HHS/key-cleanup-and-docs
remove dead code;add documentation for generating keys
- Loading branch information
Showing
5 changed files
with
31 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,65 +16,8 @@ | |
import "cypress-localstorage-commands"; | ||
import "cypress-axe"; | ||
import "./commands"; | ||
import * as jose from "jose"; | ||
import { login } from "../../src/components/Auth/authSlice"; | ||
|
||
const users = [ | ||
{ | ||
name: "admin", | ||
first_name: "Emily", | ||
last_name: "Ball", | ||
division: 1, | ||
email: "[email protected]", | ||
role: "Admin", | ||
oidc_id: "00000000-0000-1111-a111-000000000001" | ||
}, | ||
{ | ||
name: "director", | ||
first_name: "Bethanne", | ||
last_name: "Barnes", | ||
division: 4, | ||
email: "[email protected]", | ||
role: "Division Director", | ||
oidc_id: "00000000-0000-1111-a111-000000000002" | ||
}, | ||
{ | ||
name: "cor", | ||
first_name: "Meryl", | ||
last_name: "Barofsky", | ||
division: 1, | ||
email: "[email protected]", | ||
role: "COR", | ||
oidc_id: "00000000-0000-1111-a111-000000000003" | ||
}, | ||
{ | ||
name: "basic", | ||
first_name: "Anne", | ||
last_name: "Bergan", | ||
division: 3, | ||
email: "[email protected]", | ||
role: "View-Only", | ||
oidc_id: "00000000-0000-1111-a111-000000000004" | ||
} | ||
]; | ||
|
||
const generateJWT = async (name) => { | ||
const alg = "RS256"; | ||
const keyBase64 = Cypress.env("testkey"); | ||
const key = Buffer.from(keyBase64, "base64"); | ||
const privateKey = await jose.importPKCS8(key.toString(), "RS256"); | ||
let user = users.find((u) => u.name === name); | ||
|
||
const jwt = await new jose.SignJWT({ type: "access" }) | ||
.setProtectedHeader({ alg }) | ||
.setIssuedAt() | ||
.setSubject(user.oidc_id) | ||
.setExpirationTime("2h") | ||
.sign(privateKey); | ||
|
||
return jwt; | ||
}; | ||
|
||
Cypress.Commands.add("login", () => { | ||
window.localStorage.setItem("access_token", "123"); | ||
}); | ||
|
@@ -88,7 +31,7 @@ Cypress.Commands.add("FakeAuth", (user) => { | |
} else if (user === "basic") { | ||
cy.contains("Basic User").click(); | ||
} | ||
// eslint-disable-next-line cypress/no-unnecessary-waiting | ||
|
||
cy.wait(100); | ||
cy.logLocalStorage(); | ||
// TODO: Figure out why the below tests are required for this to complete.\ | ||
|
@@ -113,19 +56,6 @@ Cypress.Commands.add("FakeAuth", (user) => { | |
}); | ||
}); | ||
|
||
Cypress.Commands.add("fakeLogin", (name) => { | ||
cy.session([name], async () => { | ||
cy.visit("/"); | ||
const jwt = await generateJWT(name); | ||
window.localStorage.setItem("access_token", jwt); | ||
//win.store.dispatch(login()); | ||
}); | ||
}); | ||
|
||
Cypress.Commands.add("setIsLoggedIn", (win) => { | ||
win.store.dispatch(login()); | ||
}); | ||
|
||
Cypress.Commands.add("logLocalStorage", () => { | ||
cy.window().then((window) => { | ||
console.log("localStorage contents:", window.localStorage); | ||
|