-
Notifications
You must be signed in to change notification settings - Fork 217
chore(fxa-auth): Replace accountDevices call for refresh-token auth scheme #19698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Hm, I didn't see the tests had failed! I'll get them fixed |
fce5cfb to
1a7b5a2
Compare
| }); | ||
| }); | ||
| describe('Device.findByUidAndRefreshTokenId', () => { | ||
| const { Device } = require('../../../../db/models/auth'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason not to have these at the top of the file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uh, probably not! Not sure why I left that. I'll go through and clean up the tests in general for what I added, kinda rushed them
|
|
||
| assert.isNotNull(device); | ||
| assert.isObject(device.availableCommands); | ||
| assert.isTrue(Object.keys(device.availableCommands).length >= 2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not assert is greater than? Also why not check exact number of commands.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point. I have a habit of using greater/less but for no particular reason. Definitely better to assert the exact number here!
| const refreshTokenId = | ||
| 'abcdef0123456789abcdef0123456789abcdef00000000000000000000000000'; | ||
|
|
||
| await knex.raw( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing we don't, but do we need some DB clean after test suite runs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an existing "cleanup" in the setup step - it just drops the whole db when calling testDatabaseSetup. That said, I suppose we could have a beforeEach or afterEach that does a cleanup since we only run the setup function once per test module. I'll add something for these tests at least since they do need to insert data like they do
| @@ -0,0 +1,27 @@ | |||
| CREATE PROCEDURE `deviceFromRefreshTokenId_1` ( | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for keeping this updated too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeahhh, I don't like this pattern but definitely want tests for it!
I put a ticket in the backlog to see if we can do this better. I THINK we should be able to use the same mysql migration tool that we do for dev/stage/prod when running tests and point it to our existing migration scripts. That way the testAdmin db that we're creating is always a mirror of the actual fxa db, and we don't have to duplicate scripts like this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found the issue I logged up! https://mozilla-hub.atlassian.net/browse/FXA-12691
| uid, | ||
| refreshTokenId | ||
| ); | ||
| if (!device) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just record if it was or was not found. Might make graphing more useful?
Because
accountDevices_XXstored procedureThis pull request
Issue that this pull request solves
Closes: FXA-12692
Checklist
Put an
xin the boxes that applyScreenshots (Optional)
Please attach the screenshots of the changes made in case of change in user interface.
Other information (Optional)
For testing this, I wanted to be a thorough as possible using batches of seed data to compare using the prior
accountDevices_XXsproc to the newdeviceFromRefreshTokenId_1. The main advantage the the new query is that we're offloading the filter to mysql, reducing the number of scanned and joined rows:To this, I needed a way to insert a bunch of mock data in sessionTokens, refreshTokens, devices, etc. to cover a number of cases (noted below). I put all of the scripts necessary on a separate branch if you want to check it out!
Process:
UNHEX()causing added overheadperformance_schema.events_statements_summary_by_digestandperformance_schema.events_statements_summary_by_programwere truncated to start with a clean slate10times (though a larger data set might be valuable!)This shows a pretty clear picture that the new query improves execution time by about 2x. It's worth noting, most of these cases are extremes, with dozens or hundreds of devices, but even with low device/session accounts we're still seeing an improvement since there is no join to the
sessionTokentable necessary here.Results:
33333333333333333333333333333333- account with 100 devices, each with refresh token but no sessionTokens55555555555555555555555555555555- 50 devices with both sessionTokenId and refreshTokenIds, requiring join for all before sorting/filtering11111111111111111111111111111121- HUGE number of devices, 500 all with refresh tokens and sessionTokens99999999999999999999999999999999- devices with a LOT of device commands (not very pratical, but demonstrates overhead when joining and fan-out from joins) 20 devices for account each with 15 commands11111111111111111111111111111126- 500 devices all with sessionTokens and refreshTokensCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC- devices with dangling refresh token id’s that don’t exist in the oauth db. Should have no impact, but worth testing11111111111111111111111111111122- mixed commands, some devices have commands some don’t. our specific device requested doesAdditional Testing
I wanted to ensure that I didn't also break endpoints that accept this auth strategy. So, I leveraged the auth-client unit tests to call creating an OAuthToken and use that to request data from the various devices endpoints, here's an example.
Note
This test was not committed, but including here for purposes of showing testing!