<commit_before>require File.expand_path('../spec_helper', __FILE__)

describe Signature do
  before :each do
    Time.stub!(:now).and_return(Time.at(1234))

    @token = Signature::Token.new('key', 'secret')

    @request = Signature::Request.new('POST', '/some/path', {
      "query" => "params",
      "go" => "here"
    })
  end

  describe "generating signatures" do
    before :each do
      @signature = @request.sign(@token)[:auth_signature]
    end

    it "should generate base64 encoded signature from correct key" do
      @request.send(:string_to_sign).should == "POST\n/some/path\nauth_key=key&auth_timestamp=1234&auth_version=1.0&go=here&query=params"
      @signature.should == '3b237953a5ba6619875cbb2a2d43e8da9ef5824e8a2c689f6284ac85bc1ea0db'
    end

    it "should make auth_hash available after request is signed" do
      request = Signature::Request.new('POST', '/some/path', {
        "query" => "params"
      })
      lambda {
        request.auth_hash
      }.should raise_error('Request not signed')

      request.sign(@token)
      request.auth_hash.should == {
        :auth_signature => "da078fcedd72941b6c873caa40d0d6b2000ebfc700cee802b128dd20f72e74e9",<commit_msg>Improve clarity of signing specs somewhat<commit_after>require File.expand_path('../spec_helper', __FILE__)

describe Signature do
  before :each do
    Time.stub!(:now).and_return(Time.at(1234))

    @token = Signature::Token.new('key', 'secret')

    @request = Signature::Request.new('POST', '/some/path', {
      "query" => "params",
      "go" => "here"
    })
  end

  describe "generating signatures" do
    before :each do
      @signature = "3b237953a5ba6619875cbb2a2d43e8da9ef5824e8a2c689f6284ac85bc1ea0db"
    end

    it "should generate signature correctly" do
      @request.sign(@token)
      string = @request.send(:string_to_sign)
      string.should == "POST\n/some/path\nauth_key=key&auth_timestamp=1234&auth_version=1.0&go=here&query=params"

      digest = OpenSSL::Digest::SHA256.new
      signature = OpenSSL::HMAC.hexdigest(digest, @token.secret, string)
      signature.should == @signature
    end

    it "should make auth_hash available after request is signed" do
      @request.query_hash = {
        "query" => "params"
      }
      lambda {
        @request.auth_hash
      }.should raise_error('Request not signed')

      @request.sign(@token)
      @request.auth_hash.should == {
        :auth_signature => "da078fcedd72941b6c873caa40d0d6b2000ebfc700cee802b128dd20f72e74e9",
{'fraction_non_alphanumeric': 0.12844036697247707, 'fraction_numerical': 0.06900678101316314, 'mean_word_length': 3.5934065934065935, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '200359', 'n_tokens_mistral': 954, 'n_tokens_neox': 838, 'n_words': 149}