Sha256: 4f3693276019487210adc8e798d467f9ec2b956ca2d0ebc1fc8797a3c2cdd5af

Contents?: true

Size: 1.43 KB

Versions: 34

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

34 entries across 34 versions & 1 rubygems

Version Path
routemaster-drain-3.0.0 spec/routemaster/middleware/authenticate_spec.rb
routemaster-drain-2.5.4 spec/routemaster/middleware/authenticate_spec.rb
routemaster-drain-2.5.3 spec/routemaster/middleware/authenticate_spec.rb
routemaster-drain-2.5.2 spec/routemaster/middleware/authenticate_spec.rb
routemaster-drain-2.5.1 spec/routemaster/middleware/authenticate_spec.rb
routemaster-drain-2.5.0 spec/routemaster/middleware/authenticate_spec.rb
routemaster-drain-2.4.4 spec/routemaster/middleware/authenticate_spec.rb
routemaster-drain-2.4.3 spec/routemaster/middleware/authenticate_spec.rb
routemaster-drain-2.4.2 spec/routemaster/middleware/authenticate_spec.rb
routemaster-drain-2.4.1 spec/routemaster/middleware/authenticate_spec.rb
routemaster-drain-2.4.0 spec/routemaster/middleware/authenticate_spec.rb
routemaster-drain-2.3.0 spec/routemaster/middleware/authenticate_spec.rb
routemaster-drain-2.2.2 spec/routemaster/middleware/authenticate_spec.rb
routemaster-drain-2.0.0 spec/routemaster/middleware/authenticate_spec.rb