Skip to content

Conversation

@bajtos
Copy link
Member

@bajtos bajtos commented Feb 23, 2017

Description

Fix the code invalidating access tokens on user email/password changes to correctly handle the case when the relation "AccessToken belongs to (subclassed) user" is not configured.

cc @ebarault @greaterweb

Related issues

Checklist

  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style
    guide

Fix the code invalidating access tokens on user email/password changes
to correctly handle the case when the relation
"AccessToken belongs to (subclassed) user" is not configured.
@ebarault
Copy link
Contributor

ebarault commented Feb 23, 2017

👍
@bajtos : not clear to me what part from the multiuser patch specifically broke the default accesstoken --> user belongsto relation inheritance from base User?

Copy link
Member

@raymondfeng raymondfeng left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@superkhau superkhau left a comment

Choose a reason for hiding this comment

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

Minor nit about the comment/assertion, otherwise LGTM.

.then(u => {
u.email = 'updated@example.com';
return u.save();
// the test passes when save() does not throw any error
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

@superkhau superkhau Feb 23, 2017

Choose a reason for hiding this comment

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

You wrote the style guide entry though so you would know better. ;) What I'm suggesting is we should have something that catches and calls expect.fail() instead of the comment.

Copy link
Member Author

Choose a reason for hiding this comment

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

What I'm suggesting is we should have something that catches and calls expect.fail() instead of the comment.

By calling expect.fail, the test would hide the original error and report an unhelpful failure.

Note that we are asserting a resolved promise here, not a rejected promise as is described in the style guide link you pasted.

I suppose I could rewrite this test as follows, would you find it easier to read?

.then(u => {
  u.email = 'updated@example.com';
  return u.save();
})
.then(u => {
  // the test passes when save() does not throw any error
});

Copy link
Contributor

Choose a reason for hiding this comment

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

A bit better, but not worth the effort. LGTM. ;)

@greaterweb
Copy link
Contributor

Good work on addressing this, @bajtos!

As far as this PR goes, I've tested this branch in my sample repo and another Loopback project of mine, in both cases the app is no longer crashing and the issue raised is resolved. I'm going to add some more discussions though to the original ticket as I want to clarify a few points on best practices.

@bajtos
Copy link
Member Author

bajtos commented Feb 24, 2017

@ebarault @raymondfeng @superkhau thank you for the review!

@greaterweb thank you for verifying my fix in your codebase. Let's get it landed to address the immediate problem and then continue the discussion in the original issue.

@bajtos bajtos merged commit ec9274c into master Feb 24, 2017
@bajtos bajtos deleted the fix/invalidate-tokens branch February 24, 2017 08:20
@bajtos
Copy link
Member Author

bajtos commented Feb 24, 2017

Released in loopback@3.4.0

@bajtos
Copy link
Member Author

bajtos commented Feb 24, 2017

@ebarault

not clear to me what part from the multiuser patch specifically broke the default accesstoken --> user belongsto relation inheritance from base User?

It's not your patch that break the relation, it's the application that did not correctly configure this relation. Your patch was just not prepared to handle such misconfiguration, which I fixed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants