Skip to content

Commit

Permalink
Merge pull request #1254 from alphagov/fix-secrets-deprecation
Browse files Browse the repository at this point in the history
Resolve `Rails.application.secrets` deprecation warning
  • Loading branch information
brucebolt authored Nov 30, 2023
2 parents 5d7895d + 4556eac commit 8b985dc
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/controllers/media_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def temporary_redirect?
def set_token_payload
token = params.fetch(:token, cookies[:auth_bypass_token])
@token_payload = if token
secret = Rails.application.secrets.jwt_auth_secret
secret = Rails.application.config_for(:secrets).jwt_auth_secret
JWT.decode(token, secret, true, algorithm: "HS256").first
end
rescue JWT::DecodeError
Expand Down
2 changes: 1 addition & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Application < Rails::Application

config.assets.prefix = "/asset-manager"

unless Rails.application.secrets.jwt_auth_secret
unless Rails.application.config_for(:secrets).jwt_auth_secret
raise "JWT auth secret is not configured. See config/secrets.yml"
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/controllers/media_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ def download
let(:token_with_draft_asset_manager_access) do
JWT.encode(
{ "draft_asset_manager_access" => true },
Rails.application.secrets.jwt_auth_secret,
Rails.application.config_for(:secrets).jwt_auth_secret,
"HS256",
)
end
Expand Down Expand Up @@ -447,14 +447,14 @@ def download
let(:valid_token) do
JWT.encode(
{ "sub" => auth_bypass_id },
Rails.application.secrets.jwt_auth_secret,
Rails.application.config_for(:secrets).jwt_auth_secret,
"HS256",
)
end
let(:token_with_draft_asset_manager_access) do
JWT.encode(
{ "draft_asset_manager_access" => true },
Rails.application.secrets.jwt_auth_secret,
Rails.application.config_for(:secrets).jwt_auth_secret,
"HS256",
)
end
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/whitehall_media_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,14 @@
let(:valid_token) do
JWT.encode(
{ "sub" => auth_bypass_id },
Rails.application.secrets.jwt_auth_secret,
Rails.application.config_for(:secrets).jwt_auth_secret,
"HS256",
)
end
let(:token_with_draft_asset_manager_access) do
JWT.encode(
{ "draft_asset_manager_access" => true },
Rails.application.secrets.jwt_auth_secret,
Rails.application.config_for(:secrets).jwt_auth_secret,
"HS256",
)
end
Expand Down
10 changes: 5 additions & 5 deletions spec/requests/media_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
end

it "serves the asset with a valid token" do
secret = Rails.application.secrets.jwt_auth_secret
secret = Rails.application.config_for(:secrets).jwt_auth_secret
valid_token = JWT.encode({ "sub" => auth_bypass_id }, secret, "HS256")
get download_media_path(id: asset, filename: "asset.png", params: { token: valid_token })
expect(response).to be_successful
Expand All @@ -129,7 +129,7 @@
end

it "serves the asset with a valid token" do
secret = Rails.application.secrets.jwt_auth_secret
secret = Rails.application.config_for(:secrets).jwt_auth_secret
valid_token = JWT.encode({ "sub" => auth_bypass_id }, secret, "HS256")
get download_media_path(id: asset, filename: "asset.png", params: { token: valid_token })
expect(response).to be_successful
Expand All @@ -153,7 +153,7 @@
end

it "serves the asset with a valid token" do
secret = Rails.application.secrets.jwt_auth_secret
secret = Rails.application.config_for(:secrets).jwt_auth_secret
valid_token = JWT.encode({ "sub" => auth_bypass_id }, secret, "HS256")
get download_media_path(id: asset, filename: "asset.png", params: { token: valid_token })
expect(response).to be_successful
Expand All @@ -180,7 +180,7 @@
end

it "serves the asset with a valid token" do
secret = Rails.application.secrets.jwt_auth_secret
secret = Rails.application.config_for(:secrets).jwt_auth_secret
valid_token = JWT.encode({ "sub" => auth_bypass_id }, secret, "HS256")
get download_media_path(id: asset, filename: "asset.png", params: { token: valid_token })
expect(response).to be_successful
Expand All @@ -203,7 +203,7 @@
end

it "serves the asset with a valid token" do
secret = Rails.application.secrets.jwt_auth_secret
secret = Rails.application.config_for(:secrets).jwt_auth_secret
valid_token = JWT.encode({ "sub" => auth_bypass_id }, secret, "HS256")
get download_media_path(id: asset, filename: "asset.png", params: { token: valid_token })
expect(response).to be_successful
Expand Down
4 changes: 2 additions & 2 deletions spec/requests/whitehall_media_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@
let(:path) { "/government/uploads/asset.png" }
let(:auth_bypass_id) { "bypass-id" }

let(:valid_token) { JWT.encode({ "sub" => auth_bypass_id }, Rails.application.secrets.jwt_auth_secret, "HS256") }
let(:token_without_access) { JWT.encode({ "sub" => "not-the-right-bypass-id" }, Rails.application.secrets.jwt_auth_secret, "HS256") }
let(:valid_token) { JWT.encode({ "sub" => auth_bypass_id }, Rails.application.config_for(:secrets).jwt_auth_secret, "HS256") }
let(:token_without_access) { JWT.encode({ "sub" => "not-the-right-bypass-id" }, Rails.application.config_for(:secrets).jwt_auth_secret, "HS256") }

context "when the asset is not access limited" do
let(:asset) do
Expand Down

0 comments on commit 8b985dc

Please sign in to comment.