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

Use a new random user for every test run #1792

Merged
Show file tree
Hide file tree
Changes from all 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
64 changes: 42 additions & 22 deletions packages/files-ui/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export interface Web3LoginOptions {
clearCSFBucket?: boolean
clearTrashBucket?: boolean
deleteShareBucket?: boolean
withNewUser?: boolean
}

Cypress.Commands.add(
Expand All @@ -55,40 +56,58 @@ Cypress.Commands.add(
url = localHost,
clearCSFBucket = false,
clearTrashBucket = false,
deleteShareBucket = false
deleteShareBucket = false,
withNewUser = true
}: Web3LoginOptions = {}) => {

cy.on("window:before:load", (win) => {
const provider = new ethers.providers.JsonRpcProvider(
"https://rinkeby.infura.io/v3/4bf032f2d38a4ed6bb975b80d6340847",
4
)
const signer = new Wallet(testPrivateKey, provider)
const signer = withNewUser
? Wallet.createRandom()
: new Wallet(testPrivateKey, provider)
// inject ethereum object in the global window
Object.defineProperty(win, "ethereum", {
get: () => new CustomizedBridge(signer as any, provider as any)
get: () => new CustomizedBridge(signer as any, signer.address, provider as any)
})
})

// with nothing in localstorage (and in session storage)
// the whole login flow should kick in
cy.session("web3login", () => {
cy.visit(url)
authenticationPage.web3Button().click()
authenticationPage.showMoreButton().click()
authenticationPage.detectedWallet().click()
authenticationPage.web3SignInButton().safeClick()
authenticationPage.loginPasswordButton().click()
authenticationPage.loginPasswordInput().type(`${testAccountPassword}{enter}`)

if (saveBrowser) {
// this is taking forever for test accounts
authenticationPage.saveBrowserButton().click()
} else {
authenticationPage.doNotSaveBrowserButton().click()
}
homePage.appHeaderLabel().should("be.visible")
})
if (withNewUser){
cy.session("web3loginNewUser", () => {
cy.visit(url)
authenticationPage.web3Button().click()
authenticationPage.showMoreButton().click()
authenticationPage.detectedWallet().click()
authenticationPage.web3SignInButton().safeClick()
authenticationPage.signInExplainerContinueButton().safeClick()
// we are using the testAccount password here, but we could input anything
authenticationPage.signInSetupPasswordInput().type(`${testAccountPassword}`)
authenticationPage.signInSetupPasswordVerificationInput().type(`${testAccountPassword}{enter}`)

homePage.appHeaderLabel().should("be.visible")
})
} else {
cy.session("web3loginTestUser", () => {
cy.visit(url)
authenticationPage.web3Button().click()
authenticationPage.showMoreButton().click()
authenticationPage.detectedWallet().click()
authenticationPage.web3SignInButton().safeClick()
authenticationPage.loginPasswordButton().click()
authenticationPage.loginPasswordInput().type(`${testAccountPassword}{enter}`)

if (saveBrowser) {
// this is taking forever for test accounts
authenticationPage.saveBrowserButton().click()
} else {
authenticationPage.doNotSaveBrowserButton().click()
}
homePage.appHeaderLabel().should("be.visible")
})
}


cy.visit(url)
homePage.appHeaderLabel().should("be.visible")
Expand Down Expand Up @@ -136,6 +155,7 @@ declare global {
* @param {Boolean} options.clearCSFBucket - (default: false) - whether any file in the csf bucket should be deleted.
* @param {Boolean} options.clearTrashBucket - (default: false) - whether any file in the trash bucket should be deleted.
* @param {Boolean} options.deleteShareBucket - (default: false) - whether any shared bucket should be deleted.
* @param {Boolean} options.withNewUser - (default: true) - whether to create a new user for this session.
* @example cy.web3Login({saveBrowser: true, url: 'http://localhost:8080'})
*/
web3Login: (options?: Web3LoginOptions) => void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export const authenticationPage = {
// sign in section elements
loginPasswordButton: () => cy.get("[data-cy=login-password-button]", { timeout: 20000 }),
loginPasswordInput: () => cy.get("[data-cy=login-password-input]"),
signInExplainerContinueButton: () => cy.get("[data-cy=sign-in-explainer-continue-button]", { timeout: 20000 }),
signInSetupPasswordInput: () => cy.get("[data-cy=sign-in-password-input]"),
signInSetupPasswordVerificationInput: () => cy.get("[data-cy=sign-in-password-verification-input]"),
signInSetupPasswordSubmitButton: () => cy.get("[data-cy=sign-in-password-button]"),

// save browser section elements
saveBrowserButton: () => cy.get("[data-cy=save-browser-button]"),
Expand Down
19 changes: 13 additions & 6 deletions packages/files-ui/cypress/support/utils/CustomBridge.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { Eip1193Bridge } from "@ethersproject/experimental/lib/eip1193-bridge"
import { ethers } from "ethers"
import { toUtf8String } from "ethers/lib/utils"
import { testAddress } from "../../fixtures/loginData"

export class CustomizedBridge extends Eip1193Bridge {
expectedAddress = ""

constructor(signer: ethers.Signer, address: string, provider?: ethers.providers.Provider) {
super(signer as any, provider as any)
this.expectedAddress = address
}

async sendAsync(...args: Array<any>) {
return this.send(...args)
}
Expand Down Expand Up @@ -30,17 +37,17 @@ export class CustomizedBridge extends Eip1193Bridge {
const message = params[0]

if (
(addr as string).toLowerCase() !== testAddress.toLowerCase()
(addr as string).toLowerCase() !== this.expectedAddress.toLowerCase()
) {
return Promise.reject(
`Wrong address, expected ${testAddress}, but got ${addr}`
`Wrong address, expected ${this.expectedAddress}, but got ${addr}`
)
}

try {
const sig = await this.signer.signMessage(toUtf8String(message))
return sig
} catch (e) {
} catch (e: any) {
return Promise.reject(
`Error in CustomizedBridge for personal_sign: ${e.message}`
)
Expand All @@ -49,9 +56,9 @@ export class CustomizedBridge extends Eip1193Bridge {

if (method === "eth_requestAccounts" || method === "eth_accounts") {
if (isCallbackForm) {
callback({ result: [testAddress] })
callback({ result: [this.expectedAddress] })
} else {
return Promise.resolve([testAddress])
return Promise.resolve([this.expectedAddress])
}
}

Expand Down
13 changes: 9 additions & 4 deletions packages/files-ui/cypress/tests/survey-banner-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe("Survey Banner", () => {
body: { [dismissedSurveyKey]: "false" }
})

cy.web3Login()
cy.web3Login({ withNewUser: false })
homePage.surveyBanner().should("be.visible")

// set up a spy for the POST response
Expand All @@ -42,7 +42,7 @@ describe("Survey Banner", () => {
body: { [dismissedSurveyKey]: "true" }
})

cy.web3Login()
cy.web3Login({ withNewUser: false })
homePage.surveyBanner().should("not.exist")
})

Expand All @@ -51,7 +51,7 @@ describe("Survey Banner", () => {
body: {}
})

cy.web3Login()
cy.web3Login({ withNewUser: false })
homePage.surveyBanner().should("be.visible")
})

Expand All @@ -67,7 +67,12 @@ describe("Survey Banner", () => {
body: {}
})

cy.web3Login()
cy.web3Login({ withNewUser: false })
homePage.surveyBanner().should("not.exist")
})

it("A new user should not see the banner", () => {
cy.web3Login({ withNewUser: true })
homePage.surveyBanner().should("not.exist")
})
})
Expand Down
3 changes: 3 additions & 0 deletions packages/files-ui/src/Components/Elements/PasswordForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,15 @@ const PasswordForm = ({ buttonLabel, setPassword }: Props) => {
label={t`Password:`}
labelClassName={classes.inputLabel}
captionMessage={<StrengthIndicator fieldName="password" />}
data-cy="sign-in-password-input"
/>
<FormikTextInput
type="password"
className={classes.input}
name="confirmPassword"
label={t`Confirm Password:`}
labelClassName={classes.inputLabel}
data-cy="sign-in-password-verification-input"
/>
<Button
className={clsx(classes.button, "passwordFormButton")}
Expand All @@ -119,6 +121,7 @@ const PasswordForm = ({ buttonLabel, setPassword }: Props) => {
type="submit"
loading={loading}
disabled={loading}
data-cy="sign-in-password-button"
>
{displayLabel}
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ const ConciseExplainer: React.FC<IConciseExplainerProps> = ({ className, onConti
variant="primary"
onClick={onContinue}
className={classes.continue}
data-cy="sign-in-explainer-continue-button"
>
<Trans>
Continue
Expand Down