1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-08-08 15:05:28 +02:00

WIP fix sso test

This commit is contained in:
zinyando 2016-07-06 00:36:29 +02:00
parent 3dccfc6a24
commit 7955da433c
6 changed files with 654 additions and 611 deletions

View file

@ -7,9 +7,10 @@ export default Ember.Route.extend({
this.get("session").authenticate('authenticator:documize', token) this.get("session").authenticate('authenticator:documize', token)
.then(() => { .then(() => {
this.transitionTo('folders.folder'); this.transitionTo('folders.folder');
}, () => { })
.catch(() => {
this.transitionTo('auth.login'); this.transitionTo('auth.login');
console.log(">>>>> Documize SSO failure"); console.log(">>>>> Documize SSO failure");
}); });
}, }
}); });

View file

@ -1,15 +1,17 @@
export default function() { import Mirage from 'ember-cli-mirage';
export default function () {
this.passthrough('https://widget.intercom.io/widget/%7Bapp_id%7D'); this.passthrough('https://widget.intercom.io/widget/%7Bapp_id%7D');
this.urlPrefix = 'https://localhost:5001'; // make this `http://localhost:8080`, for example, if your API is on a different server this.urlPrefix = 'https://localhost:5001'; // make this `http://localhost:8080`, for example, if your API is on a different server
this.namespace = 'api'; // make this `api`, for example, if your API is namespaced this.namespace = 'api'; // make this `api`, for example, if your API is namespaced
// this.timing = 400; // delay for each request, automatically set to 0 during testing // this.timing = 400; // delay for each request, automatically set to 0 during testing
this.get('/public/meta', function(schema) { this.get('/public/meta', function (schema) {
return schema.db.meta[0]; return schema.db.meta[0];
}); });
this.get('/public/validate', function(schema, request) { this.get('/public/validate', function (schema, request) {
let serverToken = request.queryParams.token; let serverToken = request.queryParams.token;
let token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkb21haW4iOiIiLCJleHAiOjE0NjQwMjM2NjcsImlzcyI6IkRvY3VtaXplIiwib3JnIjoiVnpNdXlFd18zV3FpYWZjRCIsInN1YiI6IndlYmFwcCIsInVzZXIiOiJWek11eUV3XzNXcWlhZmNFIn0.NXZ6bo8mtvdZF_b9HavbidVUJqhmBA1zr0fSAPvbah0"; let token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkb21haW4iOiIiLCJleHAiOjE0NjQwMjM2NjcsImlzcyI6IkRvY3VtaXplIiwib3JnIjoiVnpNdXlFd18zV3FpYWZjRCIsInN1YiI6IndlYmFwcCIsInVzZXIiOiJWek11eUV3XzNXcWlhZmNFIn0.NXZ6bo8mtvdZF_b9HavbidVUJqhmBA1zr0fSAPvbah0";
@ -42,7 +44,7 @@ export default function() {
} }
}); });
this.get('/users/0/permissions', function() { this.get('/users/0/permissions', function () {
return [{ return [{
"folderId": "VzMygEw_3WrtFzto", "folderId": "VzMygEw_3WrtFzto",
"userId": "", "userId": "",
@ -51,11 +53,11 @@ export default function() {
}]; }];
}); });
this.get('/templates', function() { this.get('/templates', function () {
return []; return [];
}); });
this.get('/documents', function(schema, request) { this.get('/documents', function (schema, request) {
let folder_id = request.queryParams.folder; let folder_id = request.queryParams.folder;
if (folder_id = "VzMuyEw_3WqiafcG") { if (folder_id = "VzMuyEw_3WqiafcG") {
@ -96,32 +98,37 @@ export default function() {
"userId": "VzMuyEw_3WqiafcE", "userId": "VzMuyEw_3WqiafcE",
"folderType": 1 "folderType": 1
}; };
} else if (folder_id = 'V0Vy5Uw_3QeDAMW9'){ } else if (folder_id = 'V0Vy5Uw_3QeDAMW9') {
return null; return null;
} }
}); });
this.get('/folders', function(schema) { this.get('/folders', function (schema) {
return schema.db.folders; return schema.db.folders;
}); });
this.post('/folders', function(schema, request) { this.post('/folders', function (schema, request) {
var name = JSON.parse(request.requestBody).name; var name = JSON.parse(request.requestBody).name;
let newFolder = { let newFolder = {
"id":"V0Vy5Uw_3QeDAMW9", "id": "V0Vy5Uw_3QeDAMW9",
"created":"2016-05-25T09:39:49Z", "created": "2016-05-25T09:39:49Z",
"revised":"2016-05-25T09:39:49Z", "revised": "2016-05-25T09:39:49Z",
"name":name, "name": name,
"orgId":"VzMuyEw_3WqiafcD", "orgId": "VzMuyEw_3WqiafcD",
"userId":"VzMuyEw_3WqiafcE", "userId": "VzMuyEw_3WqiafcE",
"folderType":2 "folderType": 2
}; };
let folder = schema.db.folders.insert(newFolder); let folder = schema.db.folders.insert(newFolder);
return folder; return folder;
}); });
this.post('/public/authenticate', () => { this.post('/public/authenticate', (schema, request) => {
debugger;
let authorization = request.requestHeaders.Authorization;
let expectedAuthorization = "Basic OmJyaXpkaWdpdGFsQGdtYWlsLmNvbTp6aW55YW5kbzEyMw==";
if (expectedAuthorization == authorization) {
return { return {
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkb21haW4iOiIiLCJleHAiOjE0NjQwMjM2NjcsImlzcyI6IkRvY3VtaXplIiwib3JnIjoiVnpNdXlFd18zV3FpYWZjRCIsInN1YiI6IndlYmFwcCIsInVzZXIiOiJWek11eUV3XzNXcWlhZmNFIn0.NXZ6bo8mtvdZF_b9HavbidVUJqhmBA1zr0fSAPvbah0", "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkb21haW4iOiIiLCJleHAiOjE0NjQwMjM2NjcsImlzcyI6IkRvY3VtaXplIiwib3JnIjoiVnpNdXlFd18zV3FpYWZjRCIsInN1YiI6IndlYmFwcCIsInVzZXIiOiJWek11eUV3XzNXcWlhZmNFIn0.NXZ6bo8mtvdZF_b9HavbidVUJqhmBA1zr0fSAPvbah0",
"user": { "user": {
@ -150,6 +157,39 @@ export default function() {
}] }]
} }
}; };
} else if (expectedAuthorization != authorization) {
return new Mirage.Response(400);
} else {
return {
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkb21haW4iOiIiLCJleHAiOjE0NjQwMjM2NjcsImlzcyI6IkRvY3VtaXplIiwib3JnIjoiVnpNdXlFd18zV3FpYWZjRCIsInN1YiI6IndlYmFwcCIsInVzZXIiOiJWek11eUV3XzNXcWlhZmNFIn0.NXZ6bo8mtvdZF_b9HavbidVUJqhmBA1zr0fSAPvbah0",
"user": {
"id": "VzMuyEw_3WqiafcE",
"created": "2016-05-11T15:08:24Z",
"revised": "2016-05-11T15:08:24Z",
"firstname": "Lennex",
"lastname": "Zinyando",
"email": "brizdigital@gmail.com",
"initials": "LZ",
"active": true,
"editor": true,
"admin": true,
"accounts": [{
"id": "VzMuyEw_3WqiafcF",
"created": "2016-05-11T15:08:24Z",
"revised": "2016-05-11T15:08:24Z",
"admin": true,
"editor": true,
"userId": "VzMuyEw_3WqiafcE",
"orgId": "VzMuyEw_3WqiafcD",
"company": "EmberSherpa",
"title": "EmberSherpa",
"message": "This Documize instance contains all our team documentation",
"domain": ""
}]
}
};
}
}); });
this.get('/users/VzMuyEw_3WqiafcE/permissions', (schema) => { this.get('/users/VzMuyEw_3WqiafcE/permissions', (schema) => {
@ -157,49 +197,43 @@ export default function() {
}); });
this.get('/folders/VzMuyEw_3WqiafcG/permissions', () => { this.get('/folders/VzMuyEw_3WqiafcG/permissions', () => {
return [ return [{
{ "folderId": "VzMuyEw_3WqiafcG",
"folderId":"VzMuyEw_3WqiafcG", "userId": "VzMuyEw_3WqiafcE",
"userId":"VzMuyEw_3WqiafcE", "canView": true,
"canView":true, "canEdit": true
"canEdit":true }];
}
];
}); });
this.put('/folders/VzMygEw_3WrtFzto/permissions', () => { this.put('/folders/VzMygEw_3WrtFzto/permissions', () => {
return [ return [{
{ "orgId": "VzMuyEw_3WqiafcD",
"orgId":"VzMuyEw_3WqiafcD", "folderId": "VzMygEw_3WrtFzto",
"folderId":"VzMygEw_3WrtFzto", "userId": "",
"userId":"", "canEdit": true,
"canEdit":true, "canView": true
"canView":true }, {
},{ "orgId": "VzMuyEw_3WqiafcD",
"orgId":"VzMuyEw_3WqiafcD", "folderId": "VzMygEw_3WrtFzto",
"folderId":"VzMygEw_3WrtFzto", "userId": "VzMyp0w_3WrtFztq",
"userId":"VzMyp0w_3WrtFztq", "canEdit": false,
"canEdit":false, "canView": false
"canView":false }, {
},{ "orgId": "",
"orgId":"", "folderId": "VzMygEw_3WrtFzto",
"folderId":"VzMygEw_3WrtFzto", "userId": "VzMuyEw_3WqiafcE",
"userId":"VzMuyEw_3WqiafcE", "canEdit": true,
"canEdit":true, "canView": true
"canView":true }];
}
];
}); });
this.get('/folders/VzMygEw_3WrtFzto/permissions', () => { this.get('/folders/VzMygEw_3WrtFzto/permissions', () => {
return [ return [{
{ "folderId": "VzMygEw_3WrtFzto",
"folderId":"VzMygEw_3WrtFzto", "userId": "VzMuyEw_3WqiafcE",
"userId":"VzMuyEw_3WqiafcE", "canView": true,
"canView":true, "canEdit": true
"canEdit":true }];
}
];
}); });
this.put('/folders/:id', (schema, request) => { this.put('/folders/:id', (schema, request) => {
@ -211,13 +245,13 @@ export default function() {
this.put('/folders/V0Vy5Uw_3QeDAMW9', () => { this.put('/folders/V0Vy5Uw_3QeDAMW9', () => {
return { return {
"id":"V0Vy5Uw_3QeDAMW9", "id": "V0Vy5Uw_3QeDAMW9",
"created":"2016-05-25T09:39:49Z", "created": "2016-05-25T09:39:49Z",
"revised":"2016-05-25T09:39:49Z", "revised": "2016-05-25T09:39:49Z",
"name":"Test Folder", "name": "Test Folder",
"orgId":"VzMuyEw_3WqiafcD", "orgId": "VzMuyEw_3WqiafcD",
"userId":"VzMuyEw_3WqiafcE", "userId": "VzMuyEw_3WqiafcE",
"folderType":2 "folderType": 2
}; };
}); });
@ -316,59 +350,59 @@ export default function() {
let email = JSON.parse(request.requestBody).email; let email = JSON.parse(request.requestBody).email;
return { return {
"id":"V0RmtUw_3QeDAMW7", "id": "V0RmtUw_3QeDAMW7",
"created":"2016-05-24T14:35:33Z", "created": "2016-05-24T14:35:33Z",
"revised":"2016-05-24T14:35:33Z", "revised": "2016-05-24T14:35:33Z",
"firstname":`${firstname}`, "firstname": `${firstname}`,
"lastname":`${lastname}`, "lastname": `${lastname}`,
"email":`${email}`, "email": `${email}`,
"initials":"TU", "initials": "TU",
"active":true, "active": true,
"editor":true, "editor": true,
"admin":false, "admin": false,
"accounts":[{ "accounts": [{
"id":"V0RmtUw_3QeDAMW8", "id": "V0RmtUw_3QeDAMW8",
"created":"2016-05-24T14:35:34Z", "created": "2016-05-24T14:35:34Z",
"revised":"2016-05-24T14:35:34Z", "revised": "2016-05-24T14:35:34Z",
"admin":false, "admin": false,
"editor":true, "editor": true,
"userId":"V0RmtUw_3QeDAMW7", "userId": "V0RmtUw_3QeDAMW7",
"orgId":"VzMuyEw_3WqiafcD", "orgId": "VzMuyEw_3WqiafcD",
"company":"EmberSherpa", "company": "EmberSherpa",
"title":"EmberSherpa", "title": "EmberSherpa",
"message":"This Documize instance contains all our team documentation", "message": "This Documize instance contains all our team documentation",
"domain":"" "domain": ""
} }]
]}; };
}); });
this.get('/users/VzMuyEw_3WqiafcE', () => { this.get('/users/VzMuyEw_3WqiafcE', () => {
return { return {
"id":"VzMuyEw_3WqiafcE", "id": "VzMuyEw_3WqiafcE",
"created":"2016-05-11T15:08:24Z", "created": "2016-05-11T15:08:24Z",
"revised":"2016-05-11T15:08:24Z", "revised": "2016-05-11T15:08:24Z",
"firstname":"Lennex", "firstname": "Lennex",
"lastname":"Zinyando", "lastname": "Zinyando",
"email":"brizdigital@gmail.com", "email": "brizdigital@gmail.com",
"initials":"LZ", "initials": "LZ",
"active":true, "active": true,
"editor":true, "editor": true,
"admin":true, "admin": true,
"accounts":[{ "accounts": [{
"id":"VzMuyEw_3WqiafcF", "id": "VzMuyEw_3WqiafcF",
"created":"2016-05-11T15:08:24Z", "created": "2016-05-11T15:08:24Z",
"revised":"2016-05-11T15:08:24Z", "revised": "2016-05-11T15:08:24Z",
"admin":true, "admin": true,
"editor":true, "editor": true,
"userId":"VzMuyEw_3WqiafcE", "userId": "VzMuyEw_3WqiafcE",
"orgId":"VzMuyEw_3WqiafcD", "orgId": "VzMuyEw_3WqiafcD",
"company":"EmberSherpa", "company": "EmberSherpa",
"title":"EmberSherpa", "title": "EmberSherpa",
"message":"This Documize instance contains all our team documentation", "message": "This Documize instance contains all our team documentation",
"domain":"" "domain": ""
} }]
]}; };
}); });
this.put('/users/VzMuyEw_3WqiafcE', (schema, request) => { this.put('/users/VzMuyEw_3WqiafcE', (schema, request) => {
@ -377,30 +411,30 @@ export default function() {
let email = JSON.parse(request.requestBody).email; let email = JSON.parse(request.requestBody).email;
return { return {
"id":"VzMuyEw_3WqiafcE", "id": "VzMuyEw_3WqiafcE",
"created":"2016-05-11T15:08:24Z", "created": "2016-05-11T15:08:24Z",
"revised":"2016-05-11T15:08:24Z", "revised": "2016-05-11T15:08:24Z",
"firstname":`${firstname}`, "firstname": `${firstname}`,
"lastname":`${lastname}`, "lastname": `${lastname}`,
"email":`${email}`, "email": `${email}`,
"initials":"LZ", "initials": "LZ",
"active":true, "active": true,
"editor":true, "editor": true,
"admin":true, "admin": true,
"accounts":[{ "accounts": [{
"id":"VzMuyEw_3WqiafcF", "id": "VzMuyEw_3WqiafcF",
"created":"2016-05-11T15:08:24Z", "created": "2016-05-11T15:08:24Z",
"revised":"2016-05-11T15:08:24Z", "revised": "2016-05-11T15:08:24Z",
"admin":true, "admin": true,
"editor":true, "editor": true,
"userId":"VzMuyEw_3WqiafcE", "userId": "VzMuyEw_3WqiafcE",
"orgId":"VzMuyEw_3WqiafcD", "orgId": "VzMuyEw_3WqiafcD",
"company":"EmberSherpa", "company": "EmberSherpa",
"title":"EmberSherpa", "title": "EmberSherpa",
"message":"This Documize instance contains all our team documentation", "message": "This Documize instance contains all our team documentation",
"domain":"" "domain": ""
} }]
]}; };
}); });
this.post('/folders/VzMuyEw_3WqiafcG/invitation', () => { this.post('/folders/VzMuyEw_3WqiafcG/invitation', () => {
@ -410,11 +444,11 @@ export default function() {
/** /**
very helpful for debugging very helpful for debugging
*/ */
this.handledRequest = function(verb, path) { this.handledRequest = function (verb, path) {
console.log(`👊${verb} ${path}`); console.log(`👊${verb} ${path}`);
}; };
this.unhandledRequest = function(verb, path) { this.unhandledRequest = function (verb, path) {
console.log(`🔥${verb} ${path}`); console.log(`🔥${verb} ${path}`);
}; };

View file

@ -7,7 +7,6 @@ test('visiting / when not authenticated and with { allowAnonymousAccess: true }
server.create('meta', { allowAnonymousAccess: true }); server.create('meta', { allowAnonymousAccess: true });
server.createList('folder', 2); server.createList('folder', 2);
visit('/'); visit('/');
// return pauseTest();
andThen(function () { andThen(function () {
assert.equal(find('.login').length, 1, 'Login button is displayed'); assert.equal(find('.login').length, 1, 'Login button is displayed');

View file

@ -13,7 +13,7 @@ test('visiting /auth/login and logging in', function (assert) {
click('button'); click('button');
andThen(function () { andThen(function () {
assert.equal(currentURL(), '/s/VzMygEw_3WrtFzto/test', 'Login successfull'); assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project', 'Login successful');
}); });
}); });
@ -25,18 +25,29 @@ test('logging out a user', function (assert) {
visit('/auth/logout'); visit('/auth/logout');
andThen(function () { andThen(function () {
assert.equal(currentURL(), '/auth/login', 'Logging out successfull'); assert.equal(currentURL(), '/auth/login', 'Logging out successful');
}); });
}); });
test('sso login', function (assert) { test('successful sso login authenticates redirects to dashboard', function (assert) {
server.create('meta', { allowAnonymousAccess: false }); server.create('meta', { allowAnonymousAccess: false });
server.createList('folder', 2); server.createList('folder', 2);
userLogin();
visit('/auth/sso/OmJyaXpkaWdpdGFsQGdtYWlsLmNvbTp6aW55YW5kbzEyMw=='); visit('/auth/sso/OmJyaXpkaWdpdGFsQGdtYWlsLmNvbTp6aW55YW5kbzEyMw==');
// return pauseTest();
andThen(function () { andThen(function () {
assert.equal(currentURL(), '/s/VzMygEw_3WrtFzto/test', 'Login successfull'); assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project', 'SSO login successful');
});
});
test('sso login with bad token should redirect to login', function (assert) {
server.create('meta', { allowAnonymousAccess: false });
server.createList('folder', 2);
visit('/auth/sso/randomToken1234567890');
andThen(function () {
assert.equal(currentURL(), '/auth/login', 'SSO login unsuccessful');
}); });
}); });

View file

@ -48,7 +48,6 @@ skip('Adding a document to a space', function (assert) {
let numberOfDocuments = find('.documents-list li').length; let numberOfDocuments = find('.documents-list li').length;
assert.equal(numberOfDocuments, 3, '3 documents listed'); assert.equal(numberOfDocuments, 3, '3 documents listed');
assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project'); assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project');
// return pauseTest();
}); });
}); });
@ -130,7 +129,6 @@ test('changing space permissions', function (assert) {
click('.button-blue'); click('.button-blue');
visit('/s/VzMygEw_3WrtFzto/test'); visit('/s/VzMygEw_3WrtFzto/test');
// return pauseTest();
andThen(function () { andThen(function () {
let numberOfPublicFolders = find('.folders-list div:contains(EVERYONE) .list a').length; let numberOfPublicFolders = find('.folders-list div:contains(EVERYONE) .list a').length;