nov / json-jwt

JSON Web Token and its family (JSON Web Signature, JSON Web Encryption and JSON Web Key) in Ruby
MIT License
299 stars 80 forks source link

test failures with ruby3.0 #96

Closed boutil closed 2 years ago

boutil commented 2 years ago

Hi,

when trying to rebuild the Debian package associated to this gem with ruby3.0, we get the following failures: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=996303

I can reproduce these issues, with the HEAD of the repo. Everything is fine with ruby2.7, but the following 8 tests fail with ruby3.0.

Failures:

  1) JSON::JWS#to_json when syntax option given when general should return General JWS JSON Serialization
     Failure/Error:
       signed.to_json(syntax: :general).should == {
         payload: Base64.urlsafe_encode64(claims.to_json, padding: false),
         signatures: [{
           protected: Base64.urlsafe_encode64(signed.header.to_json, padding: false),
           signature: Base64.urlsafe_encode64(signed.signature, padding: false)
         }]
       }.to_json

       expected: "{\"payload\":\"eyJpc3MiOiJqb2UiLCJleHAiOjEzMDA4MTkzODAsImh0dHA6Ly9leGFtcGxlLmNvbS9pc19yb290Ijp0cnVlf...GUopIoxoqe4XjoBpzE5UvhrVl5LYbdjbyJhu5ZIA8GLsgwtUFh3dfdIechORoR3k5NSFSv8157bAEa8t4iwgWD2MSNSQnw\"}]}"
            got: "{\"iss\":\"joe\",\"exp\":1300819380,\"http://example.com/is_root\":true}" (using ==)
     # ./spec/json/jws_spec.rb:383:in `block (5 levels) in <top (required)>'

  2) JSON::JWS#to_json when syntax option given when general with blank payload should return General JWS JSON Serialization
     Failure/Error:
       signed_blank.to_json(syntax: :general).should == {
         payload: '',
         signatures: [{
           protected: Base64.urlsafe_encode64(signed_blank.header.to_json, padding: false),
           signature: Base64.urlsafe_encode64(signed_blank.signature, padding: false)
         }]
       }.to_json

       expected: "{\"payload\":\"\",\"signatures\":[{\"protected\":\"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9\",\"signatur...s43GtT5bm-aJoMLct0nO1GBapQAiKUknTsw24IfOkX4vJNQzIWVSzx3zOxXjcVHlH92af6NknIlPCfRparLC9YEK2NkJYg\"}]}"
            got: "{}" (using ==)
     # ./spec/json/jws_spec.rb:393:in `block (6 levels) in <top (required)>'

  3) JSON::JWS#to_json when syntax option given when general when not signed yet should not fail
     Failure/Error:
       jws.to_json(syntax: :general).should == {
         payload: Base64.urlsafe_encode64(claims.to_json, padding: false),
         signatures: [{
           protected: Base64.urlsafe_encode64(jws.header.to_json, padding: false),
           signature: Base64.urlsafe_encode64('', padding: false)
         }]
       }.to_json

       expected: "{\"payload\":\"eyJpc3MiOiJqb2UiLCJleHAiOjEzMDA4MTkzODAsImh0dHA6Ly9leGFtcGxlLmNvbS9pc19yb290Ijp0cnVlfQ\",\"signatures\":[{\"protected\":\"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9\",\"signature\":\"\"}]}"
            got: "{\"iss\":\"joe\",\"exp\":1300819380,\"http://example.com/is_root\":true}" (using ==)
     # ./spec/json/jws_spec.rb:405:in `block (6 levels) in <top (required)>'

  4) JSON::JWS#to_json when syntax option given when general when not signed yet with blank payload should not fail
     Failure/Error:
       jws_blank.to_json(syntax: :general).should == {
         payload: '',
         signatures: [{
           protected: Base64.urlsafe_encode64(jws_blank.header.to_json, padding: false),
           signature: Base64.urlsafe_encode64('', padding: false)
         }]
       }.to_json

       expected: "{\"payload\":\"\",\"signatures\":[{\"protected\":\"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9\",\"signature\":\"\"}]}"
            got: "{}" (using ==)
     # ./spec/json/jws_spec.rb:415:in `block (7 levels) in <top (required)>'

  5) JSON::JWS#to_json when syntax option given when flattened should return Flattened JWS JSON Serialization
     Failure/Error:
       signed.to_json(syntax: :flattened).should == {
         protected: Base64.urlsafe_encode64(signed.header.to_json, padding: false),
         payload: Base64.urlsafe_encode64(claims.to_json, padding: false),
         signature: Base64.urlsafe_encode64(signed.signature, padding: false)
       }.to_json

       expected: "{\"protected\":\"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9\",\"payload\":\"eyJpc3MiOiJqb2UiLCJleHAiOjEzMD...LVGUopIoxoqe4XjoBpzE5UvhrVl5LYbdjbyJhu5ZIA8GLsgwtUFh3dfdIechORoR3k5NSFSv8157bAEa8t4iwgWD2MSNSQnw\"}"
            got: "{\"iss\":\"joe\",\"exp\":1300819380,\"http://example.com/is_root\":true}" (using ==)
     # ./spec/json/jws_spec.rb:429:in `block (5 levels) in <top (required)>'

  6) JSON::JWS#to_json when syntax option given when flattened with blank payload should return Flattened JWS JSON Serialization
     Failure/Error:
       signed_blank.to_json(syntax: :flattened).should == {
         protected: Base64.urlsafe_encode64(signed_blank.header.to_json, padding: false),
         payload: '',
         signature: Base64.urlsafe_encode64(signed_blank.signature, padding: false)
       }.to_json

       expected: "{\"protected\":\"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9\",\"payload\":\"\",\"signature\":\"WthQjouPVbE...Mns43GtT5bm-aJoMLct0nO1GBapQAiKUknTsw24IfOkX4vJNQzIWVSzx3zOxXjcVHlH92af6NknIlPCfRparLC9YEK2NkJYg\"}"
            got: "{}" (using ==)
     # ./spec/json/jws_spec.rb:437:in `block (6 levels) in <top (required)>'

  7) JSON::JWS#to_json when syntax option given when flattened when not signed yet should not fail
     Failure/Error:
       jws.to_json(syntax: :flattened).should == {
         protected: Base64.urlsafe_encode64(jws.header.to_json, padding: false),
         payload: Base64.urlsafe_encode64(claims.to_json, padding: false),
         signature: Base64.urlsafe_encode64('', padding: false)
       }.to_json

       expected: "{\"protected\":\"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9\",\"payload\":\"eyJpc3MiOiJqb2UiLCJleHAiOjEzMDA4MTkzODAsImh0dHA6Ly9leGFtcGxlLmNvbS9pc19yb290Ijp0cnVlfQ\",\"signature\":\"\"}"
            got: "{\"iss\":\"joe\",\"exp\":1300819380,\"http://example.com/is_root\":true}" (using ==)
     # ./spec/json/jws_spec.rb:447:in `block (6 levels) in <top (required)>'

  8) JSON::JWS#to_json when syntax option given when flattened when not signed yet with blank payload should not fail
     Failure/Error:
       jws_blank.to_json(syntax: :flattened).should == {
         protected: Base64.urlsafe_encode64(jws_blank.header.to_json, padding: false),
         payload: '',
         signature: Base64.urlsafe_encode64('', padding: false)
       }.to_json

       expected: "{\"protected\":\"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9\",\"payload\":\"\",\"signature\":\"\"}"
            got: "{}" (using ==)
     # ./spec/json/jws_spec.rb:455:in `block (7 levels) in <top (required)>'

