Skip to content
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.

Commit

Permalink
Merge pull request #62 from braydonf/master
Browse files Browse the repository at this point in the history
Fix validation
  • Loading branch information
dylanlott committed Feb 21, 2017
2 parents 7092ae4 + de8bd87 commit 78b3fbd
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/models/contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var ContactSchema = new mongoose.Schema({
},
userAgent: {
type: String,
required: true
required: false
}
});

Expand Down
9 changes: 8 additions & 1 deletion lib/models/pubkey.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const mongoose = require('mongoose');
const SchemaOptions = require('../options');
const elliptic = require('elliptic');
const ecdsa = new elliptic.ec(elliptic.curves.secp256k1);
const utils = require('../utils');

/**
* Represents a public key
Expand All @@ -16,7 +17,13 @@ var PublicKey = new mongoose.Schema({
required: true
},
user: {
type: mongoose.SchemaTypes.Email,
type: String,
validate: {
validator: function(v) {
return utils.isValidEmail(v);
},
message: '{VALUE} is not a valid email!'
},
ref: 'User'
},
label: {
Expand Down
21 changes: 21 additions & 0 deletions test/contact.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,27 @@ describe('Storage/models/Contact', function() {
});
});

it('it should not give validation error', function(done) {
const data = {
nodeID: '082305b1b4119cf393a8ad392e45cb2b8abd8e43',
protocol: '0.7.0',
address: '154.220.116.201',
port: 18078,
lastSeen: 1465599426699
};
Contact.record(data, function(err, contact) {
if (err) {
return done(err);
}
contact.save((err) => {
if (err) {
return done(err);
}
done();
});
});
});

});

describe('#recordTimeoutFailure', function() {
Expand Down
20 changes: 20 additions & 0 deletions test/pubkey.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,26 @@ describe('Storage/models/PublicKey', function() {
});
});

it('should create the public with spam resistent email', function(done) {

var publicKey2 = storj.KeyPair().getPublicKey();

PublicKey.create({
_id: 'user+nospam@domain.tld'
}, publicKey2, function(err, pubkey) {
if (err) {
return done(err);
}
pubkey.save((err) => {
if (err) {
return done(err);
}
expect(pubkey._id).to.equal(publicKey2);
done();
});
});
});

it('should not create duplicate key', function(done) {
PublicKey.create({
_id: 'user@domain.tld'
Expand Down

0 comments on commit 78b3fbd

Please sign in to comment.