test(`the LoginForm can check for valid login attempts`, (assert) => {
  const formEl = createFormElement();
  const form = new LoginForm(formEl, `email@email.com`);

  assert.ok(form.validate(`aaron@theironyard.com`, `password123`),
    `The form should validate with credentials aaron@theironyard.com:password123`);
  assert.ok(form.validate(`admin@google.com`, `pandas`),
    `The form should validate with credentials admin@google.com:pandas`);
  assert.ok(form.validate(`email@email.com`, `honeycrisp`),
    `The form should validate with credentials email@email.com:pandas`);

  assert.notOk(form.validate(``, ``),
    `The form should not validate with empty credentials`);
  assert.notOk(form.validate(`notavalidemail`, `pass`),
    `The form should not validate with an invalid email notavalidemail:pass`);
  assert.notOk(form.validate(`email@email.com`, `pandas`),
    `The form should not validate with mixed credentials email@email.com:pandas`);

  const formDiff = new LoginForm(formEl, `ryan@theironyard.com`);

  assert.ok(formDiff.validate(`ryan@theironyard.com`, `honeycrisp`),
    `The form should validate with email passed in to the constructor email@email.com:pandas`);
  assert.notOk(formDiff.validate(`email@email.com`, `honeycrisp`),
    `The form should not validate with an email
     not passed into the constructor email@email.com:pandas`);
});
 it('should return an error if there is no end_time for a financial request', () => {
   const postParams = _.merge(_.omit(defaultPostParams, ['end_time']), { financialRequestAmount: 1000 })
   const errors = PostValidator.validate(postParams)
   expect(errors).to.have.lengthOf(2)
   expect(errors).to.contain("deadline can't be blank for financial requests")
   expect(errors).to.contain("deadline can not be in the past")
 })
    it('should return an error if financialRequestAmount is not numeric', () => {
      const postParams = _.merge({}, defaultPostParams, { financialRequestAmount: '1000' })

      const errors = PostValidator.validate(postParams)
      expect(errors).to.have.lengthOf(1)
      expect(errors).to.contain('financial request amount must be a numeric value')
    })
    }, function (req, accessToken, done) {
        console.log('bearer stretegy');
        tokenizer.validate(accessToken, function (err, token) {
            if (err) {
                return done(err);
            }

            User.findOne({
                '_id': token.userId
            }, function (err, user) {
                if (err) {
                    return done(err);
                }
                if (!user) {
                    return done(null, false, {
                        reason: 'invalid-user'
                    });
                }

                // token info can be used for handling REST API
                // so token info is set to result which is returned after authentication 
                user.tokenInfo = token;
                return done(null, user);
            });
        });
    }));
Exemple #5
0
  signValidation : (req, res, next) => {

    if (!req.body.name || !req.body.surName || !req.body.email || !req.body.password) {
      next(new Error(`You miss one of the required fields(name,surName.email,password)`))
    }

    const productJoi = {
      name : Joi.string().required().min(2).max(20),
      surName : Joi.string().required().min(2).max(20),
      email : Joi.string().required().email(),
      password : Joi.string().required().min(6).max(10),
      date : Joi.date().format(`YYYY-MM-DD`)
    };

    Joi.validate({
      name : req.body.name,
      surName : req.body.surName,
      email : req.body.email,
      password : req.body.password,
      date : req.body.date
    }, productJoi, (error, userInfo) => {
      if (error) {
        error.statusCode = 404;
        next(error)
      } else {
        next();
      }
    })
  }
Exemple #6
0
		return function () {
			args.validate(arguments, num_args, config);

			var _query = query;
			var deffered = q.defer();

			for (var i = 0; i < arguments.length; i++) {
				_query = _query.replace(/\?/, arguments[i]);
			};

			adapter.connect(function(err) {
				if (err) {
					deffered.reject(err);
				}

				adapter.query(_query, function(err, result) {
					if (err) {
						deffered.reject(err);
					}

					deffered.resolve(result);
				});
			});

			return deffered.promise;
		};
