Skip to content

Commit

Permalink
Expire ApiKey without validation. (#4456)
Browse files Browse the repository at this point in the history
  • Loading branch information
simi authored Feb 15, 2024
1 parent 4d5f25f commit ad8d2b0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/models/api_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ def expired?
end

def expire!
update!(expires_at: Time.current)
transaction do
update_column(:expires_at, Time.current)
record_expire_event
end
end

private
Expand Down
18 changes: 18 additions & 0 deletions test/models/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,24 @@ class UserTest < ActiveSupport::TestCase
end
end

context "block invalid legacy user" do
setup do
@user = create(:user, handle: "MikeJudge")
@api_key = create(:api_key, owner: @user)

# simulate legacy invalid api key
@api_key.update_columns(show_dashboard: true, add_owner: true)

refute_predicate @api_key, :valid?
end

should "block user anyway" do
assert_changed(@user, :email, :password, :api_key, :remember_token) do
@user.block!
end
end
end

context ".normalize_email" do
should "return the normalized email" do
assert_equal "[email protected]", User.normalize_email(:"UsEr@ example . COM")
Expand Down

0 comments on commit ad8d2b0

Please sign in to comment.