File: digest_auth_spec.rb

package info (click to toggle)
ruby-em-http-request 1.1.2-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 628 kB
  • ctags: 243
  • sloc: ruby: 3,478; makefile: 2
file content (48 lines) | stat: -rw-r--r-- 1,902 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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