Finished in 0.56325 seconds (files took 0.55478 seconds to load)
380 examples, 8 failures, 6 pending

Thanks!

nov commented 2 years ago

Hum, not sure about Debian package, but I couldn't reproduce the errors with ruby 3.0.2 installed via rbenv on my mac.

boutil commented 2 years ago

Thanks for your quick answer. Could you share the versions of the dependencies you use to run the tests?

nov commented 2 years ago

In my local, json gem is v2.5.1, and this is my Gemfile.lock.

PATH
  remote: .
  specs:
    json-jwt (1.13.0)
      activesupport (>= 4.2)
      aes_key_wrap
      bindata

GEM
  remote: http://rubygems.org/
  specs:
    activesupport (6.1.4.1)
      concurrent-ruby (~> 1.0, >= 1.0.2)
      i18n (>= 1.6, < 2)
      minitest (>= 5.1)
      tzinfo (~> 2.0)
      zeitwerk (~> 2.3)
    aes_key_wrap (1.1.0)
    bindata (2.4.10)
    concurrent-ruby (1.1.9)
    diff-lcs (1.4.4)
    docile (1.4.0)
    i18n (1.8.11)
      concurrent-ruby (~> 1.0)
    minitest (5.14.4)
    rake (13.0.6)
    rspec (3.10.0)
      rspec-core (~> 3.10.0)
      rspec-expectations (~> 3.10.0)
      rspec-mocks (~> 3.10.0)
    rspec-core (3.10.1)
      rspec-support (~> 3.10.0)
    rspec-expectations (3.10.1)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.10.0)
    rspec-its (1.3.0)
      rspec-core (>= 3.0.0)
      rspec-expectations (>= 3.0.0)
    rspec-mocks (3.10.2)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.10.0)
    rspec-support (3.10.3)
    simplecov (0.21.2)
      docile (~> 1.1)
      simplecov-html (~> 0.11)
      simplecov_json_formatter (~> 0.1)
    simplecov-html (0.12.3)
    simplecov_json_formatter (0.1.3)
    tzinfo (2.0.4)
      concurrent-ruby (~> 1.0)
    zeitwerk (2.5.1)

