signet 0.11.0 → 0.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +51 -15
- data/Gemfile +5 -4
- data/README.md +4 -6
- data/Rakefile +107 -37
- data/lib/signet.rb +17 -14
- data/lib/signet/errors.rb +4 -4
- data/lib/signet/oauth_1.rb +129 -154
- data/lib/signet/oauth_1/client.rb +309 -343
- data/lib/signet/oauth_1/credential.rb +40 -37
- data/lib/signet/oauth_1/server.rb +197 -203
- data/lib/signet/oauth_1/signature_methods/hmac_sha1.rb +11 -10
- data/lib/signet/oauth_1/signature_methods/plaintext.rb +8 -7
- data/lib/signet/oauth_1/signature_methods/rsa_sha1.rb +11 -11
- data/lib/signet/oauth_2.rb +41 -43
- data/lib/signet/oauth_2/client.rb +328 -313
- data/lib/signet/version.rb +2 -73
- data/signet.gemspec +37 -39
- data/spec/signet/oauth_1/client_spec.rb +313 -315
- data/spec/signet/oauth_1/credential_spec.rb +64 -56
- data/spec/signet/oauth_1/server_spec.rb +362 -362
- data/spec/signet/oauth_1/signature_methods/hmac_sha1_spec.rb +26 -26
- data/spec/signet/oauth_1/signature_methods/plaintext_spec.rb +28 -28
- data/spec/signet/oauth_1/signature_methods/rsa_sha1_spec.rb +34 -35
- data/spec/signet/oauth_1_spec.rb +553 -524
- data/spec/signet/oauth_2/client_spec.rb +652 -576
- data/spec/signet/oauth_2_spec.rb +88 -89
- data/spec/signet_spec.rb +41 -41
- data/spec/spec_helper.rb +7 -7
- data/spec/spec_helper_spec.rb +8 -8
- metadata +64 -52
- data/tasks/clobber.rake +0 -2
- data/tasks/gem.rake +0 -34
- data/tasks/git.rake +0 -40
- data/tasks/metrics.rake +0 -41
- data/tasks/spec.rake +0 -34
- data/tasks/wiki.rake +0 -38
- data/tasks/yard.rake +0 -21
| @@ -11,121 +11,129 @@ | |
| 11 11 | 
             
            #    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
         | 
| 12 12 | 
             
            #    See the License for the specific language governing permissions and
         | 
| 13 13 | 
             
            #    limitations under the License.
         | 
| 14 | 
            -
            require  | 
| 15 | 
            -
            require  | 
| 14 | 
            +
            require "spec_helper"
         | 
| 15 | 
            +
            require "signet/oauth_1/credential"
         | 
| 16 16 |  | 
| 17 | 
            -
            describe Signet::OAuth1::Credential,  | 
| 17 | 
            +
            describe Signet::OAuth1::Credential, "with a Hash for initialization" do
         | 
| 18 18 | 
             
              it 'should accept "oauth_token" and "oauth_token_secret" pairs' do
         | 