exports.go = function (req, res) {
  var b = captcha.validate(req, 'cap');
  res.render(__dirname + '/views/captcha', {
    'captcha': req.session['capcaptchaCode'],
    b: b
  });
}
 it('augmented object validates with execution_options and additional params', function() {
   var crudObj = new CrudObject({}, 'endpoint', ['id']);
   ObjectValidation.call(crudObj);
   var crudSave = sinon.stub(crudObj, 'save');
   crudObj.validate({param: 1});
   crudSave.should.have.been.calledWith({param: 1, execution_options: ['validate_only']});
 });
    it('should return an error if financialRequestAmount is NaN', () => {
      const postParams = _.merge({}, defaultPostParams, { financialRequestAmount: NaN })

      const errors = PostValidator.validate(postParams)
      expect(errors).to.have.lengthOf(1)
      expect(errors).to.contain('financial requests must be between 0 and 100,000')
    })
 it('should be able to validate sent email', function(done) {
     var mail = new Mail();
     mail.validate(function(error) {
         expect(error).to.exist;
         expect(error.name).to.equal('ValidationError');
         done();
     });
 });
Exemple #11
0
exports.validatePlatformOptions = function (logger, config, cli, commandName) {
	var platform = exports.resolvePlatform(cli.argv.platform),
		platformCommand = path.join(path.dirname(module.filename), '..', '..', '..', manifest.platforms[manifest.platforms.indexOf(platform)], 'cli', 'commands', '_' + commandName + '.js');
	if (fs.existsSync(platformCommand)) {
		var command = require(platformCommand);
		return command && typeof command.validate == 'function' ? command.validate(logger, config, cli) : null;
	}
};
Exemple #12
0
	it('Should return an error if there were no files at given path', function(done) {
		var smalley 	= require(appRoot + '/smalley');
		var badInput	= require(appRoot + '/test/testInput/badData1'); 
		
		smalley.validate({data: badInput, definitionPath: 'test/'}, function(err, results) {
			should.exist(err);
			done();
		});
	});
    it('should allow div tags', function(done) {
      var dirty = '<html><div>hello world</div></html>';

      validator.validate(dirty, function(err, validated) {
        expect(err).to.be.equal(null);
        expect(validated).to.be.equal('<div>hello world</div>');
        done();
      });
    });
    it('should keep html entities', function(done) {
      var dirty = '<span style="font-family: &#34;courier new&#34;">hello world</span>';

      validator.validate(dirty, function(err, validated) {
        expect(err).to.be.equal(null);
        expect(validated).to.be.equal('<span style="font-family: &#34;courier new&#34;">hello world</span>');
        done();
      });
    });
Exemple #15
0
 it('should test basic validation', function() {
   var js = 'return 42;\nvar func = function(test){console.log( test );};';
   var errors = jsfmt.validate(js);
   errors.should.have.length(1);
   errors[0].index.should.eql(6);
   errors[0].lineNumber.should.eql(1);
   errors[0].column.should.eql(7);
   errors[0].description.should.eql('Illegal return statement');
 });
	it('validates yaml config', (done) => {
		try{
			proxyValidator.validate(cachedJSON);
		}catch(err){
			console.error(err);
			assert.equal(err, null);
		}
		done();
	});
	it('validates proxies in config', (done) => {
		try{
			proxyValidator.validate(proxyConfig);
		}catch(err){
			console.error(err);
			assert.equal(err, null);
		}
		done();
	});
    it('should show no error for a valid project with financialRequestAmount', () => {
      const postParams = _.merge({}, defaultPostParams, {
        financialRequestAmount: 100,
        type: 'project'
      })

      const errors = PostValidator.validate(postParams)
      expect(errors).to.eql([])
    })
    it('should remove html tags', function(done) {
      var dirty = '<html>hello world</html>';

      validator.validate(dirty, function(err, validated) {
        expect(err).to.be.equal(null);
        expect(validated).to.be.equal('hello world');
        done();
      });
    });
Exemple #20
0
	    setTimeout(function() {
		validator.validate(task.file, function(err, isValid) {
		    if (err) throw err;
		    var res = {};
		    res.file = task.file;
		    res.isValid = isValid;
		    cb(err, res);
		});
	    }, 2000);
