Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions test/access-token.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,40 @@ describe('loopback.token(options)', function() {
});
});

it('should overwrite invalid existing token (is !== undefined and has no "id" property) ' +
' when enableDoubkecheck is true',
function(done) {
var token = this.token;

app.use(function(req, res, next) {
req.accessToken = null;
next();
});

app.use(loopback.token({
model: Token,
enableDoublecheck: true,
}));

app.get('/', function(req, res, next) {
res.send(req.accessToken);
});

request(app).get('/')
.set('Authorization', token.id)
.expect(200)
.end(function(err, res) {
if (err) return done(err);
expect(res.body).to.eql({

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to check all token properties here? I am worried that if we add a new Token property in the future, we will have to fix way too many tests that don't really depend on specific Token properties.

It think it is enough to check that res.body.id is the same as token.id, isn't it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in my last unit test, I did exactly that - and you commented that only checking on id wouldn't be enough.
Let me know which one you prefer

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, sorry for me not being consistent! Let's keep what you have now.

id: token.id,
ttl: token.ttl,
userId: token.userId,
created: token.created.toJSON(),
});
done();
});
});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add an empty line after the test case to serve as a visual delimiter.


it('should overwrite existing token when enableDoublecheck ' +
'and overwriteExistingToken options are truthy',
function(done) {
Expand Down