Skip to content

Commit

Permalink
Merge pull request #150 from Kashoo/issue-149-permissions
Browse files Browse the repository at this point in the history
Issue 149: Ensure add permissions are only valid for add operations
  • Loading branch information
dkichler authored Oct 2, 2017
2 parents 0f48188 + 987ff5e commit c4b69ae
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 2 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
language: node_js
node_js:
- "node"
- "lts/*"
- "0.10"
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
Nothing yet
### Fixed
- [#149](https://github.com/Kashoo/synctos/issues/149): Permissions for add operations sometimes applied to other operation types

## [1.9.1] - 2017-05-01
### Fixed
Expand Down
2 changes: 1 addition & 1 deletion etc/sync-function-authorization-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function() {
} else if (!isDocumentMissingOrDeleted(oldDoc) && authorizationMap.replace) {
writeAuthorizationFound = true;
appendToAuthorizationList(requiredAuthorizations, authorizationMap.replace);
} else if (authorizationMap.add) {
} else if (isDocumentMissingOrDeleted(oldDoc) && authorizationMap.add) {
writeAuthorizationFound = true;
appendToAuthorizationList(requiredAuthorizations, authorizationMap.add);
}
Expand Down
28 changes: 28 additions & 0 deletions test/authorization-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,34 @@ describe('Authorization:', function() {
});
});

describe('for a document with write channels and an explicit add channel defined', function() {
it('allows document addition for a user with only the add channel', function() {
var doc = { _id: 'writeAndAddChannelsDoc' };

testHelper.verifyDocumentCreated(doc, [ 'edit', 'add' ]);
});

it('rejects document replacement for a user with only the add channel', function() {
var doc = {
_id: 'writeAndAddChannelsDoc',
stringProp: 'foobar'
};
var oldDoc = { _id: 'writeAndAddChannelsDoc' };

testHelper.verifyAccessDenied(doc, oldDoc, 'edit');
});

it('rejects document deletion for a user with only the add channel', function() {
var doc = {
_id: 'writeAndAddChannelsDoc',
_deleted: true
};
var oldDoc = { _id: 'writeAndAddChannelsDoc' };

testHelper.verifyAccessDenied(doc, oldDoc, 'edit');
});
});

describe('for a document with dynamically-assigned roles, channels and users', function() {
var expectedWriteChannels = [ 'dynamicChannelsRolesAndUsersDoc-write' ];
var expectedWriteRoles = [ 'write-role1', 'write-role2' ];
Expand Down
14 changes: 14 additions & 0 deletions test/resources/authorization-doc-definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@
}
}
},
writeAndAddChannelsDoc: {
channels: {
write: 'edit',
add: 'add'
},
typeFilter: function(doc) {
return doc._id === 'writeAndAddChannelsDoc';
},
propertyValidators: {
stringProp: {
type: 'string'
}
}
},
dynamicChannelsRolesAndUsersDoc: {
typeFilter: function(doc) {
return doc._id === 'dynamicChannelsRolesAndUsersDoc';
Expand Down

0 comments on commit c4b69ae

Please sign in to comment.