Skip to content

Commit

Permalink
fix jscs errors
Browse files Browse the repository at this point in the history
  • Loading branch information
rhalff committed Nov 21, 2014
1 parent 38757c1 commit 36e1f68
Show file tree
Hide file tree
Showing 26 changed files with 701 additions and 711 deletions.
4 changes: 2 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ module.exports = function(grunt) {
gruntfile: 'Gruntfile.js',
lib: ['lib/**/*.js'],
common: ['common/**/*.js'],
server: ['server/**/*.js']
// TODO(bajtos) - test/**/*.js
server: ['server/**/*.js'],
test: ['test/**/*.js']
},
watch: {
gruntfile: {
Expand Down
20 changes: 10 additions & 10 deletions test/access-control.integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ var USER = {email: '[email protected]', password: 'test'};
var CURRENT_USER = {email: '[email protected]', password: 'test'};
var debug = require('debug')('loopback:test:access-control.integration');

describe('access control - integration', function () {
describe('access control - integration', function() {

lt.beforeEach.withApp(app);

/*
describe('accessToken', function() {
// it('should be a sublcass of AccessToken', function () {
// it('should be a sublcass of AccessToken', function() {
// assert(app.models.accessToken.prototype instanceof loopback.AccessToken);
// });
it('should have a validate method', function () {
it('should have a validate method', function() {
var token = new app.models.accessToken;
assert.equal(typeof token.validate, 'function');
});
Expand Down Expand Up @@ -60,7 +60,7 @@ describe('access control - integration', function () {
});
*/

describe('/users', function () {
describe('/users', function() {

lt.beforeEach.givenModel('user', USER, 'randomUser');

Expand All @@ -70,7 +70,7 @@ describe('access control - integration', function () {

lt.it.shouldBeDeniedWhenCalledAnonymously('GET', urlForUser);
lt.it.shouldBeDeniedWhenCalledUnauthenticated('GET', urlForUser);
lt.it.shouldBeDeniedWhenCalledByUser(CURRENT_USER,'GET', urlForUser);
lt.it.shouldBeDeniedWhenCalledByUser(CURRENT_USER, 'GET', urlForUser);

lt.it.shouldBeAllowedWhenCalledAnonymously(
'POST', '/api/users', newUserData());
Expand Down Expand Up @@ -133,7 +133,7 @@ describe('access control - integration', function () {
}
});

describe('/banks', function () {
describe('/banks', function() {
lt.beforeEach.givenModel('bank');

lt.it.shouldBeAllowedWhenCalledAnonymously('GET', '/api/banks');
Expand Down Expand Up @@ -161,13 +161,13 @@ describe('access control - integration', function () {
}
});

describe('/accounts', function () {
describe('/accounts', function() {
var count = 0;
before(function() {
var roleModel = loopback.getModelByType(loopback.Role);
roleModel.registerResolver('$dummy', function (role, context, callback) {
process.nextTick(function () {
if(context.remotingContext) {
roleModel.registerResolver('$dummy', function(role, context, callback) {
process.nextTick(function() {
if (context.remotingContext) {
count++;
}
callback && callback(null, false); // Always true
Expand Down
46 changes: 23 additions & 23 deletions test/access-token.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,40 @@ var ACL = loopback.ACL;
describe('loopback.token(options)', function() {
beforeEach(createTestingToken);

it('should populate req.token from the query string', function (done) {
it('should populate req.token from the query string', function(done) {
createTestAppAndRequest(this.token, done)
.get('/?access_token=' + this.token.id)
.expect(200)
.end(done);
});

it('should populate req.token from an authorization header', function (done) {
it('should populate req.token from an authorization header', function(done) {
createTestAppAndRequest(this.token, done)
.get('/')
.set('authorization', this.token.id)
.expect(200)
.end(done);
});

it('should populate req.token from an X-Access-Token header', function (done) {
it('should populate req.token from an X-Access-Token header', function(done) {
createTestAppAndRequest(this.token, done)
.get('/')
.set('X-Access-Token', this.token.id)
.expect(200)
.end(done);
});

it('should populate req.token from an authorization header with bearer token', function (done) {
it('should populate req.token from an authorization header with bearer token', function(done) {
var token = this.token.id;
token = 'Bearer '+ new Buffer(token).toString('base64');
token = 'Bearer ' + new Buffer(token).toString('base64');
createTestAppAndRequest(this.token, done)
.get('/')
.set('authorization', this.token.id)
.expect(200)
.end(done);
});

it('should populate req.token from a secure cookie', function (done) {
it('should populate req.token from a secure cookie', function(done) {
var app = createTestApp(this.token, done);

request(app)
Expand All @@ -52,7 +52,7 @@ describe('loopback.token(options)', function() {
});
});

it('should populate req.token from a header or a secure cookie', function (done) {
it('should populate req.token from a header or a secure cookie', function(done) {
var app = createTestApp(this.token, done);
var id = this.token.id;
request(app)
Expand Down Expand Up @@ -88,20 +88,20 @@ describe('loopback.token(options)', function() {
});
});

describe('AccessToken', function () {
describe('AccessToken', function() {
beforeEach(createTestingToken);

it('should auto-generate id', function () {
it('should auto-generate id', function() {
assert(this.token.id);
assert.equal(this.token.id.length, 64);
});

it('should auto-generate created date', function () {
it('should auto-generate created date', function() {
assert(this.token.created);
assert(Object.prototype.toString.call(this.token.created), '[object Date]');
});

it('should be validateable', function (done) {
it('should be validateable', function(done) {
this.token.validate(function(err, isValid) {
assert(isValid);
done();
Expand Down Expand Up @@ -144,31 +144,31 @@ describe('AccessToken', function () {
describe('app.enableAuth()', function() {
beforeEach(createTestingToken);

it('prevents remote call with 401 status on denied ACL', function (done) {
it('prevents remote call with 401 status on denied ACL', function(done) {
createTestAppAndRequest(this.token, done)
.del('/tests/123')
.expect(401)
.set('authorization', this.token.id)
.end(done);
});

it('prevent remote call with app setting status on denied ACL', function (done) {
it('prevent remote call with app setting status on denied ACL', function(done) {
createTestAppAndRequest(this.token, {app:{aclErrorStatus:403}}, done)
.del('/tests/123')
.expect(403)
.set('authorization', this.token.id)
.end(done);
});

it('prevent remote call with app setting status on denied ACL', function (done) {
it('prevent remote call with app setting status on denied ACL', function(done) {
createTestAppAndRequest(this.token, {model:{aclErrorStatus:404}}, done)
.del('/tests/123')
.expect(404)
.set('authorization', this.token.id)
.end(done);
});

it('prevent remote call if the accessToken is missing and required', function (done) {
it('prevent remote call if the accessToken is missing and required', function(done) {
createTestAppAndRequest(null, done)
.del('/tests/123')
.expect(401)
Expand Down Expand Up @@ -210,8 +210,8 @@ describe('app.enableAuth()', function() {

function createTestingToken(done) {
var test = this;
Token.create({}, function (err, token) {
if(err) return done(err);
Token.create({}, function(err, token) {
if (err) return done(err);
test.token = token;
done();
});
Expand All @@ -223,8 +223,8 @@ function createTestAppAndRequest(testToken, settings, done) {
}

function createTestApp(testToken, settings, done) {
done = arguments[arguments.length-1];
if(settings == done) settings = {};
done = arguments[arguments.length - 1];
if (settings == done) settings = {};
settings = settings || {};

var appSettings = settings.app || {};
Expand All @@ -238,19 +238,19 @@ function createTestApp(testToken, settings, done) {
res.cookie('authorization', testToken.id, {signed: true});
res.end();
});
app.get('/', function (req, res) {
app.get('/', function(req, res) {
try {
assert(req.accessToken, 'req should have accessToken');
assert(req.accessToken.id === testToken.id);
} catch(e) {
} catch (e) {
return done(e);
}
res.send('ok');
});
app.use(loopback.rest());
app.enableAuth();

Object.keys(appSettings).forEach(function(key){
Object.keys(appSettings).forEach(function(key) {
app.set(key, appSettings[key]);
});

Expand All @@ -266,7 +266,7 @@ function createTestApp(testToken, settings, done) {
]
};

Object.keys(modelSettings).forEach(function(key){
Object.keys(modelSettings).forEach(function(key) {
modelOptions[key] = modelSettings[key];
});

Expand Down
Loading

0 comments on commit 36e1f68

Please sign in to comment.