Skip to content

Commit 989c3bb

Browse files
authored
Merge pull request #3259 from strongloop/backport/fix-verifyHref-uid
Fix User.verify to convert uid to string
2 parents 10fddb6 + 91502db commit 989c3bb

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

common/models/user.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ module.exports = function(User) {
430430
displayPort +
431431
urlPath +
432432
'?' + qs.stringify({
433-
uid: options.user[pkName],
433+
uid: '' + options.user[pkName],
434434
redirect: options.redirect,
435435
});
436436

test/user.test.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,6 +1428,53 @@ describe('User', function() {
14281428
});
14291429
});
14301430

1431+
it('converts uid value to string', function(done) {
1432+
var idString = '58be263abc88dd483956030a';
1433+
var actualVerifyHref;
1434+
1435+
User.afterRemote('create', function(ctx, user, next) {
1436+
assert(user, 'afterRemote should include result');
1437+
1438+
var options = {
1439+
type: 'email',
1440+
to: user.email,
1441+
1442+
redirect: '/',
1443+
protocol: ctx.req.protocol,
1444+
host: ctx.req.get('host'),
1445+
templateFn: function(options, cb) {
1446+
actualVerifyHref = options.verifyHref;
1447+
cb(null, 'dummy body');
1448+
},
1449+
};
1450+
1451+
// replace the string id with an object
1452+
// TODO: find a better way to do this
1453+
Object.defineProperty(user, 'pk', {
1454+
get: function() { return this.__data.pk; },
1455+
set: function(value) { this.__data.pk = value; },
1456+
});
1457+
user.pk = {toString: function() { return idString; }};
1458+
1459+
user.verify(options, function(err, result) {
1460+
expect(result.uid).to.be.an('object');
1461+
expect(result.uid.toString()).to.equal(idString);
1462+
var parsed = url.parse(actualVerifyHref, true);
1463+
expect(parsed.query.uid, 'uid query field').to.eql(idString);
1464+
done();
1465+
});
1466+
});
1467+
1468+
request(app)
1469+
.post('/test-users')
1470+
.expect('Content-Type', /json/)
1471+
.expect(200)
1472+
.send({email: '[email protected]', password: 'bar', pk: idString})
1473+
.end(function(err, res) {
1474+
if (err) return done(err);
1475+
});
1476+
});
1477+
14311478
it('Verify a user\'s email address with custom token generator', function(done) {
14321479
User.afterRemote('create', function(ctx, user, next) {
14331480
assert(user, 'afterRemote should include result');

0 commit comments

Comments
 (0)