Sha256: 04f52187d122b363713b52b0af8a3c2eedfb11959dee8b8ee6808464ec6665b4

Contents?: true

Size: 1.66 KB

Versions: 1

Compression:

Stored size: 1.66 KB

Contents

require 'spec_helper'

describe Grape::Middleware::Auth::DSL do
  subject { Class.new(Grape::API) }

  let(:block) { ->() {} }
  let(:settings) do
    {
      opaque: "secret",
      proc: block,
      realm: "API Authorization",
      type: :http_digest
    }
  end

  describe '.auth' do
    it 'stets auth parameters' do
      expect(subject).to receive(:use).with(Grape::Middleware::Auth::Base, settings)

      subject.auth :http_digest, realm: settings[:realm], opaque: settings[:opaque], &settings[:proc]
      expect(subject.auth).to eq(settings)
    end

    it 'can be called multiple times' do
      expect(subject).to receive(:use).with(Grape::Middleware::Auth::Base, settings)
      expect(subject).to receive(:use).with(Grape::Middleware::Auth::Base, settings.merge(realm: 'super_secret'))

      subject.auth :http_digest, realm: settings[:realm], opaque: settings[:opaque], &settings[:proc]
      first_settings = subject.auth

      subject.auth :http_digest, realm: 'super_secret', opaque: settings[:opaque], &settings[:proc]

      expect(subject.auth).to eq(settings.merge(realm: 'super_secret'))
      expect(subject.auth.object_id).not_to eq(first_settings.object_id)
    end

  end

  describe '.http_basic' do
    it 'stets auth parameters' do
      subject.http_basic realm: 'my_realm', &settings[:proc]
      expect(subject.auth).to eq(realm: 'my_realm', type: :http_basic, proc: block)
    end
  end

  describe '.http_digest' do
    it 'stets auth parameters' do
      subject.http_digest realm: 'my_realm', opaque: 'my_opaque', &settings[:proc]
      expect(subject.auth).to eq(realm: 'my_realm', type: :http_digest, proc: block, opaque: 'my_opaque')
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
grape-0.9.0 spec/grape/middleware/auth/dsl_spec.rb