From eb4188c373eff5223bdf8b3fc6d431c9db37ec66 Mon Sep 17 00:00:00 2001 From: Ritchie Martori Date: Tue, 10 Apr 2012 12:09:53 -0700 Subject: [PATCH] removed mdoq patch from tests --- lib/validation.js | 1 + test/dashboard.test.js | 12 ++++++------ test/root.test.js | 15 ++++++++------- test/users.test.js | 17 +++++++++-------- test/xdomain.test.js | 23 ----------------------- 5 files changed, 24 insertions(+), 44 deletions(-) delete mode 100644 test/xdomain.test.js diff --git a/lib/validation.js b/lib/validation.js index 44f03a9..80ba5c1 100644 --- a/lib/validation.js +++ b/lib/validation.js @@ -47,6 +47,7 @@ module.exports = function (req, res, next) { // default _id to current user when logging out if(!req.isRoot && resource.type === 'UserCollection' && req.url.indexOf('/logout') === req.url.lastIndexOf('/')) { + if(!req.session) return next({status: 404}); req.query._id = req.session._id; return next(); } diff --git a/test/dashboard.test.js b/test/dashboard.test.js index 41c52b5..3d6b2a7 100644 --- a/test/dashboard.test.js +++ b/test/dashboard.test.js @@ -22,10 +22,10 @@ describe("Dashboard", function() { }); }); - // it('should return a 404 for a bad filename', function(done) { - // dashboard.use('/bogus/file').get(function(err, result) { - // expect(result).to.not.exist; - // done(); - // }); - // }); + it('should return a 404 for a bad filename', function(done) { + dashboard.use('/bogus/file').get(function(err, result) { + expect(result).to.not.exist; + done(); + }); + }); }); \ No newline at end of file diff --git a/test/root.test.js b/test/root.test.js index 7875b47..6e28542 100644 --- a/test/root.test.js +++ b/test/root.test.js @@ -1,15 +1,15 @@ - - describe('Internal Collections', function(){ describe('* /keys', function(){ it('should not be available over http without a dpd key', function(done) { var ex = {key: 'foo', secret: 'bar'} - , unauthed = require('../lib/client').use(client.url); + , unauthed = require('../lib/client').use(client.url) + , keys = unauthed.use('/keys') + ; - unauthed.use('/keys').post(ex, function (e, r) { - unauthed.use('/keys').put(ex, function (err, res) { - unauthed.use('/keys').del(function (error, resp) { - unauthed.use('/keys').get(function (gerror, gresp) { + keys.post(ex, function (e, r) { + keys.put(ex, function (err, res) { + keys.del(function (error, resp) { + keys.get(function (gerror, gresp) { expect(e && err && error && gerror).to.exist; expect(r || res || resp || gresp).to.not.exist; done(); @@ -19,6 +19,7 @@ describe('Internal Collections', function(){ }) }) }) + describe('* /resources', function(){ it('should not be available over http without a dpd key', function(done) { var ex = {key: 'foo', secret: 'bar'} diff --git a/test/users.test.js b/test/users.test.js index 267a208..11b3de7 100644 --- a/test/users.test.js +++ b/test/users.test.js @@ -24,9 +24,9 @@ describe('Users', function(){ }) describe('POST /users/login', function(){ - var login = users.use('/login'); it('should login if provided the correct credentials', function(done) { + var login = users.use('/login'); login.post({email: data.users[0].email, password: data.users[0].password}, function (err, session, req, res) { expect(session._id).to.have.length(24); expect(session.user.password).to.not.exist; @@ -36,6 +36,7 @@ describe('Users', function(){ }) it('should not respond to a GET', function(done) { + var login = users.use('/login'); login.get(function (err, res) { expect(err).to.exist; done(); @@ -46,7 +47,7 @@ describe('Users', function(){ describe('GET /users/me', function(){ it('should return the current session', function(done) { users.use('/login').post({email: data.users[0].email, password: data.users[0].password}, function (err, session, req, res) { - client.use('/users/me').get(function (err, user) { + users.use('/me').get(function (err, user) { expect(user).to.exist; expect(user._id).to.have.length(24); expect(user.password).to.not.exist; @@ -59,9 +60,9 @@ describe('Users', function(){ describe('POST /users/logout', function(){ it('should logout the current user', function(done) { users.use('/login').post({email: data.users[0].email, password: data.users[0].password}, function (err, session, req, res) { - unauthed.use('/users/logout').post(function (err, res) { + users.use('/logout').post(function (err, res) { expect(err).to.not.exist; - unauthed.use('/users/me').get(function (err, res) { + users.use('/me').get(function (err, res) { expect(err).to.exist; done(); }); @@ -71,9 +72,9 @@ describe('Users', function(){ it('should not respond to DELETE', function(done) { users.use('/login').post({email: data.users[0].email, password: data.users[0].password}, function (err, session, req, res) { - unauthed.use('/users/logout').del(function (err, res) { + users.use('/logout').del(function (err, res) { expect(err).to.exist; - unauthed.use('/users/me').get(function (err, res) { + users.use('/me').get(function (err, res) { expect(err).to.not.exist; done(); }); @@ -82,7 +83,7 @@ describe('Users', function(){ }) it('should return an error if trying to logout twice', function(done) { - client.use('/users/logout').post(function (err, body, req, res) { + users.use('/logout').post(function (err, body, req, res) { expect(err).to.exist; done(); }); @@ -91,7 +92,7 @@ describe('Users', function(){ describe('GET /users', function(){ it('should return a user if an id is provided', function(done) { - client.use('/users').get({_id: data.users[0]._id}, function (err, user) { + users.get({_id: data.users[0]._id}, function (err, user) { expect(user).to.exist; expect(user).to.have.length(1); expect(user[0].password).to.not.exist; diff --git a/test/xdomain.test.js b/test/xdomain.test.js deleted file mode 100644 index 9784d30..0000000 --- a/test/xdomain.test.js +++ /dev/null @@ -1,23 +0,0 @@ -// describe('Cross Domain Support', function(){ -// describe('OPTIONS /todo', function(){ -// it('should include Access-Control-Allow-Headers', function(done) { -// var hdrs = 'GET, POST, PUT, DELETE' -// , req = {method: 'OPTIONS', url: todos.url, headers: {'Access-Control-Request-Headers': hdrs}} -// ; -// todos.exec(req, function (err, body, req, res) { -// expect(body).to.equal('OK'); -// done(err); -// }) -// }) -// }) -// describe('* /todos', function(){ -// it('should include Access-Control-Allow-* headers', function(done) { -// todos.get(function (err, body, req, res) { -// expect(res.headers['Access-Control-Allow-Origin'.toLowerCase()]).to.equal('*'); -// expect(res.headers['Access-Control-Allow-Methods'.toLowerCase()]).to.equal('GET, POST, PUT, DELETE, OPTIONS'); -// expect(res.headers['Access-Control-Allow-Credentials'.toLowerCase()]).to.equal('true'); -// done(err); -// }) -// }) -// }) -// }) \ No newline at end of file