Skip to content

Commit

Permalink
Merge pull request #165 from rails/rm-json-serializer
Browse files Browse the repository at this point in the history
Make tests pass in Rails 7.1
  • Loading branch information
rafaelfranca committed Sep 2, 2023
2 parents 2fab171 + d371dd1 commit 4ec9833
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/global_id/signed_global_id.rb
Expand Up @@ -42,7 +42,7 @@ def verify_with_legacy_self_validated_metadata(sgid, options)

raise_if_expired(metadata['expires_at'])

metadata['gid'] if pick_purpose(options) == metadata['purpose']
metadata['gid'] if pick_purpose(options)&.to_s == metadata['purpose']&.to_s
rescue ActiveSupport::MessageVerifier::InvalidSignature, ExpiredMessage
nil
end
Expand Down
4 changes: 2 additions & 2 deletions lib/global_id/verifier.rb
Expand Up @@ -3,11 +3,11 @@
class GlobalID
class Verifier < ActiveSupport::MessageVerifier
private
def encode(data)
def encode(data, **)
::Base64.urlsafe_encode64(data)
end

def decode(data)
def decode(data, **)
::Base64.urlsafe_decode64(data)
end
end
Expand Down
1 change: 1 addition & 0 deletions test/cases/railtie_test.rb
Expand Up @@ -16,6 +16,7 @@ def setup
@app.config.eager_load = false
@app.config.logger = Logger.new(nil)
@app.config.secret_key_base = ('x' * 30)
@app.config.active_support.cache_format_version = Rails::VERSION::STRING.to_f
end

test 'GlobalID.app for Blog::Application defaults to blog' do
Expand Down
4 changes: 3 additions & 1 deletion test/cases/signed_global_id_test.rb
Expand Up @@ -71,7 +71,9 @@ class SignedGlobalIDPurposeTest < ActiveSupport::TestCase

test 'parse is backwards compatible with the self validated metadata' do
legacy_sgid = "eyJnaWQiOiJnaWQ6Ly9iY3gvUGVyc29uLzUiLCJwdXJwb3NlIjoibG9naW4iLCJleHBpcmVzX2F0IjpudWxsfQ==--4b9630f3a1fb3d7d6584d95d4fac96433ec2deef"
assert_equal @login_sgid, SignedGlobalID.parse(legacy_sgid, for: 'login')
parsed_sgid = SignedGlobalID.parse(legacy_sgid, for: :login)
assert_equal @login_sgid.uri, parsed_sgid.uri
assert_equal @login_sgid.purpose, parsed_sgid.purpose.to_s
end

test 'equal only with same purpose' do
Expand Down

0 comments on commit 4ec9833

Please sign in to comment.