Changes rules for names in templates

Now valid names can start with numbers and can contain dashes (-).
Closes #306
This commit is contained in:
Raul Ochoa 2015-06-04 10:41:40 -04:00
parent 7c315b3afd
commit 3f0d344313
3 changed files with 45 additions and 25 deletions

View File

@ -404,7 +404,7 @@ POST /api/v1/map/named
##### Arguments ##### Arguments
- **name**: There can be at most _one_ template with the same name for any user. Valid names start with a letter, and only contain letters, numbers, or underscores (_). - **name**: There can be at most _one_ template with the same name for any user. Valid names start with a letter or a number, and only contain letters, numbers, dashes (-) or underscores (_).
- **auth**: - **auth**:
- **method** `"token"` or `"open"` (the default if no `"method"` is given). - **method** `"token"` or `"open"` (the default if no `"method"` is given).
- **valid_tokens** when `"method"` is set to `"token"`, the values listed here allow you to instantiate the named map. - **valid_tokens** when `"method"` is set to `"token"`, the values listed here allow you to instantiate the named map.

View File

@ -88,7 +88,7 @@ o._redisCmd = function(redisFunc, redisArgs, callback) {
); );
}; };
var _reValidIdentifier = /^[a-zA-Z][0-9a-zA-Z_]*$/; var _reValidIdentifier = /^[a-z0-9][0-9a-z_\-]*$/i;
// jshint maxcomplexity:15 // jshint maxcomplexity:15
o._checkInvalidTemplate = function(template) { o._checkInvalidTemplate = function(template) {
if ( template.version != '0.0.1' ) { if ( template.version != '0.0.1' ) {

View File

@ -59,30 +59,50 @@ describe('template_maps', function() {
); );
}); });
it('does not accept template with invalid name', function(done) { describe('naming', function() {
var tmap = new TemplateMaps(redis_pool);
assert.ok(tmap); function createTemplate(name) {
var tpl = { version:'0.0.1', return {
auth: {}, layergroup: {layers:[wadusLayer]} }; version:'0.0.1',
var invalidnames = [ "ab|", "a b", "a@b", "1ab", "_x", "", " x", "x " ]; name: name,
var testNext = function() { auth: {},
if ( ! invalidnames.length ) { done(); return; } layergroup: {
var n = invalidnames.pop(); layers: [
tpl.name = n; wadusLayer
tmap.addTemplate('me', tpl, function(err) { ]
if ( ! err ) { }
done(new Error("Unexpected success with invalid name '" + n + "'")); };
} }
else if ( ! err.message.match(/template.*name/i) ) { var templateMaps = new TemplateMaps(redis_pool);
done(new Error("Unexpected error message with invalid name '" + n + "': " + err));
} var invalidNames = [ "ab|", "a b", "a@b", "-1ab", "_x", "", " x", "x " ];
else { invalidNames.forEach(function(invalidName) {
testNext(); it('should NOT accept template with invalid name: ' + invalidName, function(done) {
} templateMaps.addTemplate('me', createTemplate(invalidName), function(err) {
}); assert.ok(err, "Unexpected success with invalid name '" + invalidName + "'");
}; assert.ok(
testNext(); err.message.match(/template.*name/i),
}); "Unexpected error message with invalid name '" + invalidName + "': " + err.message
);
done();
});
});
});
var validNames = [
"AB", "1ab", "DFD19A1A-0AC6-11E5-B0CA-6476BA93D4F6", "25ad8300-0ac7-11e5-b93f-6476ba93d4f6"
];
validNames.forEach(function(validName) {
it('should accept template with valid name: ' + validName, function(done) {
templateMaps.addTemplate('me', createTemplate(validName), function(err) {
assert.ok(!err, "Unexpected error with valid name '" + validName + "': " + err);
done();
});
});
});
});
it('does not accept template with invalid placeholder name', function(done) { it('does not accept template with invalid placeholder name', function(done) {
var tmap = new TemplateMaps(redis_pool); var tmap = new TemplateMaps(redis_pool);