Skip to content

Commit

Permalink
Add tests for SSO Push jobs for retired apps
Browse files Browse the repository at this point in the history
This covers the scenario where an app is retired *after* the job is
enqueued but *before* it is executed.

The behaviour being tested was actually introduced when we added the
`not_retired` scope to the default scope for `Doorkeeper::Application`
in this commit [1] in #2446. This is because both jobs call
`Doorkeeper::Application.find_by` in their `#perform` methods which will
include the default scope and so if the app is retired will return `nil`
and be caught by the guard condition.

[1]: 9a9cd02
  • Loading branch information
floehopper committed Oct 24, 2023
1 parent 3d4410c commit 94fd9a0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions test/jobs/permission_updater_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ def users_url(application)
PermissionUpdater.new.perform(@user.uid, @application.id + 42)
end

should "do nothing if the application is retired" do
@application = create(:application, retired: true)

SSOPushClient.expects(:new).never

PermissionUpdater.new.perform(@user.uid, @application.id)
end

should "do nothing if the application doesn't support push updates" do
@application = create(:application, supports_push_updates: false)

Expand Down
10 changes: 10 additions & 0 deletions test/jobs/reauth_enforcer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,15 @@ class ReauthEnforcerTest < ActiveSupport::TestCase

ReauthEnforcer.new.perform("a-uid", app.id)
end

should "do nothing if the application is retired" do
app = create(:application, retired: true)

mock_client = mock("sso_push_client")
SSOPushClient.stubs(:new).returns(mock_client)
mock_client.expects(:reauth_user).never

ReauthEnforcer.new.perform("a-uid", app.id)
end
end
end

0 comments on commit 94fd9a0

Please sign in to comment.