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

View file

@ -1,15 +1,16 @@
import Ember from 'ember';
export default Ember.Route.extend({
session: Ember.inject.service(),
session: Ember.inject.service(),
model({ token }) {
this.get("session").authenticate('authenticator:documize', token)
.then(() => {
this.transitionTo('folders.folder');
}, () => {
this.transitionTo('auth.login');
console.log(">>>>> Documize SSO failure");
});
},
model({ token }) {
this.get("session").authenticate('authenticator:documize', token)
.then(() => {
this.transitionTo('folders.folder');
})
.catch(() => {
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');
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
export default function () {
this.get('/public/meta', function(schema) {
return schema.db.meta[0];
});
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.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) {
let serverToken = request.queryParams.token;
let token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkb21haW4iOiIiLCJleHAiOjE0NjQwMjM2NjcsImlzcyI6IkRvY3VtaXplIiwib3JnIjoiVnpNdXlFd18zV3FpYWZjRCIsInN1YiI6IndlYmFwcCIsInVzZXIiOiJWek11eUV3XzNXcWlhZmNFIn0.NXZ6bo8mtvdZF_b9HavbidVUJqhmBA1zr0fSAPvbah0";
this.get('/public/meta', function (schema) {
return schema.db.meta[0];
});
if (token = serverToken) {
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.get('/public/validate', function (schema, request) {
let serverToken = request.queryParams.token;
let token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkb21haW4iOiIiLCJleHAiOjE0NjQwMjM2NjcsImlzcyI6IkRvY3VtaXplIiwib3JnIjoiVnpNdXlFd18zV3FpYWZjRCIsInN1YiI6IndlYmFwcCIsInVzZXIiOiJWek11eUV3XzNXcWlhZmNFIn0.NXZ6bo8mtvdZF_b9HavbidVUJqhmBA1zr0fSAPvbah0";
this.get('/users/0/permissions', function() {
return [{
"folderId": "VzMygEw_3WrtFzto",
"userId": "",
"canView": true,
"canEdit": false
}];
});
if (token = serverToken) {
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.get('/templates', function() {
return [];
});
this.get('/users/0/permissions', function () {
return [{
"folderId": "VzMygEw_3WrtFzto",
"userId": "",
"canView": true,
"canEdit": false
}];
});
this.get('/documents', function(schema, request) {
let folder_id = request.queryParams.folder;
this.get('/templates', function () {
return [];
});
if (folder_id = "VzMuyEw_3WqiafcG") {
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.get('/documents', function (schema, request) {
let folder_id = request.queryParams.folder;
this.get('/folders', function(schema) {
return schema.db.folders;
});
if (folder_id = "VzMuyEw_3WqiafcG") {
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) {
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.get('/folders', function (schema) {
return schema.db.folders;
});
let folder = schema.db.folders.insert(newFolder);
return folder;
});
this.post('/folders', function (schema, request) {
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', () => {
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": ""
}]
}
};
});
let folder = schema.db.folders.insert(newFolder);
return folder;
});
this.get('/users/VzMuyEw_3WqiafcE/permissions', (schema) => {
return schema.db.permissions;
});
this.post('/public/authenticate', (schema, request) => {
debugger;
let authorization = request.requestHeaders.Authorization;
let expectedAuthorization = "Basic OmJyaXpkaWdpdGFsQGdtYWlsLmNvbTp6aW55YW5kbzEyMw==";
this.get('/folders/VzMuyEw_3WqiafcG/permissions', () => {
return [
{
"folderId":"VzMuyEw_3WqiafcG",
"userId":"VzMuyEw_3WqiafcE",
"canView":true,
"canEdit":true
}
];
});
if (expectedAuthorization == authorization) {
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": ""
}]
}
};
} 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', () => {
return [
{
"folderId":"VzMygEw_3WrtFzto",
"userId":"VzMuyEw_3WqiafcE",
"canView":true,
"canEdit":true
}
];
});
this.get('/users/VzMuyEw_3WqiafcE/permissions', (schema) => {
return schema.db.permissions;
});
this.put('/folders/:id', (schema, request) => {
let id = request.params.id;
let attrs = JSON.parse(request.requestBody);
let folder = schema.db.folders.update(id, attrs);
return folder;
});
this.get('/folders/VzMuyEw_3WqiafcG/permissions', () => {
return [{
"folderId": "VzMuyEw_3WqiafcG",
"userId": "VzMuyEw_3WqiafcE",
"canView": true,
"canEdit": true
}];
});
this.put('/folders/V0Vy5Uw_3QeDAMW9', () => {
return {
"id":"V0Vy5Uw_3QeDAMW9",
"created":"2016-05-25T09:39:49Z",
"revised":"2016-05-25T09:39:49Z",
"name":"Test Folder",
"orgId":"VzMuyEw_3WqiafcD",
"userId":"VzMuyEw_3WqiafcE",
"folderType":2
};
});
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/:id', (schema, request) => {
let id = request.params.id;
return schema.db.folders.find(id);
});
this.get('/folders/VzMygEw_3WrtFzto/permissions', () => {
return [{
"folderId": "VzMygEw_3WrtFzto",
"userId": "VzMuyEw_3WqiafcE",
"canView": true,
"canEdit": true
}];
});
this.get('/organizations/VzMuyEw_3WqiafcD', () => {
return {
"id": "VzMuyEw_3WqiafcD",
"created": "2016-05-11T15:08:24Z",
"revised": "2016-05-23T11:23:20Z",
"title": "EmberSherpa",
"message": "This Documize instance contains all our team documentation",
"url": "",
"domain": "",
"email": "brizdigital@gmail.com",
"allowAnonymousAccess": false
};
});
this.put('/folders/:id', (schema, request) => {
let id = request.params.id;
let attrs = JSON.parse(request.requestBody);
let folder = schema.db.folders.update(id, attrs);
return folder;
});
this.put('/organizations/VzMuyEw_3WqiafcD', (schema, request) => {
let title = JSON.parse(request.requestBody).title;
let message = JSON.parse(request.requestBody).title;
let allowAnonymousAccess = JSON.parse(request.requestBody).allowAnonymousAccess;
this.put('/folders/V0Vy5Uw_3QeDAMW9', () => {
return {
"id": "V0Vy5Uw_3QeDAMW9",
"created": "2016-05-25T09:39:49Z",
"revised": "2016-05-25T09:39:49Z",
"name": "Test Folder",
"orgId": "VzMuyEw_3WqiafcD",
"userId": "VzMuyEw_3WqiafcE",
"folderType": 2
};
});
return {
"id": "VzMuyEw_3WqiafcD",
"created": "2016-05-11T15:08:24Z",
"revised": "2016-05-23T11:23:20Z",
"title": `${title}`,
"message": `${message}`,
"url": "",
"domain": "",
"email": "brizdigital@gmail.com",
"allowAnonymousAccess": `${allowAnonymousAccess}`
};
});
this.get('folders/:id', (schema, request) => {
let id = request.params.id;
return schema.db.folders.find(id);
});
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": ""
}]
}];
});
this.get('/organizations/VzMuyEw_3WqiafcD', () => {
return {
"id": "VzMuyEw_3WqiafcD",
"created": "2016-05-11T15:08:24Z",
"revised": "2016-05-23T11:23:20Z",
"title": "EmberSherpa",
"message": "This Documize instance contains all our team documentation",
"url": "",
"domain": "",
"email": "brizdigital@gmail.com",
"allowAnonymousAccess": false
};
});
this.post('/users', (schema, request) => {
let firstname = JSON.parse(request.requestBody).firstname;
let lastname = JSON.parse(request.requestBody).lastname;
let email = JSON.parse(request.requestBody).email;
this.put('/organizations/VzMuyEw_3WqiafcD', (schema, request) => {
let title = JSON.parse(request.requestBody).title;
let message = JSON.parse(request.requestBody).title;
let allowAnonymousAccess = JSON.parse(request.requestBody).allowAnonymousAccess;
return {
"id":"V0RmtUw_3QeDAMW7",
"created":"2016-05-24T14:35:33Z",
"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 {
"id": "VzMuyEw_3WqiafcD",
"created": "2016-05-11T15:08:24Z",
"revised": "2016-05-23T11:23:20Z",
"title": `${title}`,
"message": `${message}`,
"url": "",
"domain": "",
"email": "brizdigital@gmail.com",
"allowAnonymousAccess": `${allowAnonymousAccess}`
};
});
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 {
"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) => {
let firstname = JSON.parse(request.requestBody).firstname;
let lastname = JSON.parse(request.requestBody).lastname;
let email = JSON.parse(request.requestBody).email;
this.put('/users/VzMuyEw_3WqiafcE', (schema, request) => {
let firstname = JSON.parse(request.requestBody).firstname;
let lastname = JSON.parse(request.requestBody).lastname;
let email = JSON.parse(request.requestBody).email;
return {
"id": "V0RmtUw_3QeDAMW7",
"created": "2016-05-24T14:35:33Z",
"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 {
"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.get('/users/VzMuyEw_3WqiafcE', () => {
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": ""
}]
};
});
/**
very helpful for debugging
*/
this.handledRequest = function(verb, path) {
console.log(`👊${verb} ${path}`);
};
this.put('/users/VzMuyEw_3WqiafcE', (schema, request) => {
let firstname = JSON.parse(request.requestBody).firstname;
let lastname = JSON.parse(request.requestBody).lastname;
let email = JSON.parse(request.requestBody).email;
this.unhandledRequest = function(verb, path) {
console.log(`🔥${verb} ${path}`);
};
return {
"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');
test('visiting / when not authenticated and with { allowAnonymousAccess: true } takes user to folder view', function (assert) {
server.create('meta', { allowAnonymousAccess: true });
server.createList('folder', 2);
visit('/');
// return pauseTest();
server.create('meta', { allowAnonymousAccess: true });
server.createList('folder', 2);
visit('/');
andThen(function () {
assert.equal(find('.login').length, 1, 'Login button is 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');
});
andThen(function () {
assert.equal(find('.login').length, 1, 'Login button is 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');
});
});
test('visiting / when authenticated and with { allowAnonymousAccess: true } takes user to dashboard', function (assert) {
server.create('meta', { allowAnonymousAccess: true });
server.createList('folder', 2);
visit('/');
server.create('meta', { allowAnonymousAccess: true });
server.createList('folder', 2);
visit('/');
andThen(function () {
assert.equal(find('.login').length, 1, 'Login button is displayed');
assert.equal(currentURL(), '/s/VzMygEw_3WrtFzto/test', 'Dashboard displayed without being signed in');
});
andThen(function () {
assert.equal(find('.login').length, 1, 'Login button is displayed');
assert.equal(currentURL(), '/s/VzMygEw_3WrtFzto/test', 'Dashboard displayed without being signed in');
});
userLogin();
userLogin();
andThen(function () {
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');
});
andThen(function () {
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');
});
});

View file

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