-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2418 from alphagov/rotate-sso-push-access-tokens-…
…before-expiry Create a new access token for the SSO Push API user *before* expiry not *at* expiry
- Loading branch information
Showing
24 changed files
with
157 additions
and
29 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module Doorkeeper | ||
class AccessGrant < ::ActiveRecord::Base # rubocop:disable Rails/ApplicationRecord | ||
include Models::ExpirationTimeSqlMath | ||
|
||
scope :expired, -> { where.not(expires_in: nil).where("#{sanitize_sql(expiration_time_sql)} < ?", Time.current) } | ||
end | ||
end |
This file contains 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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Doorkeeper | ||
class AccessToken < ::ActiveRecord::Base # rubocop:disable Rails/ApplicationRecord | ||
scope :not_revoked, -> { where(revoked_at: nil) } | ||
scope :expires_after, ->(time) { where.not(expires_in: nil).where("#{sanitize_sql(expiration_time_sql)} > ?", time) } | ||
scope :expired, -> { where.not(expires_in: nil).where("#{sanitize_sql(expiration_time_sql)} < ?", Time.current) } | ||
scope :ordered_by_expires_at, -> { order(expiration_time_sql) } | ||
scope :ordered_by_application_name, -> { includes(:application).merge(Doorkeeper::Application.ordered_by_name) } | ||
end | ||
end |
This file contains 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require "test_helper" | ||
|
||
class Doorkeeper::AccessGrantTest < ActiveSupport::TestCase | ||
context ".expired" do | ||
should "return grants that have expired" do | ||
grant_expiring_1_day_ago = create(:access_grant, expires_in: -1.day) | ||
grant_expiring_in_1_day = create(:access_grant, expires_in: 1.day) | ||
|
||
grants = Doorkeeper::AccessGrant.expired | ||
|
||
assert_includes grants, grant_expiring_1_day_ago | ||
assert_not_includes grants, grant_expiring_in_1_day | ||
end | ||
end | ||
end |
This file contains 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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
require "test_helper" | ||
|
||
class Doorkeeper::AccessTokenTest < ActiveSupport::TestCase | ||
context ".not_revoked" do | ||
should "return tokens that have not been revoked" do | ||
revoked_token = create(:access_token, revoked_at: Time.current) | ||
non_revoked_token = create(:access_token, revoked_at: nil) | ||
|
||
tokens = Doorkeeper::AccessToken.not_revoked | ||
|
||
assert_not_includes tokens, revoked_token | ||
assert_includes tokens, non_revoked_token | ||
end | ||
end | ||
|
||
context ".expires_after" do | ||
should "return tokens expiring after specified time" do | ||
token_expiring_in_1_week = create(:access_token, expires_in: 1.week) | ||
token_expiring_in_3_weeks = create(:access_token, expires_in: 3.weeks) | ||
|
||
tokens = Doorkeeper::AccessToken.expires_after(2.weeks.from_now) | ||
|
||
assert_not_includes tokens, token_expiring_in_1_week | ||
assert_includes tokens, token_expiring_in_3_weeks | ||
end | ||
end | ||
|
||
context ".expired" do | ||
should "return tokens that have expired" do | ||
token_expiring_1_day_ago = create(:access_token, expires_in: -1.day) | ||
token_expiring_in_1_day = create(:access_token, expires_in: 1.day) | ||
|
||
tokens = Doorkeeper::AccessToken.expired | ||
|
||
assert_includes tokens, token_expiring_1_day_ago | ||
assert_not_includes tokens, token_expiring_in_1_day | ||
end | ||
end | ||
|
||
context ".ordered_by_expires_at" do | ||
should "return tokens ordered by expiry time" do | ||
token_expiring_in_2_weeks = create(:access_token, expires_in: 2.weeks) | ||
token_expiring_in_1_week = create(:access_token, expires_in: 1.week) | ||
|
||
tokens = Doorkeeper::AccessToken.ordered_by_expires_at | ||
|
||
assert_equal [token_expiring_in_1_week, token_expiring_in_2_weeks], tokens | ||
end | ||
end | ||
|
||
context ".ordered_by_application_name" do | ||
should "return tokens ordered by application name" do | ||
application_named_foo = create(:application, name: "Foo") | ||
application_named_bar = create(:application, name: "Bar") | ||
|
||
token_for_foo = create(:access_token, application: application_named_foo) | ||
token_for_bar = create(:access_token, application: application_named_bar) | ||
|
||
tokens = Doorkeeper::AccessToken.ordered_by_application_name | ||
|
||
assert_equal [token_for_bar, token_for_foo], tokens | ||
end | ||
end | ||
end |
This file contains 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 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