Sha256: ddcff071ef30e104851717b94157150f36bc4c62dd500d83f0c68d839b936aef

Contents?: true

Size: 1.09 KB

Versions: 21

Compression:

Stored size: 1.09 KB

Contents

require 'rest-core/test'

describe RC::AuthBasic do
  before do
    @auth = RC::AuthBasic.new(RC::Dry.new, nil, nil)
  end

  env = {RC::REQUEST_HEADERS => {}}

  would 'do nothing' do
    @auth.call({}){ |res| res.should.eq({}) }
  end

  would 'send Authorization header' do
    @auth.instance_eval{@username = 'Aladdin'}
    @auth.instance_eval{@password = 'open sesame'}

    @auth.call(env){ |res|
      res.should.eq(RC::REQUEST_HEADERS =>
        {'Authorization' => 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=='})
    }

    acc = {'Accept' => 'text/plain'}
    env = {RC::REQUEST_HEADERS => acc}

    @auth.call(env){ |res|
      res.should.eq({RC::REQUEST_HEADERS =>
        {'Authorization' => 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=='}.merge(acc)})
    }
  end

  would 'leave a log if username are not both provided' do
    @auth.instance_eval{@username = 'Aladdin'}
    @auth.call(env){ |res| res[RC::LOG].size.should.eq 1 }
  end

  would 'leave a log if password are not both provided' do
    @auth.instance_eval{@password = 'open sesame'}
    @auth.call(env){ |res| res[RC::LOG].size.should.eq 1 }
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
rest-core-4.0.1 test/test_auth_basic.rb
rest-core-4.0.0 test/test_auth_basic.rb
rest-core-3.6.0 test/test_auth_basic.rb
rest-core-3.5.92 test/test_auth_basic.rb
rest-core-3.5.91 test/test_auth_basic.rb
rest-core-3.5.9 test/test_auth_basic.rb
rest-core-3.5.8 test/test_auth_basic.rb
rest-core-3.5.7 test/test_auth_basic.rb
rest-core-3.5.6 test/test_auth_basic.rb
rest-core-3.5.5 test/test_auth_basic.rb
rest-core-3.5.4 test/test_auth_basic.rb
rest-core-3.5.3 test/test_auth_basic.rb
rest-core-3.5.2 test/test_auth_basic.rb
rest-core-3.5.1 test/test_auth_basic.rb
rest-core-3.5.0 test/test_auth_basic.rb
rest-core-3.4.1 test/test_auth_basic.rb
rest-core-3.4.0 test/test_auth_basic.rb
rest-core-3.3.3 test/test_auth_basic.rb
rest-core-3.3.2 test/test_auth_basic.rb
rest-core-3.3.1 test/test_auth_basic.rb