2018-01-03 04:05:53 +00:00
|
|
|
// Copyright IBM Corp. 2013,2018. All Rights Reserved.
|
2016-05-03 22:50:21 +00:00
|
|
|
// Node module: loopback
|
|
|
|
// This file is licensed under the MIT License.
|
|
|
|
// License text available at https://opensource.org/licenses/MIT
|
|
|
|
|
2016-11-15 21:46:23 +00:00
|
|
|
'use strict';
|
2013-12-20 22:58:29 +00:00
|
|
|
var loopback = require('../');
|
2015-12-31 23:41:18 +00:00
|
|
|
var lt = require('./helpers/loopback-testing-helper');
|
2013-12-18 05:10:05 +00:00
|
|
|
var path = require('path');
|
|
|
|
var ACCESS_CONTROL_APP = path.join(__dirname, 'fixtures', 'access-control');
|
2015-04-20 16:23:44 +00:00
|
|
|
var app = require(path.join(ACCESS_CONTROL_APP, 'server/server.js'));
|
2013-12-18 05:10:05 +00:00
|
|
|
var assert = require('assert');
|
2016-11-15 21:46:23 +00:00
|
|
|
var USER = {email: 'test@test.test', password: 'test'};
|
|
|
|
var CURRENT_USER = {email: 'current@test.test', password: 'test'};
|
2014-06-06 12:51:13 +00:00
|
|
|
var debug = require('debug')('loopback:test:access-control.integration');
|
2013-12-18 05:10:05 +00:00
|
|
|
|
2014-11-21 02:35:36 +00:00
|
|
|
describe('access control - integration', function() {
|
2013-12-18 05:10:05 +00:00
|
|
|
lt.beforeEach.withApp(app);
|
|
|
|
|
2014-03-19 22:09:20 +00:00
|
|
|
/*
|
2013-12-18 05:10:05 +00:00
|
|
|
describe('accessToken', function() {
|
2014-11-21 02:35:36 +00:00
|
|
|
// it('should be a sublcass of AccessToken', function() {
|
2013-12-20 22:58:29 +00:00
|
|
|
// assert(app.models.accessToken.prototype instanceof loopback.AccessToken);
|
|
|
|
// });
|
2013-12-18 05:10:05 +00:00
|
|
|
|
2014-11-21 02:35:36 +00:00
|
|
|
it('should have a validate method', function() {
|
2013-12-18 05:10:05 +00:00
|
|
|
var token = new app.models.accessToken;
|
2014-11-21 01:46:21 +00:00
|
|
|
assert.equal(typeof token.validate, 'function');
|
2013-12-18 05:10:05 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('/accessToken', function() {
|
|
|
|
|
|
|
|
lt.beforeEach.givenModel('accessToken', {}, 'randomToken');
|
|
|
|
|
|
|
|
lt.it.shouldBeAllowedWhenCalledAnonymously('POST', '/api/accessTokens');
|
|
|
|
lt.it.shouldBeAllowedWhenCalledUnauthenticated('POST', '/api/accessTokens');
|
|
|
|
lt.it.shouldBeAllowedWhenCalledByUser(USER, 'POST', '/api/accessTokens');
|
|
|
|
|
|
|
|
lt.it.shouldBeDeniedWhenCalledAnonymously('GET', '/api/accessTokens');
|
|
|
|
lt.it.shouldBeDeniedWhenCalledUnauthenticated('GET', '/api/accessTokens');
|
|
|
|
lt.it.shouldBeDeniedWhenCalledByUser(USER, 'GET', '/api/accessTokens');
|
|
|
|
|
|
|
|
lt.it.shouldBeDeniedWhenCalledAnonymously('PUT', '/api/accessTokens');
|
|
|
|
lt.it.shouldBeDeniedWhenCalledUnauthenticated('PUT', '/api/accessTokens');
|
|
|
|
lt.it.shouldBeDeniedWhenCalledByUser(USER, 'PUT', '/api/accessTokens');
|
|
|
|
|
|
|
|
lt.it.shouldBeDeniedWhenCalledAnonymously('GET', urlForToken);
|
|
|
|
lt.it.shouldBeDeniedWhenCalledUnauthenticated('GET', urlForToken);
|
|
|
|
lt.it.shouldBeDeniedWhenCalledByUser(USER, 'GET', urlForToken);
|
|
|
|
|
|
|
|
lt.it.shouldBeDeniedWhenCalledAnonymously('PUT', urlForToken);
|
|
|
|
lt.it.shouldBeDeniedWhenCalledUnauthenticated('PUT', urlForToken);
|
|
|
|
lt.it.shouldBeDeniedWhenCalledByUser(USER, 'PUT', urlForToken);
|
|
|
|
|
|
|
|
lt.it.shouldBeDeniedWhenCalledAnonymously('DELETE', urlForToken);
|
|
|
|
lt.it.shouldBeDeniedWhenCalledUnauthenticated('DELETE', urlForToken);
|
|
|
|
lt.it.shouldBeDeniedWhenCalledByUser(USER, 'DELETE', urlForToken);
|
|
|
|
|
|
|
|
function urlForToken() {
|
|
|
|
return '/api/accessTokens/' + this.randomToken.id;
|
|
|
|
}
|
|
|
|
});
|
2014-03-21 19:53:04 +00:00
|
|
|
*/
|
2013-12-18 05:10:05 +00:00
|
|
|
|
2014-11-21 02:35:36 +00:00
|
|
|
describe('/users', function() {
|
2013-12-18 05:10:05 +00:00
|
|
|
lt.beforeEach.givenModel('user', USER, 'randomUser');
|
|
|
|
|
|
|
|
lt.it.shouldBeDeniedWhenCalledAnonymously('GET', '/api/users');
|
|
|
|
lt.it.shouldBeDeniedWhenCalledUnauthenticated('GET', '/api/users');
|
|
|
|
lt.it.shouldBeDeniedWhenCalledByUser(CURRENT_USER, 'GET', '/api/users');
|
2014-11-21 01:46:21 +00:00
|
|
|
|
2013-12-18 05:10:05 +00:00
|
|
|
lt.it.shouldBeDeniedWhenCalledAnonymously('GET', urlForUser);
|
|
|
|
lt.it.shouldBeDeniedWhenCalledUnauthenticated('GET', urlForUser);
|
2014-11-21 02:35:36 +00:00
|
|
|
lt.it.shouldBeDeniedWhenCalledByUser(CURRENT_USER, 'GET', urlForUser);
|
2013-12-18 05:10:05 +00:00
|
|
|
|
2014-06-09 07:53:05 +00:00
|
|
|
lt.it.shouldBeAllowedWhenCalledAnonymously(
|
2018-08-08 15:22:20 +00:00
|
|
|
'POST', '/api/users', newUserData()
|
|
|
|
);
|
2014-06-09 07:53:05 +00:00
|
|
|
|
|
|
|
lt.it.shouldBeAllowedWhenCalledByUser(
|
2018-08-08 15:22:20 +00:00
|
|
|
CURRENT_USER, 'POST', '/api/users', newUserData()
|
|
|
|
);
|
2013-12-18 05:10:05 +00:00
|
|
|
|
2013-12-18 05:22:05 +00:00
|
|
|
lt.it.shouldBeAllowedWhenCalledByUser(CURRENT_USER, 'POST', '/api/users/logout');
|
|
|
|
|
2013-12-18 05:10:05 +00:00
|
|
|
lt.describe.whenCalledRemotely('DELETE', '/api/users', function() {
|
|
|
|
lt.it.shouldNotBeFound();
|
|
|
|
});
|
|
|
|
|
|
|
|
lt.it.shouldBeDeniedWhenCalledAnonymously('PUT', urlForUser);
|
|
|
|
lt.it.shouldBeDeniedWhenCalledUnauthenticated('PUT', urlForUser);
|
|
|
|
lt.it.shouldBeDeniedWhenCalledByUser(CURRENT_USER, 'PUT', urlForUser);
|
|
|
|
|
|
|
|
lt.it.shouldBeDeniedWhenCalledAnonymously('PUT', urlForUser);
|
|
|
|
lt.it.shouldBeDeniedWhenCalledUnauthenticated('PUT', urlForUser);
|
|
|
|
lt.it.shouldBeDeniedWhenCalledByUser(CURRENT_USER, 'PUT', urlForUser);
|
|
|
|
|
|
|
|
lt.describe.whenLoggedInAsUser(CURRENT_USER, function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
this.url = '/api/users/' + this.user.id + '?ok';
|
|
|
|
});
|
|
|
|
lt.describe.whenCalledRemotely('DELETE', '/api/users/:id', function() {
|
|
|
|
lt.it.shouldBeAllowed();
|
|
|
|
});
|
|
|
|
lt.describe.whenCalledRemotely('GET', '/api/users/:id', function() {
|
|
|
|
lt.it.shouldBeAllowed();
|
2014-03-21 19:53:04 +00:00
|
|
|
it('should not include a password', function() {
|
2014-06-06 12:51:13 +00:00
|
|
|
debug('GET /api/users/:id response: %s\nheaders: %j\nbody string: %s',
|
|
|
|
this.res.statusCode,
|
|
|
|
this.res.headers,
|
|
|
|
this.res.text);
|
2014-03-21 19:53:04 +00:00
|
|
|
var user = this.res.body;
|
|
|
|
assert.equal(user.password, undefined);
|
|
|
|
});
|
2013-12-18 05:10:05 +00:00
|
|
|
});
|
2016-05-09 19:24:03 +00:00
|
|
|
|
|
|
|
// user has replaceOnPUT = false; so then both PUT and PATCH should be allowed for update
|
2013-12-18 05:10:05 +00:00
|
|
|
lt.describe.whenCalledRemotely('PUT', '/api/users/:id', function() {
|
|
|
|
lt.it.shouldBeAllowed();
|
|
|
|
});
|
2016-05-09 19:24:03 +00:00
|
|
|
|
|
|
|
lt.describe.whenCalledRemotely('PATCH', '/api/users/:id', function() {
|
|
|
|
lt.it.shouldBeAllowed();
|
|
|
|
});
|
2013-12-18 05:10:05 +00:00
|
|
|
});
|
|
|
|
|
2016-09-02 12:40:47 +00:00
|
|
|
lt.it.shouldBeDeniedWhenCalledAnonymously('POST', '/api/users/upsertWithWhere');
|
|
|
|
lt.it.shouldBeDeniedWhenCalledUnauthenticated('POST', '/api/users/upsertWithWhere');
|
|
|
|
lt.it.shouldBeDeniedWhenCalledByUser(CURRENT_USER, 'POST', '/api/users/upsertWithWhere');
|
|
|
|
|
2013-12-18 05:10:05 +00:00
|
|
|
lt.it.shouldBeDeniedWhenCalledAnonymously('DELETE', urlForUser);
|
|
|
|
lt.it.shouldBeDeniedWhenCalledUnauthenticated('DELETE', urlForUser);
|
|
|
|
lt.it.shouldBeDeniedWhenCalledByUser(CURRENT_USER, 'DELETE', urlForUser);
|
|
|
|
|
|
|
|
function urlForUser() {
|
|
|
|
return '/api/users/' + this.randomUser.id;
|
|
|
|
}
|
2014-06-09 07:53:05 +00:00
|
|
|
|
|
|
|
var userCounter;
|
|
|
|
function newUserData() {
|
|
|
|
userCounter = userCounter ? ++userCounter : 1;
|
2016-05-05 04:09:06 +00:00
|
|
|
|
2014-06-09 07:53:05 +00:00
|
|
|
return {
|
|
|
|
email: 'new-' + userCounter + '@test.test',
|
2016-04-01 09:14:26 +00:00
|
|
|
password: 'test',
|
2014-06-09 07:53:05 +00:00
|
|
|
};
|
|
|
|
}
|
2013-12-18 05:10:05 +00:00
|
|
|
});
|
|
|
|
|
2014-11-21 02:35:36 +00:00
|
|
|
describe('/banks', function() {
|
2016-11-15 21:46:23 +00:00
|
|
|
var SPECIAL_USER = {email: 'special@test.test', password: 'test'};
|
2016-08-16 15:02:34 +00:00
|
|
|
|
|
|
|
// define dynamic role that would only grant access when the authenticated user's email is equal to
|
|
|
|
// SPECIAL_USER's email
|
|
|
|
|
|
|
|
before(function() {
|
|
|
|
var roleModel = app.registry.getModel('Role');
|
|
|
|
var userModel = app.registry.getModel('user');
|
|
|
|
|
|
|
|
roleModel.registerResolver('$dynamic-role', function(role, context, callback) {
|
|
|
|
if (!(context && context.accessToken && context.accessToken.userId)) {
|
|
|
|
return process.nextTick(function() {
|
2016-11-22 14:30:04 +00:00
|
|
|
if (callback) callback(null, false);
|
2016-08-16 15:02:34 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
var accessToken = context.accessToken;
|
|
|
|
userModel.findById(accessToken.userId, function(err, user) {
|
|
|
|
if (err) {
|
|
|
|
return callback(err, false);
|
|
|
|
}
|
|
|
|
if (user && user.email === SPECIAL_USER.email) {
|
|
|
|
return callback(null, true);
|
|
|
|
}
|
|
|
|
return callback(null, false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-12-18 05:10:05 +00:00
|
|
|
lt.beforeEach.givenModel('bank');
|
|
|
|
|
|
|
|
lt.it.shouldBeAllowedWhenCalledAnonymously('GET', '/api/banks');
|
|
|
|
lt.it.shouldBeAllowedWhenCalledUnauthenticated('GET', '/api/banks');
|
|
|
|
lt.it.shouldBeAllowedWhenCalledByUser(CURRENT_USER, 'GET', '/api/banks');
|
|
|
|
|
|
|
|
lt.it.shouldBeAllowedWhenCalledAnonymously('GET', urlForBank);
|
|
|
|
lt.it.shouldBeAllowedWhenCalledUnauthenticated('GET', urlForBank);
|
|
|
|
lt.it.shouldBeAllowedWhenCalledByUser(CURRENT_USER, 'GET', urlForBank);
|
|
|
|
|
|
|
|
lt.it.shouldBeDeniedWhenCalledAnonymously('POST', '/api/banks');
|
|
|
|
lt.it.shouldBeDeniedWhenCalledUnauthenticated('POST', '/api/banks');
|
|
|
|
lt.it.shouldBeDeniedWhenCalledByUser(CURRENT_USER, 'POST', '/api/banks');
|
|
|
|
|
|
|
|
lt.it.shouldBeDeniedWhenCalledAnonymously('PUT', urlForBank);
|
|
|
|
lt.it.shouldBeDeniedWhenCalledUnauthenticated('PUT', urlForBank);
|
|
|
|
lt.it.shouldBeDeniedWhenCalledByUser(CURRENT_USER, 'PUT', urlForBank);
|
|
|
|
|
|
|
|
lt.it.shouldBeDeniedWhenCalledAnonymously('DELETE', urlForBank);
|
|
|
|
lt.it.shouldBeDeniedWhenCalledUnauthenticated('DELETE', urlForBank);
|
|
|
|
lt.it.shouldBeDeniedWhenCalledByUser(CURRENT_USER, 'DELETE', urlForBank);
|
2016-08-16 15:02:34 +00:00
|
|
|
lt.it.shouldBeAllowedWhenCalledByUser(SPECIAL_USER, 'DELETE', urlForBank);
|
2013-12-18 05:10:05 +00:00
|
|
|
|
2016-09-02 12:40:47 +00:00
|
|
|
lt.it.shouldBeDeniedWhenCalledAnonymously('POST', '/api/banks/upsertWithWhere');
|
|
|
|
lt.it.shouldBeDeniedWhenCalledUnauthenticated('POST', '/api/banks/upsertWithWhere');
|
|
|
|
lt.it.shouldBeDeniedWhenCalledByUser(CURRENT_USER, 'POST', '/api/banks/upsertWithWhere');
|
|
|
|
|
2013-12-18 05:10:05 +00:00
|
|
|
function urlForBank() {
|
|
|
|
return '/api/banks/' + this.bank.id;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-05-09 19:24:03 +00:00
|
|
|
describe('/accounts with replaceOnPUT true', function() {
|
2014-08-08 05:19:27 +00:00
|
|
|
var count = 0;
|
|
|
|
before(function() {
|
|
|
|
var roleModel = loopback.getModelByType(loopback.Role);
|
2014-11-21 02:35:36 +00:00
|
|
|
roleModel.registerResolver('$dummy', function(role, context, callback) {
|
|
|
|
process.nextTick(function() {
|
|
|
|
if (context.remotingContext) {
|
2014-08-08 05:19:27 +00:00
|
|
|
count++;
|
|
|
|
}
|
2016-11-22 14:30:04 +00:00
|
|
|
if (callback) callback(null, false); // Always true
|
2014-08-08 05:19:27 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-05-09 19:24:03 +00:00
|
|
|
lt.beforeEach.givenModel('accountWithReplaceOnPUTtrue');
|
2013-12-18 05:10:05 +00:00
|
|
|
|
2016-05-09 19:24:03 +00:00
|
|
|
lt.it.shouldBeDeniedWhenCalledAnonymously('GET', '/api/accounts-replacing');
|
|
|
|
lt.it.shouldBeDeniedWhenCalledUnauthenticated('GET', '/api/accounts-replacing');
|
|
|
|
lt.it.shouldBeDeniedWhenCalledByUser(CURRENT_USER, 'GET', '/api/accounts-replacing');
|
2013-12-18 05:10:05 +00:00
|
|
|
|
|
|
|
lt.it.shouldBeDeniedWhenCalledAnonymously('GET', urlForAccount);
|
|
|
|
lt.it.shouldBeDeniedWhenCalledUnauthenticated('GET', urlForAccount);
|
|
|
|
lt.it.shouldBeDeniedWhenCalledByUser(CURRENT_USER, 'GET', urlForAccount);
|
|
|
|
|
2016-05-09 19:24:03 +00:00
|
|
|
lt.it.shouldBeDeniedWhenCalledAnonymously('POST', '/api/accounts-replacing');
|
|
|
|
lt.it.shouldBeDeniedWhenCalledUnauthenticated('POST', '/api/accounts-replacing');
|
|
|
|
lt.it.shouldBeDeniedWhenCalledByUser(CURRENT_USER, 'POST', '/api/accounts-replacing');
|
|
|
|
|
|
|
|
lt.it.shouldBeDeniedWhenCalledAnonymously('POST', urlForReplaceAccountPOST);
|
|
|
|
lt.it.shouldBeDeniedWhenCalledUnauthenticated('POST', urlForReplaceAccountPOST);
|
|
|
|
lt.it.shouldBeDeniedWhenCalledByUser(CURRENT_USER, 'POST', urlForReplaceAccountPOST);
|
2013-12-18 05:10:05 +00:00
|
|
|
|
|
|
|
lt.it.shouldBeDeniedWhenCalledAnonymously('PUT', urlForAccount);
|
|
|
|
lt.it.shouldBeDeniedWhenCalledUnauthenticated('PUT', urlForAccount);
|
|
|
|
lt.it.shouldBeDeniedWhenCalledByUser(CURRENT_USER, 'PUT', urlForAccount);
|
|
|
|
|
2016-05-09 19:24:03 +00:00
|
|
|
lt.it.shouldBeDeniedWhenCalledAnonymously('PATCH', urlForAccount);
|
|
|
|
lt.it.shouldBeDeniedWhenCalledUnauthenticated('PATCH', urlForAccount);
|
|
|
|
lt.it.shouldBeDeniedWhenCalledByUser(CURRENT_USER, 'PATCH', urlForAccount);
|
|
|
|
|
2013-12-18 05:10:05 +00:00
|
|
|
lt.describe.whenLoggedInAsUser(CURRENT_USER, function() {
|
2016-05-09 19:24:03 +00:00
|
|
|
var actId;
|
2014-03-19 22:09:20 +00:00
|
|
|
beforeEach(function(done) {
|
|
|
|
var self = this;
|
|
|
|
// Create an account under the given user
|
2016-05-09 19:24:03 +00:00
|
|
|
app.models.accountWithReplaceOnPUTtrue.create({
|
2014-03-19 22:09:20 +00:00
|
|
|
userId: self.user.id,
|
2016-04-01 09:14:26 +00:00
|
|
|
balance: 100,
|
2014-03-19 22:09:20 +00:00
|
|
|
}, function(err, act) {
|
2016-05-09 19:24:03 +00:00
|
|
|
actId = act.id;
|
|
|
|
self.url = '/api/accounts-replacing/' + actId;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2016-05-05 04:09:06 +00:00
|
|
|
|
2016-05-09 19:24:03 +00:00
|
|
|
lt.describe.whenCalledRemotely('PATCH', '/api/accounts-replacing/:id', function() {
|
|
|
|
lt.it.shouldBeAllowed();
|
|
|
|
});
|
|
|
|
lt.describe.whenCalledRemotely('PUT', '/api/accounts-replacing/:id', function() {
|
|
|
|
lt.it.shouldBeAllowed();
|
|
|
|
});
|
|
|
|
lt.describe.whenCalledRemotely('GET', '/api/accounts-replacing/:id', function() {
|
|
|
|
lt.it.shouldBeAllowed();
|
|
|
|
});
|
|
|
|
lt.describe.whenCalledRemotely('DELETE', '/api/accounts-replacing/:id', function() {
|
|
|
|
lt.it.shouldBeDenied();
|
|
|
|
});
|
|
|
|
describe('replace on POST verb', function() {
|
|
|
|
beforeEach(function(done) {
|
|
|
|
this.url = '/api/accounts-replacing/' + actId + '/replace';
|
2014-03-19 22:09:20 +00:00
|
|
|
done();
|
|
|
|
});
|
2016-05-09 19:24:03 +00:00
|
|
|
lt.describe.whenCalledRemotely('POST', '/api/accounts-replacing/:id/replace', function() {
|
|
|
|
lt.it.shouldBeAllowed();
|
|
|
|
});
|
2013-12-18 05:10:05 +00:00
|
|
|
});
|
2016-05-09 19:24:03 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
lt.it.shouldBeDeniedWhenCalledAnonymously('DELETE', urlForAccount);
|
|
|
|
lt.it.shouldBeDeniedWhenCalledUnauthenticated('DELETE', urlForAccount);
|
|
|
|
lt.it.shouldBeDeniedWhenCalledByUser(CURRENT_USER, 'DELETE', urlForAccount);
|
2016-04-01 09:14:26 +00:00
|
|
|
|
2016-05-09 19:24:03 +00:00
|
|
|
function urlForAccount() {
|
|
|
|
return '/api/accounts-replacing/' + this.accountWithReplaceOnPUTtrue.id;
|
|
|
|
}
|
|
|
|
function urlForReplaceAccountPOST() {
|
|
|
|
return '/api/accounts-replacing/' + this.accountWithReplaceOnPUTtrue.id + '/replace';
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('/accounts with replaceOnPUT false', function() {
|
|
|
|
lt.beforeEach.givenModel('accountWithReplaceOnPUTfalse');
|
|
|
|
lt.it.shouldBeDeniedWhenCalledAnonymously('POST', urlForReplaceAccountPOST);
|
|
|
|
lt.it.shouldBeDeniedWhenCalledUnauthenticated('POST', urlForReplaceAccountPOST);
|
|
|
|
lt.it.shouldBeDeniedWhenCalledByUser(CURRENT_USER, 'POST', urlForReplaceAccountPOST);
|
|
|
|
|
|
|
|
lt.it.shouldBeDeniedWhenCalledAnonymously('PUT', urlForAccount);
|
|
|
|
lt.it.shouldBeDeniedWhenCalledUnauthenticated('PUT', urlForAccount);
|
|
|
|
lt.it.shouldBeDeniedWhenCalledByUser(CURRENT_USER, 'PUT', urlForAccount);
|
|
|
|
|
|
|
|
lt.it.shouldBeDeniedWhenCalledAnonymously('PATCH', urlForAccount);
|
|
|
|
lt.it.shouldBeDeniedWhenCalledUnauthenticated('PATCH', urlForAccount);
|
|
|
|
lt.it.shouldBeDeniedWhenCalledByUser(CURRENT_USER, 'PATCH', urlForAccount);
|
|
|
|
|
|
|
|
lt.describe.whenLoggedInAsUser(CURRENT_USER, function() {
|
|
|
|
var actId;
|
|
|
|
beforeEach(function(done) {
|
|
|
|
var self = this;
|
|
|
|
// Create an account under the given user
|
|
|
|
app.models.accountWithReplaceOnPUTfalse.create({
|
|
|
|
userId: self.user.id,
|
|
|
|
balance: 100,
|
|
|
|
}, function(err, act) {
|
|
|
|
actId = act.id;
|
|
|
|
self.url = '/api/accounts-updating/' + actId;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
lt.describe.whenCalledRemotely('PATCH', '/api/accounts-updating/:id', function() {
|
|
|
|
lt.it.shouldBeAllowed();
|
|
|
|
});
|
|
|
|
|
|
|
|
lt.describe.whenCalledRemotely('PUT', '/api/accounts-updating/:id', function() {
|
2013-12-18 05:10:05 +00:00
|
|
|
lt.it.shouldBeAllowed();
|
|
|
|
});
|
2016-05-09 19:24:03 +00:00
|
|
|
lt.describe.whenCalledRemotely('GET', '/api/accounts-updating/:id', function() {
|
2014-03-19 22:09:20 +00:00
|
|
|
lt.it.shouldBeAllowed();
|
|
|
|
});
|
2016-05-09 19:24:03 +00:00
|
|
|
lt.describe.whenCalledRemotely('DELETE', '/api/accounts-updating/:id', function() {
|
2013-12-18 05:10:05 +00:00
|
|
|
lt.it.shouldBeDenied();
|
|
|
|
});
|
2016-05-09 19:24:03 +00:00
|
|
|
|
|
|
|
describe('replace on POST verb', function() {
|
|
|
|
beforeEach(function(done) {
|
|
|
|
this.url = '/api/accounts-updating/' + actId + '/replace';
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
lt.describe.whenCalledRemotely('POST', '/api/accounts-updating/:id/replace', function() {
|
|
|
|
lt.it.shouldBeAllowed();
|
|
|
|
});
|
|
|
|
});
|
2013-12-18 05:10:05 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
lt.it.shouldBeDeniedWhenCalledAnonymously('DELETE', urlForAccount);
|
|
|
|
lt.it.shouldBeDeniedWhenCalledUnauthenticated('DELETE', urlForAccount);
|
|
|
|
lt.it.shouldBeDeniedWhenCalledByUser(CURRENT_USER, 'DELETE', urlForAccount);
|
|
|
|
|
|
|
|
function urlForAccount() {
|
2016-05-09 19:24:03 +00:00
|
|
|
return '/api/accounts-updating/' + this.accountWithReplaceOnPUTfalse.id;
|
|
|
|
}
|
|
|
|
function urlForReplaceAccountPOST() {
|
|
|
|
return '/api/accounts-updating/' + this.accountWithReplaceOnPUTfalse.id + '/replace';
|
2013-12-18 05:10:05 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|