PLATFORMS
  x86_64-darwin-21

DEPENDENCIES
  json-jwt!
  rake
  rspec
  rspec-its
  simplecov

BUNDLED WITH
   2.2.31
dleidert commented 2 years ago

Hi. I just rebuilt the package on Debian Sid and the error is gone with activesupport 6.1.4.1. It is still reproducible with activesupport 6.0.3.7 and tzinfo 1.x in Debian Testing, which were not Ruby 3 compatible. I think this report can be closed.

Here is the relevant Gemfile.lock when the build fails:

PATH
  remote: .
  specs:
    json-jwt (1.11.0)
      activesupport (>= 4.2)
      aes_key_wrap
      bindata

GEM
  remote: http://rubygems.org/
  specs:
    activesupport (6.0.3.7)
      concurrent-ruby (~> 1.0, >= 1.0.2)
      i18n (>= 0.7, < 2)
      minitest (~> 5.1)
      tzinfo (~> 1.1)
      zeitwerk (~> 2.2, >= 2.2.2)
    aes_key_wrap (1.0.1)
    bindata (2.4.8)
    concurrent-ruby (1.1.6)
    diff-lcs (1.4.4)
    i18n (1.8.11)
      concurrent-ruby (~> 1.0)
    minitest (5.13.0)
    rake (13.0.3)
    rspec (3.9.0)
      rspec-core (~> 3.9.0)
      rspec-expectations (~> 3.9.0)
      rspec-mocks (~> 3.9.0)
    rspec-core (3.9.2)
      rspec-support (~> 3.9.3)
    rspec-expectations (3.9.2)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.9.0)
    rspec-its (1.3.0)
      rspec-core (>= 3.0.0)
      rspec-expectations (>= 3.0.0)
    rspec-mocks (3.9.1)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.9.0)
    rspec-support (3.9.3)
    thread_safe (0.3.6)
    tzinfo (1.2.6)
      thread_safe (~> 0.1)
    zeitwerk (2.4.2)

PLATFORMS
  ruby

DEPENDENCIES
  json-jwt!
  rake
  rspec
  rspec-its

BUNDLED WITH
   2.1.4
boutil commented 2 years ago

Thank you @nov for the details and @dleidert for the additional investigation. I can confirm your conclusion. I am therefore closing this bug report, as the problem was not in this gem.