Skip to content
This repository has been archived by the owner on Dec 15, 2020. It is now read-only.

Commit

Permalink
Merge pull request #13 from thaliproject/aaladev_12
Browse files Browse the repository at this point in the history
Added attachment id
  • Loading branch information
andrew-aladev committed Nov 22, 2016
2 parents 32abe64 + ee250d0 commit 5182ec5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
9 changes: 5 additions & 4 deletions lib/index.js
Expand Up @@ -48,7 +48,8 @@ Salti.defaults = {
stripTrailingSlash: true,
dbPrefix: undefined,
dbPathTemplate: '{:db}',
idTokenTemplate: '{:id}'
idTokenTemplate: '{:id}',
attachmentIdTemplate: '{:attachmentId}'
};

Salti.THALI_PREFIX = '/_local/thali_';
Expand Down Expand Up @@ -167,10 +168,10 @@ Salti.prototype.handler = function (request, response, nextHandler) {
}
}

else if (pathParts.length === 3 && pathParts[2] === 'attachment') {
// Is /{:id}/attachment authorized?
else if (pathParts.length === 3) {
// Is /{:id}/{:attachmentId} authorized?
lookupPath = this.dbPrefix + '/' + this.options.idTokenTemplate +
'/attachment';
'/' + this.options.attachmentIdTemplate;
if (this.lookupPathVerb(paths, lookupPath) === Salti.PATH_VERB_FOUND) {
return this.authorized('passed attachment check');
} else {
Expand Down
2 changes: 1 addition & 1 deletion test/acl-block.1.js
Expand Up @@ -32,7 +32,7 @@ module.exports = [{
'verbs': ['GET']
},
{
'path': '/{:db}/{:id}/attachment',
'path': '/{:db}/{:id}/{:attachmentId}',
'verbs': ['GET']
},
{
Expand Down
10 changes: 5 additions & 5 deletions test/test-core-attachment.js
Expand Up @@ -2,7 +2,7 @@

/** this will check the following:
** DB spedific paths - note that ':db' token to be substituted with the db name in that context
** | /:db/:id/attachment | GET, | |
** | /:db/:id/:attachmentId | GET, | |
*/

var request = require('supertest');
Expand All @@ -15,15 +15,15 @@ var lib = require('../lib/index');
var acl = require('./acl-block.1.js');

var dbName = 'foobar';
var path = '/' + dbName + '/1234/attachment';
var path = '/' + dbName + '/1234/attachmentId';

function genericHandlers(router, path) {
router.get(path, handlers.get);
return router;
}

describe(
'test-core-attachment.js - calling the /db/id/attachment path', function () {
'test-core-attachment.js - calling the /db/id/attachmentId path', function () {
describe('using repl identity', function () {
var app = express();
var router = express.Router();
Expand Down Expand Up @@ -76,11 +76,11 @@ describe(
.expect(401, done);
});

it('GET zzz should be 401', function (done) {
it('GET zzz should be 404', function (done) {
request(app)
.get(path + 'zzz')
.set('Accept', 'application/json')
.expect(401, done);
.expect(404, done);
});
});
});
5 changes: 3 additions & 2 deletions test/test-core-resources.js
Expand Up @@ -89,11 +89,12 @@ describe('test-core-resources calling the /db/{id} path', function () {
.expect(401, done);
});

it('GET should be 401 on /1234/1234', function (done) {
// this looks like attachment: {:id}/{:attachmentId}
it('GET should be 404 on /1234/1234', function (done) {
request(app)
.get('/' + path + '/1234')
.set('Accept', 'application/json')
.expect(401, done);
.expect(404, done);
});
it('PUT should be 401', function (done) {
request(app)
Expand Down

0 comments on commit 5182ec5

Please sign in to comment.