forked from compdemocracy/polis
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use nodemailer for sending email (with local email dev solution) (com…
…pdemocracy#433) * Updated database schema to bugfix password reset process. [Fixes compdemocracy#273] * Added maildev docker container for inspecting emails during dev. * Ensured the proxied services are seeing the origin host. * Small fixup from rebase. * Added SMTP port exposure to maildev container. * Migrated AWS_REGION config into envvar. * Added mailgun nodemailer transport. Added fallback through multiple transport mechanisms. * Added ability for cypress to check maildev inbox on another port. * e2e: Fixed create_user test. * e2e: Added checks of password reset flow. * e2e: Added test stubs for types of emails sent. * e2e: Run through whole password reset flow, and confirm new password. * e2e: Added plugin to output more details to stdout. * e2e: Make more clear when reporter prints to terminal. * Added log command for troubleshooting GitHub Actions issue. * e2e: Fixed issue with matching password reset token. * Added testing of email transport failover. * Adding docs for email transport configuration. [skip ci] * Check maildev via API instead of UI. * Improved documentation of cypress workflow for email transports. * e2e: Added note about cypress-terminal-report in README. * Removed straggling TODO. * Set email transport defaults to match current production.
- Loading branch information
Showing
18 changed files
with
937 additions
and
101 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 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
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
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 |
---|---|---|
@@ -0,0 +1,111 @@ | ||
describe('Emails', () => { | ||
const MAILDEV_HTTP_PORT = '1080' | ||
// See: https://github.com/maildev/maildev/blob/master/docs/rest.md | ||
const MAILDEV_API_BASE = `${Cypress.config().baseUrl}:${MAILDEV_HTTP_PORT}` | ||
|
||
beforeEach(() => { | ||
cy.server() | ||
cy.route('POST', Cypress.config().apiPath + '/auth/pwresettoken').as('resetPassword') | ||
|
||
cy.request('DELETE', MAILDEV_API_BASE + '/email/all') | ||
}) | ||
|
||
it('sends for failed password reset', function () { | ||
const nonExistingEmail = 'nonexistent@polis.test' | ||
cy.visit('/pwresetinit') | ||
cy.get('input[placeholder="email"]').type(nonExistingEmail) | ||
cy.contains('button', 'Send password reset email').click() | ||
cy.wait('@resetPassword').its('status').should('eq', 200) | ||
cy.location('pathname').should('eq', '/pwresetinit/done') | ||
|
||
cy.request('GET', MAILDEV_API_BASE + '/email') | ||
.then(resp => { | ||
const email = resp.body.shift() | ||
console.log(email) | ||
cy.wrap(email).its('subject').should('contain', 'Password Reset Failed') | ||
cy.wrap(email).its('to').its(0).its('address').should('contain', nonExistingEmail) | ||
}) | ||
}) | ||
|
||
it('sends for successful password reset', function () { | ||
// Create a new user account, so we can actually change password. | ||
const randomInt = Math.floor(Math.random() * 10000) | ||
const newUser = { | ||
email: `user${randomInt}@polis.test`, | ||
name: `Test User ${randomInt}`, | ||
password: 'testpassword', | ||
newPassword: 'newpassword', | ||
} | ||
|
||
const strictFail = true | ||
cy.signup(newUser.name, newUser.email, newUser.password, strictFail) | ||
|
||
cy.logout() | ||
|
||
// Request password reset on new account | ||
cy.visit('/pwresetinit') | ||
cy.get('input[placeholder="email"]').type(newUser.email) | ||
cy.contains('button', 'Send password reset email').click() | ||
cy.wait('@resetPassword').its('status').should('eq', 200) | ||
cy.location('pathname').should('eq', '/pwresetinit/done') | ||
|
||
cy.request('GET', MAILDEV_API_BASE + '/email') | ||
.then(resp => { | ||
const email = resp.body.shift() | ||
cy.wrap(email).its('subject').should('contain', 'Polis Password Reset') | ||
cy.wrap(email).its('to').its(0).its('address').should('contain', newUser.email) | ||
|
||
// Has password reset link with proper hostname. | ||
cy.wrap(email).its('text').should('contain', `${Cypress.config().baseUrl}/pwreset/`) | ||
|
||
const emailContent = email.text | ||
console.log(email) | ||
const tokenRegex = new RegExp('/pwreset/([a-zA-Z0-9]+)\n', 'g') | ||
const match = tokenRegex.exec(emailContent) | ||
// First "url" is email domain. Second url is the one we want. | ||
cy.log(JSON.stringify(match)) | ||
const passwordResetToken = match[1] | ||
|
||
// Submit password reset form with new password. | ||
cy.visit(`/pwreset/${passwordResetToken}`) | ||
|
||
cy.route('POST', Cypress.config().apiPath + '/auth/password').as('newPassword') | ||
|
||
cy.get('form').within(() => { | ||
cy.get('input[placeholder="new password"]').type(newUser.newPassword) | ||
cy.get('input[placeholder="repeat new password"]').type(newUser.newPassword) | ||
cy.get('button').click() | ||
}) | ||
|
||
cy.wait('@newPassword').then((xhr) => { | ||
expect(xhr.status).to.equal(200) | ||
}) | ||
}) | ||
|
||
cy.logout() | ||
|
||
// Login with new password. | ||
cy.login(newUser.email, newUser.newPassword) | ||
|
||
cy.url().should('eq', Cypress.config().baseUrl + '/') | ||
}) | ||
|
||
// TODO: Re-enabled account verification. | ||
it.skip('sends when new account requires verification', function () { | ||
}) | ||
|
||
// TODO: Allow batch interval to be skipped or reduced for tests. | ||
it.skip('sends when new statements arrive', function () { | ||
}) | ||
|
||
// TODO: Fix data export. | ||
it.skip('sends when data export is run', function () { | ||
}) | ||
|
||
// TODO: Find way to test embedded iframe. | ||
it.skip('sends when new conversation is auto-created', function () { | ||
}) | ||
|
||
it.skip('sends when new statement available for moderation', function () { | ||
}) | ||
}) |
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
Oops, something went wrong.