From abd5476c58b142cfd55038abf0e2ca1e83eabae1 Mon Sep 17 00:00:00 2001 From: Joakim Antman Date: Wed, 16 Oct 2024 19:01:49 +0300 Subject: [PATCH] renamed enabled_crits to allowed_crits --- lib/jwt/encoded_token.rb | 18 +++++++----------- spec/jwt/encoded_token_spec.rb | 2 +- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/lib/jwt/encoded_token.rb b/lib/jwt/encoded_token.rb index 5c873be6..2329e613 100644 --- a/lib/jwt/encoded_token.rb +++ b/lib/jwt/encoded_token.rb @@ -11,7 +11,6 @@ module JWT # encoded_token = JWT::EncodedToken.new(token.jwt) # encoded_token.verify_signature!algorithm: 'HS256', key: 'secret') # encoded_token.payload # => {'pay' => 'load'} - # class EncodedToken include Claims::VerificationMethods @@ -22,17 +21,15 @@ class EncodedToken # Initializes a new EncodedToken instance. # # @param jwt [String] the encoded JWT token. - # @param enabled_crits [Array] the list of enabled critical headers. - # @param allow_unverified [Boolean] whether to allow access to payload for unverified tokens. + # @param allowed_crits [Array] the list of allowed critical headers. # @raise [ArgumentError] if the provided JWT is not a String. - # @raise [ArgumentError] if enabled_crits is not an Array. - def initialize(jwt, enabled_crits: []) + # @raise [ArgumentError] if allowed_crits is not an Array. + def initialize(jwt, allowed_crits: []) raise ArgumentError, 'Provided JWT must be a String' unless jwt.is_a?(String) - raise ArgumentError, 'enabled_crits must be an Array' unless enabled_crits.is_a?(Array) + raise ArgumentError, 'allowed_crits must be an Array' unless allowed_crits.is_a?(Array) - @enabled_crits = enabled_crits + @allowed_crits = allowed_crits @jwt = jwt - @signature_verified = false @encoded_header, @encoded_payload, @encoded_signature = jwt.split('.') end @@ -62,7 +59,6 @@ def header # Returns the payload of the JWT token. # - # @param allow_unverified [Boolean] whether to allow payloads to be accessed for unverified tokens. # @return [Hash] the payload. def payload @payload ||= decode_payload @@ -122,7 +118,7 @@ def verify_crit!(crit) raise InvalidCritError, "'#{crit}' missing from crit header" end - return if Array(enabled_crits).include?(crit) + return if Array(allowed_crits).include?(crit) raise InvalidCritError, "'#{crit}' not enabled for token instance" end @@ -131,7 +127,7 @@ def verify_crit!(crit) private - attr_reader :enabled_crits + attr_reader :allowed_crits def decode_payload raise JWT::DecodeError, 'Encoded payload is empty' if encoded_payload == '' diff --git a/spec/jwt/encoded_token_spec.rb b/spec/jwt/encoded_token_spec.rb index a0120f0d..90dfbdee 100644 --- a/spec/jwt/encoded_token_spec.rb +++ b/spec/jwt/encoded_token_spec.rb @@ -30,7 +30,7 @@ end context 'when payload is not encoded and the b64 crit is enabled' do - subject(:token) { described_class.new(encoded_token, enabled_crits: ['b64']) } + subject(:token) { described_class.new(encoded_token, allowed_crits: ['b64']) } let(:encoded_token) { 'eyJhbGciOiJIUzI1NiIsImI2NCI6ZmFsc2UsImNyaXQiOlsiYjY0Il19..signature' } before { token.encoded_payload = '{"foo": "bar"}' }