-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3259 from strongloop/backport/fix-verifyHref-uid
Fix User.verify to convert uid to string
- Loading branch information
Showing
2 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'); | ||
|