Permalink
Browse files

[fix] Add correct validations to name property

  • Loading branch information...
1 parent 91b371d commit 8097ad39ec1e9917c825bc29502915ed79e33f6a @julianduque julianduque committed Mar 14, 2013
Showing with 109 additions and 7 deletions.
  1. +1 −1 lib/jitsu/package.js
  2. +6 −6 test/commands/package-test.js
  3. +102 −0 test/lib/package-test.js
View
2 lib/jitsu/package.js
@@ -541,7 +541,7 @@ package.properties = function (dir) {
name: 'name',
unique: true,
message: 'App name',
- validator: /^[\w|\-]+$/,
+ validator: /^[\w|\-|\.]+$/,
default: path.basename(dir)
},
{
View
12 test/commands/package-test.js
@@ -4,7 +4,7 @@
* (C) 2010, Nodejitsu Inc.
*
*/
-
+
var assert = require('assert'),
fs = require('fs'),
path = require('path'),
@@ -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);
}
@@ -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
//
@@ -52,7 +52,7 @@ vows.describe('jitsu/commands/package').addBatch({
};
fs.writeFileSync(packageFile, JSON.stringify(pkg, true, 2))
-
+
//
// Attempt to remove any existing tarballs
//
View
102 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.