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

Clarify in email hint text that shared inbox is not allowed #1746

Merged
merged 9 commits into from
Jan 29, 2024

Conversation

whabanks
Copy link
Contributor

Summary | Résumé

  • Changed the password field's validation message to clarify what a hard to guess password is
  • Fixed the aria-invalid attribute on text boxes
  • Add cypress tests for registration page
  • Use jsrsasign to generate JWTs for admin api access in cypress tests

- Changed the password field's validation message to clarify what a hard to guess password is
- Fixed the aria-invalid attribute on text boxes
- Add cypress tests for registration page
- Use jsrsasign to generate JWTs for admin api access in cypress tests
Copy link

@@ -9,12 +9,12 @@
"cypress-recurse": "^1.23.0",
"html-validate": "^8.7.1",
"imap-simple": "^5.1.0",
"jsonwebtoken": "^9.0.0",
"jsrsasign": "^11.0.0",
Copy link
Contributor Author

@whabanks whabanks Jan 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was tricky to get working. jsonwebtoken depends on the crypto node package which is server side, not browser facing. Suggestions online were to use polyfills to inject cyrpto into Cypress via cypress.config.js which in turn required additional node builtins like os and process. Switching to a pure JS lib made more sense instead of bulking up the webpack size.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting! No problem switching packages here, but curious what was the problem with jsonwebtoken to begin with?

Keep in mind all of these packages are separate from admin's npm packages - none of this is deployed/bundled with the app!

Copy link
Contributor Author

@whabanks whabanks Jan 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the sign class in jsonwebtoken it requires KeyObject, createSecretKey, createPublicKey from crypto which it is unable to resolve. The devs claim crypto is unresolvable because it's not intended to be accessed/executed from a browser environment but serverside where node.js is running.

It's odd to me though because we're using node 16 which includes the imports that jsonwebtoken requests from crypto. There seems to be some separation between what Cypress serves up for the browser gui / running tests, and the Cypress backend.

That said we can do some pretty neat stuff with polyfills by customizing Cypress's internal webpack config which I attempted initially with some success. But it resulted in bunch of odd stuff:

  • Import paths were different
  • The a11y suite completely broke
  • Specified imports like import { LoginPage } from "../../Notify/Admin/Pages/all" got really weird. It refused to import the specific class from the module, resulting in access looking like LoginPage.default.LoginPage.<someMethod()>

My guess is that we have to pass a webpack config of our own in to Cypress if we enable the webpack preprocessor to do polyfills.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. What was the issue with the JWTs though? They had been working in the rest of the test suite - unless a recent package update broke something?

Copy link
Contributor Author

@whabanks whabanks Jan 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm maybe a package update did break it. Whenever I called CreateJWT it failed on the call to jwt.sign() with KeyObject, createSecretKey, createPublicKey all being undefined.
Happy to dig a bit more, it's probably best to continue using jsonwebtoken at it seems to be the go to standard.

Copy link
Member

@andrewleith andrewleith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything works as expected, some comments on the tests but I think functionally we are good to go here.

@@ -9,12 +9,12 @@
"cypress-recurse": "^1.23.0",
"html-validate": "^8.7.1",
"imap-simple": "^5.1.0",
"jsonwebtoken": "^9.0.0",
"jsrsasign": "^11.0.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting! No problem switching packages here, but curious what was the problem with jsonwebtoken to begin with?

Keep in mind all of these packages are separate from admin's npm packages - none of this is deployed/bundled with the app!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

});

it('Succeeds with a valid form', () => {
CreateAccountPage.CreateAccount("john doe", "[email protected]", "16132532223", "BestPassword123!");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea on using aliases for this! 🏅

CreateAccountPage.CreateAccount("john doe", "[email protected]", "16132532223", "BestPassword123!");

// Ensure registration email is received and click registration link
cy.contains('p', 'To complete your registration for GC Notify, please click the link:').should('be.visible');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this test ensures the email is received, awesome! 🚀

tests_cypress/cypress/e2e/admin/register.cy.js Outdated Show resolved Hide resolved
whabanks and others added 3 commits January 29, 2024 14:36
- Pulled the wait for confirmation email code into it's own action and out of CreateAccount
- Added nanoid and use it for unique aliases on the email address
- Fetch the confirmation link in a more sane way
@whabanks whabanks merged commit 3e2c41a into main Jan 29, 2024
9 checks passed
@whabanks whabanks deleted the shared-inbox-hint-text branch January 29, 2024 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants