Class: AuthenticationMiddlewareTest
Instance Method Summary
collapse
#capture_warnings, jruby?, rbx?, ssl_mode?, #test_default
#live_server, #live_server=, #live_server?
Instance Method Details
4
5
6
7
8
9
10
11
12
13
|
# File 'test/authentication_middleware_test.rb', line 4
def conn
Faraday::Connection.new('http://example.net/') do |builder|
yield(builder)
builder.adapter :test do |stub|
stub.get('/auth-echo') do |env|
[200, {}, env[:request_headers]['Authorization']]
end
end
end
end
|
#test_authorization_middleware_with_hash ⇒ Object
58
59
60
61
62
63
64
|
# File 'test/authentication_middleware_test.rb', line 58
def test_authorization_middleware_with_hash
response = conn { |b|
b.request :authorization, 'baz', :foo => 42
}.get('/auth-echo')
assert_match(/^baz /, response.body)
assert_match(/foo="42"/, response.body)
end
|
#test_authorization_middleware_with_string ⇒ Object
51
52
53
54
55
56
|
# File 'test/authentication_middleware_test.rb', line 51
def test_authorization_middleware_with_string
response = conn { |b|
b.request :authorization, 'custom', 'abc def'
}.get('/auth-echo')
assert_match(/^custom abc def$/, response.body)
end
|
15
16
17
18
|
# File 'test/authentication_middleware_test.rb', line 15
def
response = conn { |b| b.request :basic_auth, 'aladdin', 'opensesame' }.get('/auth-echo')
assert_equal 'Basic YWxhZGRpbjpvcGVuc2VzYW1l', response.body
end
|
20
21
22
23
|
# File 'test/authentication_middleware_test.rb', line 20
def
response = conn { |b| b.request :basic_auth, 'A' * 255, '' }.get('/auth-echo')
assert_equal "Basic #{'QUFB' * 85}Og==", response.body
end
|
#test_basic_middleware_does_not_interfere_with_existing_authorization ⇒ Object
25
26
27
28
29
|
# File 'test/authentication_middleware_test.rb', line 25
def test_basic_middleware_does_not_interfere_with_existing_authorization
response = conn { |b| b.request :basic_auth, 'aladdin', 'opensesame' }.
get('/auth-echo', nil, :authorization => 'Token token="bar"')
assert_equal 'Token token="bar"', response.body
end
|
31
32
33
34
|
# File 'test/authentication_middleware_test.rb', line 31
def
response = conn { |b| b.request :token_auth, 'quux' }.get('/auth-echo')
assert_equal 'Token token="quux"', response.body
end
|
#test_token_middleware_does_not_interfere_with_existing_authorization ⇒ Object
45
46
47
48
49
|
# File 'test/authentication_middleware_test.rb', line 45
def test_token_middleware_does_not_interfere_with_existing_authorization
response = conn { |b| b.request :token_auth, 'quux' }.
get('/auth-echo', nil, :authorization => 'Token token="bar"')
assert_equal 'Token token="bar"', response.body
end
|
#test_token_middleware_includes_other_values_if_provided ⇒ Object
36
37
38
39
40
41
42
43
|
# File 'test/authentication_middleware_test.rb', line 36
def test_token_middleware_includes_other_values_if_provided
response = conn { |b|
b.request :token_auth, 'baz', :foo => 42
}.get('/auth-echo')
assert_match(/^Token /, response.body)
assert_match(/token="baz"/, response.body)
assert_match(/foo="42"/, response.body)
end
|