Sha256: 26053366b969690c35f0edd7082907c7a5f27133558c364a04bdb6d71e087f87

Contents?: true

Size: 1.38 KB

Versions: 3

Compression:

Stored size: 1.38 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe Enigma do

  Enigma.server_key = "abcd1234abcd1234"
  
  class TestApp < Sinatra::Base
    get '/' do
      signature = request.env["HTTP_" + Enigma::SIGNATURE_HEADER]
      method    = request.request_method.downcase
      path      = request.path
      payload   = request.body.read

      if Enigma.matches?(signature, method, path, payload)
        status 200
      else
        status 403
      end
    end
  end

  def app
    @app ||= TestApp.new
  end

  def client
    @client ||= Enigma::Spec::RackTestClient.new(app)
  end

  describe "with correct authentication" do
    it "should be successful" do
      response = client.execute(
        :method  => :get,
        :path    => "/",
        :headers => {"X_ENIGMA_SIGNATURE" => Enigma.signature('get', '/', '')}
      )

      response.code.should == 200
    end
  end

  describe "with incorrect authentication" do
    it "should be forbidden" do
      response = client.execute(
        :method  => :get,
        :path    => "/",
        :headers => {"X_ENIGMA_SIGNATURE" => "h4x0r"}
      )

      response.code.should == 403
    end
  end

  describe "with empty authorization" do
    it "should be forbidden" do
      response = client.execute(
        :method => :get,
        :path => "/",
        :headers => {})

      response.code.should == 403
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
enigma-0.0.5 spec/enigma_spec.rb
enigma-0.0.4 spec/enigma_spec.rb
enigma-0.0.3 spec/enigma_spec.rb