Skip to content

Commit

Permalink
[fix] Add correct validations to name property
Browse files Browse the repository at this point in the history
  • Loading branch information
julianduque committed Mar 14, 2013
1 parent 91b371d commit 8097ad3
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/jitsu/package.js
Expand Up @@ -541,7 +541,7 @@ package.properties = function (dir) {
name: 'name',
unique: true,
message: 'App name',
validator: /^[\w|\-]+$/,
validator: /^[\w|\-|\.]+$/,
default: path.basename(dir)
},
{
Expand Down
12 changes: 6 additions & 6 deletions test/commands/package-test.js
Expand Up @@ -4,7 +4,7 @@
* (C) 2010, Nodejitsu Inc.
*
*/

var assert = require('assert'),
fs = require('fs'),
path = require('path'),
Expand All @@ -16,13 +16,13 @@ var assert = require('assert'),

var shouldNodejitsuOk = macros.shouldNodejitsuOk;

vows.describe('jitsu/commands/package').addBatch({
var suite = vows.describe('jitsu/commands/package').addBatch({
'package create': shouldNodejitsuOk(
'should create the target tarball',
function (_, err) {
var tmproot = jitsu.config.get('tmproot'),
targetPackage = path.join(tmproot, 'tester-example-app-0.0.0-1.tgz');

try {
fs.statSync(targetPackage);
}
Expand All @@ -34,10 +34,10 @@ vows.describe('jitsu/commands/package').addBatch({
var tmproot = jitsu.config.get('tmproot'),
targetPackage = path.join(tmproot, 'tester-example-app-0.0.0-1.tgz'),
packageFile = path.join(__dirname, '..', 'fixtures', 'example-app', 'package.json');;

jitsu.argv.noanalyze = true;
jitsu.prompt.override['invite code'] = 'f4387f4';

//
// Change directory to the sample app
//
Expand All @@ -52,7 +52,7 @@ vows.describe('jitsu/commands/package').addBatch({
};

fs.writeFileSync(packageFile, JSON.stringify(pkg, true, 2))

//
// Attempt to remove any existing tarballs
//
Expand Down
102 changes: 102 additions & 0 deletions test/lib/package-test.js
@@ -0,0 +1,102 @@
/*
* apps-test.js: Tests for `jitsu apps *` command(s).
*
* (C) 2010, Nodejitsu Inc.
*
*/

var assert = require('assert'),
fs = require('fs'),
path = require('path'),
vows = require('vows'),
jitsu = require('../../lib/jitsu');

var mainDirectory = process.cwd();

function setupPackage (options) {
options = options || {};
return {
name: options.name || 'example-app',
subdomain: options.subdomain || 'example-app',
scripts: { start: 'server.js' },
version: '0.0.0-1',
engines: { node: '0.6.x' }
};
}

function isValid(property, value) {
// Use package properties
var properties = jitsu.package.properties(mainDirectory);

// Filter by property name
properties = properties.filter(function (el) {
return el.name === property;
});

var desc = properties[0] || {};

if (desc.validator) {
if (desc.validator instanceof RegExp) {
return desc.validator.test(value);
}

return desc.validator(value);
}
return false;
}

var suite = vows.describe('jitsu/package').addBatch({
'name': {
'starting with .': {
topic: setupPackage({ name: '.example-app' }),

'should be invalid': function (topic) {
assert.ok(isValid('name', topic.name));
}
},
'containing -': {
topic: setupPackage(),

'should be valid': function (topic) {
assert.ok(isValid('name', topic.name));
}
},
'containing spaces': {
topic: setupPackage({ name: 'example app' }),

'should be invalid': function (topic) {
assert.ok(!isValid('name', topic.name));
}
},
'containing .': {
topic: setupPackage({ name: 'example.app' }),

'should be valid': function (topic) {
assert.ok(isValid('name', topic.name));
}
},
'containing %': {
topic: setupPackage({ name: 'example%app' }),

'should be invalid': function (topic) {
assert.ok(!isValid('name', topic.name));
}
},
'containing @': {
topic: setupPackage({ name: 'example@app' }),

'should be invalid': function (topic) {
assert.ok(!isValid('name', topic.name));
}
},
'containing :': {
topic: setupPackage({ name: 'example:app' }),

'should be invalid': function (topic) {
assert.ok(!isValid('name', topic.name));
}
}
}
});

suite.export(module);

0 comments on commit 8097ad3

Please sign in to comment.