File: digest_scenario_test.rb

package info (click to toggle)
ruby-httpauth 0.2.1%2Bgh-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch
  • size: 192 kB
  • ctags: 127
  • sloc: ruby: 925; makefile: 2
file content (29 lines) | stat: -rw-r--r-- 1,175 bytes parent folder | download | duplicates (3)
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
# encoding: utf-8
$LOAD_PATH.unshift File.dirname(__FILE__)
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'

require 'test/unit'
require 'test_helper'
require 'httpauth/digest'

class DigestScenarioTest < Test::Unit::TestCase
  def setup
    remove_tmpdir
    create_tmpdir
  end

  def test_simple
    password = 'secret'

    server_challenge = HTTPAuth::Digest::Challenge.new :realm => 'httpauth@example.com'
    client_challenge = HTTPAuth::Digest::Challenge.from_header server_challenge.to_header
    assert_equal server_challenge.h, client_challenge.h
    client_credentials = HTTPAuth::Digest::Credentials.from_challenge client_challenge,
                                                                      :uri => '/post/12', :username => 'Marcél', :password => password, :method => 'GET'
    server_credentials = HTTPAuth::Digest::Credentials.from_header client_credentials.to_header
    assert server_credentials.validate(
      :password => password, :method => 'GET')
    server_auth_info = HTTPAuth::Digest::AuthenticationInfo.from_credentials server_credentials
    HTTPAuth::Digest::AuthenticationInfo.from_header server_auth_info.to_header
  end
end