<commit_before># encoding: utf-8
proc { |p| $:.unshift(p) unless $:.any? { |lp| File.expand_path(lp) == p } }.call(File.expand_path('.', File.dirname(__FILE__)))
require 'helper'

describe OAuthenticator::SignedRequest do
  %w(timestamp_valid_period consumer_secret access_token_secret nonce_used? use_nonce! access_token_belongs_to_consumer?).each do |method_without_default|
    it "complains when #{method_without_default} is not implemented" do
      exc = assert_raises(NotImplementedError) do
        OAuthenticator::SignedRequest.new({}).public_send(method_without_default)
      end
      assert_match /included in a subclass of OAuthenticator::SignedRequest/, exc.message
    end
    it "uses the method #{method_without_default} when implemented" do
      called = false
      mod = Module.new { define_method(method_without_default) { called = true } }
      OAuthenticator::SignedRequest.including_config(mod).new({}).public_send(method_without_default)
      assert called
    end
  end
  it "complains when a method without a default is not implemented, using middleware" do
    exc = assert_raises(NotImplementedError) do
      OAuthenticator::Middleware.new(proc {}, {:config_methods => Module.new}).call({'HTTP_AUTHORIZATION' => %q(OAuth oauth_timestamp="1")})
    end
    assert_match /passed to OAuthenticator::Middleware using the option :config_methods./, exc.message
  end
  it 'uses timestamp_valid_period if that is implemented but timestamp_valid_past or timestamp_valid_future is not' do
    called = 0
    mod = Module.new { define_method(:timestamp_valid_period) { called +=1 } }
    OAuthenticator::SignedRequest.including_config(mod).new({}).public_send(:timestamp_valid_future)
    OAuthenticator::SignedRequest.including_config(mod).new({}).public_send(:timestamp_valid_past)
    assert_equal 2, called
  end
  it 'uses the default value for allowed signature methods' do
    assert_equal OAuthenticator::SignedRequest::VALID_SIGNATURE_METHODS, OAuthenticator::SignedRequest.new({}).allowed_signature_methods
  end
end<commit_msg>test middleware given no config methods<commit_after># encoding: utf-8
proc { |p| $:.unshift(p) unless $:.any? { |lp| File.expand_path(lp) == p } }.call(File.expand_path('.', File.dirname(__FILE__)))
require 'helper'

describe OAuthenticator::SignedRequest do
  %w(timestamp_valid_period consumer_secret access_token_secret nonce_used? use_nonce! access_token_belongs_to_consumer?).each do |method_without_default|
    it "complains when #{method_without_default} is not implemented" do
      exc = assert_raises(NotImplementedError) do
        OAuthenticator::SignedRequest.new({}).public_send(method_without_default)
      end
      assert_match /included in a subclass of OAuthenticator::SignedRequest/, exc.message
    end
    it "uses the method #{method_without_default} when implemented" do
      called = false
      mod = Module.new { define_method(method_without_default) { called = true } }
      OAuthenticator::SignedRequest.including_config(mod).new({}).public_send(method_without_default)
      assert called
    end
  end
  it "complains when a method without a default is not implemented, using middleware" do
    exc = assert_raises(NotImplementedError) do
      OAuthenticator::Middleware.new(proc {}, {:config_methods => Module.new}).call({'HTTP_AUTHORIZATION' => %q(OAuth oauth_timestamp="1")})
    end
    assert_match /passed to OAuthenticator::Middleware using the option :config_methods./, exc.message
  end
  it "complains middleware is not given config methods" do
    assert_raises(ArgumentError) do
      OAuthenticator::Middleware.new(proc {})
    end
  end
  it 'uses timestamp_valid_period if that is implemented but timestamp_valid_past or timestamp_valid_future is not' do
    called = 0
    mod = Module.new { define_method(:timestamp_valid_period) { called +=1 } }
    OAuthenticator::SignedRequest.including_config(mod).new({}).public_send(:timestamp_valid_future)
    OAuthenticator::SignedRequest.including_config(mod).new({}).public_send(:timestamp_valid_past)
    assert_equal 2, called
  end
  it 'uses the default value for allowed signature methods' do
    assert_equal OAuthenticator::SignedRequest::VALID_SIGNATURE_METHODS, OAuthenticator::SignedRequest.new({}).allowed_signature_methods
  end
end
{'fraction_non_alphanumeric': 0.09872241579558652, 'fraction_numerical': 0.0023228803716608595, 'mean_word_length': 5.276967930029154, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3488027', 'n_tokens_mistral': 1295, 'n_tokens_neox': 1271, 'n_words': 304}