<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'

# not going to test a ton here, since the Faraday middleware mostly just calls to SignableRequest which is 
# rather well-tested 
describe OAuthenticator::FaradaySigner do
  def assert_response(expected_status, expected_body, faraday_response)
    assert_equal expected_status.to_i, faraday_response.status.to_i, "Expected status to be #{expected_status.inspect}" +
      "; got #{faraday_response.status.inspect}. body was: #{faraday_response.body}"
    assert expected_body === faraday_response.body, "Expected match for #{expected_body}; got #{faraday_response.body}"
  end

  it 'succeeds' do
    signing_options = {
      :signature_method => 'PLAINTEXT',
      :consumer_key => consumer_key,
      :consumer_secret => consumer_secret,
      :token => token,
      :token_secret => token_secret,
    }

    connection = Faraday.new(:url => 'http://example.com') do |faraday|
      faraday.request :oauthenticator_signer, signing_options
      faraday.adapter :rack, oapp
    end
    response = connection.get '/'
    assert_response 200, '☺', response
  end

  it 'succeeds with form-encoded with HMAC' do
    signing_options = {
      :signature_method => 'HMAC-SHA1',
      :consumer_key => consumer_key,
      :consumer_secret => consumer_secret,
      :token => token,
      :token_secret => token_secret,
    }

    connection = Faraday.new(:url => 'http://example.com') do |faraday|
      faraday.request :url_encoded
      faraday.request :oauthenticator_signer, signing_options
      faraday.adapter :rack, oapp
    end
    response = connection.put('/', :foo => {:bar => :baz})
    assert_response 200, '☺', response
  end

  it 'is unauthorized' do
    signing_options = {
      :signature_method => 'PLAINTEXT',
      :consumer_key => consumer_key,
      :consumer_secret => 'nope',<commit_msg>test faraday with content-type that includes more than media type<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'

# not going to test a ton here, since the Faraday middleware mostly just calls to SignableRequest which is 
# rather well-tested 
describe OAuthenticator::FaradaySigner do
  def assert_response(expected_status, expected_body, faraday_response)
    assert_equal expected_status.to_i, faraday_response.status.to_i, "Expected status to be #{expected_status.inspect}" +
      "; got #{faraday_response.status.inspect}. body was: #{faraday_response.body}"
    assert expected_body === faraday_response.body, "Expected match for #{expected_body}; got #{faraday_response.body}"
  end

  it 'succeeds' do
    signing_options = {
      :signature_method => 'PLAINTEXT',
      :consumer_key => consumer_key,
      :consumer_secret => consumer_secret,
      :token => token,
      :token_secret => token_secret,
    }

    connection = Faraday.new(:url => 'http://example.com') do |faraday|
      faraday.request :oauthenticator_signer, signing_options
      faraday.adapter :rack, oapp
    end
    response = connection.get '/'
    assert_response 200, '☺', response
  end

  it 'succeeds with form-encoded with HMAC' do
    signing_options = {
      :signature_method => 'HMAC-SHA1',
      :consumer_key => consumer_key,
      :consumer_secret => consumer_secret,
      :token => token,
      :token_secret => token_secret,
    }

    connection = Faraday.new(:url => 'http://example.com') do |faraday|
      faraday.request :url_encoded
      faraday.request :oauthenticator_signer, signing_options
      faraday.adapter :rack, oapp
    end
    response = connection.put('/', :foo => {:bar => :baz})
    assert_response 200, '☺', response
  end

  it 'succeeds with charset' do
    signing_options = {
      :signature_method => 'HMAC-SHA1',
      :consumer_key => consumer_key,
      :consumer_secret => consumer_secret,
      :token => token,
      :token_secret => token_secret,
    }

    connection = Faraday.new(:url => 'http://example.com', :headers => {'Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8'}) do |faraday|
      faraday.request :oauthenticator_signer, signing_options
      faraday.adapter :rack, oapp
    end
    response = connection.post('/', 'a=b')
    assert_response 200, '☺', response
  end

  it 'is unauthorized' do
    signing_options = {
      :signature_method => 'PLAINTEXT',
      :consumer_key => consumer_key,
      :consumer_secret => 'nope',
{'fraction_non_alphanumeric': 0.125, 'fraction_numerical': 0.004541522491349481, 'mean_word_length': 3.6389167502507522, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, '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': '1434721', 'n_tokens_mistral': 1531, 'n_tokens_neox': 1425, 'n_words': 350}