Exemple #21
0
	it('Should import the valid file path json', function(done) {
		var smalley 	= require(appRoot + '/smalley');
		var goodInput	= require(appRoot + '/test/testInput/goodData1');
		
		smalley.validate({data: goodInput, definitionPath: 'test/customerDefs'}, function(err, results) {
			should.not.exist(err);
			results.should.equal("Data was validated.");
			done();
		});
	});
Exemple #22
0
exports.validate = function(test){
    var f = new JSONFileFormat();
    f.addVersion(1,validateFunc);
    f.addVersion(2,schema);
    var instance1 = {
            version:1,
        },
        instance2 = {
            version:2,
        },
        instance3 = {
            version:2,
            notAllowedProperty:'asdf'
        };
    test.ok(f.validate(instance1));
    test.ok(f.validate(instance2));
    test.ok(!f.validate(instance3));
    test.done();
};
Exemple #23
0
	it('Should return a message that certain attributes couldn\'t be validated', function(done) {
		var smalley 	= require(appRoot + '/smalley');
		var goodInput	= require(appRoot + '/test/testInput/goodData2');
		
		smalley.validate({data: goodInput, definitionPath: 'test/customerDefs'}, function(err, results) {
			should.not.exist(err);
			results.should.equal("Could not validate dojo, callSign, but everything else was valid.");
			done();
		});
	});
Exemple #24
0
	it('Should return an error with missing required data', function(done) {
		var smalley 	= require(appRoot + '/smalley');
		var badInput	= require(appRoot + '/test/testInput/badData1'); 
		
		smalley.validate({data: badInput, definitionPath: 'test/customerDefs'}, function(err, results) {
			should.exist(err);
			err.toString().should.equal('Error: lastName did not exist, but is a required attribute.');
			done();
		});
	});
Exemple #25
0
	it('Should validate sample sale_created event', function(done) {
		var smalley 	= require(appRoot + '/smalley');
		var goodInput	= require(appRoot + '/test/testInput/goodData4');
		
		smalley.validate({data: goodInput, definitionPath: 'test/eventDefs'}, function(err, results) {
			should.not.exist(err);
			results.should.equal("Data was validated.");
			done();
		});
	});
Exemple #26
0
	it('Should return an error with mismatched data types', function(done) {
		var smalley 	= require(appRoot + '/smalley');
		var badInput	= require(appRoot + '/test/testInput/badData2'); 
		
		smalley.validate({data: badInput, definitionPath: 'test/customerDefs'}, function(err, results) {
			should.exist(err);
			err.toString().should.equal('Error: The type ([object Number]) of phone did not match the definition type [object String].');
			done();
		});
	});
Exemple #27
0
	it('Should return an error if field was null but config not nullable', function(done) {
		var smalley 	= require(appRoot + '/smalley');
		var badInput	= require(appRoot + '/test/testInput/badData4'); 
		
		smalley.validate({data: badInput, definitionPath: 'test/eventDefs'}, function(err, results) {
			should.exist(err);
			err.toString().should.equal("Error: The type ([object Null]) of orderId did not match the definition type [object Number].");
			done();
		});
	});
    it('should return an error if there is a financial request but the type is not a project', () => {
      const postParams = _.merge({}, defaultPostParams, {
        type: 'comment',
        financialRequestAmount: 100
      })

      const errors = PostValidator.validate(postParams)
      expect(errors).to.have.lengthOf(1)
      expect(errors).to.contain("only posts of type 'project' may have a financial request")
    })
Exemple #29
0
exports.validatePlatformOptions = function (logger, config, cli, commandName) {
	var platform = exports.resolvePlatform(cli.argv.platform),
		platformCommand = path.join(path.dirname(module.filename), '..', '..', '..', manifest.platforms[manifest.platforms.indexOf(platform)], 'cli', 'commands', '_' + commandName + '.js');
	
	if (afs.exists(platformCommand)) {
		var command = require(platformCommand),
			result = command && command.validate ? command.validate(logger, config, cli) : null;
		if (result === false) {
			return false;
		}
	}
};
Exemple #30
0
  loginValidation : (req, res, next) => {

    const productJoi = {
      email : Joi.string().required().email(),
      password : Joi.string().required().min(6).max(10)
    };

    Joi.validate({
      email : req.body.email,
      password : req.body.password
    }, productJoi, (error, userInfo) => {
      error ? next(error) : next();
    })
  },