Sha256: a9593baa045967ac63a3873120534a9cf162475c009597d71632cec5d86ab4a4

Contents?: true

Size: 1.43 KB

Versions: 7

Compression:

Stored size: 1.43 KB

Contents

require 'spec_helper'
require 'spec/support/rack_test'
require 'spec/support/events'
require 'routemaster/middleware/authenticate'
require 'json'

describe Routemaster::Middleware::Authenticate do
  let(:app) { described_class.new(ErrorRackApp.new, options) }
  let(:listener) { double 'listener', on_authenticate: nil }
  let(:options) {{ uuid: 'demo' }}
  
  def perform
    post '/whatever'
  end
  
  before { Wisper.subscribe(listener, scope: described_class.name, prefix: true) }
  after { Wisper::GlobalListeners.clear }

  context 'with valid credentials' do
    before { authorize 'demo', 'x' }

    it 'passes' do
      perform
      expect(last_response.status).to eq(501) # 501 from ErrorRackApp
    end

    it 'broadcasts :authenticate :succeeded' do
      expect(listener).to receive(:on_authenticate).with(:succeeded, anything)
      perform
    end
  end

  context 'with invalid credentials' do
    before { authorize 'h4xx0r', 'x' }

    it 'fails' do
      perform
      expect(last_response.status).to eq(403)
    end

    it 'broadcasts :authenticate :failed' do
      expect(listener).to receive(:on_authenticate).with(:failed, anything)
      perform
    end
  end

  context 'without credentials' do
    it 'fails' do
      perform
      expect(last_response.status).to eq(401)
    end

    it 'broadcasts :authenticate :missing' do
      expect(listener).to receive(:on_authenticate).with(:missing, anything)
      perform
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
routemaster-drain-1.1.0 spec/routemaster/middleware/authenticate_spec.rb
routemaster-drain-1.0.5 spec/routemaster/middleware/authenticate_spec.rb
routemaster-drain-1.0.4 spec/routemaster/middleware/authenticate_spec.rb
routemaster-drain-1.0.3 spec/routemaster/middleware/authenticate_spec.rb
routemaster-drain-1.0.2 spec/routemaster/middleware/authenticate_spec.rb
routemaster-drain-1.0.1 spec/routemaster/middleware/authenticate_spec.rb
routemaster-drain-1.0.0 spec/routemaster/middleware/authenticate_spec.rb