1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-08-08 06:55: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

@ -5,55 +5,55 @@ import netUtil from '../utils/net';
import models from '../utils/model'; import models from '../utils/model';
const { const {
isPresent, isPresent,
RSVP: { resolve, reject }, RSVP: { resolve, reject },
inject: { service } inject: { service }
} = Ember; } = Ember;
export default Base.extend({ export default Base.extend({
ajax: service(), ajax: service(),
appMeta: service(), appMeta: service(),
restore(data) { restore(data) {
// TODO: verify authentication data // TODO: verify authentication data
if (data) { if (data) {
return resolve(data); return resolve(data);
} }
return reject(); return reject();
}, },
authenticate(credentials) { authenticate(credentials) {
let domain = netUtil.getSubdomain(); let domain = netUtil.getSubdomain();
let encoded; let encoded;
if (typeof credentials === 'object') { if (typeof credentials === 'object') {
let { password, email } = credentials; let { password, email } = credentials;
if (!isPresent(password) || !isPresent(email)) { if (!isPresent(password) || !isPresent(email)) {
return Ember.RSVP.reject("invalid"); return Ember.RSVP.reject("invalid");
} }
encoded = encodingUtil.Base64.encode(`${domain}:${email}:${password}`); encoded = encodingUtil.Base64.encode(`${domain}:${email}:${password}`);
} else if (typeof credentials === 'string') { } else if (typeof credentials === 'string') {
encoded = credentials; encoded = credentials;
} else { } else {
return Ember.RSVP.reject("invalid"); return Ember.RSVP.reject("invalid");
} }
var headers = { var headers = {
'Authorization': 'Basic ' + encoded 'Authorization': 'Basic ' + encoded
}; };
return this.get('ajax').post('public/authenticate', { return this.get('ajax').post('public/authenticate', {
headers headers
}); });
}, },
invalidate() { invalidate() {
return resolve(); return resolve();
} }
}); });

View file

@ -1,15 +1,16 @@
import Ember from 'ember'; import Ember from 'ember';
export default Ember.Route.extend({ export default Ember.Route.extend({
session: Ember.inject.service(), session: Ember.inject.service(),
model({ token }) { model({ token }) {
this.get("session").authenticate('authenticator:documize', token) this.get("session").authenticate('authenticator:documize', token)
.then(() => { .then(() => {
this.transitionTo('folders.folder'); this.transitionTo('folders.folder');
}, () => { })
this.transitionTo('auth.login'); .catch(() => {
console.log(">>>>> Documize SSO failure"); this.transitionTo('auth.login');
}); console.log(">>>>> Documize SSO failure");
}, });
}
}); });

View file

