2015-11-04 18:20:11 +03:00
|
|
|
/* jshint expr:true */
|
|
|
|
import {
|
|
|
|
describe,
|
|
|
|
it,
|
|
|
|
beforeEach,
|
|
|
|
afterEach
|
|
|
|
} from 'mocha';
|
|
|
|
import { expect } from 'chai';
|
|
|
|
import Ember from 'ember';
|
|
|
|
import startApp from '../helpers/start-app';
|
2015-11-30 20:21:39 +03:00
|
|
|
import destroyApp from '../helpers/destroy-app';
|
2015-11-04 18:20:11 +03:00
|
|
|
import { authenticateSession, currentSession, invalidateSession } from 'ghost/tests/helpers/ember-simple-auth';
|
|
|
|
import Mirage from 'ember-cli-mirage';
|
|
|
|
import windowProxy from 'ghost/utils/window-proxy';
|
|
|
|
|
|
|
|
describe('Acceptance: Authentication', function () {
|
|
|
|
let application,
|
|
|
|
originalReplaceLocation;
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
application = startApp();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function () {
|
2015-11-30 20:21:39 +03:00
|
|
|
destroyApp(application);
|
2015-11-04 18:20:11 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('general page', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
originalReplaceLocation = windowProxy.replaceLocation;
|
|
|
|
windowProxy.replaceLocation = function (url) {
|
|
|
|
visit(url);
|
|
|
|
};
|
|
|
|
|
|
|
|
server.loadFixtures();
|
2015-10-28 14:36:45 +03:00
|
|
|
let role = server.create('role', {name: 'Administrator'});
|
|
|
|
let user = server.create('user', {roles: [role], slug: 'test-user'});
|
2015-11-04 18:20:11 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
windowProxy.replaceLocation = originalReplaceLocation;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('invalidates session on 401 API response', function () {
|
|
|
|
// return a 401 when attempting to retrieve tags
|
|
|
|
server.get('/users/', (db, request) => {
|
|
|
|
return new Mirage.Response(401, {}, {
|
|
|
|
errors: [
|
|
|
|
{message: 'Access denied.', errorType: 'UnauthorizedError'}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
authenticateSession(application);
|
|
|
|
visit('/team');
|
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
expect(currentURL(), 'url after 401').to.equal('/signin');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('editor', function () {
|
|
|
|
let origDebounce = Ember.run.debounce;
|
|
|
|
let origThrottle = Ember.run.throttle;
|
|
|
|
|
|
|
|
// we don't want the autosave interfering in this test
|
|
|
|
beforeEach(function () {
|
|
|
|
Ember.run.debounce = function () { };
|
|
|
|
Ember.run.throttle = function () { };
|
|
|
|
});
|
|
|
|
|
|
|
|
it('displays re-auth modal attempting to save with invalid session', function () {
|
2015-10-28 14:36:45 +03:00
|
|
|
let role = server.create('role', {name: 'Administrator'});
|
|
|
|
let user = server.create('user', {roles: [role]});
|
2015-11-04 18:20:11 +03:00
|
|
|
|
|
|
|
// simulate an invalid session when saving the edited post
|
|
|
|
server.put('/posts/:id/', (db, request) => {
|
2015-10-28 14:36:45 +03:00
|
|
|
let post = db.posts.find(request.params.id);
|
|
|
|
let [attrs] = JSON.parse(request.requestBody).posts;
|
2015-11-04 18:20:11 +03:00
|
|
|
|
|
|
|
if (attrs.markdown === 'Edited post body') {
|
|
|
|
return new Mirage.Response(401, {}, {
|
|
|
|
errors: [
|
|
|
|
{message: 'Access denied.', errorType: 'UnauthorizedError'}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return {
|
|
|
|
posts: [post]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
server.loadFixtures();
|
|
|
|
authenticateSession(application);
|
|
|
|
|
|
|
|
visit('/editor');
|
|
|
|
|
|
|
|
// create the post
|
|
|
|
fillIn('#entry-title', 'Test Post');
|
|
|
|
fillIn('textarea.markdown-editor', 'Test post body');
|
|
|
|
click('.js-publish-button');
|
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
// we shouldn't have a modal at this point
|
|
|
|
expect(find('.modal-container #login').length, 'modal exists').to.equal(0);
|
|
|
|
// we also shouldn't have any alerts
|
|
|
|
expect(find('.gh-alert').length, 'no of alerts').to.equal(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
// update the post
|
|
|
|
fillIn('textarea.markdown-editor', 'Edited post body');
|
|
|
|
click('.js-publish-button');
|
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
// we should see a re-auth modal
|
|
|
|
expect(find('.modal-container #login').length, 'modal exists').to.equal(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// don't clobber debounce/throttle for future tests
|
|
|
|
afterEach(function () {
|
|
|
|
Ember.run.debounce = origDebounce;
|
|
|
|
Ember.run.throttle = origThrottle;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|