Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

deployd

Package Overview
Dependencies
Maintainers
1
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

deployd - npm Package Compare versions

Comparing version 0.4.1 to 0.4.2

39

lib/collections/resources.js

@@ -29,7 +29,19 @@ /**

// rename
collection.use(rename).rename(resource.path.replace('/', ''), function (err) {
next(err);
});
if(resource.type === 'Static') {
// rename
collection.use(rename + '.chunks').rename(resource.path.replace('/', '') + '.chunks', function (err) {
if(err) return next(err);
collection.use(rename + '.files').rename(resource.path.replace('/', '') + '.files', function (err) {
next(err);
});
});
} else {
// rename
collection.use(rename).rename(resource.path.replace('/', ''), function (err) {
next(err);
});
}
return;

@@ -54,3 +66,3 @@ }

}
})
});

@@ -61,2 +73,19 @@ if(!renames) {

} else if(req.method === 'DELETE' && req.query._id) {
resources.get(req.query).first(function (err, res) {
if(err || !res) return next(err);
if(res.type === 'Static') {
collection.use(res.path + '.files').del(function () {
collection.use(res.path + '.chunks').del(function () {
next();
})
})
} else {
collection.use(res.path).del(function (err) {
// continue on collection not found errors - still remove resource
if(err && ~err.message.indexOf('ns not found')) err = undefined;
next(err);
});
}
});
} else {

@@ -63,0 +92,0 @@ next();

@@ -137,2 +137,8 @@ /**

}
// process dates
Object.keys(data).forEach(function (key) {
if(data[key] && data[key].toISOString && data[key].toISOString.call) data[key] = data[key].toISOString();
})
}

@@ -139,0 +145,0 @@

@@ -27,3 +27,7 @@ /**

if(req.query && req.query.q && req.query.q[0] === '{') {
req.query = JSON.parse(req.query.q);
try {
req.query = JSON.parse(req.query.q);
} catch(e) {
return next({message: 'Error when parsing query: ' + e.message, status: 400});
}
// mixin orderby support

@@ -30,0 +34,0 @@ if (req.query.$orderby) {

@@ -5,3 +5,5 @@ /**

var sessions = require('./collections/sessions');
var sessions = require('./collections/sessions')
, collection = require('./types/collection')
;

@@ -15,5 +17,14 @@ module.exports = function (req, res, next) {

req.session = session;
if(session.type && session.user && session.user._id) {
collection.use('/' + session.type).get({_id: session.user._id}).first(function (err, user) {
delete user.password;
session.user = user;
next(err);
})
} else {
next(err);
}
} else {
next(err);
}
next(err);
})

@@ -20,0 +31,0 @@ } else {

40

lib/types/user-collection.js

@@ -15,5 +15,5 @@ /**

// TODO change index of to something re-usable
if(~req.url.indexOf('/login')) {
if(req.method != 'POST') {
// refuse login request from other methods
return next({status: 404});

@@ -29,3 +29,4 @@ }

// login successful - create session
sessions.post({user: user}, function (e, session) {
sessions.post({user: user, type: req.resource.path.replace('/', '')}, function (e, session) {
// store resource path
res.data = session;

@@ -66,18 +67,33 @@ res.cookie('sid', session._id, {path: '/'});

} else {
var isRootOrCurrentUser = req.isRoot || (req.query && req.session && req.session.user && req.session.user._id.toString() === req.query._id.toString());
// always remove password
req.fields = {password: 0};
if(req.method === 'GET' && !isRootOrCurrentUser) {
req.fields.email = 0;
}
// prevent GET, PUT, DELETE without _id (unless root)
if(req.method != 'POST' && !req.query._id && !req.isRoot) {
return next({message: 'Must include an _id when querying or updating a user'});
} else {
col.exec(req, function (err, docs) {
res.data = docs;
// only allow put / delete by current user
if((req.method === 'PUT' || req.method === 'DELETE') && !isRootOrCurrentUser) {
return next({status: 401});
}
// update should only set properties (not overwrite the entire object)
if(req.method === 'PUT') {
var data = req.data || req.body;
delete data._id;
req.body = req.data = {
$set: data
};
}
col.exec(req, function (err, docs) {
res.data = docs;
if(res.data && res.data.password) delete res.data.password;
if(res.data && res.data.password) delete res.data.password;
next(err);
});
}
next(err);
});
}
};

@@ -37,2 +37,4 @@ /**

req.one = true;
// alias POST w/ _id to PUT
if(req.method === 'POST') req.method = 'PUT';
}

@@ -39,0 +41,0 @@

{
"author": "Ritchie Martori",
"name": "deployd",
"version": "0.4.1",
"version": "0.4.2",
"repository": {

@@ -6,0 +6,0 @@ "url": "git://github.com/deployd/deployd.git"

@@ -151,2 +151,17 @@ describe('Collection Actions', function(){

it('should also update a single item when using POST', function(done) {
todos.post({title: 'another random todo', completed: true}, function (e, t) {
t.title = 'foobar';
todos.use('/' + t._id).post(t, function (error, todo) {
todos.use('/' + t._id).get(function (err, todo) {
expect(todo).to.exist;
expect(todo._id).to.exist;
expect(todo.completed).to.equal(true);
expect(todo.title).to.equal('foobar');
done(err);
})
})
})
})
it('should error when an id is not included', function(done) {

@@ -153,0 +168,0 @@ unauthed.use('/todos').put({title: 'foo'}, function (err) {

@@ -116,3 +116,3 @@ describe('Application Resource Types', function(){

describe('DELETE /resources', function(){
describe('DELETE /resources/', function(){
it('should remove all resources or those that match the query', function(done) {

@@ -127,2 +127,20 @@ resources.del(function (err) {

})
describe('DELETE /resources/<ObjectID>', function(){
it('should remove the resource and all of its data', function(done) {
todos.post({title: 'another todo...'}, function (err, res) {
resources.get({path: '/todos'}, function (e, res) {
res = res[0];
resources.use('/' + res._id).del(function (err, upd) {
resources.post(data.resources.todos, function (e) {
todos.get(function (err, res) {
expect(res).to.not.exist;
done(err);
})
});
})
})
})
})
})
})

@@ -33,3 +33,3 @@ describe('Static', function(){

client.use('/avatars/eg.jpg').post(file, function (err, body, req, res) {
client.use('/avatars/eg.jpg').post(file, function (err, body, req, res) {
client.use('/avatars/eg.jpg').pipe(out).get(function (err) {

@@ -36,0 +36,0 @@ var same = fs.readFileSync(__dirname + '/support/eg.jpg').toString('base64') === fs.readFileSync(__dirname + '/support/out-eg.jpg').toString('base64');

@@ -27,15 +27,28 @@ describe('Users', function(){

describe('PUT /users/:id', function(){
it('should update the user', function(done) {
data.users[0].username = 'foobar';
users.use('/' + data.users[0]._id).put(data.users[0], function (err) {
users.use('/' + data.users[0]._id).get(function (err, user) {
expect(user.email).to.eql(data.users[0].email);
expect(user.password).to.not.exist;
expect(user.username).to.equal('foobar');
done(err);
it('should update the user and still be able login', function(done) {
users.use('/login').post({email: data.users[0].email, password: data.users[0].password}, function (err, session, req, res) {
users.use('/' + session.user._id).put({username: 'foobar'}, function (err) {
users.use('/' + session.user._id).get(function (err, user) {
expect(user.email).to.eql(data.users[0].email);
expect(user.password).to.not.exist;
expect(user.username).to.equal('foobar');
// should still login
users.use('/logout').post(function () {
users.use('/login').post({email: data.users[0].email, password: data.users[0].password}, function (err, session, req, res) {
done(err);
});
})
})
})
})
})
it('should only allow the current user', function(done) {
users.use('/logout').del(function (err, res) {
users.use('/' + data.users[0]._id).put({password: 'hax'}, function (err) {
expect(err).to.exist;
done();
})
})
})
})

@@ -124,9 +137,10 @@

it('should not return a user when an _id is not provided', function(done) {
it('should not return an email unless requested from the current user', function(done) {
var unAuthed = require('../lib/client').use('http://localhost:3003/users');
unAuthed.get(function (err, res) {
expect(err).to.exist;
expect(res).to.not.exist;
done();
res.forEach(function (user) {
expect(user.email).to.not.exist;
});
done(err);
})

@@ -133,0 +147,0 @@ })

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc