2019-01-02 12:58:55 +03:00
|
|
|
import {authenticateSession, invalidateSession} from 'ember-simple-auth/test-support';
|
2022-05-27 15:28:29 +03:00
|
|
|
import {blur, click, currentRouteName, fillIn, find, focus} from '@ember/test-helpers';
|
2019-01-02 12:58:55 +03:00
|
|
|
import {describe, it} from 'mocha';
|
2017-05-29 21:50:03 +03:00
|
|
|
import {expect} from 'chai';
|
2019-01-02 12:58:55 +03:00
|
|
|
import {setupApplicationTest} from 'ember-mocha';
|
2019-05-27 11:37:05 +03:00
|
|
|
import {setupMirage} from 'ember-cli-mirage/test-support';
|
2019-01-02 12:58:55 +03:00
|
|
|
import {visit} from '../helpers/visit';
|
2016-07-22 16:36:50 +03:00
|
|
|
|
2018-01-05 18:38:23 +03:00
|
|
|
describe('Acceptance: Signup', function () {
|
2019-01-02 12:58:55 +03:00
|
|
|
let hooks = setupApplicationTest();
|
|
|
|
setupMirage(hooks);
|
2016-07-22 16:36:50 +03:00
|
|
|
|
2018-01-05 18:38:23 +03:00
|
|
|
it('can signup successfully', async function () {
|
2019-01-02 12:58:55 +03:00
|
|
|
let server = this.server;
|
|
|
|
|
2016-11-14 16:16:51 +03:00
|
|
|
server.get('/authentication/invitation', function () {
|
2016-09-30 14:43:40 +03:00
|
|
|
return {
|
|
|
|
invitation: [{valid: true}]
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2017-01-02 21:50:36 +03:00
|
|
|
server.post('/authentication/invitation/', function ({users}, {requestBody}) {
|
|
|
|
let params = JSON.parse(requestBody);
|
2016-09-30 14:43:40 +03:00
|
|
|
expect(params.invitation[0].name).to.equal('Test User');
|
|
|
|
expect(params.invitation[0].email).to.equal('kevin+test2@ghost.org');
|
2017-10-26 13:02:17 +03:00
|
|
|
expect(params.invitation[0].password).to.equal('thisissupersafe');
|
2016-09-30 14:43:40 +03:00
|
|
|
expect(params.invitation[0].token).to.equal('MTQ3MDM0NjAxNzkyOXxrZXZpbit0ZXN0MkBnaG9zdC5vcmd8MmNEblFjM2c3ZlFUajluTks0aUdQU0dmdm9ta0xkWGY2OEZ1V2dTNjZVZz0');
|
|
|
|
|
|
|
|
// ensure that `/users/me/` request returns a user
|
2017-01-02 21:50:36 +03:00
|
|
|
let role = server.create('role', {name: 'Author'});
|
|
|
|
users.create({email: 'kevin@test2@ghost.org', roles: [role]});
|
2016-09-30 14:43:40 +03:00
|
|
|
|
|
|
|
return {
|
|
|
|
invitation: [{
|
|
|
|
message: 'Invitation accepted.'
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2016-07-22 16:36:50 +03:00
|
|
|
// token details:
|
|
|
|
// "1470346017929|kevin+test2@ghost.org|2cDnQc3g7fQTj9nNK4iGPSGfvomkLdXf68FuWgS66Ug="
|
2017-04-24 15:29:48 +03:00
|
|
|
await visit('/signup/MTQ3MDM0NjAxNzkyOXxrZXZpbit0ZXN0MkBnaG9zdC5vcmd8MmNEblFjM2c3ZlFUajluTks0aUdQU0dmdm9ta0xkWGY2OEZ1V2dTNjZVZz0');
|
2016-07-22 16:36:50 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
expect(currentRouteName()).to.equal('signup');
|
2016-07-22 16:36:50 +03:00
|
|
|
|
|
|
|
// focus out in Name field triggers inline error
|
2022-05-27 15:28:29 +03:00
|
|
|
await focus('[data-test-input="name"]');
|
2019-01-31 13:27:40 +03:00
|
|
|
await blur('[data-test-input="name"]');
|
2016-07-22 16:36:50 +03:00
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
expect(
|
2019-01-31 13:27:40 +03:00
|
|
|
find('[data-test-input="name"]').closest('.form-group'),
|
2017-04-24 15:29:48 +03:00
|
|
|
'name field group has error class when empty'
|
2019-01-02 12:58:55 +03:00
|
|
|
).to.have.class('error');
|
2016-07-22 16:36:50 +03:00
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
expect(
|
2019-01-31 13:27:40 +03:00
|
|
|
find('[data-test-input="name"]').closest('.form-group').querySelector('.response').textContent,
|
2017-04-24 15:29:48 +03:00
|
|
|
'name inline-error text'
|
2019-01-02 12:58:55 +03:00
|
|
|
).to.have.string('Please enter a name');
|
2016-07-22 16:36:50 +03:00
|
|
|
|
|
|
|
// entering text in Name field clears error
|
2019-01-31 13:27:40 +03:00
|
|
|
await fillIn('[data-test-input="name"]', 'Test User');
|
|
|
|
await blur('[data-test-input="name"]');
|
2016-07-22 16:36:50 +03:00
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
expect(
|
2019-01-31 13:27:40 +03:00
|
|
|
find('[data-test-input="name"]').closest('.form-group'),
|
2017-04-24 15:29:48 +03:00
|
|
|
'name field loses error class after text input'
|
2019-01-02 12:58:55 +03:00
|
|
|
).to.not.have.class('error');
|
2016-07-22 16:36:50 +03:00
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
expect(
|
2019-01-31 13:27:40 +03:00
|
|
|
find('[data-test-input="name"]').closest('.form-group').querySelector('.response').textContent.trim(),
|
2017-04-24 15:29:48 +03:00
|
|
|
'name field error is removed after text input'
|
2019-01-02 12:58:55 +03:00
|
|
|
).to.be.empty;
|
2016-07-22 16:36:50 +03:00
|
|
|
|
2019-02-11 15:35:47 +03:00
|
|
|
// focus out in Email field triggers inline error
|
2019-02-11 16:52:51 +03:00
|
|
|
await click('[data-test-input="email"]');
|
2019-02-11 15:35:47 +03:00
|
|
|
await blur('[data-test-input="email"]');
|
|
|
|
|
|
|
|
expect(
|
|
|
|
find('[data-test-input="email"]').closest('.form-group'),
|
|
|
|
'email field group has error class when empty'
|
|
|
|
).to.have.class('error');
|
|
|
|
|
|
|
|
expect(
|
|
|
|
find('[data-test-input="email"]').closest('.form-group').querySelector('.response').textContent,
|
|
|
|
'email inline-error text'
|
|
|
|
).to.have.string('Please enter an email');
|
|
|
|
|
|
|
|
// entering text in email field clears error
|
|
|
|
await fillIn('[data-test-input="email"]', 'kevin+test2@ghost.org');
|
|
|
|
await blur('[data-test-input="email"]');
|
|
|
|
|
|
|
|
expect(
|
|
|
|
find('[data-test-input="email"]').closest('.form-group'),
|
|
|
|
'email field loses error class after text input'
|
|
|
|
).to.not.have.class('error');
|
|
|
|
|
|
|
|
expect(
|
|
|
|
find('[data-test-input="email"]').closest('.form-group').querySelector('.response').textContent.trim(),
|
|
|
|
'email field error is removed after text input'
|
|
|
|
).to.be.empty;
|
|
|
|
|
2017-10-26 13:02:17 +03:00
|
|
|
// check password validation
|
|
|
|
// focus out in password field triggers inline error
|
|
|
|
// no password
|
2019-01-31 13:27:40 +03:00
|
|
|
await click('[data-test-input="password"]');
|
2019-01-02 12:58:55 +03:00
|
|
|
await blur();
|
2016-07-22 16:36:50 +03:00
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
expect(
|
2019-01-31 13:27:40 +03:00
|
|
|
find('[data-test-input="password"]').closest('.form-group'),
|
2017-04-24 15:29:48 +03:00
|
|
|
'password field group has error class when empty'
|
2019-01-02 12:58:55 +03:00
|
|
|
).to.have.class('error');
|
2016-07-22 16:36:50 +03:00
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
expect(
|
2019-01-31 13:27:40 +03:00
|
|
|
find('[data-test-input="password"]').closest('.form-group').querySelector('.response').textContent,
|
2017-04-24 15:29:48 +03:00
|
|
|
'password field error text'
|
2019-01-02 12:58:55 +03:00
|
|
|
).to.have.string('must be at least 10 characters');
|
2016-07-22 16:36:50 +03:00
|
|
|
|
2017-10-26 13:02:17 +03:00
|
|
|
// password too short
|
2019-01-31 13:27:40 +03:00
|
|
|
await fillIn('[data-test-input="password"]', 'short');
|
|
|
|
await blur('[data-test-input="password"]');
|
2017-10-26 13:02:17 +03:00
|
|
|
|
|
|
|
expect(
|
2019-01-31 13:27:40 +03:00
|
|
|
find('[data-test-input="password"]').closest('.form-group').querySelector('.response').textContent,
|
2017-10-26 13:02:17 +03:00
|
|
|
'password field error text'
|
2019-01-02 12:58:55 +03:00
|
|
|
).to.have.string('must be at least 10 characters');
|
2017-10-26 13:02:17 +03:00
|
|
|
|
|
|
|
// password must not be a bad password
|
2019-01-31 13:27:40 +03:00
|
|
|
await fillIn('[data-test-input="password"]', '1234567890');
|
|
|
|
await blur('[data-test-input="password"]');
|
2017-10-26 13:02:17 +03:00
|
|
|
|
|
|
|
expect(
|
2019-01-31 13:27:40 +03:00
|
|
|
find('[data-test-input="password"]').closest('.form-group').querySelector('.response').textContent,
|
2017-10-26 13:02:17 +03:00
|
|
|
'password field error text'
|
2019-01-02 12:58:55 +03:00
|
|
|
).to.have.string('you cannot use an insecure password');
|
2017-10-26 13:02:17 +03:00
|
|
|
|
|
|
|
// password must not be a disallowed password
|
2019-01-31 13:27:40 +03:00
|
|
|
await fillIn('[data-test-input="password"]', 'password99');
|
|
|
|
await blur('[data-test-input="password"]');
|
2017-10-26 13:02:17 +03:00
|
|
|
|
|
|
|
expect(
|
2019-01-31 13:27:40 +03:00
|
|
|
find('[data-test-input="password"]').closest('.form-group').querySelector('.response').textContent,
|
2017-10-26 13:02:17 +03:00
|
|
|
'password field error text'
|
2019-01-02 12:58:55 +03:00
|
|
|
).to.have.string('you cannot use an insecure password');
|
2017-10-26 13:02:17 +03:00
|
|
|
|
|
|
|
// password must not have repeating characters
|
2019-01-31 13:27:40 +03:00
|
|
|
await fillIn('[data-test-input="password"]', '2222222222');
|
|
|
|
await blur('[data-test-input="password"]');
|
2017-10-26 13:02:17 +03:00
|
|
|
|
|
|
|
expect(
|
2019-01-31 13:27:40 +03:00
|
|
|
find('[data-test-input="password"]').closest('.form-group').querySelector('.response').textContent,
|
2017-10-26 13:02:17 +03:00
|
|
|
'password field error text'
|
2019-01-02 12:58:55 +03:00
|
|
|
).to.have.string('you cannot use an insecure password');
|
2017-10-26 13:02:17 +03:00
|
|
|
|
2016-07-22 16:36:50 +03:00
|
|
|
// entering valid text in Password field clears error
|
2019-01-31 13:27:40 +03:00
|
|
|
await fillIn('[data-test-input="password"]', 'thisissupersafe');
|
|
|
|
await blur('[data-test-input="password"]');
|
2016-07-22 16:36:50 +03:00
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
expect(
|
2019-01-31 13:27:40 +03:00
|
|
|
find('[data-test-input="password"]').closest('.form-group'),
|
2017-04-24 15:29:48 +03:00
|
|
|
'password field loses error class after text input'
|
2019-01-02 12:58:55 +03:00
|
|
|
).to.not.have.class('error');
|
2016-07-22 16:36:50 +03:00
|
|
|
|
2017-04-24 15:29:48 +03:00
|
|
|
expect(
|
2019-01-31 13:27:40 +03:00
|
|
|
find('[data-test-input="password"]').closest('.form-group').querySelector('.response').textContent.trim(),
|
2017-04-24 15:29:48 +03:00
|
|
|
'password field error is removed after text input'
|
|
|
|
).to.equal('');
|
2016-07-22 16:36:50 +03:00
|
|
|
|
|
|
|
// submitting sends correct details and redirects to content screen
|
2022-03-08 20:30:46 +03:00
|
|
|
await click('[data-test-button="signup"]');
|
2016-07-22 16:36:50 +03:00
|
|
|
|
2021-02-24 18:56:18 +03:00
|
|
|
expect(currentRouteName()).to.equal('site');
|
2016-07-22 16:36:50 +03:00
|
|
|
});
|
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
it('redirects if already logged in', async function () {
|
|
|
|
this.server.get('/authentication/invitation', function () {
|
|
|
|
return {
|
|
|
|
invitation: [{valid: true}]
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
let role = this.server.create('role', {name: 'Author'});
|
|
|
|
this.server.create('user', {roles: [role], slug: 'test-user'});
|
|
|
|
|
|
|
|
await authenticateSession();
|
|
|
|
// token details:
|
|
|
|
// "1470346017929|kevin+test2@ghost.org|2cDnQc3g7fQTj9nNK4iGPSGfvomkLdXf68FuWgS66Ug="
|
|
|
|
await visit('/signup/MTQ3MDM0NjAxNzkyOXxrZXZpbit0ZXN0MkBnaG9zdC5vcmd8MmNEblFjM2c3ZlFUajluTks0aUdQU0dmdm9ta0xkWGY2OEZ1V2dTNjZVZz0');
|
|
|
|
|
2021-02-24 18:56:18 +03:00
|
|
|
expect(currentRouteName()).to.equal('site');
|
2019-01-02 12:58:55 +03:00
|
|
|
expect(find('.gh-alert-content').textContent).to.have.string('sign out to register');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('redirects with alert on invalid token', async function () {
|
|
|
|
await invalidateSession();
|
|
|
|
await visit('/signup/---invalid---');
|
|
|
|
|
|
|
|
expect(currentRouteName()).to.equal('signin');
|
|
|
|
expect(find('.gh-alert-content').textContent).to.have.string('Invalid token');
|
|
|
|
});
|
|
|
|
|
2023-10-31 18:21:44 +03:00
|
|
|
it('redirects with alert on non-existent or expired token', async function () {
|
2019-01-02 12:58:55 +03:00
|
|
|
this.server.get('/authentication/invitation', function () {
|
|
|
|
return {
|
|
|
|
invitation: [{valid: false}]
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
await invalidateSession();
|
|
|
|
await visit('/signup/expired');
|
|
|
|
|
|
|
|
expect(currentRouteName()).to.equal('signin');
|
|
|
|
expect(find('.gh-alert-content').textContent).to.have.string('not exist');
|
|
|
|
});
|
2016-07-22 16:36:50 +03:00
|
|
|
});
|