Permalink
Browse files

initial

  • Loading branch information...
0 parents commit 990be4e918219b8894b21b88146864d29e5cd03a @robertkowalski robertkowalski committed Apr 19, 2013
Showing with 201 additions and 0 deletions.
  1. +13 −0 .gitignore
  2. +13 −0 .npmignore
  3. +27 −0 LICENSE
  4. +3 −0 README.md
  5. +35 −0 npm-user-validate.js
  6. +26 −0 package.json
  7. +26 −0 test/email.test.js
  8. +32 −0 test/pw.test.js
  9. +26 −0 test/username.test.js
@@ -0,0 +1,13 @@
+*.swp
+.*.swp
+
+.DS_Store
+*~
+.project
+.settings
+npm-debug.log
+coverage.html
+.idea
+lib-cov
+
+node_modules
@@ -0,0 +1,13 @@
+*.swp
+.*.swp
+
+.DS_Store
+*~
+.project
+.settings
+npm-debug.log
+coverage.html
+.idea
+lib-cov
+
+node_modules
27 LICENSE
@@ -0,0 +1,27 @@
+Copyright (c) Robert Kowalski
+All rights reserved.
+
+The BSD License
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
+BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,3 @@
+## npmvalidate
+
+Validation for the npm client and npm-www (and probably other npm projects)
@@ -0,0 +1,35 @@
+exports.email = email
+exports.pw = pw
+exports.username = username
+
+function username (un) {
+ if (un !== un.toLowerCase()) {
+ return new Error('Username must be lowercase')
+ }
+
+ if (un !== encodeURIComponent(un)) {
+ return new Error('Username may not contain non-url-safe chars')
+ }
+
+ if (un.charAt(0) === '.') {
+ return new Error('Username may not start with "."')
+ }
+
+ return null
+}
+
+function email (em) {
+ if (!em.match(/^.+@.+\..+$/)) {
+ return new Error('Email must be an email address')
+ }
+
+ return null
+}
+
+function pw (pw) {
+ if (pw.match(/['!:@"]/)) {
+ return new Error('Sorry, passwords cannot contain these characters: \'!:@"')
+ }
+
+ return null
+}
@@ -0,0 +1,26 @@
+{
+ "name": "npm-user-validate",
+ "version": "0.0.1",
+ "description": "User validations for npm",
+ "main": "npm-user-validate.js",
+ "scripts": {
+ "test": "npm test"
+ },
+ "devDependencies": {
+ "tap": "0.4.1"
+ },
+ "scripts": {
+ "test": "tap test/*.js"
+ },
+ "repository": "",
+ "keywords": [
+ "npm",
+ "validation"
+ ],
+ "author": "Robert Kowalski <rok@kowalski.gd>",
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/robertkowalski/npm-user-validate"
+ },
+ "license": "BSD"
+}
@@ -0,0 +1,26 @@
+var test = require('tap').test
+var v = require('../npm-user-validate.js').email
+
+test('email misses an @', function (t) {
+ err = v('namedomain')
+ t.type(err, 'object')
+ t.end()
+})
+
+test('email misses a dot', function (t) {
+ err = v('name@domain')
+ t.type(err, 'object')
+ t.end()
+})
+
+test('email misses a string before the @', function (t) {
+ err = v('@domain')
+ t.type(err, 'object')
+ t.end()
+})
+
+test('email is ok', function (t) {
+ err = v('name@domain.com')
+ t.type(err, 'null')
+ t.end()
+})
@@ -0,0 +1,32 @@
+var test = require('tap').test
+var v = require('../npm-user-validate.js').pw
+
+test('pw contains a \'', function (t) {
+ err = v('\'')
+ t.type(err, 'object')
+ t.end()
+})
+
+test('pw contains a :', function (t) {
+ err = v(':')
+ t.type(err, 'object')
+ t.end()
+})
+
+test('pw contains a @', function (t) {
+ err = v('@')
+ t.type(err, 'object')
+ t.end()
+})
+
+test('pw contains a "', function (t) {
+ err = v('"')
+ t.type(err, 'object')
+ t.end()
+})
+
+test('pw is ok', function (t) {
+ err = v('duck')
+ t.type(err, 'null')
+ t.end()
+})
@@ -0,0 +1,26 @@
+var test = require('tap').test
+var v = require('../npm-user-validate.js').username
+
+test('username must be lowercase', function (t) {
+ err = v('ERRR')
+ t.type(err, 'object')
+ t.end()
+})
+
+test('username may not contain non-url-safe chars', function (t) {
+ err = v('f ')
+ t.type(err, 'object')
+ t.end()
+})
+
+test('username may not start with "."', function (t) {
+ err = v('.username')
+ t.type(err, 'object')
+ t.end()
+})
+
+test('username is ok', function (t) {
+ err = v('ente')
+ t.type(err, 'null')
+ t.end()
+})

0 comments on commit 990be4e

Please sign in to comment.