xenon 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- metadata +13 -145
- data/.codeclimate.yml +0 -18
- data/.gitignore +0 -25
- data/.rspec +0 -3
- data/.travis.yml +0 -6
- data/Gemfile +0 -13
- data/Guardfile +0 -16
- data/LICENSE +0 -22
- data/README.md +0 -86
- data/Rakefile +0 -8
- data/examples/hello_world/config.ru +0 -3
- data/examples/hello_world/hello_world.rb +0 -17
- data/lib/xenon.rb +0 -253
- data/lib/xenon/auth.rb +0 -63
- data/lib/xenon/errors.rb +0 -5
- data/lib/xenon/etag.rb +0 -48
- data/lib/xenon/headers.rb +0 -112
- data/lib/xenon/headers/accept.rb +0 -34
- data/lib/xenon/headers/accept_charset.rb +0 -59
- data/lib/xenon/headers/accept_encoding.rb +0 -63
- data/lib/xenon/headers/accept_language.rb +0 -59
- data/lib/xenon/headers/authorization.rb +0 -50
- data/lib/xenon/headers/cache_control.rb +0 -56
- data/lib/xenon/headers/content_type.rb +0 -23
- data/lib/xenon/headers/if_match.rb +0 -53
- data/lib/xenon/headers/if_modified_since.rb +0 -22
- data/lib/xenon/headers/if_none_match.rb +0 -53
- data/lib/xenon/headers/if_range.rb +0 -45
- data/lib/xenon/headers/if_unmodified_since.rb +0 -22
- data/lib/xenon/headers/user_agent.rb +0 -65
- data/lib/xenon/headers/www_authenticate.rb +0 -70
- data/lib/xenon/media_type.rb +0 -162
- data/lib/xenon/parsers/basic_rules.rb +0 -86
- data/lib/xenon/parsers/header_rules.rb +0 -60
- data/lib/xenon/parsers/media_type.rb +0 -53
- data/lib/xenon/quoted_string.rb +0 -20
- data/lib/xenon/routing/directives.rb +0 -14
- data/lib/xenon/routing/header_directives.rb +0 -32
- data/lib/xenon/routing/method_directives.rb +0 -26
- data/lib/xenon/routing/param_directives.rb +0 -22
- data/lib/xenon/routing/path_directives.rb +0 -37
- data/lib/xenon/routing/route_directives.rb +0 -51
- data/lib/xenon/routing/security_directives.rb +0 -20
- data/lib/xenon/version.rb +0 -3
- data/spec/spec_helper.rb +0 -94
- data/spec/xenon/etag_spec.rb +0 -19
- data/spec/xenon/headers/accept_charset_spec.rb +0 -31
- data/spec/xenon/headers/accept_encoding_spec.rb +0 -40
- data/spec/xenon/headers/accept_language_spec.rb +0 -33
- data/spec/xenon/headers/accept_spec.rb +0 -54
- data/spec/xenon/headers/authorization_spec.rb +0 -47
- data/spec/xenon/headers/cache_control_spec.rb +0 -64
- data/spec/xenon/headers/if_match_spec.rb +0 -73
- data/spec/xenon/headers/if_modified_since_spec.rb +0 -19
- data/spec/xenon/headers/if_none_match_spec.rb +0 -79
- data/spec/xenon/headers/if_range_spec.rb +0 -45
- data/spec/xenon/headers/if_unmodified_since_spec.rb +0 -19
- data/spec/xenon/headers/user_agent_spec.rb +0 -67
- data/spec/xenon/headers/www_authenticate_spec.rb +0 -43
- data/spec/xenon/media_type_spec.rb +0 -267
- data/xenon.gemspec +0 -30
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'xenon/routing/route_directives'
|
2
|
-
|
3
|
-
module Xenon
|
4
|
-
module Routing
|
5
|
-
module ParamDirectives
|
6
|
-
include RouteDirectives
|
7
|
-
|
8
|
-
def param_hash
|
9
|
-
extract_request do |request|
|
10
|
-
yield request.param_hash
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def params(*names)
|
15
|
-
param_hash do |hash|
|
16
|
-
yield *hash.slice(*names).values
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'xenon/routing/route_directives'
|
2
|
-
|
3
|
-
module Xenon
|
4
|
-
module Routing
|
5
|
-
module PathDirectives
|
6
|
-
include RouteDirectives
|
7
|
-
|
8
|
-
def path_prefix(pattern)
|
9
|
-
extract_request do |request|
|
10
|
-
match = request.unmatched_path.match(pattern)
|
11
|
-
if match && match.pre_match == ''
|
12
|
-
map_request unmatched_path: match.post_match do
|
13
|
-
yield *match.captures
|
14
|
-
end
|
15
|
-
else
|
16
|
-
reject nil # path rejections are nil to allow more specific rejections to be seen
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def path_end
|
22
|
-
path_prefix(/\Z/) do
|
23
|
-
yield
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def path(pattern)
|
28
|
-
path_prefix(pattern) do |*captures|
|
29
|
-
path_end do
|
30
|
-
yield *captures
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
require 'rack/utils'
|
2
|
-
|
3
|
-
module Xenon
|
4
|
-
module Routing
|
5
|
-
module RouteDirectives
|
6
|
-
|
7
|
-
def map_request(map)
|
8
|
-
context.branch do
|
9
|
-
context.request = map.respond_to?(:call) ? map.call(context.request) : context.request.copy(map)
|
10
|
-
yield
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def map_response(map)
|
15
|
-
context.branch do
|
16
|
-
context.response = map.respond_to?(:call) ? map.call(context.response) : context.response.copy(map)
|
17
|
-
yield
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def complete(status, body)
|
22
|
-
map_response complete: true, status: Rack::Utils.status_code(status), body: body do
|
23
|
-
throw :complete
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def reject(rejection, info = {})
|
28
|
-
return if rejection.nil?
|
29
|
-
rejection = Rejection.new(rejection, info) unless rejection.is_a?(Rejection)
|
30
|
-
context.rejections << rejection
|
31
|
-
end
|
32
|
-
|
33
|
-
def fail(status, developer_message = nil)
|
34
|
-
body = {
|
35
|
-
status: status,
|
36
|
-
developer_message: developer_message || Rack::Utils::HTTP_STATUS_CODES[status]
|
37
|
-
}
|
38
|
-
complete status, body
|
39
|
-
end
|
40
|
-
|
41
|
-
def extract(lambda)
|
42
|
-
yield lambda.call(context)
|
43
|
-
end
|
44
|
-
|
45
|
-
def extract_request(lambda = nil)
|
46
|
-
yield lambda ? lambda.call(context.request) : context.request
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'xenon/routing/route_directives'
|
2
|
-
|
3
|
-
module Xenon
|
4
|
-
module Routing
|
5
|
-
module SecurityDirectives
|
6
|
-
include RouteDirectives
|
7
|
-
|
8
|
-
def authenticate(authenticator)
|
9
|
-
extract_request(authenticator) do |user|
|
10
|
-
if user
|
11
|
-
yield user
|
12
|
-
else
|
13
|
-
reject :unauthorized, { scheme: authenticator.scheme }.merge(authenticator.auth_params)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
data/lib/xenon/version.rb
DELETED
data/spec/spec_helper.rb
DELETED
@@ -1,94 +0,0 @@
|
|
1
|
-
require "codeclimate-test-reporter"
|
2
|
-
CodeClimate::TestReporter.start
|
3
|
-
|
4
|
-
# This file was generated by the `rspec --init` command. Conventionally, all
|
5
|
-
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
6
|
-
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
7
|
-
# this file to always be loaded, without a need to explicitly require it in any
|
8
|
-
# files.
|
9
|
-
#
|
10
|
-
# Given that it is always loaded, you are encouraged to keep this file as
|
11
|
-
# light-weight as possible. Requiring heavyweight dependencies from this file
|
12
|
-
# will add to the boot time of your test suite on EVERY test run, even for an
|
13
|
-
# individual file that may not need all of that loaded. Instead, consider making
|
14
|
-
# a separate helper file that requires the additional dependencies and performs
|
15
|
-
# the additional setup, and require it from the spec files that actually need
|
16
|
-
# it.
|
17
|
-
#
|
18
|
-
# The `.rspec` file also contains a few flags that are not defaults but that
|
19
|
-
# users commonly want.
|
20
|
-
#
|
21
|
-
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
22
|
-
RSpec.configure do |config|
|
23
|
-
# rspec-expectations config goes here. You can use an alternate
|
24
|
-
# assertion/expectation library such as wrong or the stdlib/minitest
|
25
|
-
# assertions if you prefer.
|
26
|
-
config.expect_with :rspec do |expectations|
|
27
|
-
# This option will default to `true` in RSpec 4. It makes the `description`
|
28
|
-
# and `failure_message` of custom matchers include text for helper methods
|
29
|
-
# defined using `chain`, e.g.:
|
30
|
-
# be_bigger_than(2).and_smaller_than(4).description
|
31
|
-
# # => "be bigger than 2 and smaller than 4"
|
32
|
-
# ...rather than:
|
33
|
-
# # => "be bigger than 2"
|
34
|
-
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
35
|
-
end
|
36
|
-
|
37
|
-
# rspec-mocks config goes here. You can use an alternate test double
|
38
|
-
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
39
|
-
config.mock_with :rspec do |mocks|
|
40
|
-
# Prevents you from mocking or stubbing a method that does not exist on
|
41
|
-
# a real object. This is generally recommended, and will default to
|
42
|
-
# `true` in RSpec 4.
|
43
|
-
mocks.verify_partial_doubles = true
|
44
|
-
end
|
45
|
-
|
46
|
-
# The settings below are suggested to provide a good initial experience
|
47
|
-
# with RSpec, but feel free to customize to your heart's content.
|
48
|
-
=begin
|
49
|
-
# These two settings work together to allow you to limit a spec run
|
50
|
-
# to individual examples or groups you care about by tagging them with
|
51
|
-
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
52
|
-
# get run.
|
53
|
-
config.filter_run :focus
|
54
|
-
config.run_all_when_everything_filtered = true
|
55
|
-
|
56
|
-
# Limits the available syntax to the non-monkey patched syntax that is
|
57
|
-
# recommended. For more details, see:
|
58
|
-
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
59
|
-
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
60
|
-
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
61
|
-
config.disable_monkey_patching!
|
62
|
-
|
63
|
-
# This setting enables warnings. It's recommended, but in some cases may
|
64
|
-
# be too noisy due to issues in dependencies.
|
65
|
-
config.warnings = true
|
66
|
-
|
67
|
-
# Many RSpec users commonly either run the entire suite or an individual
|
68
|
-
# file, and it's useful to allow more verbose output when running an
|
69
|
-
# individual spec file.
|
70
|
-
if config.files_to_run.one?
|
71
|
-
# Use the documentation formatter for detailed output,
|
72
|
-
# unless a formatter has already been configured
|
73
|
-
# (e.g. via a command-line flag).
|
74
|
-
config.default_formatter = 'doc'
|
75
|
-
end
|
76
|
-
|
77
|
-
# Print the 10 slowest examples and example groups at the
|
78
|
-
# end of the spec run, to help surface which specs are running
|
79
|
-
# particularly slow.
|
80
|
-
config.profile_examples = 10
|
81
|
-
|
82
|
-
# Run specs in random order to surface order dependencies. If you find an
|
83
|
-
# order dependency and want to debug it, you can fix the order by providing
|
84
|
-
# the seed, which is printed after each run.
|
85
|
-
# --seed 1234
|
86
|
-
config.order = :random
|
87
|
-
|
88
|
-
# Seed global randomization in this process using the `--seed` CLI option.
|
89
|
-
# Setting this allows you to use `--seed` to deterministically reproduce
|
90
|
-
# test failures related to randomization by passing the same `--seed` value
|
91
|
-
# as the one that triggered the failure.
|
92
|
-
Kernel.srand config.seed
|
93
|
-
=end
|
94
|
-
end
|
data/spec/xenon/etag_spec.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'xenon/etag'
|
2
|
-
|
3
|
-
describe Xenon::ETag do
|
4
|
-
|
5
|
-
describe '::parse' do
|
6
|
-
it 'can parse a strong etag' do
|
7
|
-
etag = Xenon::ETag.parse('"xyzzy"')
|
8
|
-
expect(etag.opaque_tag).to eq 'xyzzy'
|
9
|
-
expect(etag).to be_strong
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'can parse a weak etag' do
|
13
|
-
etag = Xenon::ETag.parse('W/"xyzzy"')
|
14
|
-
expect(etag.opaque_tag).to eq 'xyzzy'
|
15
|
-
expect(etag).to be_weak
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'xenon/headers/accept_charset'
|
2
|
-
|
3
|
-
describe Xenon::Headers::AcceptCharset do
|
4
|
-
|
5
|
-
context '::parse' do
|
6
|
-
it 'can parse a basic charset range' do
|
7
|
-
header = Xenon::Headers::AcceptCharset.parse('unicode-1-1;q=0.8')
|
8
|
-
expect(header.charset_ranges.size).to eq(1)
|
9
|
-
expect(header.charset_ranges[0].to_s).to eq('unicode-1-1; q=0.8')
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'can parse the example from RFC 7231 § 5.3.3 with the right precedence' do
|
13
|
-
header = Xenon::Headers::AcceptCharset.parse('iso-8859-5, unicode-1-1;q=0.8')
|
14
|
-
expect(header.charset_ranges.size).to eq(2)
|
15
|
-
expect(header.charset_ranges[0].to_s).to eq('iso-8859-5')
|
16
|
-
expect(header.charset_ranges[1].to_s).to eq('unicode-1-1; q=0.8')
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
context '#merge' do
|
21
|
-
it 'can merge two headers with the right precedence' do
|
22
|
-
h1 = Xenon::Headers::AcceptCharset.parse('unicode-1-1;q=0.8')
|
23
|
-
h2 = Xenon::Headers::AcceptCharset.parse('iso-8859-5')
|
24
|
-
header = h1.merge(h2)
|
25
|
-
expect(header.charset_ranges.size).to eq(2)
|
26
|
-
expect(header.charset_ranges[0].to_s).to eq('iso-8859-5')
|
27
|
-
expect(header.charset_ranges[1].to_s).to eq('unicode-1-1; q=0.8')
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'xenon/headers/accept_encoding'
|
2
|
-
|
3
|
-
describe Xenon::Headers::AcceptEncoding do
|
4
|
-
|
5
|
-
context '::parse' do
|
6
|
-
%w(identity compress x-compress deflate gzip x-gzip *).each do |cc|
|
7
|
-
it "can parse the #{cc} content coding" do
|
8
|
-
header = Xenon::Headers::AcceptEncoding.parse(cc)
|
9
|
-
expect(header.coding_ranges.size).to eq(1)
|
10
|
-
expect(header.coding_ranges[0].to_s).to eq(cc)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'can parse the fifth example from RFC 7231 § 5.3.4 with the right precedence' do
|
15
|
-
header = Xenon::Headers::AcceptEncoding.parse('gzip;q=1.0, identity; q=0.5, *;q=0')
|
16
|
-
expect(header.coding_ranges.size).to eq(3)
|
17
|
-
expect(header.coding_ranges[0].to_s).to eq('gzip')
|
18
|
-
expect(header.coding_ranges[1].to_s).to eq('identity; q=0.5')
|
19
|
-
expect(header.coding_ranges[2].to_s).to eq('*; q=0.0')
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'parses an empty header as containing no codings' do
|
23
|
-
header = Xenon::Headers::AcceptEncoding.parse('')
|
24
|
-
expect(header.coding_ranges.size).to eq(0)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
context '#merge' do
|
29
|
-
it 'can merge two headers with the right precedence' do
|
30
|
-
h1 = Xenon::Headers::AcceptEncoding.parse('identity; q=0.5')
|
31
|
-
h2 = Xenon::Headers::AcceptEncoding.parse('gzip;q=1.0, *;q=0')
|
32
|
-
header = h1.merge(h2)
|
33
|
-
expect(header.coding_ranges.size).to eq(3)
|
34
|
-
expect(header.coding_ranges[0].to_s).to eq('gzip')
|
35
|
-
expect(header.coding_ranges[1].to_s).to eq('identity; q=0.5')
|
36
|
-
expect(header.coding_ranges[2].to_s).to eq('*; q=0.0')
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'xenon/headers/accept_language'
|
2
|
-
|
3
|
-
describe Xenon::Headers::AcceptLanguage do
|
4
|
-
|
5
|
-
context '::parse' do
|
6
|
-
it 'can parse a basic language range' do
|
7
|
-
header = Xenon::Headers::AcceptLanguage.parse('en-gb;q=0.8')
|
8
|
-
expect(header.language_ranges.size).to eq(1)
|
9
|
-
expect(header.language_ranges[0].to_s).to eq('en-gb; q=0.8')
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'can parse the example from RFC 7231 § 5.3.5 with the right precedence' do
|
13
|
-
header = Xenon::Headers::AcceptLanguage.parse('da, en-gb;q=0.8, en;q=0.7')
|
14
|
-
expect(header.language_ranges.size).to eq(3)
|
15
|
-
expect(header.language_ranges[0].to_s).to eq('da')
|
16
|
-
expect(header.language_ranges[1].to_s).to eq('en-gb; q=0.8')
|
17
|
-
expect(header.language_ranges[2].to_s).to eq('en; q=0.7')
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
context '#merge' do
|
22
|
-
it 'can merge two headers with the right precedence' do
|
23
|
-
h1 = Xenon::Headers::AcceptLanguage.parse('da, en;q=0.7')
|
24
|
-
h2 = Xenon::Headers::AcceptLanguage.parse('en-gb;q=0.8')
|
25
|
-
header = h1.merge(h2)
|
26
|
-
expect(header.language_ranges.size).to eq(3)
|
27
|
-
expect(header.language_ranges[0].to_s).to eq('da')
|
28
|
-
expect(header.language_ranges[1].to_s).to eq('en-gb; q=0.8')
|
29
|
-
expect(header.language_ranges[2].to_s).to eq('en; q=0.7')
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
require 'xenon/headers/accept'
|
2
|
-
|
3
|
-
describe Xenon::Headers::Accept do
|
4
|
-
|
5
|
-
context '::parse' do
|
6
|
-
it 'can parse a basic accept range' do
|
7
|
-
header = Xenon::Headers::Accept.parse('text/plain; q=0.5')
|
8
|
-
expect(header.media_ranges.size).to eq(1)
|
9
|
-
expect(header.media_ranges[0].to_s).to eq('text/plain; q=0.5')
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'can parse the first example from RFC 7231 § 5.3.2 with the right precedence' do
|
13
|
-
header = Xenon::Headers::Accept.parse('text/plain; q=0.5, text/html, text/x-dvi; q=0.8, text/x-c')
|
14
|
-
expect(header.media_ranges.size).to eq(4)
|
15
|
-
expect(header.media_ranges[0].to_s).to eq('text/html')
|
16
|
-
expect(header.media_ranges[1].to_s).to eq('text/x-c')
|
17
|
-
expect(header.media_ranges[2].to_s).to eq('text/x-dvi; q=0.8')
|
18
|
-
expect(header.media_ranges[3].to_s).to eq('text/plain; q=0.5')
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'can parse the second example from RFC 7231 § 5.3.2 with the right precedence' do
|
22
|
-
header = Xenon::Headers::Accept.parse('text/*, text/plain, text/plain;format=flowed, */*')
|
23
|
-
expect(header.media_ranges.size).to eq(4)
|
24
|
-
expect(header.media_ranges[0].to_s).to eq('text/plain; format=flowed')
|
25
|
-
expect(header.media_ranges[1].to_s).to eq('text/plain')
|
26
|
-
expect(header.media_ranges[2].to_s).to eq('text/*')
|
27
|
-
expect(header.media_ranges[3].to_s).to eq('*/*')
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'can parse the third example from RFC 7231 § 5.3.2 with the right precedence' do
|
31
|
-
header = Xenon::Headers::Accept.parse('text/*;q=0.3, text/html;q=0.7, text/html;level=1, text/html;level=2;q=0.4, */*;q=0.5')
|
32
|
-
expect(header.media_ranges.size).to eq(5)
|
33
|
-
expect(header.media_ranges[0].to_s).to eq('text/html; level=1')
|
34
|
-
expect(header.media_ranges[1].to_s).to eq('text/html; level=2; q=0.4')
|
35
|
-
expect(header.media_ranges[2].to_s).to eq('text/html; q=0.7')
|
36
|
-
expect(header.media_ranges[3].to_s).to eq('text/*; q=0.3')
|
37
|
-
expect(header.media_ranges[4].to_s).to eq('*/*; q=0.5')
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
context '#merge' do
|
42
|
-
it 'can merge two headers with the right precedence' do
|
43
|
-
h1 = Xenon::Headers::Accept.parse('text/plain; q=0.5, text/html')
|
44
|
-
h2 = Xenon::Headers::Accept.parse('text/x-c, text/x-dvi; q=0.8')
|
45
|
-
header = h1.merge(h2)
|
46
|
-
expect(header.media_ranges.size).to eq(4)
|
47
|
-
expect(header.media_ranges[0].to_s).to eq('text/html')
|
48
|
-
expect(header.media_ranges[1].to_s).to eq('text/x-c')
|
49
|
-
expect(header.media_ranges[2].to_s).to eq('text/x-dvi; q=0.8')
|
50
|
-
expect(header.media_ranges[3].to_s).to eq('text/plain; q=0.5')
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'xenon/headers/authorization'
|
2
|
-
|
3
|
-
describe Xenon::Headers::Authorization do
|
4
|
-
|
5
|
-
context '::parse' do
|
6
|
-
it 'can parse Basic credentials' do
|
7
|
-
header = Xenon::Headers::Authorization.parse('Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==')
|
8
|
-
expect(header.credentials.class).to eq(Xenon::BasicCredentials)
|
9
|
-
expect(header.credentials.username).to eq('Aladdin')
|
10
|
-
expect(header.credentials.password).to eq('open sesame')
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'can parse Digest credentials' do
|
14
|
-
header = Xenon::Headers::Authorization.parse('Digest username="Mufasa"' +
|
15
|
-
', realm="testrealm@host.com"' +
|
16
|
-
', nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093"' +
|
17
|
-
', uri="/dir/index.html"' +
|
18
|
-
', qop=auth' +
|
19
|
-
', nc=00000001' +
|
20
|
-
', cnonce="0a4f113b"' +
|
21
|
-
', response="6629fae49393a05397450978507c4ef1"' +
|
22
|
-
', opaque="5ccc069c403ebaf9f0171e9517f40e41"')
|
23
|
-
expect(header.credentials.class).to eq(Xenon::GenericCredentials)
|
24
|
-
expect(header.credentials.scheme).to eq('Digest')
|
25
|
-
expect(header.credentials.token).to eq(nil)
|
26
|
-
expect(header.credentials.params).to eq(
|
27
|
-
'username' => 'Mufasa',
|
28
|
-
'realm' => 'testrealm@host.com',
|
29
|
-
'nonce' => 'dcd98b7102dd2f0e8b11d0f600bfb0c093',
|
30
|
-
'uri' => '/dir/index.html',
|
31
|
-
'qop' => 'auth',
|
32
|
-
'nc' => '00000001',
|
33
|
-
'cnonce' => '0a4f113b',
|
34
|
-
'response' => '6629fae49393a05397450978507c4ef1',
|
35
|
-
'opaque' => '5ccc069c403ebaf9f0171e9517f40e41')
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'can parse Bearer credentials' do
|
39
|
-
header = Xenon::Headers::Authorization.parse('Bearer eyJhbGciOiJub25lIn0.eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFtcGxlLmNvbS9pc19yb290Ijp0cnVlfQ.')
|
40
|
-
expect(header.credentials.class).to eq(Xenon::GenericCredentials)
|
41
|
-
expect(header.credentials.scheme).to eq('Bearer')
|
42
|
-
expect(header.credentials.token).to eq('eyJhbGciOiJub25lIn0.eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFtcGxlLmNvbS9pc19yb290Ijp0cnVlfQ.')
|
43
|
-
expect(header.credentials.params).to eq({})
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|