| 19 | 
            -
                token = Signet::OAuth1::Credential.new( | 
| 20 | 
            -
                  "oauth_token" | 
| 19 | 
            +
                token = Signet::OAuth1::Credential.new(
         | 
| 20 | 
            +
                  "oauth_token"        => "dpf43f3p2l4k3l03",
         | 
| 21 21 | 
             
                  "oauth_token_secret" => "kd94hf93k423kf44"
         | 
| 22 | 
            -
                 | 
| 22 | 
            +
                )
         | 
| 23 23 | 
             
                expect(token.key).to eq "dpf43f3p2l4k3l03"
         | 
| 24 24 | 
             
                expect(token.secret).to eq "kd94hf93k423kf44"
         | 
| 25 25 | 
             
              end
         | 
| 26 26 |  | 
| 27 | 
            -
              it  | 
| 28 | 
            -
                token = Signet::OAuth1::Credential.new( | 
| 29 | 
            -
                  : | 
| 30 | 
            -
                  : | 
| 31 | 
            -
                 | 
| 27 | 
            +
              it "should accept :oauth_token and :oauth_token_secret pairs" do
         | 
| 28 | 
            +
                token = Signet::OAuth1::Credential.new(
         | 
| 29 | 
            +
                  oauth_token:        "dpf43f3p2l4k3l03",
         | 
| 30 | 
            +
                  oauth_token_secret: "kd94hf93k423kf44"
         | 
| 31 | 
            +
                )
         | 
| 32 32 | 
             
                expect(token.key).to eq "dpf43f3p2l4k3l03"
         | 
| 33 33 | 
             
                expect(token.secret).to eq "kd94hf93k423kf44"
         | 
| 34 34 | 
             
              end
         | 
| 35 35 |  | 
| 36 36 | 
             
              it 'should accept "key" and "secret" pairs' do
         | 
| 37 | 
            -
                token = Signet::OAuth1::Credential.new( | 
| 38 | 
            -
                  "key" | 
| 37 | 
            +
                token = Signet::OAuth1::Credential.new(
         | 
| 38 | 
            +
                  "key"    => "dpf43f3p2l4k3l03",
         | 
| 39 39 | 
             
                  "secret" => "kd94hf93k423kf44"
         | 
| 40 | 
            -
                 | 
| 40 | 
            +
                )
         | 
| 41 41 | 
             
                expect(token.key).to eq "dpf43f3p2l4k3l03"
         | 
| 42 42 | 
             
                expect(token.secret).to eq "kd94hf93k423kf44"
         | 
| 43 43 | 
             
              end
         | 
| 44 44 |  | 
| 45 | 
            -
              it  | 
| 45 | 
            +
              it "should accept :key and :secret pairs" do
         | 
| 46 46 | 
             
                token = Signet::OAuth1::Credential.new(
         | 
| 47 | 
            -
                  : | 
| 48 | 
            -
                  : | 
| 47 | 
            +
                  key:    "dpf43f3p2l4k3l03",
         | 
| 48 | 
            +
                  secret: "kd94hf93k423kf44"
         | 
| 49 49 | 
             
                )
         | 
| 50 50 | 
             
                expect(token.key).to eq "dpf43f3p2l4k3l03"
         | 
| 51 51 | 
             
                expect(token.secret).to eq "kd94hf93k423kf44"
         | 
| 52 52 | 
             
              end
         | 
| 53 53 |  | 
| 54 | 
            -
              it  | 
| 55 | 
            -
                token = Signet::OAuth1::Credential.new( | 
| 56 | 
            -
                  "oauth_token" | 
| 54 | 
            +
              it "should not complain about additional parameters" do
         | 
| 55 | 
            +
                token = Signet::OAuth1::Credential.new(
         | 
| 56 | 
            +
                  "oauth_token"        => "dpf43f3p2l4k3l03",
         | 
| 57 57 | 
             
                  "oauth_token_secret" => "kd94hf93k423kf44",
         | 
| 58 | 
            -
                  "oauth_version" | 
| 59 | 
            -
                 | 
| 58 | 
            +
                  "oauth_version"      => "1.0"
         | 
| 59 | 
            +
                )
         | 
| 60 60 | 
             
                expect(token.key).to eq "dpf43f3p2l4k3l03"
         | 
| 61 61 | 
             
                expect(token.secret).to eq "kd94hf93k423kf44"
         | 
| 62 62 | 
             
              end
         | 
| 63 63 |  | 
| 64 | 
            -
              it  | 
| 64 | 
            +
              it "should allow parameters to be specified as an implicit Hash" do
         | 
| 65 65 | 
             
                class ParameterHashSet
         | 
| 66 | 
            -
                  def initialize | 
| 67 | 
            -
                    @parameters = parameters. | 
| 66 | 
            +
                  def initialize parameters
         | 
| 67 | 
            +
                    @parameters = parameters.each_with_object({}) { |(k, v), h| h[k] = v; }
         | 
| 68 68 | 
             
                  end
         | 
| 69 69 |  | 
| 70 70 | 
             
                  def to_hash
         | 
| 71 | 
            -
                     | 
| 71 | 
            +
                    @parameters
         | 
| 72 72 | 
             
                  end
         | 
| 73 73 | 
             
                end
         | 
| 74 74 |  | 
| 75 | 
            -
                token = Signet::OAuth1::Credential.new( | 
| 76 | 
            -
                   | 
| 77 | 
            -
             | 
| 78 | 
            -
             | 
| 79 | 
            -
             | 
| 75 | 
            +
                token = Signet::OAuth1::Credential.new(
         | 
| 76 | 
            +
                  ParameterHashSet.new(
         | 
| 77 | 
            +
                    "oauth_token"        => "dpf43f3p2l4k3l03",
         | 
| 78 | 
            +
                    "oauth_token_secret" => "kd94hf93k423kf44",
         | 
| 79 | 
            +
                    "oauth_version"      => "1.0"
         | 
| 80 | 
            +
                  )
         | 
| 81 | 
            +
                )
         | 
| 80 82 | 
             
                expect(token.key).to eq "dpf43f3p2l4k3l03"
         | 
| 81 83 | 
             
                expect(token.secret).to eq "kd94hf93k423kf44"
         | 
| 82 84 | 
             
              end
         | 
| 83 85 |  | 
| 84 | 
            -
              it  | 
| 85 | 
            -
                token = Signet::OAuth1::Credential.new( | 
| 86 | 
            -
                  [ | 
| 87 | 
            -
             | 
| 88 | 
            -
             | 
| 89 | 
            -
             | 
| 86 | 
            +
              it "should allow parameters to be specified as an Enumerable" do
         | 
| 87 | 
            +
                token = Signet::OAuth1::Credential.new(
         | 
| 88 | 
            +
                  [
         | 
| 89 | 
            +
                    %w[oauth_token dpf43f3p2l4k3l03],
         | 
| 90 | 
            +
                    %w[oauth_token_secret kd94hf93k423kf44],
         | 
| 91 | 
            +
                    ["oauth_version", "1.0"]
         | 
| 92 | 
            +
                  ]
         | 
| 93 | 
            +
                )
         | 
| 90 94 | 
             
                expect(token.key).to eq "dpf43f3p2l4k3l03"
         | 
| 91 95 | 
             
                expect(token.secret).to eq "kd94hf93k423kf44"
         | 
| 92 96 | 
             
              end
         | 
| 93 97 |  | 
| 94 | 
            -
              it  | 
| 98 | 
            +
              it "should allow parameters to be specified as an implicit Array" do
         | 
| 95 99 | 
             
                class ParameterArraySet
         | 
| 96 | 
            -
                  def initialize | 
| 100 | 
            +
                  def initialize parameters
         | 
| 97 101 | 
             
                    @parameters = parameters
         | 
| 98 102 | 
             
                  end
         | 
| 99 103 |  | 
| 100 104 | 
             
                  def to_ary
         | 
| 101 | 
            -
                     | 
| 105 | 
            +
                    @parameters
         | 
| 102 106 | 
             
                  end
         | 
| 103 107 | 
             
                end
         | 
| 104 108 |  | 
| 105 | 
            -
                token = Signet::OAuth1::Credential.new( | 
| 106 | 
            -
                   | 
| 107 | 
            -
             | 
| 108 | 
            -
             | 
| 109 | 
            -
             | 
| 109 | 
            +
                token = Signet::OAuth1::Credential.new(
         | 
| 110 | 
            +
                  ParameterArraySet.new(
         | 
| 111 | 
            +
                    [
         | 
| 112 | 
            +
                      %w[oauth_token dpf43f3p2l4k3l03],
         | 
| 113 | 
            +
                      %w[oauth_token_secret kd94hf93k423kf44],
         | 
| 114 | 
            +
                      ["oauth_version", "1.0"]
         | 
| 115 | 
            +
                    ]
         | 
| 116 | 
            +
                  )
         | 
| 117 | 
            +
                )
         | 
| 110 118 | 
             
                expect(token.key).to eq "dpf43f3p2l4k3l03"
         | 
| 111 119 | 
             
                expect(token.secret).to eq "kd94hf93k423kf44"
         | 
| 112 120 | 
             
              end
         | 
| 113 121 |  | 
| 114 | 
            -
              it  | 
| 122 | 
            +
              it "should raise an error if key and secret are not present" do
         | 
| 115 123 | 
             
                expect(lambda do
         | 
| 116 124 | 
             
                  Signet::OAuth1::Credential.new({})
         | 
| 117 125 | 
             
                end).to raise_error(ArgumentError)
         | 
| 118 126 | 
             
              end
         | 
| 119 127 |  | 
| 120 | 
            -
              it  | 
| 128 | 
            +
              it "should allow key and secret to be passed in as a tuple" do
         | 
| 121 129 | 
             
                token = Signet::OAuth1::Credential.new(
         | 
| 122 | 
            -
                  [ | 
| 130 | 
            +
                  %w[dpf43f3p2l4k3l03 kd94hf93k423kf44]
         | 
| 123 131 | 
             
                )
         | 
| 124 132 | 
             
                expect(token.key).to eq "dpf43f3p2l4k3l03"
         | 
| 125 133 | 
             
                expect(token.secret).to eq "kd94hf93k423kf44"
         | 
| 126 134 | 
             
              end
         | 
| 127 135 |  | 
| 128 | 
            -
              it  | 
| 136 | 
            +
              it "should allow key and secret to be passed in as normal parameters" do
         | 
| 129 137 | 
             
                token = Signet::OAuth1::Credential.new(
         | 
| 130 138 | 
             
                  "dpf43f3p2l4k3l03", "kd94hf93k423kf44"
         | 
| 131 139 | 
             
                )
         | 
| @@ -133,16 +141,16 @@ describe Signet::OAuth1::Credential, 'with a Hash for initialization' do | |
| 133 141 | 
             
                expect(token.secret).to eq "kd94hf93k423kf44"
         | 
| 134 142 | 
             
              end
         | 
| 135 143 |  | 
| 136 | 
            -
              it  | 
| 144 | 
            +
              it "should raise an error if key or secret are of the wrong type" do
         | 
| 137 145 | 
             
                expect(lambda do
         | 
| 138 | 
            -
                  Signet::OAuth1::Credential.new | 
| 146 | 
            +
                  Signet::OAuth1::Credential.new "dpf43f3p2l4k3l03", 42
         | 
| 139 147 | 
             
                end).to raise_error(TypeError)
         | 
| 140 148 | 
             
                expect(lambda do
         | 
| 141 | 
            -
                  Signet::OAuth1::Credential.new | 
| 149 | 
            +
                  Signet::OAuth1::Credential.new 42, "kd94hf93k423kf44"
         | 
| 142 150 | 
             
                end).to raise_error(TypeError)
         | 
| 143 151 | 
             
              end
         | 
| 144 152 |  | 
| 145 | 
            -
              it  | 
| 153 | 
            +
              it "should raise an error if the wrong number of arguments are passed" do
         | 
| 146 154 | 
             
                expect(lambda do
         | 
| 147 155 | 
             
                  Signet::OAuth1::Credential.new(
         | 
| 148 156 | 
             
                    "dpf43f3p2l4k3l03", "kd94hf93k423kf44", "something else"
         | 
| @@ -150,12 +158,12 @@ describe Signet::OAuth1::Credential, 'with a Hash for initialization' do | |
| 150 158 | 
             
                end).to raise_error(ArgumentError)
         | 
| 151 159 | 
             
              end
         | 
| 152 160 |  | 
| 153 | 
            -
              it  | 
| 161 | 
            +
              it "should convert to a Hash object" do
         | 
| 154 162 | 
             
                token = Signet::OAuth1::Credential.new(
         | 
| 155 163 | 
             
                  "dpf43f3p2l4k3l03", "kd94hf93k423kf44"
         | 
| 156 164 | 
             
                )
         | 
| 157 165 | 
             
                parameters = token.to_h
         | 
| 158 | 
            -
                expect(parameters[ | 
| 159 | 
            -
                expect(parameters[ | 
| 166 | 
            +
                expect(parameters["oauth_token"]).to eq "dpf43f3p2l4k3l03"
         | 
| 167 | 
            +
                expect(parameters["oauth_token_secret"]).to eq "kd94hf93k423kf44"
         | 
| 160 168 | 
             
              end
         | 
| 161 169 | 
             
            end
         | 
| @@ -11,92 +11,91 @@ | |
| 11 11 | 
             
            #    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
         | 
| 12 12 | 
             
            #    See the License for the specific language governing permissions and
         | 
| 13 13 | 
             
            #    limitations under the License.
         | 
| 14 | 
            -
            require  | 
| 15 | 
            -
            require  | 
| 16 | 
            -
            require  | 
| 17 | 
            -
            require  | 
| 18 | 
            -
            require  | 
| 14 | 
            +
            require "spec_helper"
         | 
| 15 | 
            +
            require "signet/oauth_1/server"
         | 
| 16 | 
            +
            require "signet/oauth_1/client"
         | 
| 17 | 
            +
            require "addressable/uri"
         | 
| 18 | 
            +
            require "stringio"
         | 
| 19 19 |  | 
| 20 | 
            -
            def merge_body | 
| 20 | 
            +
            def merge_body chunked_body
         | 
| 21 21 | 
             
              merged_body = StringIO.new
         | 
| 22 22 | 
             
              chunked_body.each do |chunk|
         | 
| 23 | 
            -
                merged_body.write | 
| 23 | 
            +
                merged_body.write chunk
         | 
| 24 24 | 
             
              end
         | 
| 25 | 
            -
               | 
| 25 | 
            +
              merged_body.string
         | 
| 26 26 | 
             
            end
         | 
| 27 27 |  | 
| 28 | 
            -
            def make_oauth_signature_header | 
| 29 | 
            -
              [oauth_headers({ | 
| 28 | 
            +
            def make_oauth_signature_header real_headers = {}
         | 
| 29 | 
            +
              [oauth_headers({ "oauth_signature" => "oauth_signature" }.merge(real_headers))]
         | 
| 30 30 | 
             
            end
         | 
| 31 | 
            -
             | 
| 32 | 
            -
             | 
| 31 | 
            +
             | 
| 32 | 
            +
            def make_oauth_token_header real_headers = {}
         | 
| 33 | 
            +
              [oauth_headers({ "oauth_token" => "oauth_token" }.merge(real_headers))]
         | 
| 33 34 | 
             
            end
         | 
| 34 35 |  | 
| 35 | 
            -
            def oauth_headers | 
| 36 | 
            +
            def oauth_headers real_headers = {}
         | 
| 36 37 | 
             
              headers = {}
         | 
| 37 38 | 
             
              %w[oauth_consumer_key oauth_timestamp oauth_nonce].each do |key|
         | 
| 38 39 | 
             
                headers[key] = key
         | 
| 39 40 | 
             
              end
         | 
| 40 | 
            -
              headers[ | 
| 41 | 
            -
              headers[ | 
| 42 | 
            -
              headers.merge! | 
| 43 | 
            -
              [ | 
| 41 | 
            +
              headers["oauth_signature_method"] = "HMAC-SHA1"
         | 
| 42 | 
            +
              headers["oauth_version"] = "1.0"
         | 
| 43 | 
            +
              headers.merge! real_headers
         | 
| 44 | 
            +
              ["Authorization", ::Signet::OAuth1.generate_authorization_header(headers, nil)]
         | 
| 44 45 | 
             
            end
         | 
| 45 46 |  | 
| 46 | 
            -
            def make_temporary_credential_request | 
| 47 | 
            +
            def make_temporary_credential_request client, callback = nil, uri = nil, realm = nil
         | 
| 47 48 | 
             
              client.callback = callback if callback
         | 
| 48 | 
            -
              client.temporary_credential_uri = uri ||  | 
| 49 | 
            -
              client.generate_temporary_credential_request | 
| 49 | 
            +
              client.temporary_credential_uri = uri || "http://photos.example.net/initiate"
         | 
| 50 | 
            +
              client.generate_temporary_credential_request realm: realm
         | 
| 50 51 | 
             
            end
         | 
| 51 52 |  | 
| 52 | 
            -
            def make_token_credential_request | 
| 53 | 
            -
              client.token_credential_uri = uri ||  | 
| 54 | 
            -
              client.generate_token_credential_request(:verifier | 
| 55 | 
            -
                                                       :realm | 
| 56 | 
            -
                                                      )
         | 
| 53 | 
            +
            def make_token_credential_request client, verifier = nil, realm = nil, uri = nil
         | 
| 54 | 
            +
              client.token_credential_uri = uri || "http://photos.example.net/token"
         | 
| 55 | 
            +
              client.generate_token_credential_request(verifier: verifier || "12345",
         | 
| 56 | 
            +
                                                       realm:    realm)
         | 
| 57 57 | 
             
            end
         | 
| 58 58 |  | 
| 59 | 
            -
            def make_resource_request | 
| 60 | 
            -
             | 
| 59 | 
            +
            def make_resource_request client, real_request = {}, realm = nil
         | 
| 61 60 | 
             
              client.generate_authenticated_request(
         | 
| 62 | 
            -
             | 
| 63 | 
            -
             | 
| 64 | 
            -
             | 
| 65 | 
            -
             | 
| 66 | 
            -
             | 
| 67 | 
            -
             | 
| 61 | 
            +
                method:  real_request[:method] || "GET",
         | 
| 62 | 
            +
                uri:     real_request[:uri] || "http://photos.example.net/photos",
         | 
| 63 | 
            +
                body:    real_request[:body],
         | 
| 64 | 
            +
                headers: real_request[:headers],
         | 
| 65 | 
            +
                realm:   realm
         | 
| 66 | 
            +
              )
         | 
| 68 67 | 
             
            end
         | 
| 69 68 |  | 
| 70 69 |  | 
| 71 | 
            -
            describe Signet::OAuth1::Server,  | 
| 70 | 
            +
            describe Signet::OAuth1::Server, "unconfigured" do
         | 
| 72 71 | 
             
              before do
         | 
| 73 72 | 
             
                @server = Signet::OAuth1::Server.new
         | 
| 74 73 | 
             
              end
         | 
| 75 | 
            -
              it  | 
| 74 | 
            +
              it "should not have a client_credential Proc" do
         | 
| 76 75 | 
             
                expect(@server.client_credential).to eq nil
         | 
| 77 76 | 
             
              end
         | 
| 78 | 
            -
              it  | 
| 77 | 
            +
              it "should not have a token_credential Proc" do
         | 
| 79 78 | 
             
                expect(@server.token_credential).to eq nil
         | 
| 80 79 | 
             
              end
         | 
| 81 | 
            -
              it  | 
| 80 | 
            +
              it "should not have a nonce_timestamp Proc" do
         | 
| 82 81 | 
             
                expect(@server.nonce_timestamp).to eq nil
         | 
| 83 82 | 
             
              end
         | 
| 84 | 
            -
              it  | 
| 83 | 
            +
              it "should not have a verifier Proc" do
         | 
| 85 84 | 
             
                expect(@server.verifier).to eq nil
         | 
| 86 85 | 
             
              end
         | 
| 87 86 | 
             
            end
         | 
| 88 87 |  | 
| 89 88 |  | 
| 90 | 
            -
            describe Signet::OAuth1::Server,  | 
| 89 | 
            +
            describe Signet::OAuth1::Server, "configured" do
         | 
| 91 90 | 
             
              before do
         | 
| 92 91 | 
             
                @server = Signet::OAuth1::Server.new
         | 
| 93 | 
            -
                @client_credential_key =  | 
| 94 | 
            -
                @client_credential_secret =  | 
| 95 | 
            -
                @token_credential_key =  | 
| 96 | 
            -
                @token_credential_secret =  | 
| 97 | 
            -
                @temporary_credential_key =  | 
| 98 | 
            -
                @temporary_credential_secret =  | 
| 99 | 
            -
                @verifier =  | 
| 92 | 
            +
                @client_credential_key = "dpf43f3p2l4k3l03"
         | 
| 93 | 
            +
                @client_credential_secret = "kd94hf93k423kf44"
         | 
| 94 | 
            +
                @token_credential_key = "nnch734d00sl2jdk"
         | 
| 95 | 
            +
                @token_credential_secret = "pfkkdhi9sl3r4s00"
         | 
| 96 | 
            +
                @temporary_credential_key = "hh5s93j4hdidpola"
         | 
| 97 | 
            +
                @temporary_credential_secret = "hdhd0244k9j7ao03"
         | 
| 98 | 
            +
                @verifier = "hfdp7dh39dks9884"
         | 
| 100 99 |  | 
| 101 100 | 
             
                @server.client_credential =
         | 
| 102 101 | 
             
                  lambda do |x|
         | 
| @@ -117,10 +116,10 @@ describe Signet::OAuth1::Server, 'configured' do | |
| 117 116 | 
             
                  lambda do |nonce, timestamp|
         | 
| 118 117 | 
             
                    !(nonce.nil? && timestamp.nil?)
         | 
| 119 118 | 
             
                  end
         | 
| 120 | 
            -
                @server.verifier =  | 
| 119 | 
            +
                @server.verifier = ->(x) { x == @verifier }
         | 
| 121 120 | 
             
              end
         | 
| 122 121 |  | 
| 123 | 
            -
              it  | 
| 122 | 
            +
              it "should raise an error if the client credential Proc is not set" do
         | 
| 124 123 | 
             
                @server.client_credential = nil
         | 
| 125 124 | 
             
                expect(lambda do
         | 
| 126 125 | 
             
                  @server.authenticate_resource_request
         | 
| @@ -148,96 +147,98 @@ describe Signet::OAuth1::Server, 'configured' do | |
| 148 147 | 
             
                end).to raise_error(ArgumentError)
         | 
| 149 148 | 
             
              end
         | 
| 150 149 |  | 
| 151 | 
            -
              it  | 
| 150 | 
            +
              it "should raise an error if no request is provided" do
         | 
| 152 151 | 
             
                expect(lambda do
         | 
| 153 152 | 
             
                  @server.authenticate_resource_request
         | 
| 154 153 | 
             
                end).to raise_error(ArgumentError)
         | 
| 155 154 | 
             
              end
         | 
| 156 155 |  | 
| 157 | 
            -
              it  | 
| 156 | 
            +
              it "should raise an error if a bogus request is provided" do
         | 
| 158 157 | 
             
                expect(lambda do
         | 
| 159 158 | 
             
                  @server.authenticate_resource_request(
         | 
| 160 | 
            -
                    : | 
| 159 | 
            +
                    request: []
         | 
| 161 160 | 
             
                  )
         | 
| 162 161 | 
             
                end).to raise_error(ArgumentError)
         | 
| 163 162 | 
             
              end
         | 
| 164 163 |  | 
| 165 | 
            -
              it  | 
| 164 | 
            +
              it "should raise an error if no Authentication header is provided" do
         | 
| 166 165 | 
             
                expect(lambda do
         | 
| 167 166 | 
             
                  @server.authenticate_resource_request(
         | 
| 168 | 
            -
                    : | 
| 169 | 
            -
                    : | 
| 170 | 
            -
                    : | 
| 171 | 
            -
                    : | 
| 167 | 
            +
                    method:  "GET",
         | 
| 168 | 
            +
                    uri:     "https://photos.example.net/photos",
         | 
| 169 | 
            +
                    headers: [["Authorization", ""]],
         | 
| 170 | 
            +
                    body:    ""
         | 
| 172 171 | 
             
                  )
         | 
| 173 172 | 
             
                end).to raise_error(Signet::MalformedAuthorizationError)
         | 
| 174 173 | 
             
              end
         | 
| 175 174 |  | 
| 176 | 
            -
              it  | 
| 175 | 
            +
              it "should raise an error if no URI is provided" do
         | 
| 177 176 | 
             
                expect(lambda do
         | 
| 178 177 | 
             
                  @server.authenticate_resource_request(
         | 
| 179 | 
            -
                    : | 
| 180 | 
            -
                    : | 
| 181 | 
            -
                    : | 
| 178 | 
            +
                    method:  "GET",
         | 
| 179 | 
            +
                    headers: [],
         | 
| 180 | 
            +
                    body:    ""
         | 
| 182 181 | 
             
                  )
         | 
| 183 182 | 
             
                end).to raise_error(ArgumentError)
         | 
| 184 183 | 
             
              end
         | 
| 185 184 |  | 
| 186 | 
            -
              it  | 
| 187 | 
            -
                bad_method =  | 
| 185 | 
            +
              it "should reject a request with the wrong signature method" do
         | 
| 186 | 
            +
                bad_method = "FOO"
         | 
| 188 187 | 
             
                expect(lambda do
         | 
| 189 188 | 
             
                  @server.authenticate_resource_request(
         | 
| 190 | 
            -
                    : | 
| 191 | 
            -
                    : | 
| 192 | 
            -
                    : | 
| 189 | 
            +
                    method:  "GET",
         | 
| 190 | 
            +
                    uri:     "http://photos.example.net/photos",
         | 
| 191 | 
            +
                    headers: make_oauth_token_header("oauth_signature_method"=>bad_method)
         | 
| 193 192 | 
             
                  )
         | 
| 194 193 | 
             
                end).to raise_error(NotImplementedError,
         | 
| 195 | 
            -
             | 
| 196 | 
            -
                                       )
         | 
| 194 | 
            +
                                    "Unsupported signature method: #{bad_method}")
         | 
| 197 195 | 
             
              end
         | 
| 198 196 |  | 
| 199 197 |  | 
| 200 | 
            -
              describe  | 
| 201 | 
            -
                it  | 
| 198 | 
            +
              describe "calling find_temporary_credential" do
         | 
| 199 | 
            +
                it "should return a Signet credential if the Proc provides one" do
         | 
| 202 200 | 
             
                  @server.temporary_credential =
         | 
| 203 201 | 
             
                    lambda do |x|
         | 
| 204 202 | 
             
                      x.nil? ? nil : Signet::OAuth1::Credential.new(
         | 
| 205 | 
            -
             | 
| 206 | 
            -
             | 
| 203 | 
            +
                        @temporary_credential_key, @temporary_credential_secret
         | 
| 204 | 
            +
                      )
         | 
| 207 205 | 
             
                    end
         | 
| 208 206 | 
             
                  expect(@server.find_temporary_credential(@temporary_credential_key)).to eq(
         | 
| 209 207 | 
             
                    Signet::OAuth1::Credential.new(@temporary_credential_key,
         | 
| 210 | 
            -
                                                   @temporary_credential_secret) | 
| 208 | 
            +
                                                   @temporary_credential_secret)
         | 
| 209 | 
            +
                  )
         | 
| 211 210 | 
             
                end
         | 
| 212 | 
            -
                it  | 
| 211 | 
            +
                it "should return a Signet credential if the Proc provides a key/secret pair" do
         | 
| 213 212 | 
             
                  @server.temporary_credential =
         | 
| 214 | 
            -
                    lambda do | | 
| 215 | 
            -
                      {: | 
| 213 | 
            +
                    lambda do |_x|
         | 
| 214 | 
            +
                      { key: @temporary_credential_key, secret: @temporary_credential_secret }
         | 
| 216 215 | 
             
                    end
         | 
| 217 216 | 
             
                  expect(@server.find_temporary_credential(@temporary_credential_key)).to eq(
         | 
| 218 217 | 
             
                    Signet::OAuth1::Credential.new(@temporary_credential_key,
         | 
| 219 | 
            -
                                                   @temporary_credential_secret) | 
| 218 | 
            +
                                                   @temporary_credential_secret)
         | 
| 219 | 
            +
                  )
         | 
| 220 220 | 
             
                end
         | 
| 221 | 
            -
                it  | 
| 222 | 
            -
                    | 
| 221 | 
            +
                it "should return a Signet credential if the Proc provides " \
         | 
| 222 | 
            +
                   "a key/secret Enumerable" do
         | 
| 223 223 | 
             
                  @server.temporary_credential =
         | 
| 224 | 
            -
                    lambda do | | 
| 224 | 
            +
                    lambda do |_x|
         | 
| 225 225 | 
             
                      [@temporary_credential_key, @temporary_credential_secret]
         | 
| 226 226 | 
             
                    end
         | 
| 227 227 | 
             
                  expect(@server.find_temporary_credential(@temporary_credential_key)).to eq(
         | 
| 228 228 | 
             
                    Signet::OAuth1::Credential.new(@temporary_credential_key,
         | 
| 229 | 
            -
                                                   @temporary_credential_secret) | 
| 229 | 
            +
                                                   @temporary_credential_secret)
         | 
| 230 | 
            +
                  )
         | 
| 230 231 | 
             
                end
         | 
| 231 232 |  | 
| 232 | 
            -
                it  | 
| 233 | 
            -
                  @server.temporary_credential =  | 
| 233 | 
            +
                it "should return nil if the Proc does not provide a usable response" do
         | 
| 234 | 
            +
                  @server.temporary_credential = ->(_x) { nil }
         | 
| 234 235 | 
             
                  expect(@server.find_temporary_credential(@temporary_credential_key)).to eq nil
         | 
| 235 236 | 
             
                end
         | 
| 236 237 | 
             
              end
         | 
| 237 238 |  | 
| 238 239 |  | 
| 239 | 
            -
              describe  | 
| 240 | 
            -
                it  | 
| 240 | 
            +
              describe "calling find_client_credential" do
         | 
| 241 | 
            +
                it "should return a Signet credential if the Proc provides one" do
         | 
| 241 242 | 
             
                  @server.client_credential =
         | 
| 242 243 | 
             
                    lambda do |x|
         | 
| 243 244 | 
             
                      x.nil? ? nil : Signet::OAuth1::Credential.new(@client_credential_key,
         | 
| @@ -245,37 +246,40 @@ describe Signet::OAuth1::Server, 'configured' do | |
| 245 246 | 
             
                    end
         | 
| 246 247 | 
             
                  expect(@server.find_client_credential(@client_credential_key)).to eq(
         | 
| 247 248 | 
             
                    Signet::OAuth1::Credential.new(@client_credential_key,
         | 
| 248 | 
            -
                                                   @client_credential_secret) | 
| 249 | 
            +
                                                   @client_credential_secret)
         | 
| 250 | 
            +
                  )
         | 
| 249 251 | 
             
                end
         | 
| 250 | 
            -
                it  | 
| 252 | 
            +
                it "should return a Signet credential if the Proc provides a key/secret pair" do
         | 
| 251 253 | 
             
                  @server.client_credential =
         | 
| 252 | 
            -
                    lambda do | | 
| 253 | 
            -
                      {: | 
| 254 | 
            +
                    lambda do |_x|
         | 
| 255 | 
            +
                      { key: @client_credential_key, secret: @client_credential_secret }
         | 
| 254 256 | 
             
                    end
         | 
| 255 257 | 
             
                  expect(@server.find_client_credential(@client_credential_key)).to eq(
         | 
| 256 258 | 
             
                    Signet::OAuth1::Credential.new(@client_credential_key,
         | 
| 257 | 
            -
                                                   @client_credential_secret) | 
| 259 | 
            +
                                                   @client_credential_secret)
         | 
| 260 | 
            +
                  )
         | 
| 258 261 | 
             
                end
         | 
| 259 | 
            -
                it  | 
| 260 | 
            -
                    | 
| 262 | 
            +
                it "should return a Signet credential if the Proc provides " \
         | 
| 263 | 
            +
                   "a key/secret Enumerable" do
         | 
| 261 264 | 
             
                  @server.client_credential =
         | 
| 262 | 
            -
                    lambda do | | 
| 265 | 
            +
                    lambda do |_x|
         | 
| 263 266 | 
             
                      [@client_credential_key, @client_credential_secret]
         | 
| 264 267 | 
             
                    end
         | 
| 265 268 | 
             
                  expect(@server.find_client_credential(@client_credential_key)).to eq(
         | 
| 266 269 | 
             
                    Signet::OAuth1::Credential.new(@client_credential_key,
         | 
| 267 | 
            -
                                                   @client_credential_secret) | 
| 270 | 
            +
                                                   @client_credential_secret)
         | 
| 271 | 
            +
                  )
         | 
| 268 272 | 
             
                end
         | 
| 269 273 |  | 
| 270 | 
            -
                it  | 
| 271 | 
            -
                  @server.client_credential =  | 
| 274 | 
            +
                it "should return nil if the Proc does not provide a usable response" do
         | 
| 275 | 
            +
                  @server.client_credential = ->(_x) { nil }
         | 
| 272 276 | 
             
                  expect(@server.find_client_credential(@client_credential_key)).to be_nil
         | 
| 273 277 | 
             
                end
         | 
| 274 278 | 
             
              end
         | 
| 275 279 |  | 
| 276 280 |  | 
| 277 | 
            -
              describe  | 
| 278 | 
            -
                it  | 
| 281 | 
            +
              describe "calling find_token_credential" do
         | 
| 282 | 
            +
                it "should return a Signet credential if the Proc provides one" do
         | 
| 279 283 | 
             
                  @server.token_credential =
         | 
| 280 284 | 
             
                    lambda do |x|
         | 
| 281 285 | 
             
                      x.nil? ? nil : Signet::OAuth1::Credential.new(@token_credential_key,
         | 
| @@ -283,557 +287,553 @@ describe Signet::OAuth1::Server, 'configured' do | |
| 283 287 | 
             
                    end
         | 
| 284 288 | 
             
                  expect(@server.find_token_credential(@token_credential_key)).to eq(
         | 
| 285 289 | 
             
                    Signet::OAuth1::Credential.new(@token_credential_key,
         | 
| 286 | 
            -
                                                   @token_credential_secret) | 
| 290 | 
            +
                                                   @token_credential_secret)
         | 
| 291 | 
            +
                  )
         | 
| 287 292 | 
             
                end
         | 
| 288 293 |  | 
| 289 | 
            -
                it  | 
| 294 | 
            +
                it "should return a Signet credential if the Proc provides a key/secret pair" do
         | 
| 290 295 | 
             
                  @server.token_credential =
         | 
| 291 | 
            -
                    lambda do | | 
| 292 | 
            -
                      {: | 
| 296 | 
            +
                    lambda do |_x|
         | 
| 297 | 
            +
                      { key: @token_credential_key, secret: @token_credential_secret }
         | 
| 293 298 | 
             
                    end
         | 
| 294 299 | 
             
                  expect(@server.find_token_credential(@token_credential_key)).to eq(
         | 
| 295 300 | 
             
                    Signet::OAuth1::Credential.new(@token_credential_key,
         | 
| 296 | 
            -
                                                   @token_credential_secret) | 
| 301 | 
            +
                                                   @token_credential_secret)
         | 
| 302 | 
            +
                  )
         | 
| 297 303 | 
             
                end
         | 
| 298 304 |  | 
| 299 | 
            -
                it  | 
| 300 | 
            -
                    | 
| 305 | 
            +
                it "should return a Signet credential if the Proc provides " \
         | 
| 306 | 
            +
                   "a key/secret Enumerable" do
         | 
| 301 307 | 
             
                  @server.token_credential =
         | 
| 302 | 
            -
                    lambda do | | 
| 308 | 
            +
                    lambda do |_x|
         | 
| 303 309 | 
             
                      [@token_credential_key, @token_credential_secret]
         | 
| 304 310 | 
             
                    end
         | 
| 305 311 | 
             
                  expect(@server.find_token_credential(@token_credential_key)).to eq(
         | 
| 306 312 | 
             
                    Signet::OAuth1::Credential.new(@token_credential_key,
         | 
| 307 | 
            -
                                                   @token_credential_secret) | 
| 313 | 
            +
                                                   @token_credential_secret)
         | 
| 314 | 
            +
                  )
         | 
| 308 315 | 
             
                end
         | 
| 309 316 |  | 
| 310 | 
            -
                it  | 
| 311 | 
            -
                  @server.token_credential =  | 
| 317 | 
            +
                it "should return nil if the Proc does not provide a usable response" do
         | 
| 318 | 
            +
                  @server.token_credential = ->(_x) { nil }
         | 
| 312 319 | 
             
                  expect(@server.find_token_credential(@token_credential_key)).to be_nil
         | 
| 313 320 | 
             
                end
         | 
| 314 321 | 
             
              end
         | 
| 315 322 |  | 
| 316 323 |  | 
| 317 | 
            -
              describe  | 
| 318 | 
            -
                it  | 
| 319 | 
            -
                  @server.verifier =  | 
| 324 | 
            +
              describe "calling find_verifier" do
         | 
| 325 | 
            +
                it "should return false if server verifier returns false" do
         | 
| 326 | 
            +
                  @server.verifier = ->(_x) { false }
         | 
| 320 327 | 
             
                  expect(@server.find_verifier(@verifier)).to eq false
         | 
| 321 328 | 
             
                end
         | 
| 322 | 
            -
                it  | 
| 323 | 
            -
                  @server.verifier =  | 
| 329 | 
            +
                it "should return false if server verifier returns nil" do
         | 
| 330 | 
            +
                  @server.verifier = ->(_x) { nil }
         | 
| 324 331 | 
             
                  expect(@server.find_verifier(@verifier)).to eq false
         | 
| 325 332 | 
             
                end
         | 
| 326 | 
            -
                it  | 
| 327 | 
            -
                  @server.verifier =  | 
| 333 | 
            +
                it "should return true if server verifier returns a random object" do
         | 
| 334 | 
            +
                  @server.verifier = ->(x) { x.succ }
         | 
| 328 335 | 
             
                  expect(@server.find_verifier(@verifier)).to eq true
         | 
| 329 336 | 
             
                end
         | 
| 330 337 | 
             
              end
         | 
| 331 338 |  | 
| 332 | 
            -
              describe  | 
| 333 | 
            -
                it  | 
| 334 | 
            -
                  @server.nonce_timestamp =  | 
| 335 | 
            -
                  expect(@server.validate_nonce_timestamp( | 
| 339 | 
            +
              describe "calling validate_nonce_timestamp" do
         | 
| 340 | 
            +
                it "should return false if nonce_timestamp Proc returns false" do
         | 
| 341 | 
            +
                  @server.nonce_timestamp = ->(_n, _t) { false }
         | 
| 342 | 
            +
                  expect(@server.validate_nonce_timestamp("nonce", "timestamp")).to be false
         | 
| 336 343 | 
             
                end
         | 
| 337 | 
            -
                it  | 
| 338 | 
            -
                  @server.nonce_timestamp =  | 
| 339 | 
            -
                  expect(@server.validate_nonce_timestamp( | 
| 344 | 
            +
                it "should return false if nonce_timestamp Proc returns nil" do
         | 
| 345 | 
            +
                  @server.nonce_timestamp = ->(_n, _t) { nil }
         | 
| 346 | 
            +
                  expect(@server.validate_nonce_timestamp("nonce", "timestamp")).to be false
         | 
| 340 347 | 
             
                end
         | 
| 341 | 
            -
                it  | 
| 342 | 
            -
                  @server.nonce_timestamp =  | 
| 343 | 
            -
                  expect(@server.validate_nonce_timestamp( | 
| 348 | 
            +
                it "should return true if nonce_timestamp Proc returns a random object" do
         | 
| 349 | 
            +
                  @server.nonce_timestamp = ->(n, t) { n + t.to_s }
         | 
| 350 | 
            +
                  expect(@server.validate_nonce_timestamp("nonce", "timestamp")).to be true
         | 
| 344 351 | 
             
                end
         | 
| 345 352 | 
             
              end
         | 
| 346 353 |  | 
| 347 354 |  | 
| 348 | 
            -
              describe  | 
| 355 | 
            +
              describe "expecting a request for a temporary credential" do
         | 
| 349 356 | 
             
                before do
         | 
| 350 357 | 
             
                  @client = Signet::OAuth1::Client.new(
         | 
| 351 | 
            -
             | 
| 352 | 
            -
             | 
| 353 | 
            -
             | 
| 354 | 
            -
             | 
| 358 | 
            +
                    client_credential_key:    @client_credential_key,
         | 
| 359 | 
            +
                    client_credential_secret: @client_credential_secret,
         | 
| 360 | 
            +
                    temporary_credential_uri: "http://photos.example.net/initiate"
         | 
| 361 | 
            +
                  )
         | 
| 355 362 | 
             
                end
         | 
| 356 363 |  | 
| 357 | 
            -
                it  | 
| 364 | 
            +
                it "should raise an error if the client credential Proc is not set" do
         | 
| 358 365 | 
             
                  @server.client_credential = nil
         | 
| 359 366 | 
             
                  expect(lambda do
         | 
| 360 367 | 
             
                    @server.authenticate_temporary_credential_request(
         | 
| 361 | 
            -
                      : | 
| 368 | 
            +
                      request: make_temporary_credential_request(@client)
         | 
| 362 369 | 
             
                    )
         | 
| 363 370 | 
             
                  end).to raise_error(ArgumentError)
         | 
| 364 371 | 
             
                end
         | 
| 365 | 
            -
                it  | 
| 366 | 
            -
                  bad_request = make_temporary_credential_request | 
| 367 | 
            -
                  bad_request.headers[ | 
| 372 | 
            +
                it "should reject an malformed request" do
         | 
| 373 | 
            +
                  bad_request = make_temporary_credential_request @client, nil, "https://photos.example.net/photos"
         | 
| 374 | 
            +
                  bad_request.headers["Authorization"].gsub!(/(OAuth)(.+)/, (Regexp.last_match 1).to_s)
         | 
| 368 375 | 
             
                  expect(lambda do
         | 
| 369 376 | 
             
                    @server.authenticate_temporary_credential_request(
         | 
| 370 | 
            -
                      : | 
| 377 | 
            +
                      request: bad_request
         | 
| 371 378 | 
             
                    )
         | 
| 372 379 | 
             
                  end).to raise_error(Signet::MalformedAuthorizationError)
         | 
| 373 380 | 
             
                end
         | 
| 374 381 |  | 
| 375 | 
            -
                it  | 
| 376 | 
            -
                  nonce_callback = double | 
| 377 | 
            -
                  expect(nonce_callback).to receive(:call).once.with( | 
| 378 | 
            -
             | 
| 379 | 
            -
             | 
| 382 | 
            +
                it "should call a user-supplied Proc to validate a nonce/timestamp pair" do
         | 
| 383 | 
            +
                  nonce_callback = double "nonce"
         | 
| 384 | 
            +
                  expect(nonce_callback).to receive(:call).once.with(
         | 
| 385 | 
            +
                    an_instance_of(String), an_instance_of(String)
         | 
| 386 | 
            +
                  ).and_return(true)
         | 
| 380 387 |  | 
| 381 388 | 
             
                  @server.nonce_timestamp = nonce_callback
         | 
| 382 389 | 
             
                  @server.authenticate_temporary_credential_request(
         | 
| 383 | 
            -
             | 
| 390 | 
            +
                    request: make_temporary_credential_request(@client)
         | 
| 384 391 | 
             
                  )
         | 
| 385 392 | 
             
                end
         | 
| 386 393 |  | 
| 387 394 | 
             
                it "should return 'oob' for a valid request without an oauth_callback" do
         | 
| 388 | 
            -
                  bad_request = make_temporary_credential_request | 
| 395 | 
            +
                  bad_request = make_temporary_credential_request @client
         | 
| 389 396 | 
             
                  expect(@server.authenticate_temporary_credential_request(
         | 
| 390 | 
            -
             | 
| 391 | 
            -
             | 
| 397 | 
            +
                           request: bad_request
         | 
| 398 | 
            +
                         )).to eq "oob"
         | 
| 392 399 | 
             
                end
         | 
| 393 | 
            -
                it  | 
| 394 | 
            -
                    | 
| 395 | 
            -
                  callback =  | 
| 400 | 
            +
                it "should return the oauth_callback for a valid request " \
         | 
| 401 | 
            +
                   "with an oauth_callback" do
         | 
| 402 | 
            +
                  callback = "http://printer.example.com/ready"
         | 
| 396 403 | 
             
                  expect(@server.authenticate_temporary_credential_request(
         | 
| 397 | 
            -
             | 
| 398 | 
            -
             | 
| 404 | 
            +
                           request: make_temporary_credential_request(@client, callback)
         | 
| 405 | 
            +
                         )).to eq callback
         | 
| 399 406 | 
             
                end
         | 
| 400 | 
            -
                it  | 
| 401 | 
            -
                  bad_request = make_temporary_credential_request | 
| 407 | 
            +
                it "should return false for an unauthenticated request" do
         | 
| 408 | 
            +
                  bad_request = make_temporary_credential_request @client
         | 
| 402 409 | 
             
                  bad_request.headers["Authorization"].gsub!(/oauth_signature=\".+\"/,
         | 
| 403 | 
            -
             | 
| 410 | 
            +
                                                             "oauth_signature=\"foobar\"")
         | 
| 404 411 | 
             
                  expect(@server.authenticate_temporary_credential_request(
         | 
| 405 | 
            -
             | 
| 406 | 
            -
             | 
| 412 | 
            +
                           request: bad_request
         | 
| 413 | 
            +
                         )).to eq false
         | 
| 407 414 | 
             
                end
         | 
| 408 | 
            -
                it  | 
| 409 | 
            -
                  req = make_temporary_credential_request | 
| 415 | 
            +
                it "should return nil from #request_realm if no realm is provided" do
         | 
| 416 | 
            +
                  req = make_temporary_credential_request @client
         | 
| 410 417 | 
             
                  expect(@server.request_realm(
         | 
| 411 | 
            -
             | 
| 412 | 
            -
             | 
| 418 | 
            +
                           request: req
         | 
| 419 | 
            +
                         )).to eq nil
         | 
| 413 420 | 
             
                end
         | 
| 414 421 |  | 
| 415 | 
            -
                describe  | 
| 416 | 
            -
                  it  | 
| 417 | 
            -
                    req = make_temporary_credential_request | 
| 422 | 
            +
                describe "with a Realm provided" do
         | 
| 423 | 
            +
                  it "should return the realm from #request_realm" do
         | 
| 424 | 
            +
                    req = make_temporary_credential_request @client, nil, nil, "Photos"
         | 
| 418 425 | 
             
                    expect(@server.request_realm(
         | 
| 419 | 
            -
             | 
| 420 | 
            -
             | 
| 426 | 
            +
                             request: req
         | 
| 427 | 
            +
                           )).to eq "Photos"
         | 
| 421 428 | 
             
                  end
         | 
| 422 429 | 
             
                  it 'should return "oob" with a valid request without an oauth_callback' do
         | 
| 423 | 
            -
                    req = make_temporary_credential_request | 
| 430 | 
            +
                    req = make_temporary_credential_request @client, nil, nil, "Photos"
         | 
| 424 431 | 
             
                    expect(@server.authenticate_temporary_credential_request(
         | 
| 425 | 
            -
             | 
| 426 | 
            -
             | 
| 432 | 
            +
                             request: req
         | 
| 433 | 
            +
                           )).to eq "oob"
         | 
| 427 434 | 
             
                  end
         | 
| 428 435 | 
             
                end
         | 
| 429 | 
            -
             | 
| 430 436 | 
             
              end
         | 
| 431 437 |  | 
| 432 438 |  | 
| 433 | 
            -
              describe  | 
| 439 | 
            +
              describe "expecting a request for a token credential" do
         | 
| 434 440 | 
             
                before do
         | 
| 435 441 | 
             
                  @client = Signet::OAuth1::Client.new(
         | 
| 436 | 
            -
             | 
| 437 | 
            -
             | 
| 438 | 
            -
             | 
| 439 | 
            -
             | 
| 440 | 
            -
             | 
| 441 | 
            -
             | 
| 442 | 
            -
                  @return_hash = {: | 
| 443 | 
            -
             | 
| 444 | 
            -
             | 
| 445 | 
            -
             | 
| 446 | 
            -
             | 
| 447 | 
            -
             | 
| 448 | 
            -
             | 
| 449 | 
            -
                  bad_request  | 
| 450 | 
            -
                  bad_request.headers["Authorization"].gsub!(/(OAuth)(.+)/, "#{$1}")
         | 
| 442 | 
            +
                    client_credential_key:       @client_credential_key,
         | 
| 443 | 
            +
                    client_credential_secret:    @client_credential_secret,
         | 
| 444 | 
            +
                    temporary_credential_key:    @temporary_credential_key,
         | 
| 445 | 
            +
                    temporary_credential_secret: @temporary_credential_secret,
         | 
| 446 | 
            +
                    token_credential_uri:        "http://photos.example.net/token"
         | 
| 447 | 
            +
                  )
         | 
| 448 | 
            +
                  @return_hash = { client_credential:    Signet::OAuth1::Credential.new(@client_credential_key, @client_credential_secret),
         | 
| 449 | 
            +
                                   temporary_credential: Signet::OAuth1::Credential.new(@temporary_credential_key, @temporary_credential_secret),
         | 
| 450 | 
            +
                                   realm:                nil }
         | 
| 451 | 
            +
                end
         | 
| 452 | 
            +
             | 
| 453 | 
            +
                it "should reject an malformed request" do
         | 
| 454 | 
            +
                  bad_request = make_token_credential_request @client
         | 
| 455 | 
            +
                  bad_request.headers["Authorization"].gsub!(/(OAuth)(.+)/, (Regexp.last_match 1).to_s)
         | 
| 451 456 |  | 
| 452 457 | 
             
                  expect(lambda do
         | 
| 453 458 | 
             
                    @server.authenticate_token_credential_request(
         | 
| 454 | 
            -
                      : | 
| 459 | 
            +
                      request: bad_request
         | 
| 455 460 | 
             
                    )
         | 
| 456 461 | 
             
                  end).to raise_error(Signet::MalformedAuthorizationError)
         | 
| 457 462 | 
             
                end
         | 
| 458 | 
            -
                it  | 
| 459 | 
            -
                  nonce_callback = double | 
| 463 | 
            +
                it "should call a user-supplied Proc to validate a nonce/timestamp pair" do
         | 
| 464 | 
            +
                  nonce_callback = double "nonce"
         | 
| 460 465 | 
             
                  expect(nonce_callback).to receive(:call).once.with(
         | 
| 461 466 | 
             
                    an_instance_of(String), an_instance_of(String)
         | 
| 462 467 | 
             
                  ).and_return(true)
         | 
| 463 468 | 
             
                  @server.nonce_timestamp = nonce_callback
         | 
| 464 469 | 
             
                  @server.authenticate_token_credential_request(
         | 
| 465 | 
            -
                    : | 
| 470 | 
            +
                    request: make_token_credential_request(@client)
         | 
| 466 471 | 
             
                  )
         | 
| 467 472 | 
             
                end
         | 
| 468 | 
            -
                it  | 
| 473 | 
            +
                it "should return an informational hash for a valid request" do
         | 
| 469 474 | 
             
                  expect(@server.authenticate_token_credential_request(
         | 
| 470 | 
            -
             | 
| 471 | 
            -
             | 
| 475 | 
            +
                           request: make_token_credential_request(@client)
         | 
| 476 | 
            +
                         )).to eq @return_hash
         | 
| 472 477 | 
             
                end
         | 
| 473 | 
            -
                it  | 
| 474 | 
            -
                  bad_request = make_token_credential_request | 
| 478 | 
            +
                it "should return nil for an unauthenticated request" do
         | 
| 479 | 
            +
                  bad_request = make_token_credential_request @client
         | 
| 475 480 | 
             
                  bad_request.headers["Authorization"].gsub!(/oauth_signature=\".+\"/,
         | 
| 476 | 
            -
             | 
| 481 | 
            +
                                                             "oauth_signature=\"foobar\"")
         | 
| 477 482 | 
             
                  expect(@server.authenticate_token_credential_request(
         | 
| 478 | 
            -
             | 
| 479 | 
            -
             | 
| 483 | 
            +
                           request: bad_request
         | 
| 484 | 
            +
                         )).to eq nil
         | 
| 480 485 | 
             
                end
         | 
| 481 | 
            -
                it  | 
| 486 | 
            +
                it "should call a user-supplied Proc to fetch the client credential" do
         | 
| 482 487 | 
             
                  client_cred = Signet::OAuth1::Credential.new(@client_credential_key,
         | 
| 483 | 
            -
                                                               @client_credential_secret | 
| 484 | 
            -
                  key_callback = double | 
| 488 | 
            +
                                                               @client_credential_secret)
         | 
| 489 | 
            +
                  key_callback = double "client_cred"
         | 
| 485 490 | 
             
                  expect(key_callback).to receive(:call).at_least(:once).with(
         | 
| 486 491 | 
             
                    @client_credential_key
         | 
| 487 492 | 
             
                  ).and_return(client_cred)
         | 
| 488 493 |  | 
| 489 494 | 
             
                  @server.client_credential = key_callback
         | 
| 490 495 | 
             
                  @server.authenticate_token_credential_request(
         | 
| 491 | 
            -
                    : | 
| 496 | 
            +
                    request: make_token_credential_request(@client)
         | 
| 492 497 | 
             
                  )
         | 
| 493 498 | 
             
                end
         | 
| 494 499 |  | 
| 495 | 
            -
                it  | 
| 500 | 
            +
                it "should call a user-supplied Proc to fetch the temporary token credential" do
         | 
| 496 501 | 
             
                  temp_cred = Signet::OAuth1::Credential.new(@temporary_credential_key,
         | 
| 497 502 | 
             
                                                             @temporary_credential_secret)
         | 
| 498 | 
            -
                  temp_callback = double | 
| 503 | 
            +
                  temp_callback = double "temp_cred"
         | 
| 499 504 | 
             
                  expect(temp_callback).to receive(:call).at_least(:once).with(
         | 
| 500 505 | 
             
                    @temporary_credential_key
         | 
| 501 506 | 
             
                  ).and_return(temp_cred)
         | 
| 502 507 |  | 
| 503 508 | 
             
                  @server.temporary_credential = temp_callback
         | 
| 504 509 | 
             
                  @server.authenticate_token_credential_request(
         | 
| 505 | 
            -
                    : | 
| 510 | 
            +
                    request: make_token_credential_request(@client)
         | 
| 506 511 | 
             
                  )
         | 
| 507 512 | 
             
                end
         | 
| 508 | 
            -
                it  | 
| 509 | 
            -
                  req = make_token_credential_request | 
| 513 | 
            +
                it "should return nil from #request_realm if no realm is provided" do
         | 
| 514 | 
            +
                  req = make_token_credential_request @client
         | 
| 510 515 | 
             
                  expect(@server.request_realm(
         | 
| 511 | 
            -
             | 
| 512 | 
            -
             | 
| 516 | 
            +
                           request: req
         | 
| 517 | 
            +
                         )).to eq nil
         | 
| 513 518 | 
             
                end
         | 
| 514 519 |  | 
| 515 | 
            -
                describe  | 
| 520 | 
            +
                describe "with a Realm provided" do
         | 
| 516 521 | 
             
                  before do
         | 
| 517 | 
            -
                    @realm =  | 
| 522 | 
            +
                    @realm = "Photos"
         | 
| 518 523 | 
             
                    @return_hash[:realm] = @realm
         | 
| 519 524 | 
             
                  end
         | 
| 520 | 
            -
                  it  | 
| 521 | 
            -
                    req = make_token_credential_request | 
| 525 | 
            +
                  it "should return the realm from #request_realm" do
         | 
| 526 | 
            +
                    req = make_token_credential_request @client, nil, @realm
         | 
| 522 527 | 
             
                    expect(@server.request_realm(
         | 
| 523 | 
            -
             | 
| 524 | 
            -
             | 
| 528 | 
            +
                             request: req
         | 
| 529 | 
            +
                           )).to eq @realm
         | 
| 525 530 | 
             
                  end
         | 
| 526 | 
            -
                  it  | 
| 527 | 
            -
                    req = make_token_credential_request | 
| 531 | 
            +
                  it "should an informational hash with a valid request" do
         | 
| 532 | 
            +
                    req = make_token_credential_request @client, nil, @realm
         | 
| 528 533 | 
             
                    expect(@server.authenticate_token_credential_request(
         | 
| 529 | 
            -
             | 
| 530 | 
            -
             | 
| 534 | 
            +
                             request: req
         | 
| 535 | 
            +
                           )).to eq @return_hash
         | 
| 531 536 | 
             
                  end
         | 
| 532 537 | 
             
                end
         | 
| 533 | 
            -
             | 
| 534 538 | 
             
              end
         | 
| 535 539 |  | 
| 536 540 |  | 
| 537 | 
            -
              describe  | 
| 538 | 
            -
                before | 
| 541 | 
            +
              describe "expecting a request for a protected resource" do
         | 
| 542 | 
            +
                before :each do
         | 
| 539 543 | 
             
                  @client = Signet::OAuth1::Client.new(
         | 
| 540 | 
            -
             | 
| 541 | 
            -
             | 
| 542 | 
            -
             | 
| 543 | 
            -
             | 
| 544 | 
            -
             | 
| 545 | 
            -
                  @return_hash = {: | 
| 546 | 
            -
             | 
| 547 | 
            -
             | 
| 548 | 
            -
             | 
| 549 | 
            -
             | 
| 550 | 
            -
             | 
| 551 | 
            -
                it 'should not raise an error if a request body is chunked(as Array)' do
         | 
| 544 | 
            +
                    client_credential_key:    @client_credential_key,
         | 
| 545 | 
            +
                    client_credential_secret: @client_credential_secret,
         | 
| 546 | 
            +
                    token_credential_key:     @token_credential_key,
         | 
| 547 | 
            +
                    token_credential_secret:  @token_credential_secret
         | 
| 548 | 
            +
                  )
         | 
| 549 | 
            +
                  @return_hash = { client_credential: Signet::OAuth1::Credential.new(@client_credential_key, @client_credential_secret),
         | 
| 550 | 
            +
                                   token_credential:  Signet::OAuth1::Credential.new(@token_credential_key, @token_credential_secret),
         | 
| 551 | 
            +
                                   realm:             nil }
         | 
| 552 | 
            +
                end
         | 
| 553 | 
            +
             | 
| 554 | 
            +
                it "should not raise an error if a request body is chunked(as Array)" do
         | 
| 552 555 | 
             
                  approved = @server.authenticate_resource_request(
         | 
| 553 | 
            -
                    : | 
| 554 | 
            -
                    : | 
| 555 | 
            -
                    : | 
| 556 | 
            -
                    : | 
| 556 | 
            +
                    method:  "POST",
         | 
| 557 | 
            +
                    uri:     "https://photos.example.net/photos",
         | 
| 558 | 
            +
                    body:    ["A chunked body."],
         | 
| 559 | 
            +
                    headers: make_oauth_signature_header
         | 
| 557 560 | 
             
                  )
         | 
| 558 561 | 
             
                  expect(approved).to eq nil
         | 
| 559 562 | 
             
                end
         | 
| 560 563 |  | 
| 561 | 
            -
                it  | 
| 564 | 
            +
                it "should not raise an error if a request body is chunked(as StringIO)" do
         | 
| 562 565 | 
             
                  chunked_body = StringIO.new
         | 
| 563 | 
            -
                  chunked_body.write | 
| 566 | 
            +
                  chunked_body.write "A chunked body."
         | 
| 564 567 | 
             
                  chunked_body.rewind
         | 
| 565 568 | 
             
                  approved = @server.authenticate_resource_request(
         | 
| 566 | 
            -
                    : | 
| 567 | 
            -
                    : | 
| 568 | 
            -
                    : | 
| 569 | 
            -
                    : | 
| 569 | 
            +
                    method:  "POST",
         | 
| 570 | 
            +
                    uri:     "https://photos.example.net/photos",
         | 
| 571 | 
            +
                    body:    chunked_body,
         | 
| 572 | 
            +
                    headers: make_oauth_signature_header
         | 
| 570 573 | 
             
                  )
         | 
| 571 574 | 
             
                  expect(approved).to eq nil
         | 
| 572 575 | 
             
                end
         | 
| 573 576 |  | 
| 574 | 
            -
                it  | 
| 577 | 
            +
                it "should raise an error if a request body is of a bogus type" do
         | 
| 575 578 | 
             
                  expect(lambda do
         | 
| 576 579 | 
             
                    @server.authenticate_resource_request(
         | 
| 577 | 
            -
                      : | 
| 578 | 
            -
                      : | 
| 579 | 
            -
                      : | 
| 580 | 
            -
                      : | 
| 580 | 
            +
                      method:  "POST",
         | 
| 581 | 
            +
                      uri:     "https://photos.example.net/photos",
         | 
| 582 | 
            +
                      body:    42,
         | 
| 583 | 
            +
                      headers: make_oauth_signature_header
         | 
| 581 584 | 
             
                    )
         | 
| 582 585 | 
             
                  end).to raise_error(TypeError)
         | 
| 583 586 | 
             
                end
         | 
| 584 | 
            -
                it  | 
| 587 | 
            +
                it "should use form parameters in signature if request is a POSTed form" do
         | 
| 585 588 | 
             
                  req = make_resource_request(
         | 
| 586 589 | 
             
                    @client,
         | 
| 587 | 
            -
                     | 
| 588 | 
            -
                    : | 
| 589 | 
            -
                    : | 
| 590 | 
            -
                   | 
| 590 | 
            +
                    method:  "POST",
         | 
| 591 | 
            +
                    headers: { "Content-Type"=>"application/x-www-form-urlencoded" },
         | 
| 592 | 
            +
                    body:    "c2&a3=2+q"
         | 
| 593 | 
            +
                  )
         | 
| 594 | 
            +
                  expect(@server.authenticate_resource_request(request: req)).to eq @return_hash
         | 
| 591 595 | 
             
                end
         | 
| 592 | 
            -
                it  | 
| 593 | 
            -
                    | 
| 596 | 
            +
                it "should raise an error if signature is x-www-form-encoded " \
         | 
| 597 | 
            +
                   "but does not send form parameters in header" do
         | 
| 594 598 |  | 
| 595 599 | 
             
                  # Make a full request so that we can sign against the form parameters
         | 
| 596 600 | 
             
                  # that will be removed.
         | 
| 597 601 | 
             
                  req = make_resource_request(
         | 
| 598 602 | 
             
                    @client,
         | 
| 599 | 
            -
                     | 
| 600 | 
            -
                    : | 
| 601 | 
            -
                    : | 
| 603 | 
            +
                    method:  "POST",
         | 
| 604 | 
            +
                    headers: { "Content-Type"=>"application/x-www-form-urlencoded" },
         | 
| 605 | 
            +
                    body:    "c2&a3=2+q"
         | 
| 606 | 
            +
                  )
         | 
| 602 607 |  | 
| 603 | 
            -
                  req.headers["Authorization"].gsub!(/c2=\"\", a3=\"2%20q\", /,  | 
| 608 | 
            +
                  req.headers["Authorization"].gsub!(/c2=\"\", a3=\"2%20q\", /, "")
         | 
| 604 609 |  | 
| 605 610 | 
             
                  expect(lambda do
         | 
| 606 | 
            -
                    @server.authenticate_resource_request | 
| 611 | 
            +
                    @server.authenticate_resource_request request: req
         | 
| 607 612 | 
             
                  end).to raise_error(Signet::MalformedAuthorizationError,
         | 
| 608 | 
            -
             | 
| 609 | 
            -
             | 
| 610 | 
            -
                      )
         | 
| 613 | 
            +
                                      "Request is of type application/x-www-form-urlencoded but " \
         | 
| 614 | 
            +
                                      "Authentication header did not include form values")
         | 
| 611 615 | 
             
                end
         | 
| 612 616 |  | 
| 613 | 
            -
                it  | 
| 614 | 
            -
                  nonce_callback = double | 
| 617 | 
            +
                it "should call a user-supplied Proc to validate a nonce/timestamp pair" do
         | 
| 618 | 
            +
                  nonce_callback = double "nonce"
         | 
| 615 619 | 
             
                  expect(nonce_callback).to receive(:call).once.with(
         | 
| 616 620 | 
             
                    an_instance_of(String), an_instance_of(String)
         | 
| 617 621 | 
             
                  ).and_return(true)
         | 
| 618 622 |  | 
| 619 623 | 
             
                  @server.nonce_timestamp = nonce_callback
         | 
| 620 624 | 
             
                  @server.authenticate_resource_request(
         | 
| 621 | 
            -
                    : | 
| 625 | 
            +
                    request: make_resource_request(@client)
         | 
| 622 626 | 
             
                  )
         | 
| 623 627 | 
             
                end
         | 
| 624 628 |  | 
| 625 | 
            -
                it  | 
| 629 | 
            +
                it "should call a user-supplied Proc to fetch the client credential" do
         | 
| 626 630 | 
             
                  client_cred =  Signet::OAuth1::Credential.new(@client_credential_key,
         | 
| 627 | 
            -
                                                                @client_credential_secret | 
| 628 | 
            -
                  key_callback = double | 
| 631 | 
            +
                                                                @client_credential_secret)
         | 
| 632 | 
            +
                  key_callback = double "client_cred"
         | 
| 629 633 | 
             
                  expect(key_callback).to receive(:call).at_least(:once).with(
         | 
| 630 634 | 
             
                    @client_credential_key
         | 
| 631 635 | 
             
                  ).and_return(client_cred)
         | 
| 632 636 |  | 
| 633 637 | 
             
                  @server.client_credential = key_callback
         | 
| 634 638 | 
             
                  @server.authenticate_resource_request(
         | 
| 635 | 
            -
                    : | 
| 639 | 
            +
                    request: make_resource_request(@client)
         | 
| 636 640 | 
             
                  )
         | 
| 637 641 | 
             
                end
         | 
| 638 642 |  | 
| 639 | 
            -
                it  | 
| 643 | 
            +
                it "should call a user-supplied Proc to fetch the token credential" do
         | 
| 640 644 | 
             
                  token_cred = Signet::OAuth1::Credential.new(@token_credential_key,
         | 
| 641 645 | 
             
                                                              @token_credential_secret)
         | 
| 642 | 
            -
                  key_callback = double | 
| 646 | 
            +
                  key_callback = double "token_cred"
         | 
| 643 647 | 
             
                  expect(key_callback).to receive(:call).at_least(:once).with(
         | 
| 644 648 | 
             
                    @token_credential_key
         | 
| 645 649 | 
             
                  ).and_return(token_cred)
         | 
| 646 650 |  | 
| 647 651 | 
             
                  @server.token_credential = key_callback
         | 
| 648 652 | 
             
                  @server.authenticate_resource_request(
         | 
| 649 | 
            -
                    : | 
| 653 | 
            +
                    request: make_resource_request(@client)
         | 
| 650 654 | 
             
                  )
         | 
| 651 655 | 
             
                end
         | 
| 652 656 |  | 
| 653 | 
            -
                it  | 
| 657 | 
            +
                it "should return a Hash for a valid request" do
         | 
| 654 658 | 
             
                  expect(@server.authenticate_resource_request(
         | 
| 655 | 
            -
             | 
| 656 | 
            -
             | 
| 659 | 
            +
                           request: make_resource_request(@client)
         | 
| 660 | 
            +
                         )).to eq @return_hash
         | 
| 657 661 | 
             
                end
         | 
| 658 | 
            -
                it  | 
| 659 | 
            -
                  bad_request = make_resource_request | 
| 662 | 
            +
                it "should return nil for a unauthenticated request" do
         | 
| 663 | 
            +
                  bad_request = make_resource_request @client
         | 
| 660 664 | 
             
                  bad_request.headers["Authorization"].gsub!(/oauth_signature=\".+\"/,
         | 
| 661 | 
            -
             | 
| 662 | 
            -
                  expect(@server.authenticate_resource_request(: | 
| 665 | 
            +
                                                             "oauth_signature=\"foobar\"")
         | 
| 666 | 
            +
                  expect(@server.authenticate_resource_request(request: bad_request)).to eq nil
         | 
| 663 667 | 
             
                end
         | 
| 664 | 
            -
                it  | 
| 665 | 
            -
                  req = make_resource_request | 
| 668 | 
            +
                it "should return nil from #request_realm if no realm is provided" do
         | 
| 669 | 
            +
                  req = make_resource_request @client
         | 
| 666 670 | 
             
                  expect(@server.request_realm(
         | 
| 667 | 
            -
             | 
| 668 | 
            -
             | 
| 671 | 
            +
                           request: req
         | 
| 672 | 
            +
                         )).to eq nil
         | 
| 669 673 | 
             
                end
         | 
| 670 674 |  | 
| 671 | 
            -
                describe  | 
| 675 | 
            +
                describe "with a Realm provided" do
         | 
| 672 676 | 
             
                  before do
         | 
| 673 | 
            -
                    @realm =  | 
| 677 | 
            +
                    @realm = "Photos"
         | 
| 674 678 | 
             
                    @return_hash[:realm] = @realm
         | 
| 675 679 | 
             
                  end
         | 
| 676 | 
            -
                  it  | 
| 680 | 
            +
                  it "should return the realm from #request_realm" do
         | 
| 677 681 | 
             
                    req = make_resource_request(@client, {}, @realm)
         | 
| 678 682 | 
             
                    expect(@server.request_realm(
         | 
| 679 | 
            -
             | 
| 680 | 
            -
             | 
| 683 | 
            +
                             request: req
         | 
| 684 | 
            +
                           )).to eq @realm
         | 
| 681 685 | 
             
                  end
         | 
| 682 | 
            -
                  it  | 
| 686 | 
            +
                  it "should return a hash containing the realm with a valid request" do
         | 
| 683 687 | 
             
                    req = make_resource_request(@client, {}, @realm)
         | 
| 684 688 | 
             
                    expect(@server.authenticate_resource_request(
         | 
| 685 | 
            -
             | 
| 686 | 
            -
             | 
| 689 | 
            +
                             request: req
         | 
| 690 | 
            +
                           )).to eq @return_hash
         | 
| 687 691 | 
             
                  end
         | 
| 688 692 | 
             
                end
         | 
| 689 | 
            -
             | 
| 690 693 | 
             
              end
         | 
| 691 694 |  | 
| 692 695 |  | 
| 693 696 | 
             
              describe "expecting a two-legged request for a protected resource" do
         | 
| 694 697 | 
             
                before do
         | 
| 695 698 | 
             
                  @client = Signet::OAuth1::Client.new(
         | 
| 696 | 
            -
             | 
| 697 | 
            -
             | 
| 698 | 
            -
             | 
| 699 | 
            +
                    client_credential_key:    @client_credential_key,
         | 
| 700 | 
            +
                    client_credential_secret: @client_credential_secret,
         | 
| 701 | 
            +
                    two_legged:               true
         | 
| 702 | 
            +
                  )
         | 
| 699 703 |  | 
| 700 | 
            -
                  @return_hash = {: | 
| 701 | 
            -
             | 
| 702 | 
            -
             | 
| 703 | 
            -
                  }
         | 
| 704 | 
            +
                  @return_hash = { client_credential: Signet::OAuth1::Credential.new(@client_credential_key, @client_credential_secret),
         | 
| 705 | 
            +
                                   token_credential:  nil,
         | 
| 706 | 
            +
                                   realm:             nil }
         | 
| 704 707 | 
             
                end
         | 
| 705 | 
            -
                it  | 
| 708 | 
            +
                it "should not raise an error if a request body is chunked(as Array)" do
         | 
| 706 709 | 
             
                  approved = @server.authenticate_resource_request(
         | 
| 707 | 
            -
                    : | 
| 708 | 
            -
                    : | 
| 709 | 
            -
                    : | 
| 710 | 
            -
                    : | 
| 711 | 
            -
                    : | 
| 710 | 
            +
                    method:     "POST",
         | 
| 711 | 
            +
                    uri:        "https://photos.example.net/photos",
         | 
| 712 | 
            +
                    body:       ["A chunked body."],
         | 
| 713 | 
            +
                    headers:    make_oauth_signature_header,
         | 
| 714 | 
            +
                    two_legged: true
         | 
| 712 715 | 
             
                  )
         | 
| 713 716 | 
             
                  expect(approved).to eq nil
         | 
| 714 717 | 
             
                end
         | 
| 715 718 |  | 
| 716 | 
            -
                it  | 
| 719 | 
            +
                it "should not raise an error if a request body is chunked(as StringIO)" do
         | 
| 717 720 | 
             
                  chunked_body = StringIO.new
         | 
| 718 | 
            -
                  chunked_body.write | 
| 721 | 
            +
                  chunked_body.write "A chunked body."
         | 
| 719 722 | 
             
                  chunked_body.rewind
         | 
| 720 723 | 
             
                  approved = @server.authenticate_resource_request(
         | 
| 721 | 
            -
                    : | 
| 722 | 
            -
                    : | 
| 723 | 
            -
                    : | 
| 724 | 
            -
                    : | 
| 725 | 
            -
                    : | 
| 724 | 
            +
                    method:     "POST",
         | 
| 725 | 
            +
                    uri:        "https://photos.example.net/photos",
         | 
| 726 | 
            +
                    body:       chunked_body,
         | 
| 727 | 
            +
                    headers:    make_oauth_signature_header,
         | 
| 728 | 
            +
                    two_legged: true
         | 
| 726 729 | 
             
                  )
         | 
| 727 730 | 
             
                  expect(approved).to eq nil
         | 
| 728 731 | 
             
                end
         | 
| 729 732 |  | 
| 730 | 
            -
                it  | 
| 733 | 
            +
                it "should raise an error if a request body is of a bogus type" do
         | 
| 731 734 | 
             
                  expect(lambda do
         | 
| 732 735 | 
             
                    @server.authenticate_resource_request(
         | 
| 733 | 
            -
                      : | 
| 734 | 
            -
                      : | 
| 735 | 
            -
                      : | 
| 736 | 
            -
                      : | 
| 737 | 
            -
                      : | 
| 736 | 
            +
                      method:     "POST",
         | 
| 737 | 
            +
                      uri:        "https://photos.example.net/photos",
         | 
| 738 | 
            +
                      body:       42,
         | 
| 739 | 
            +
                      headers:    make_oauth_signature_header,
         | 
| 740 | 
            +
                      two_legged: true
         | 
| 738 741 | 
             
                    )
         | 
| 739 742 | 
             
                  end).to raise_error(TypeError)
         | 
| 740 743 | 
             
                end
         | 
| 741 | 
            -
                it  | 
| 744 | 
            +
                it "should use form parameters in signature if request is a POSTed form" do
         | 
| 742 745 | 
             
                  req = make_resource_request(
         | 
| 743 746 | 
             
                    @client,
         | 
| 744 | 
            -
                     | 
| 745 | 
            -
                    : | 
| 746 | 
            -
                    : | 
| 747 | 
            +
                    method:  "POST",
         | 
| 748 | 
            +
                    headers: { "Content-Type"=>"application/x-www-form-urlencoded" },
         | 
| 749 | 
            +
                    body:    "c2&a3=2+q"
         | 
| 747 750 | 
             
                  )
         | 
| 748 751 | 
             
                  expect(@server.authenticate_resource_request(
         | 
| 749 | 
            -
             | 
| 750 | 
            -
             | 
| 752 | 
            +
                           request: req, two_legged: true
         | 
| 753 | 
            +
                         )).to eq @return_hash
         | 
| 751 754 | 
             
                end
         | 
| 752 | 
            -
                it  | 
| 753 | 
            -
                    | 
| 755 | 
            +
                it "should raise an error if signature is x-www-form-encoded " \
         | 
| 756 | 
            +
                   "but does not send form parameters in header" do
         | 
| 754 757 |  | 
| 755 758 | 
             
                  # Make a full request so that we can sign against the form parameters
         | 
| 756 759 | 
             
                  # that will be removed.
         | 
| 757 760 | 
             
                  req = make_resource_request(
         | 
| 758 761 | 
             
                    @client,
         | 
| 759 | 
            -
                     | 
| 760 | 
            -
                    : | 
| 761 | 
            -
                    : | 
| 762 | 
            +
                    method:  "POST",
         | 
| 763 | 
            +
                    headers: { "Content-Type"=>"application/x-www-form-urlencoded" },
         | 
| 764 | 
            +
                    body:    "c2&a3=2+q"
         | 
| 762 765 | 
             
                  )
         | 
| 763 766 |  | 
| 764 | 
            -
                  req.headers["Authorization"].gsub!(/c2=\"\", a3=\"2%20q\", /,  | 
| 767 | 
            +
                  req.headers["Authorization"].gsub!(/c2=\"\", a3=\"2%20q\", /, "")
         | 
| 765 768 |  | 
| 766 769 | 
             
                  expect(lambda do
         | 
| 767 | 
            -
                    @server.authenticate_resource_request | 
| 770 | 
            +
                    @server.authenticate_resource_request request: req, two_legged: true
         | 
| 768 771 | 
             
                  end).to raise_error(Signet::MalformedAuthorizationError,
         | 
| 769 | 
            -
             | 
| 770 | 
            -
             | 
| 771 | 
            -
                      )
         | 
| 772 | 
            +
                                      "Request is of type application/x-www-form-urlencoded but " \
         | 
| 773 | 
            +
                                      "Authentication header did not include form values")
         | 
| 772 774 | 
             
                end
         | 
| 773 775 |  | 
| 774 | 
            -
                it  | 
| 775 | 
            -
                  nonce_callback = double | 
| 776 | 
            +
                it "should call a user-supplied Proc to validate a nonce/timestamp pair" do
         | 
| 777 | 
            +
                  nonce_callback = double "nonce"
         | 
| 776 778 | 
             
                  expect(nonce_callback).to receive(:call).once.with(
         | 
| 777 779 | 
             
                    an_instance_of(String), an_instance_of(String)
         | 
| 778 780 | 
             
                  ).and_return(true)
         | 
| 779 781 |  | 
| 780 782 | 
             
                  @server.nonce_timestamp = nonce_callback
         | 
| 781 783 | 
             
                  @server.authenticate_resource_request(
         | 
| 782 | 
            -
                    : | 
| 784 | 
            +
                    request: make_resource_request(@client), two_legged: true
         | 
| 783 785 | 
             
                  )
         | 
| 784 786 | 
             
                end
         | 
| 785 787 |  | 
| 786 | 
            -
                it  | 
| 788 | 
            +
                it "should call a user-supplied Proc to fetch the client credential" do
         | 
| 787 789 | 
             
                  client_cred = Signet::OAuth1::Credential.new(@client_credential_key,
         | 
| 788 | 
            -
                                                               @client_credential_secret | 
| 789 | 
            -
                  key_callback = double | 
| 790 | 
            +
                                                               @client_credential_secret)
         | 
| 791 | 
            +
                  key_callback = double "client_cred"
         | 
| 790 792 | 
             
                  expect(key_callback).to receive(:call).at_least(:once).with(
         | 
| 791 793 | 
             
                    @client_credential_key
         | 
| 792 794 | 
             
                  ).and_return(client_cred)
         | 
| 793 795 |  | 
| 794 796 | 
             
                  @server.client_credential = key_callback
         | 
| 795 797 | 
             
                  @server.authenticate_resource_request(
         | 
| 796 | 
            -
                    : | 
| 798 | 
            +
                    request: make_resource_request(@client), two_legged: true
         | 
| 797 799 | 
             
                  )
         | 
| 798 800 | 
             
                end
         | 
| 799 801 |  | 
| 800 | 
            -
                it  | 
| 802 | 
            +
                it "should return a informational hash for a valid request" do
         | 
| 801 803 | 
             
                  expect(@server.authenticate_resource_request(
         | 
| 802 | 
            -
             | 
| 803 | 
            -
             | 
| 804 | 
            +
                           request: make_resource_request(@client), two_legged: true
         | 
| 805 | 
            +
                         )).to eq @return_hash
         | 
| 804 806 | 
             
                end
         | 
| 805 | 
            -
                it  | 
| 806 | 
            -
                  bad_request = make_resource_request | 
| 807 | 
            +
                it "should return false for a unauthenticated request" do
         | 
| 808 | 
            +
                  bad_request = make_resource_request @client
         | 
| 807 809 | 
             
                  bad_request.headers["Authorization"].gsub!(/oauth_signature=\".+\"/,
         | 
| 808 | 
            -
             | 
| 809 | 
            -
                  expect(@server.authenticate_resource_request(: | 
| 810 | 
            +
                                                             "oauth_signature=\"foobar\"")
         | 
| 811 | 
            +
                  expect(@server.authenticate_resource_request(request: bad_request)).to eq nil
         | 
| 810 812 | 
             
                end
         | 
| 811 | 
            -
                it  | 
| 812 | 
            -
                  req = make_resource_request | 
| 813 | 
            +
                it "should return nil from #request_realm if no realm is provided" do
         | 
| 814 | 
            +
                  req = make_resource_request @client
         | 
| 813 815 | 
             
                  expect(@server.request_realm(
         | 
| 814 | 
            -
             | 
| 815 | 
            -
             | 
| 816 | 
            +
                           request: req
         | 
| 817 | 
            +
                         )).to eq nil
         | 
| 816 818 | 
             
                end
         | 
| 817 | 
            -
                describe  | 
| 819 | 
            +
                describe "with a Realm provided" do
         | 
| 818 820 | 
             
                  before do
         | 
| 819 | 
            -
                    @realm =  | 
| 821 | 
            +
                    @realm = "Photos"
         | 
| 820 822 | 
             
                    @return_hash[:realm] = @realm
         | 
| 821 823 | 
             
                  end
         | 
| 822 | 
            -
                  it  | 
| 824 | 
            +
                  it "should return the realm from #request_realm" do
         | 
| 823 825 | 
             
                    req = make_resource_request(@client, {}, @realm)
         | 
| 824 826 | 
             
                    expect(@server.request_realm(
         | 
| 825 | 
            -
             | 
| 826 | 
            -
             | 
| 827 | 
            +
                             request: req, two_legged: true
         | 
| 828 | 
            +
                           )).to eq @realm
         | 
| 827 829 | 
             
                  end
         | 
| 828 830 |  | 
| 829 | 
            -
                  it  | 
| 831 | 
            +
                  it "should return a hash containing the realm with a valid request" do
         | 
| 830 832 | 
             
                    req = make_resource_request(@client, {}, @realm)
         | 
| 831 833 | 
             
                    expect(@server.authenticate_resource_request(
         | 
| 832 | 
            -
             | 
| 833 | 
            -
             | 
| 834 | 
            +
                             request: req, two_legged: true
         | 
| 835 | 
            +
                           )).to eq @return_hash
         | 
| 834 836 | 
             
                  end
         | 
| 835 837 | 
             
                end
         | 
| 836 | 
            -
             | 
| 837 838 | 
             
              end
         | 
| 838 | 
            -
             | 
| 839 839 | 
             
            end
         |