Skip to content

Commit c4b69ae

Browse files
authored
Merge pull request #150 from Kashoo/issue-149-permissions
Issue 149: Ensure add permissions are only valid for add operations
2 parents 0f48188 + 987ff5e commit c4b69ae

5 files changed

Lines changed: 46 additions & 2 deletions

File tree

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
language: node_js
22
node_js:
33
- "node"
4+
- "lts/*"
45
- "0.10"

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

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

89
## [1.9.1] - 2017-05-01
910
### Fixed

etc/sync-function-authorization-module.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function() {
6363
} else if (!isDocumentMissingOrDeleted(oldDoc) && authorizationMap.replace) {
6464
writeAuthorizationFound = true;
6565
appendToAuthorizationList(requiredAuthorizations, authorizationMap.replace);
66-
} else if (authorizationMap.add) {
66+
} else if (isDocumentMissingOrDeleted(oldDoc) && authorizationMap.add) {
6767
writeAuthorizationFound = true;
6868
appendToAuthorizationList(requiredAuthorizations, authorizationMap.add);
6969
}

test/authorization-spec.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,34 @@ describe('Authorization:', function() {
5050
});
5151
});
5252

53+
describe('for a document with write channels and an explicit add channel defined', function() {
54+
it('allows document addition for a user with only the add channel', function() {
55+
var doc = { _id: 'writeAndAddChannelsDoc' };
56+
57+
testHelper.verifyDocumentCreated(doc, [ 'edit', 'add' ]);
58+
});
59+
60+
it('rejects document replacement for a user with only the add channel', function() {
61+
var doc = {
62+
_id: 'writeAndAddChannelsDoc',
63+
stringProp: 'foobar'
64+
};
65+
var oldDoc = { _id: 'writeAndAddChannelsDoc' };
66+
67+
testHelper.verifyAccessDenied(doc, oldDoc, 'edit');
68+
});
69+
70+
it('rejects document deletion for a user with only the add channel', function() {
71+
var doc = {
72+
_id: 'writeAndAddChannelsDoc',
73+
_deleted: true
74+
};
75+
var oldDoc = { _id: 'writeAndAddChannelsDoc' };
76+
77+
testHelper.verifyAccessDenied(doc, oldDoc, 'edit');
78+
});
79+
});
80+
5381
describe('for a document with dynamically-assigned roles, channels and users', function() {
5482
var expectedWriteChannels = [ 'dynamicChannelsRolesAndUsersDoc-write' ];
5583
var expectedWriteRoles = [ 'write-role1', 'write-role2' ];

test/resources/authorization-doc-definitions.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@
2828
}
2929
}
3030
},
31+
writeAndAddChannelsDoc: {
32+
channels: {
33+
write: 'edit',
34+
add: 'add'
35+
},
36+
typeFilter: function(doc) {
37+
return doc._id === 'writeAndAddChannelsDoc';
38+
},
39+
propertyValidators: {
40+
stringProp: {
41+
type: 'string'
42+
}
43+
}
44+
},
3145
dynamicChannelsRolesAndUsersDoc: {
3246
typeFilter: function(doc) {
3347
return doc._id === 'dynamicChannelsRolesAndUsersDoc';

0 commit comments

Comments
 (0)