/
auth1_test.rb
65 lines (46 loc) · 1.6 KB
/
auth1_test.rb
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#
# Testing rufus-verbs
#
# jmettraux@gmail.com
#
# Sun Jan 13 12:33:03 JST 2008
#
require File.dirname(__FILE__) + '/base.rb'
class Auth1Test < Test::Unit::TestCase
include TestBaseMixin
include Rufus::Verbs
#
# Using an items server with the authentication on.
#
def setup
@server = ItemServer.new :auth => :digest
@server.start
end
def test_0
#res = get :uri => "http://localhost:7777/items"
#assert_equal 200, res.code.to_i
#assert_equal "{}", res.body.strip
#res = expect 401, nil, get(:uri => "http://localhost:7777/items")
#p res['www-authenticate']
#$DEBUG = true
ep = EndPoint.new :digest_authentication => [ "test", "pass" ]
expect 200, {}, ep.get("http://localhost:7777/items")
assert_equal 2, $dcount
expect 200, {}, ep.get("http://localhost:7777/items")
assert_equal 3, $dcount
expect 201, nil, ep.post("http://localhost:7777/items/1") { "hammer" }
assert_equal 4, $dcount
expect 200, { 1 => "hammer" }, ep.get("http://localhost:7777/items")
assert_equal 5, $dcount
expect 401, nil, get(:uri => "http://localhost:7777/items")
assert_equal 6, $dcount
expect 401, nil, get(
:uri => "http://localhost:7777/items",
:http_basic_authentication => [ "toto", "toto" ])
assert_equal 7, $dcount
expect 200, { 1 => "hammer" }, get(
:uri => "http://localhost:7777/items",
:digest_authentication => [ "test", "pass" ])
assert_equal 9, $dcount
end
end