-
Notifications
You must be signed in to change notification settings - Fork 1.1k
max_number_of_devices should be used in a new session as well #1109
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
Merged
zachfeldman
merged 1 commit into
lynndylanhurley:master
from
MaicolBen:max_number_of_devices_in_new_session
Mar 20, 2018
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -72,6 +72,33 @@ class DeviseTokenAuth::SessionsControllerTest < ActionController::TestCase | |
assert_equal '0.0.0.0', @new_last_sign_in_ip | ||
end | ||
end | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't you assert that the correct tokens (i.e. the oldest tokens) are deleted here? E.g.: |
||
describe "with multiple clients and headers don't change in each request" do | ||
before do | ||
DeviseTokenAuth.max_number_of_devices = 1 | ||
DeviseTokenAuth.change_headers_on_each_request = false | ||
@tokens = [] | ||
(1..3).each do |n| | ||
post :create, | ||
params: { | ||
email: @existing_user.email, | ||
password: 'secret123' | ||
} | ||
@tokens << @existing_user.reload.tokens | ||
end | ||
end | ||
|
||
test 'should delete old tokens' do | ||
current_tokens = @existing_user.reload.tokens | ||
assert_equal 1, current_tokens.count | ||
assert_equal @tokens.pop.keys.first, current_tokens.keys.first | ||
end | ||
|
||
after do | ||
DeviseTokenAuth.max_number_of_devices = 10 | ||
DeviseTokenAuth.change_headers_on_each_request = true | ||
end | ||
end | ||
end | ||
|
||
describe 'get sign_in is not supported' do | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Isn't this code technically
O(n2)
? (TheEnumberable#min_by
call is inside awhile
loop).Even though
Enumberable#min_by
returns a single key/value pair, it still iterates over the entire collection every time it's called.I would think that it is more efficient to iterate over the collection once, sorting the key/value pairs by
:expiry
of the value, and then shift the oldest key/values from tokens in a while loop.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.
This change breaks randomically the test that you mentioned:
test/controllers/demo_user_controller_test.rb#L506
. I tried for a day fixing it but it's quite weird (and hard to debug with minitest). If we merge the PR without this change, can you create a new one and try to fix it with your comment?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.
Yeah, no problem. I can submit a second PR. Although, I think I saw random test failures on travis-ci before I even made my comment?
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.
Yes, but they weren't random, they were my errors, I haven't updated the PR yet
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.
Is the debugging a challenge because the
Minitest::Reporters::ProgressReporter
leaves out line numbers? I've definitely been challenged with debugging failing tests while using that reporter. While I prefer theProgressReporter
, I find that the default minitest reporter provides much more useful debugging info.I usually just temporarily comment out line 27 of the
test_helper.rb
while running these tests. YMMV.I've been meaning to look into the the issue and submit a PR to
kern/minitest-reporters
with a fix.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 the tip! It doesn't throw a backtrace either 😞