Skip to content

Commit

Permalink
Use the count feature of i18n to fix plurals
Browse files Browse the repository at this point in the history
  • Loading branch information
ransombriggs committed Nov 1, 2024
1 parent 8cbe710 commit ccc9773
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
5 changes: 4 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ en:
unauthorized_client: 'The client is not authorized to perform this request using this method.'
access_denied: 'The resource owner or authorization server denied the request.'
invalid_scope: 'The requested scope is invalid, unknown, or malformed.'
invalid_code_challenge_method: 'The code challenge method must be one of %{challenge_methods}.'
invalid_code_challenge_method:
zero: 'There are no acceptable code_challenge methods'
one: 'The code challenge method must be %{challenge_methods}.'
other: 'The code challenge method must be one of %{challenge_methods}.'
server_error: 'The authorization server encountered an unexpected condition which prevented it from fulfilling the request.'
temporarily_unavailable: 'The authorization server is currently unable to handle the request due to a temporary overloading or maintenance of the server.'

Expand Down
4 changes: 3 additions & 1 deletion lib/doorkeeper/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ def self.name_for_response

class InvalidCodeChallengeMethod < BaseResponseError
def self.translate_options
challenge_methods = Doorkeeper.config.pkce_code_challenge_methods_supported
{
challenge_methods: Doorkeeper.config.pkce_code_challenge_methods_supported.join(", ")
challenge_methods: challenge_methods.join(", "),
count: challenge_methods.length
}
end
end
Expand Down
18 changes: 17 additions & 1 deletion spec/lib/oauth/pre_authorization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,22 @@
expect(pre_auth).not_to be_authorizable
end

context "when pkce_code_challenge_methods is set to none" do
before do
Doorkeeper.configure do
pkce_code_challenge_methods []
end
end

it "rejects plain as a code_challenge_method" do
attributes[:code_challenge] = "a45a9fea-0676-477e-95b1-a40f72ac3cfb"
attributes[:code_challenge_method] = "plain"

expect(pre_auth).to_not be_authorizable
expect(pre_auth.error_response.description).to eq("There are no acceptable code_challenge methods")
end
end

context "when pkce_code_challenge_methods is set to only S256" do
before do
Doorkeeper.configure do
Expand All @@ -350,7 +366,7 @@
attributes[:code_challenge_method] = "plain"

expect(pre_auth).to_not be_authorizable
expect(pre_auth.error_response.description).to eq("The code challenge method must be one of S256.")
expect(pre_auth.error_response.description).to eq("The code challenge method must be S256.")
end
end

Expand Down

0 comments on commit ccc9773

Please sign in to comment.