Sha256: 2823c1e6f1785d3c875988f98902240e8bf42142951dd0f580a424584487615c

Contents?: true

Size: 1.86 KB

Versions: 10

Compression:

Stored size: 1.86 KB

Contents

require 'helper'

$: << 'lib' << '../lib'

require 'em-http/middleware/digest_auth'

describe 'Digest Auth Authentication header generation' do
  before :each do
    @reference_header = 'Digest username="digest_username", realm="DigestAuth_REALM", algorithm=MD5, uri="/", nonce="MDAxMzQzNzQwNjA2OmRjZjAyZDY3YWMyMWVkZGQ4OWE2Nzg3ZTY3YTNlMjg5", response="96829962ffc31fa2852f86dc7f9f609b", opaque="BzdNK3gsJ2ixTrBJ"'
  end

  it 'should generate the correct header'  do
    www_authenticate = 'Digest realm="DigestAuth_REALM", nonce="MDAxMzQzNzQwNjA2OmRjZjAyZDY3YWMyMWVkZGQ4OWE2Nzg3ZTY3YTNlMjg5", opaque="BzdNK3gsJ2ixTrBJ", stale=false, algorithm=MD5'

    params = {
      username: 'digest_username',
      password: 'digest_password'
    }

    middleware = EM::Middleware::DigestAuth.new(www_authenticate, params)
    middleware.build_auth_digest('GET', '/').should == @reference_header
  end

  it 'should not generate the same header for a different user' do
    www_authenticate = 'Digest realm="DigestAuth_REALM", nonce="MDAxMzQzNzQwNjA2OmRjZjAyZDY3YWMyMWVkZGQ4OWE2Nzg3ZTY3YTNlMjg5", opaque="BzdNK3gsJ2ixTrBJ", stale=false, algorithm=MD5'

    params = {
      username: 'digest_username_2',
      password: 'digest_password'
    }

    middleware = EM::Middleware::DigestAuth.new(www_authenticate, params)
    middleware.build_auth_digest('GET', '/').should_not == @reference_header
  end

  it 'should not generate the same header if the nounce changes' do
    www_authenticate = 'Digest realm="DigestAuth_REALM", nonce="MDAxMzQzNzQwNjA2OmRjZjAyZDY3YWMyMWVkZGQ4OWE2Nzg3ZTY3YTNlMjg6", opaque="BzdNK3gsJ2ixTrBJ", stale=false, algorithm=MD5'

    params = {
      username: 'digest_username_2',
      password: 'digest_password'
    }

    middleware = EM::Middleware::DigestAuth.new(www_authenticate, params)
    middleware.build_auth_digest('GET', '/').should_not == @reference_header
  end

end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
em-http-request-samesite-0.1.1 spec/digest_auth_spec.rb
em-http-request-samesite-1.1.7 spec/digest_auth_spec.rb
em-http-request-1.1.7 spec/digest_auth_spec.rb
em-http-request-1.1.6 spec/digest_auth_spec.rb
em-http-request-1.1.5 spec/digest_auth_spec.rb
em-http-request-1.1.4 spec/digest_auth_spec.rb
em-http-request-1.1.3 spec/digest_auth_spec.rb
em-http-request-1.1.2 spec/digest_auth_spec.rb
em-http-request-1.1.1 spec/digest_auth_spec.rb
em-http-request-1.1.0 spec/digest_auth_spec.rb