@ -1,421 +1,455 @@
export default function() { import Mirage from 'ember-cli-mirage';
this.passthrough('https://widget.intercom.io/widget/%7Bapp_id%7D'); export default function () {
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.timing = 400; // delay for each request, automatically set to 0 during testing
this.get('/public/meta', function(schema) { this.passthrough('https://widget.intercom.io/widget/%7Bapp_id%7D');
return schema.db.meta[0]; 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.timing = 400; // delay for each request, automatically set to 0 during testing
this.get('/public/validate', function(schema, request) { this.get('/public/meta', function (schema) {
let serverToken = request.queryParams.token; return schema.db.meta[0];
let token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkb21haW4iOiIiLCJleHAiOjE0NjQwMjM2NjcsImlzcyI6IkRvY3VtaXplIiwib3JnIjoiVnpNdXlFd18zV3FpYWZjRCIsInN1YiI6IndlYmFwcCIsInVzZXIiOiJWek11eUV3XzNXcWlhZmNFIn0.NXZ6bo8mtvdZF_b9HavbidVUJqhmBA1zr0fSAPvbah0"; });
if (token = serverToken) { this.get('/public/validate', function (schema, request) {
return { let serverToken = request.queryParams.token;
"id": "VzMuyEw_3WqiafcE", let token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkb21haW4iOiIiLCJleHAiOjE0NjQwMjM2NjcsImlzcyI6IkRvY3VtaXplIiwib3JnIjoiVnpNdXlFd18zV3FpYWZjRCIsInN1YiI6IndlYmFwcCIsInVzZXIiOiJWek11eUV3XzNXcWlhZmNFIn0.NXZ6bo8mtvdZF_b9HavbidVUJqhmBA1zr0fSAPvbah0";
"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/0/permissions', function() { if (token = serverToken) {
return [{ return {
"folderId": "VzMygEw_3WrtFzto", "id": "VzMuyEw_3WqiafcE",
"userId": "", "created": "2016-05-11T15:08:24Z",
"canView": true, "revised": "2016-05-11T15:08:24Z",
"canEdit": false "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('/templates', function() { this.get('/users/0/permissions', function () {
return []; return [{
}); "folderId": "VzMygEw_3WrtFzto",
"userId": "",
"canView": true,
"canEdit": false
}];
});
this.get('/documents', function(schema, request) { this.get('/templates', function () {
let folder_id = request.queryParams.folder; return [];
});
if (folder_id = "VzMuyEw_3WqiafcG") { this.get('/documents', function (schema, request) {
return [{ let folder_id = request.queryParams.folder;
"id": "VzMwX0w_3WrtFztd",
"created": "2016-05-11T13:15:11Z",
"revised": "2016-05-11T13:22:16Z",
"orgId": "VzMuyEw_3WqiafcD",
"folderId": "VzMuyEw_3WqiafcG",
"userId": "VzMuyEw_3WqiafcE",
"job": "",
"location": "template-0",
"name": "Empty Document",
"excerpt": "My test document",
"tags": "",
"template": false
}, {
"id": "VzMvJEw_3WqiafcI",
"created": "2016-05-11T13:09:56Z",
"revised": "2016-05-11T13:09:56Z",
"orgId": "VzMuyEw_3WqiafcD",
"folderId": "VzMuyEw_3WqiafcG",
"userId": "VzMuyEw_3WqiafcE",
"job": "0bf9b076-cb74-4e8e-75be-8ee2d24a8171",
"location": "/var/folders/d6/kr81d2fs5bsbm8rz2p092fy80000gn/T/documize/_uploads/0bf9b076-cb74-4e8e-75be-8ee2d24a8171/README.md",
"name": "README",
"excerpt": "To Document/ Instructions. GO. go- bindata- assetsfs. SSL.",
"tags": "",
"template": false
}];
} else if (folder_id = "VzMygEw_3WrtFzto") {
return {
"id": "VzMygEw_3WrtFzto",
"created": "2016-05-11T13:24:17Z",
"revised": "2016-05-11T13:25:51Z",
"name": "Test",
"orgId": "VzMuyEw_3WqiafcD",
"userId": "VzMuyEw_3WqiafcE",
"folderType": 1
};
} else if (folder_id = 'V0Vy5Uw_3QeDAMW9'){
return null;
}
});
this.get('/folders', function(schema) { if (folder_id = "VzMuyEw_3WqiafcG") {
return schema.db.folders; return [{
}); "id": "VzMwX0w_3WrtFztd",
"created": "2016-05-11T13:15:11Z",
"revised": "2016-05-11T13:22:16Z",
"orgId": "VzMuyEw_3WqiafcD",
"folderId": "VzMuyEw_3WqiafcG",
"userId": "VzMuyEw_3WqiafcE",
"job": "",
"location": "template-0",
"name": "Empty Document",
"excerpt": "My test document",
"tags": "",
"template": false
}, {
"id": "VzMvJEw_3WqiafcI",
"created": "2016-05-11T13:09:56Z",
"revised": "2016-05-11T13:09:56Z",
"orgId": "VzMuyEw_3WqiafcD",
"folderId": "VzMuyEw_3WqiafcG",
"userId": "VzMuyEw_3WqiafcE",
"job": "0bf9b076-cb74-4e8e-75be-8ee2d24a8171",
"location": "/var/folders/d6/kr81d2fs5bsbm8rz2p092fy80000gn/T/documize/_uploads/0bf9b076-cb74-4e8e-75be-8ee2d24a8171/README.md",
"name": "README",
"excerpt": "To Document/ Instructions. GO. go- bindata- assetsfs. SSL.",
"tags": "",
"template": false
}];
} else if (folder_id = "VzMygEw_3WrtFzto") {
return {
"id": "VzMygEw_3WrtFzto",
"created": "2016-05-11T13:24:17Z",
"revised": "2016-05-11T13:25:51Z",
"name": "Test",
"orgId": "VzMuyEw_3WqiafcD",
"userId": "VzMuyEw_3WqiafcE",
"folderType": 1
};
} else if (folder_id = 'V0Vy5Uw_3QeDAMW9') {
return null;
}
});
this.post('/folders', function(schema, request) { this.get('/folders', function (schema) {
var name = JSON.parse(request.requestBody).name; return schema.db.folders;
let newFolder = { });
"id":"V0Vy5Uw_3QeDAMW9",
"created":"2016-05-25T09:39:49Z",
"revised":"2016-05-25T09:39:49Z",
"name":name,
"orgId":"VzMuyEw_3WqiafcD",
"userId":"VzMuyEw_3WqiafcE",
"folderType":2
};
let folder = schema.db.folders.insert(newFolder); this.post('/folders', function (schema, request) {
return folder; var name = JSON.parse(request.requestBody).name;
}); let newFolder = {
"id": "V0Vy5Uw_3QeDAMW9",
"created": "2016-05-25T09:39:49Z",
"revised": "2016-05-25T09:39:49Z",
"name": name,
"orgId": "VzMuyEw_3WqiafcD",
"userId": "VzMuyEw_3WqiafcE",
"folderType": 2
};
this.post('/public/authenticate', () => { let folder = schema.db.folders.insert(newFolder);
return { return folder;
"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.post('/public/authenticate', (schema, request) => {
return schema.db.permissions; debugger;
}); let authorization = request.requestHeaders.Authorization;
let expectedAuthorization = "Basic OmJyaXpkaWdpdGFsQGdtYWlsLmNvbTp6aW55YW5kbzEyMw==";
this.get('/folders/VzMuyEw_3WqiafcG/permissions', () => { if (expectedAuthorization == authorization) {
return [ return {
{ "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkb21haW4iOiIiLCJleHAiOjE0NjQwMjM2NjcsImlzcyI6IkRvY3VtaXplIiwib3JnIjoiVnpNdXlFd18zV3FpYWZjRCIsInN1YiI6IndlYmFwcCIsInVzZXIiOiJWek11eUV3XzNXcWlhZmNFIn0.NXZ6bo8mtvdZF_b9HavbidVUJqhmBA1zr0fSAPvbah0",
"folderId":"VzMuyEw_3WqiafcG", "user": {
"userId":"VzMuyEw_3WqiafcE", "id": "VzMuyEw_3WqiafcE",
"canView":true, "created": "2016-05-11T15:08:24Z",
"canEdit":true "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": ""
}]
}
};
} 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.put('/folders/VzMygEw_3WrtFzto/permissions', () => { });
return [
{
"orgId":"VzMuyEw_3WqiafcD",
"folderId":"VzMygEw_3WrtFzto",
"userId":"",
"canEdit":true,
"canView":true
},{
"orgId":"VzMuyEw_3WqiafcD",
"folderId":"VzMygEw_3WrtFzto",
"userId":"VzMyp0w_3WrtFztq",
"canEdit":false,
"canView":false
},{
"orgId":"",
"folderId":"VzMygEw_3WrtFzto",
"userId":"VzMuyEw_3WqiafcE",
"canEdit":true,
"canView":true
}
];
});
this.get('/folders/VzMygEw_3WrtFzto/permissions', () => { this.get('/users/VzMuyEw_3WqiafcE/permissions', (schema) => {
return [ return schema.db.permissions;
{ });
"folderId":"VzMygEw_3WrtFzto",
"userId":"VzMuyEw_3WqiafcE",
"canView":true,
"canEdit":true
}
];
});
this.put('/folders/:id', (schema, request) => { this.get('/folders/VzMuyEw_3WqiafcG/permissions', () => {
let id = request.params.id; return [{
let attrs = JSON.parse(request.requestBody); "folderId": "VzMuyEw_3WqiafcG",
let folder = schema.db.folders.update(id, attrs); "userId": "VzMuyEw_3WqiafcE",
return folder; "canView": true,
}); "canEdit": true
}];
});
this.put('/folders/V0Vy5Uw_3QeDAMW9', () => { this.put('/folders/VzMygEw_3WrtFzto/permissions', () => {
return { return [{
"id":"V0Vy5Uw_3QeDAMW9", "orgId": "VzMuyEw_3WqiafcD",
"created":"2016-05-25T09:39:49Z", "folderId": "VzMygEw_3WrtFzto",
"revised":"2016-05-25T09:39:49Z", "userId": "",
"name":"Test Folder", "canEdit": true,
"orgId":"VzMuyEw_3WqiafcD", "canView": true
"userId":"VzMuyEw_3WqiafcE", }, {
"folderType":2 "orgId": "VzMuyEw_3WqiafcD",
}; "folderId": "VzMygEw_3WrtFzto",
}); "userId": "VzMyp0w_3WrtFztq",
"canEdit": false,
"canView": false
}, {
"orgId": "",
"folderId": "VzMygEw_3WrtFzto",
"userId": "VzMuyEw_3WqiafcE",
"canEdit": true,
"canView": true
}];
});
this.get('folders/:id', (schema, request) => { this.get('/folders/VzMygEw_3WrtFzto/permissions', () => {
let id = request.params.id; return [{
return schema.db.folders.find(id); "folderId": "VzMygEw_3WrtFzto",
}); "userId": "VzMuyEw_3WqiafcE",
"canView": true,
"canEdit": true
}];
});
this.get('/organizations/VzMuyEw_3WqiafcD', () => { this.put('/folders/:id', (schema, request) => {
return { let id = request.params.id;
"id": "VzMuyEw_3WqiafcD", let attrs = JSON.parse(request.requestBody);
"created": "2016-05-11T15:08:24Z", let folder = schema.db.folders.update(id, attrs);
"revised": "2016-05-23T11:23:20Z", return folder;
"title": "EmberSherpa", });
"message": "This Documize instance contains all our team documentation",
"url": "",
"domain": "",
"email": "brizdigital@gmail.com",
"allowAnonymousAccess": false
};
});
this.put('/organizations/VzMuyEw_3WqiafcD', (schema, request) => { this.put('/folders/V0Vy5Uw_3QeDAMW9', () => {
let title = JSON.parse(request.requestBody).title; return {
let message = JSON.parse(request.requestBody).title; "id": "V0Vy5Uw_3QeDAMW9",
let allowAnonymousAccess = JSON.parse(request.requestBody).allowAnonymousAccess; "created": "2016-05-25T09:39:49Z",
"revised": "2016-05-25T09:39:49Z",
"name": "Test Folder",
"orgId": "VzMuyEw_3WqiafcD",
"userId": "VzMuyEw_3WqiafcE",
"folderType": 2
};
});
return { this.get('folders/:id', (schema, request) => {
"id": "VzMuyEw_3WqiafcD", let id = request.params.id;
"created": "2016-05-11T15:08:24Z", return schema.db.folders.find(id);
"revised": "2016-05-23T11:23:20Z", });
"title": `${title}`,
"message": `${message}`,
"url": "",
"domain": "",
"email": "brizdigital@gmail.com",
"allowAnonymousAccess": `${allowAnonymousAccess}`
};
});
this.get('/users', () => { this.get('/organizations/VzMuyEw_3WqiafcD', () => {
return [{ return {
"id": "VzMyp0w_3WrtFztq", "id": "VzMuyEw_3WqiafcD",
"created": "2016-05-11T13:24:55Z", "created": "2016-05-11T15:08:24Z",
"revised": "2016-05-11T13:33:47Z", "revised": "2016-05-23T11:23:20Z",
"firstname": "Len", "title": "EmberSherpa",
"lastname": "Random", "message": "This Documize instance contains all our team documentation",
"email": "zinyando@gmail.com", "url": "",
"initials": "LR", "domain": "",
"active": true, "email": "brizdigital@gmail.com",
"editor": true, "allowAnonymousAccess": false
"admin": false, };
"accounts": [{ });
"id": "VzMyp0w_3WrtFztr",
"created": "2016-05-11T13:24:55Z",
"revised": "2016-05-11T13:24:55Z",
"admin": false,
"editor": true,
"userId": "VzMyp0w_3WrtFztq",
"orgId": "VzMuyEw_3WqiafcD",
"company": "EmberSherpa",
"title": "EmberSherpa",
"message": "This Documize instance contains all our team documentation",
"domain": ""
}]
}, {
"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.post('/users', (schema, request) => { this.put('/organizations/VzMuyEw_3WqiafcD', (schema, request) => {
let firstname = JSON.parse(request.requestBody).firstname; let title = JSON.parse(request.requestBody).title;
let lastname = JSON.parse(request.requestBody).lastname; let message = JSON.parse(request.requestBody).title;
let email = JSON.parse(request.requestBody).email; let allowAnonymousAccess = JSON.parse(request.requestBody).allowAnonymousAccess;
return { return {
"id":"V0RmtUw_3QeDAMW7", "id": "VzMuyEw_3WqiafcD",
"created":"2016-05-24T14:35:33Z", "created": "2016-05-11T15:08:24Z",
"revised":"2016-05-24T14:35:33Z", "revised": "2016-05-23T11:23:20Z",
"firstname":`${firstname}`, "title": `${title}`,
"lastname":`${lastname}`, "message": `${message}`,
"email":`${email}`, "url": "",
"initials":"TU", "domain": "",
"active":true, "email": "brizdigital@gmail.com",
"editor":true, "allowAnonymousAccess": `${allowAnonymousAccess}`
"admin":false, };
"accounts":[{ });
"id":"V0RmtUw_3QeDAMW8",
"created":"2016-05-24T14:35:34Z",
"revised":"2016-05-24T14:35:34Z",
"admin":false,
"editor":true,
"userId":"V0RmtUw_3QeDAMW7",
"orgId":"VzMuyEw_3WqiafcD",
"company":"EmberSherpa",
"title":"EmberSherpa",
"message":"This Documize instance contains all our team documentation",
"domain":""
}
]};
});
this.get('/users/VzMuyEw_3WqiafcE', () => { this.get('/users', () => {
return [{
"id": "VzMyp0w_3WrtFztq",
"created": "2016-05-11T13:24:55Z",
"revised": "2016-05-11T13:33:47Z",
"firstname": "Len",
"lastname": "Random",
"email": "zinyando@gmail.com",
"initials": "LR",
"active": true,
"editor": true,
"admin": false,
"accounts": [{
"id": "VzMyp0w_3WrtFztr",
"created": "2016-05-11T13:24:55Z",
"revised": "2016-05-11T13:24:55Z",
"admin": false,
"editor": true,
"userId": "VzMyp0w_3WrtFztq",
"orgId": "VzMuyEw_3WqiafcD",
"company": "EmberSherpa",
"title": "EmberSherpa",
"message": "This Documize instance contains all our team documentation",
"domain": ""
}]
}, {
"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": ""
}]
}];
});
return { this.post('/users', (schema, request) => {
"id":"VzMuyEw_3WqiafcE", let firstname = JSON.parse(request.requestBody).firstname;
"created":"2016-05-11T15:08:24Z", let lastname = JSON.parse(request.requestBody).lastname;
"revised":"2016-05-11T15:08:24Z", let email = JSON.parse(request.requestBody).email;
"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.put('/users/VzMuyEw_3WqiafcE', (schema, request) => { return {
let firstname = JSON.parse(request.requestBody).firstname; "id": "V0RmtUw_3QeDAMW7",
let lastname = JSON.parse(request.requestBody).lastname; "created": "2016-05-24T14:35:33Z",
let email = JSON.parse(request.requestBody).email; "revised": "2016-05-24T14:35:33Z",
"firstname": `${firstname}`,
"lastname": `${lastname}`,
"email": `${email}`,
"initials": "TU",
"active": true,
"editor": true,
"admin": false,
"accounts": [{
"id": "V0RmtUw_3QeDAMW8",
"created": "2016-05-24T14:35:34Z",
"revised": "2016-05-24T14:35:34Z",
"admin": false,
"editor": true,
"userId": "V0RmtUw_3QeDAMW7",
"orgId": "VzMuyEw_3WqiafcD",
"company": "EmberSherpa",
"title": "EmberSherpa",
"message": "This Documize instance contains all our team documentation",
"domain": ""
}]
};
});
return { this.get('/users/VzMuyEw_3WqiafcE', () => {
"id":"VzMuyEw_3WqiafcE",
"created":"2016-05-11T15:08:24Z",
"revised":"2016-05-11T15:08:24Z",
"firstname":`${firstname}`,
"lastname":`${lastname}`,
"email":`${email}`,
"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.post('/folders/VzMuyEw_3WqiafcG/invitation', () => { return {
return {}; "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.put('/users/VzMuyEw_3WqiafcE', (schema, request) => {
very helpful for debugging let firstname = JSON.parse(request.requestBody).firstname;
*/ let lastname = JSON.parse(request.requestBody).lastname;
this.handledRequest = function(verb, path) { let email = JSON.parse(request.requestBody).email;
console.log(`👊${verb} ${path}`);
};
this.unhandledRequest = function(verb, path) { return {
console.log(`🔥${verb} ${path}`); "id": "VzMuyEw_3WqiafcE",
}; "created": "2016-05-11T15:08:24Z",
"revised": "2016-05-11T15:08:24Z",
"firstname": `${firstname}`,
"lastname": `${lastname}`,
"email": `${email}`,
"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.post('/folders/VzMuyEw_3WqiafcG/invitation', () => {
return {};
});
/**
very helpful for debugging
*/
this.handledRequest = function (verb, path) {
console.log(`👊${verb} ${path}`);
};
this.unhandledRequest = function (verb, path) {
console.log(`🔥${verb} ${path}`);
};
} }

View file

@ -4,32 +4,31 @@ import moduleForAcceptance from 'documize/tests/helpers/module-for-acceptance';
moduleForAcceptance('Acceptance | Anon access enabled'); moduleForAcceptance('Acceptance | Anon access enabled');
test('visiting / when not authenticated and with { allowAnonymousAccess: true } takes user to folder view', function (assert) { test('visiting / when not authenticated and with { allowAnonymousAccess: true } takes user to folder view', function (assert) {
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');
assert.equal(find('.documents-list .document').length, 2, '2 document displayed'); assert.equal(find('.documents-list .document').length, 2, '2 document displayed');
assert.equal(currentURL(), '/s/VzMygEw_3WrtFzto/test', 'Dashboard and public spaces are displayed without being signed in'); assert.equal(currentURL(), '/s/VzMygEw_3WrtFzto/test', 'Dashboard and public spaces are displayed without being signed in');
}); });
}); });
test('visiting / when authenticated and with { allowAnonymousAccess: true } takes user to dashboard', function (assert) { test('visiting / when authenticated and with { allowAnonymousAccess: true } takes user to dashboard', function (assert) {
server.create('meta', { allowAnonymousAccess: true }); server.create('meta', { allowAnonymousAccess: true });
server.createList('folder', 2); server.createList('folder', 2);
visit('/'); visit('/');
andThen(function () { andThen(function () {
assert.equal(find('.login').length, 1, 'Login button is displayed'); assert.equal(find('.login').length, 1, 'Login button is displayed');
assert.equal(currentURL(), '/s/VzMygEw_3WrtFzto/test', 'Dashboard displayed without being signed in'); assert.equal(currentURL(), '/s/VzMygEw_3WrtFzto/test', 'Dashboard displayed without being signed in');
}); });
userLogin(); userLogin();
andThen(function () { andThen(function () {
assert.equal(find('.login').length, 0, 'Login button is not displayed'); assert.equal(find('.login').length, 0, 'Login button is not displayed');
assert.equal(currentURL(), '/s/VzMygEw_3WrtFzto/test', 'Dashboard is displayed after user is signed in'); assert.equal(currentURL(), '/s/VzMygEw_3WrtFzto/test', 'Dashboard is displayed after user is signed in');
}); });
}); });

View file

@ -4,39 +4,50 @@ import moduleForAcceptance from 'documize/tests/helpers/module-for-acceptance';
moduleForAcceptance('Acceptance | Authentication'); moduleForAcceptance('Acceptance | Authentication');
test('visiting /auth/login and logging in', function (assert) { test('visiting /auth/login and logging in', function (assert) {
server.create('meta', { allowAnonymousAccess: false }); server.create('meta', { allowAnonymousAccess: false });
server.createList('folder', 2); server.createList('folder', 2);
visit('/auth/login'); visit('/auth/login');
fillIn('#authEmail', 'brizdigital@gmail.com'); fillIn('#authEmail', 'brizdigital@gmail.com');
fillIn('#authPassword', 'zinyando123'); fillIn('#authPassword', 'zinyando123');
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');
}); });
}); });
test('logging out a user', function (assert) { test('logging out a user', function (assert) {
server.create('meta', { allowAnonymousAccess: false }); server.create('meta', { allowAnonymousAccess: false });
server.createList('folder', 2); server.createList('folder', 2);
userLogin(); userLogin();
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

@ -4,194 +4,192 @@ import moduleForAcceptance from 'documize/tests/helpers/module-for-acceptance';
moduleForAcceptance('Acceptance | Documents space'); moduleForAcceptance('Acceptance | Documents space');
skip('Adding a new folder space', function (assert) { skip('Adding a new folder space', function (assert) {
server.create('meta', { allowAnonymousAccess: false }); server.create('meta', { allowAnonymousAccess: false });
server.createList('folder', 2); server.createList('folder', 2);
server.createList('permission', 4); server.createList('permission', 4);
authenticateUser(); authenticateUser();
visit('/s/VzMuyEw_3WqiafcG/my-project'); visit('/s/VzMuyEw_3WqiafcG/my-project');
andThen(function () { andThen(function () {
let personalSpaces = find('.section div:contains(PERSONAL)').length; let personalSpaces = find('.section div:contains(PERSONAL)').length;
assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project'); assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project');
assert.equal(personalSpaces, 1, '1 personal space is listed'); assert.equal(personalSpaces, 1, '1 personal space is listed');
}); });
click('#add-folder-button'); click('#add-folder-button');
fillIn('#new-folder-name', 'body', 'Test Folder'); fillIn('#new-folder-name', 'body', 'Test Folder');
click('.actions div:contains(Add)', 'body'); click('.actions div:contains(Add)', 'body');
andThen(function () { andThen(function () {
assert.equal(currentURL(), '/s/V0Vy5Uw_3QeDAMW9/test-folder'); assert.equal(currentURL(), '/s/V0Vy5Uw_3QeDAMW9/test-folder');
}); });
}); });
skip('Adding a document to a space', function (assert) { skip('Adding a document to a space', function (assert) {
server.create('meta', { allowAnonymousAccess: false }); server.create('meta', { allowAnonymousAccess: false });
server.createList('folder', 2); server.createList('folder', 2);
server.createList('permission', 4); server.createList('permission', 4);
authenticateUser(); authenticateUser();
visit('/s/VzMuyEw_3WqiafcG/my-project'); visit('/s/VzMuyEw_3WqiafcG/my-project');
andThen(function () { andThen(function () {
let numberOfDocuments = find('.documents-list li').length; let numberOfDocuments = find('.documents-list li').length;
assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project'); assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project');
assert.equal(numberOfDocuments, 2, '2 documents listed'); assert.equal(numberOfDocuments, 2, '2 documents listed');
}); });
click('#start-document-button'); click('#start-document-button');
click('.actions div:contains(Add)', 'body'); click('.actions div:contains(Add)', 'body');
andThen(function () { andThen(function () {
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(); });
});
}); });
test('visiting space settings page', function (assert) { test('visiting space settings page', function (assert) {
server.create('meta', { allowAnonymousAccess: false }); server.create('meta', { allowAnonymousAccess: false });
server.createList('folder', 2); server.createList('folder', 2);
server.createList('permission', 4); server.createList('permission', 4);
authenticateUser(); authenticateUser();
visit('/s/VzMuyEw_3WqiafcG/my-project'); visit('/s/VzMuyEw_3WqiafcG/my-project');
click('#folder-settings-button'); click('#folder-settings-button');
andThen(function () { andThen(function () {
checkForCommonAsserts(); checkForCommonAsserts();
assert.equal(find('#folderName').val().trim(), 'My Project', 'Space name displayed in input box'); assert.equal(find('#folderName').val().trim(), 'My Project', 'Space name displayed in input box');
assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project/settings'); assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project/settings');
}); });
}); });
test('changing space name', function (assert) { test('changing space name', function (assert) {
server.create('meta', { allowAnonymousAccess: false }); server.create('meta', { allowAnonymousAccess: false });
server.createList('folder', 2); server.createList('folder', 2);
server.createList('permission', 4); server.createList('permission', 4);
authenticateUser(); authenticateUser();
visit('/s/VzMuyEw_3WqiafcG/my-project'); visit('/s/VzMuyEw_3WqiafcG/my-project');
click('#folder-settings-button'); click('#folder-settings-button');
fillIn('#folderName', 'Test Space'); fillIn('#folderName', 'Test Space');
click('.button-blue'); click('.button-blue');
andThen(function () { andThen(function () {
let spaceName = find('.info .title').text().trim(); let spaceName = find('.info .title').text().trim();
checkForCommonAsserts(); checkForCommonAsserts();
assert.equal(spaceName, 'Test Space', 'Space name has been changed'); assert.equal(spaceName, 'Test Space', 'Space name has been changed');
assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project/settings'); assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project/settings');
}); });
}); });
test('sharing a space', function (assert) { test('sharing a space', function (assert) {
server.create('meta', { allowAnonymousAccess: false }); server.create('meta', { allowAnonymousAccess: false });
server.createList('folder', 2); server.createList('folder', 2);
server.createList('permission', 4); server.createList('permission', 4);
authenticateUser(); authenticateUser();
visit('/s/VzMuyEw_3WqiafcG/my-project'); visit('/s/VzMuyEw_3WqiafcG/my-project');
click('#folder-settings-button'); click('#folder-settings-button');
click(('.sidebar-menu .options li:contains(Share)')); click(('.sidebar-menu .options li:contains(Share)'));
fillIn('#inviteEmail', 'share-test@gmail.com'); fillIn('#inviteEmail', 'share-test@gmail.com');
click('.button-blue'); click('.button-blue');
andThen(function () { andThen(function () {
checkForCommonAsserts(); checkForCommonAsserts();
assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project/settings'); assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project/settings');
}); });
}); });
// Test will pass after moving to factories // Test will pass after moving to factories
test('changing space permissions', function (assert) { test('changing space permissions', function (assert) {
server.create('meta', { allowAnonymousAccess: false }); server.create('meta', { allowAnonymousAccess: false });
server.createList('folder', 2); server.createList('folder', 2);
server.createList('permission', 4); server.createList('permission', 4);
authenticateUser(); authenticateUser();
visit('/s/VzMygEw_3WrtFzto/test'); visit('/s/VzMygEw_3WrtFzto/test');
andThen(function () { andThen(function () {
let numberOfPublicFolders = find('.sidebar-menu .folders-list .section .list:first a').length; let numberOfPublicFolders = find('.sidebar-menu .folders-list .section .list:first a').length;
assert.equal(numberOfPublicFolders, 1, '1 folder listed as public'); assert.equal(numberOfPublicFolders, 1, '1 folder listed as public');
assert.equal(currentURL(), '/s/VzMygEw_3WrtFzto/test'); assert.equal(currentURL(), '/s/VzMygEw_3WrtFzto/test');
}); });
click('#folder-settings-button'); click('#folder-settings-button');
click('.sidebar-menu .options li:contains(Permissions)'); click('.sidebar-menu .options li:contains(Permissions)');
click('tr:contains(Everyone) #canView-'); click('tr:contains(Everyone) #canView-');
click('tr:contains(Everyone) #canEdit-'); click('tr:contains(Everyone) #canEdit-');
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;
assert.equal(numberOfPublicFolders, 2, '2 folder listed as public'); assert.equal(numberOfPublicFolders, 2, '2 folder listed as public');
assert.equal(currentURL(), '/s/VzMygEw_3WrtFzto/test'); assert.equal(currentURL(), '/s/VzMygEw_3WrtFzto/test');
}); });
}); });
test('deleting a space', function (assert) { test('deleting a space', function (assert) {
server.create('meta', { allowAnonymousAccess: false }); server.create('meta', { allowAnonymousAccess: false });
server.createList('folder', 2); server.createList('folder', 2);
server.createList('permission', 4); server.createList('permission', 4);
authenticateUser(); authenticateUser();
visit('/s/VzMuyEw_3WqiafcG/my-project'); visit('/s/VzMuyEw_3WqiafcG/my-project');
click('#folder-settings-button'); click('#folder-settings-button');
click('.sidebar-menu .options li:contains(Delete)'); click('.sidebar-menu .options li:contains(Delete)');
andThen(function () { andThen(function () {
checkForCommonAsserts(); checkForCommonAsserts();
assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project/settings'); assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project/settings');
}); });
}); });
skip('deleting a document', function (assert) { skip('deleting a document', function (assert) {
server.create('meta', { allowAnonymousAccess: false }); server.create('meta', { allowAnonymousAccess: false });
server.createList('folder', 2); server.createList('folder', 2);
server.createList('permission', 4); server.createList('permission', 4);
authenticateUser(); authenticateUser();
visit('/s/VzMuyEw_3WqiafcG/my-project'); visit('/s/VzMuyEw_3WqiafcG/my-project');
andThen(function () { andThen(function () {
let deleteButton = find('#delete-documents-button'); let deleteButton = find('#delete-documents-button');
let numberOfDocuments = find('.documents-list li'); let numberOfDocuments = find('.documents-list li');
assert.equal(numberOfDocuments.length, 2, '2 documents are displayed'); assert.equal(numberOfDocuments.length, 2, '2 documents are displayed');
assert.equal(deleteButton.length, 0, 'Delete button not displayed'); assert.equal(deleteButton.length, 0, 'Delete button not displayed');
}); });
click('.documents-list li:first .checkbox'); click('.documents-list li:first .checkbox');
andThen(function () { andThen(function () {
let deleteButton = find('#delete-documents-button'); let deleteButton = find('#delete-documents-button');
assert.equal(deleteButton.length, 1, 'Delete button displayed after selecting document'); assert.equal(deleteButton.length, 1, 'Delete button displayed after selecting document');
}); });
click('#delete-documents-button'); click('#delete-documents-button');
waitToAppear('.drop-content'); waitToAppear('.drop-content');
click('.actions div:contains(Delete)', 'body'); click('.actions div:contains(Delete)', 'body');
andThen(function () { andThen(function () {
let numberOfDocuments = find('.documents-list li'); let numberOfDocuments = find('.documents-list li');
assert.equal(numberOfDocuments.length, 1, '1 documents is displayed'); assert.equal(numberOfDocuments.length, 1, '1 documents is displayed');
}); });
}); });
function checkForCommonAsserts() { function checkForCommonAsserts() {
findWithAssert('.sidebar-menu'); findWithAssert('.sidebar-menu');
findWithAssert('.options li:contains(General)'); findWithAssert('.options li:contains(General)');
findWithAssert('.options li:contains(Share)'); findWithAssert('.options li:contains(Share)');
findWithAssert('.options li:contains(Permissions)'); findWithAssert('.options li:contains(Permissions)');
findWithAssert('.options li:contains(Delete)'); findWithAssert('.options li:contains(Delete)');
} }