Sha256: 7ab03060c993140276f879577ae1e4e1204632418201b1e75e2ac0bd3ba48ec8

Contents?: true

Size: 1.84 KB

Versions: 6

Compression:

Stored size: 1.84 KB

Contents

require 'spec_helper'


describe "Integration" do
  subject { Shutl::Auth }

  def set_auth
    Shutl::Auth.config do |c|
      c.url           =  "http://localhost:3000"
      c.client_id     =  "QUOTE_SERVICE_CLIENT_ID"
      c.client_secret =  "QUOTE_SERVICE_CLIENT_SECRET"
    end
  end

  before do
    set_auth
  end

  context 'successful request to authentication service' do
    let(:token) { 's_CagcDP8PdsGb1B0iyLvNtanSxqZeQDQtGiIYtctKzyLzxAymhe-zGJwUrjxKQpO9EUdizDT3tqLt-iFeHapg' }

    specify do
      VCR.use_cassette 'get_token' do
        Shutl::Auth.access_token!.should == token
      end
    end

    specify "with invalid auth service url" do
      Shutl::Auth.url = ''

      expect {Shutl::Auth.access_token!}.to raise_error Shutl::Auth::InvalidUrl

      Shutl::Auth.url = 'http://'
      expect {Shutl::Auth.access_token!}.to raise_error Shutl::Auth::InvalidUrl

      Shutl::Auth.url = 'http://localhost:3000'

      VCR.use_cassette 'get_token' do
        Shutl::Auth.access_token!.should == token
      end
    end

    specify "with 500 from auth server" do
      set_auth

      stub_request(:post, /.*#{Shutl::Auth.url}.*/).to_return(
        { body: '',
           status: 500,
           headers: {"CONTENT_TYPE" => 'application/json'}}
        )

      Airbrake.should_receive(:notify)

      expect{ Shutl::Auth.access_token!}.to raise_error Shutl::Auth::InternalServerError
    end

    specify "with invalid credentials" do
      set_auth
      Shutl::Auth.client_id = 'egg'

      VCR.use_cassette 'invalid_credentials' do
        expect { Shutl::Auth.access_token!}.to raise_error Shutl::Auth::InvalidCredentials
      end

      set_auth
      Shutl::Auth.client_id = 'egg'

      VCR.use_cassette 'invalid_credentials' do
        expect { Shutl::Auth.access_token!}.to raise_error Shutl::Auth::InvalidCredentials
      end

    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
shutl_auth-0.8.5 spec/integration/integration_spec.rb
shutl_auth-0.8.4 spec/integration/integration_spec.rb
shutl_auth-0.8.3 spec/integration/integration_spec.rb
shutl_auth-0.8.2 spec/integration/integration_spec.rb
shutl_auth-0.8.1 spec/integration/integration_spec.rb
shutl_auth-0.8.0 spec/integration/integration_spec.rb