Skip to content

Commit

Permalink
Merge pull request #3259 from strongloop/backport/fix-verifyHref-uid
Browse files Browse the repository at this point in the history
Fix User.verify to convert uid to string
  • Loading branch information
bajtos authored Mar 9, 2017
2 parents 10fddb6 + 91502db commit 989c3bb
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion common/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ module.exports = function(User) {
displayPort +
urlPath +
'?' + qs.stringify({
uid: options.user[pkName],
uid: '' + options.user[pkName],
redirect: options.redirect,
});

Expand Down
47 changes: 47 additions & 0 deletions test/user.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1428,6 +1428,53 @@ describe('User', function() {
});
});

it('converts uid value to string', function(done) {
var idString = '58be263abc88dd483956030a';
var actualVerifyHref;

User.afterRemote('create', function(ctx, user, next) {
assert(user, 'afterRemote should include result');

var options = {
type: 'email',
to: user.email,
from: '[email protected]',
redirect: '/',
protocol: ctx.req.protocol,
host: ctx.req.get('host'),
templateFn: function(options, cb) {
actualVerifyHref = options.verifyHref;
cb(null, 'dummy body');
},
};

// replace the string id with an object
// TODO: find a better way to do this
Object.defineProperty(user, 'pk', {
get: function() { return this.__data.pk; },
set: function(value) { this.__data.pk = value; },
});
user.pk = {toString: function() { return idString; }};

user.verify(options, function(err, result) {
expect(result.uid).to.be.an('object');
expect(result.uid.toString()).to.equal(idString);
var parsed = url.parse(actualVerifyHref, true);
expect(parsed.query.uid, 'uid query field').to.eql(idString);
done();
});
});

request(app)
.post('/test-users')
.expect('Content-Type', /json/)
.expect(200)
.send({email: '[email protected]', password: 'bar', pk: idString})
.end(function(err, res) {
if (err) return done(err);
});
});

it('Verify a user\'s email address with custom token generator', function(done) {
User.afterRemote('create', function(ctx, user, next) {
assert(user, 'afterRemote should include result');
Expand Down

0 comments on commit 989c3bb

Please sign in to comment.