apill 3.1.3 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/apill/configuration.rb +2 -1
- data/lib/apill/errors/{invalid_api_request_error.rb → invalid_api_request.rb} +1 -1
- data/lib/apill/errors/{invalid_subdomain_error.rb → invalid_subdomain.rb} +1 -1
- data/lib/apill/errors/invalid_token.rb +21 -0
- data/lib/apill/matchers/accept_header.rb +13 -0
- data/lib/apill/matchers/{generic_matcher.rb → generic.rb} +5 -9
- data/lib/apill/matchers/{subdomain_matcher.rb → subdomain.rb} +3 -9
- data/lib/apill/matchers/{version_matcher.rb → version.rb} +4 -6
- data/lib/apill/middleware/api_request.rb +22 -21
- data/lib/apill/parameters/index.rb +1 -1
- data/lib/apill/parameters/page.rb +1 -1
- data/lib/apill/parameters/sort.rb +1 -1
- data/lib/apill/requests/base.rb +86 -10
- data/lib/apill/requests/rack.rb +34 -0
- data/lib/apill/requests/rails.rb +31 -0
- data/lib/apill/resource/model.rb +1 -1
- data/lib/apill/resource/processors/filtering.rb +2 -0
- data/lib/apill/resource/processors/indexing.rb +2 -0
- data/lib/apill/resource/processors/paging.rb +2 -0
- data/lib/apill/resource/processors/sorting.rb +2 -0
- data/lib/apill/responses/{invalid_subdomain_response.rb → invalid_api_request.rb} +3 -3
- data/lib/apill/responses/{invalid_api_request_response.rb → invalid_subdomain.rb} +3 -3
- data/lib/apill/responses/invalid_token.rb +17 -0
- data/lib/apill/tokens/invalid_request_authorization.rb +21 -0
- data/lib/apill/tokens/null_request_authorization.rb +21 -0
- data/lib/apill/tokens/request_authorization.rb +62 -0
- data/lib/apill/version.rb +1 -1
- data/lib/apill.rb +5 -5
- data/spec/apill/accept_header_spec.rb +1 -1
- data/spec/apill/errors/{invalid_api_request_error_spec.rb → invalid_api_request_spec.rb} +6 -6
- data/spec/apill/errors/{invalid_subdomain_error_spec.rb → invalid_subdomain_spec.rb} +6 -6
- data/spec/apill/errors/invalid_token_spec.rb +23 -0
- data/spec/apill/{invalid_subdomain_response_spec.rb → invalid_subdomain_spec.rb} +7 -7
- data/spec/apill/invalid_token_spec.rb +42 -0
- data/spec/apill/matchers/{accept_header_matcher_spec.rb → accept_header_spec.rb} +32 -24
- data/spec/apill/matchers/subdomain_spec.rb +81 -0
- data/spec/apill/matchers/{version_matcher_spec.rb → version_spec.rb} +31 -20
- data/spec/apill/middleware/api_request_spec.rb +36 -38
- data/spec/apill/parameters_spec.rb +1 -1
- data/spec/apill/requests/rack_spec.rb +159 -0
- data/spec/apill/requests/rails_spec.rb +151 -0
- data/spec/apill/resource/model_spec.rb +1 -1
- data/spec/apill/resource/processors/filtering_spec.rb +1 -1
- data/spec/apill/resource/processors/indexing_spec.rb +1 -1
- data/spec/apill/resource/processors/paging_spec.rb +1 -1
- data/spec/apill/resource/processors/sorting_spec.rb +1 -1
- data/spec/apill/tokens/request_authorization_spec.rb +49 -0
- data/spec/fixtures/test_rsa_key +27 -0
- data/spec/fixtures/test_rsa_key.pub +9 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/support/private_keys.rb +19 -0
- metadata +75 -29
- data/lib/apill/matchers/accept_header_matcher.rb +0 -15
- data/lib/apill/requests/rack_request.rb +0 -37
- data/lib/apill/requests/rails_request.rb +0 -29
- data/spec/apill/matchers/subdomain_matcher_spec.rb +0 -72
- data/spec/apill/requests/rack_request_spec.rb +0 -70
- data/spec/apill/requests/rails_request_spec.rb +0 -59
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'apill/configuration'
|
2
|
-
require 'apill/requests/base'
|
3
|
-
require 'apill/accept_header'
|
4
|
-
|
5
|
-
module Apill
|
6
|
-
module Requests
|
7
|
-
class RailsRequest < Base
|
8
|
-
attr_accessor :request
|
9
|
-
|
10
|
-
def initialize(request)
|
11
|
-
self.request = request
|
12
|
-
end
|
13
|
-
|
14
|
-
def accept_header_from_header
|
15
|
-
AcceptHeader.new(application: application_name,
|
16
|
-
header: request.headers['Accept'] || '')
|
17
|
-
end
|
18
|
-
|
19
|
-
def accept_header_from_params
|
20
|
-
AcceptHeader.new(application: application_name,
|
21
|
-
header: request.params['accept'] || '')
|
22
|
-
end
|
23
|
-
|
24
|
-
def application_name
|
25
|
-
request.headers['X-Application-Name'] || Apill.configuration.application_name
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,72 +0,0 @@
|
|
1
|
-
require 'rspectacular'
|
2
|
-
require 'apill/matchers/subdomain_matcher'
|
3
|
-
require 'apill/configuration'
|
4
|
-
|
5
|
-
module Apill
|
6
|
-
module Matchers
|
7
|
-
describe SubdomainMatcher do
|
8
|
-
before(:each) do
|
9
|
-
Apill.configuration.allowed_subdomains = %w{api}
|
10
|
-
Apill.configuration.allowed_api_subdomains = %w{api}
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'matches if the subdomain is API' do
|
14
|
-
request = { 'HTTP_HOST' => 'api.example.com' }
|
15
|
-
matcher = SubdomainMatcher.new(request: request)
|
16
|
-
|
17
|
-
expect(matcher.matches?).to be_a TrueClass
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'matches if the first subdomain is API' do
|
21
|
-
request = { 'HTTP_HOST' => 'api.matrix.example.com' }
|
22
|
-
matcher = SubdomainMatcher.new(request: request)
|
23
|
-
|
24
|
-
expect(matcher.matches?).to be_a TrueClass
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'does not match if the first subdomain is not API' do
|
28
|
-
request = { 'HTTP_HOST' => 'matrix.example.com' }
|
29
|
-
matcher = SubdomainMatcher.new(request: request)
|
30
|
-
|
31
|
-
expect(matcher.matches?).to be_a FalseClass
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'allows the matched subdomain to be specified' do
|
35
|
-
request = { 'HTTP_HOST' => 'matrix.example.com' }
|
36
|
-
matcher = SubdomainMatcher.new(allowed_subdomains: 'matrix',
|
37
|
-
request: request)
|
38
|
-
|
39
|
-
expect(matcher.matches?).to be_a TrueClass
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'allows more than one subdomain to be matched' do
|
43
|
-
request = { 'HTTP_HOST' => 'matrix.example.com' }
|
44
|
-
matcher = SubdomainMatcher.new(allowed_subdomains: %w{api matrix},
|
45
|
-
request: request)
|
46
|
-
|
47
|
-
expect(matcher.matches?).to be_a TrueClass
|
48
|
-
|
49
|
-
request = { 'HTTP_HOST' => 'api.example.com' }
|
50
|
-
matcher = SubdomainMatcher.new(allowed_subdomains: %w{api matrix},
|
51
|
-
request: request)
|
52
|
-
|
53
|
-
expect(matcher.matches?).to be_a TrueClass
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'can match only the api subdomain' do
|
57
|
-
request = { 'HTTP_HOST' => 'matrix.example.com' }
|
58
|
-
matcher = SubdomainMatcher.new(allowed_api_subdomains: %w{matrix},
|
59
|
-
request: request)
|
60
|
-
|
61
|
-
expect(matcher.matches_api_subdomain?).to be_a TrueClass
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'matches "api" as an api subdomain by default' do
|
65
|
-
request = { 'HTTP_HOST' => 'api.example.com' }
|
66
|
-
matcher = SubdomainMatcher.new(request: request)
|
67
|
-
|
68
|
-
expect(matcher.matches_api_subdomain?).to be_a TrueClass
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
@@ -1,70 +0,0 @@
|
|
1
|
-
require 'rspectacular'
|
2
|
-
require 'apill/requests/rack_request'
|
3
|
-
|
4
|
-
module Apill
|
5
|
-
module Requests
|
6
|
-
describe RackRequest do
|
7
|
-
it 'finds the accept header from the headers if it is valid' do
|
8
|
-
raw_request = {
|
9
|
-
'HTTP_ACCEPT' => 'application/vnd.matrix+zion;version=10.0',
|
10
|
-
'QUERY_STRING' => '',
|
11
|
-
'HTTP_X_APPLICATION_NAME' => 'matrix',
|
12
|
-
}
|
13
|
-
request = RackRequest.new(raw_request)
|
14
|
-
|
15
|
-
expect(request.accept_header.to_s).to eql 'application/vnd.matrix+zion;version=10.0'
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'finds the accept header from the headers if it is invalid but there is no ' \
|
19
|
-
'accept header in the params' do
|
20
|
-
|
21
|
-
raw_request = {
|
22
|
-
'HTTP_ACCEPT' => 'invalid/vnd.matrix+zion;version=10.0',
|
23
|
-
'QUERY_STRING' => '',
|
24
|
-
'HTTP_X_APPLICATION_NAME' => 'matrix',
|
25
|
-
}
|
26
|
-
request = RackRequest.new(raw_request)
|
27
|
-
|
28
|
-
expect(request.accept_header.to_s).to eql 'invalid/vnd.matrix+zion;version=10.0'
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'finds the accept header from the params if it is valid' do
|
32
|
-
raw_request = {
|
33
|
-
'HTTP_ACCEPT' => '',
|
34
|
-
'QUERY_STRING' => 'accept=application/vnd.matrix+zion;version=10.0',
|
35
|
-
'HTTP_X_APPLICATION_NAME' => 'matrix',
|
36
|
-
}
|
37
|
-
request = RackRequest.new(raw_request)
|
38
|
-
|
39
|
-
expect(request.accept_header.to_s).to eql 'application/vnd.matrix+zion;version=10.0'
|
40
|
-
end
|
41
|
-
|
42
|
-
# rubocop:disable Metrics/LineLength
|
43
|
-
it 'finds the accept header from the query string if it is encoded' do
|
44
|
-
raw_request = {
|
45
|
-
'HTTP_ACCEPT' => '',
|
46
|
-
'QUERY_STRING' => 'accept=application%2Fvnd.matrix%2Bzion%3Bversion%3D10.0',
|
47
|
-
'HTTP_X_APPLICATION_NAME' => 'matrix',
|
48
|
-
}
|
49
|
-
request = RackRequest.new(raw_request)
|
50
|
-
|
51
|
-
expect(request.accept_header.to_s).to eql 'application/vnd.matrix+zion;version=10.0'
|
52
|
-
end
|
53
|
-
# rubocop:enable Metrics/LineLength
|
54
|
-
|
55
|
-
it 'defaults to the application name in the configuration if none is found in ' \
|
56
|
-
'the header' do
|
57
|
-
|
58
|
-
Apill.configuration.application_name = 'zion'
|
59
|
-
|
60
|
-
raw_request = {
|
61
|
-
'HTTP_ACCEPT' => '',
|
62
|
-
'QUERY_STRING' => 'accept=application/vnd.zion+zion;version=10.0',
|
63
|
-
}
|
64
|
-
request = RackRequest.new(raw_request)
|
65
|
-
|
66
|
-
expect(request.accept_header.to_s).to eql 'application/vnd.zion+zion;version=10.0'
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
require 'ostruct'
|
2
|
-
require 'rspectacular'
|
3
|
-
require 'apill/requests/rails_request'
|
4
|
-
|
5
|
-
module Apill
|
6
|
-
module Requests
|
7
|
-
describe RailsRequest do
|
8
|
-
it 'finds the accept header from the headers if it is valid' do
|
9
|
-
raw_request = OpenStruct.new(
|
10
|
-
headers: {
|
11
|
-
'X-Application-Name' => 'matrix',
|
12
|
-
'Accept' => 'application/vnd.matrix+zion;version=10.0',
|
13
|
-
},
|
14
|
-
params: {})
|
15
|
-
request = RailsRequest.new(raw_request)
|
16
|
-
|
17
|
-
expect(request.accept_header.to_s).to eql 'application/vnd.matrix+zion;version=10.0'
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'finds the accept header from the headers if it is invalid but there is no ' \
|
21
|
-
'accept header in the params' do
|
22
|
-
|
23
|
-
raw_request = OpenStruct.new(
|
24
|
-
headers: {
|
25
|
-
'X-Application-Name' => 'matrix',
|
26
|
-
'Accept' => 'invalid/vnd.matrix+zion;version=10.0',
|
27
|
-
},
|
28
|
-
params: {})
|
29
|
-
request = RailsRequest.new(raw_request)
|
30
|
-
|
31
|
-
expect(request.accept_header.to_s).to eql 'invalid/vnd.matrix+zion;version=10.0'
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'finds the accept header from the params if it is valid' do
|
35
|
-
raw_request = OpenStruct.new(
|
36
|
-
headers: {
|
37
|
-
'X-Application-Name' => 'matrix',
|
38
|
-
},
|
39
|
-
params: { 'accept' => 'application/vnd.matrix+zion;version=10.0' })
|
40
|
-
request = RailsRequest.new(raw_request)
|
41
|
-
|
42
|
-
expect(request.accept_header.to_s).to eql 'application/vnd.matrix+zion;version=10.0'
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'defaults to the application name in the configuration if none is found in ' \
|
46
|
-
'the header' do
|
47
|
-
|
48
|
-
Apill.configuration.application_name = 'zion'
|
49
|
-
|
50
|
-
raw_request = OpenStruct.new(
|
51
|
-
headers: {},
|
52
|
-
params: { 'accept' => 'application/vnd.zion+zion;version=10.0' })
|
53
|
-
request = RailsRequest.new(raw_request)
|
54
|
-
|
55
|
-
expect(request.accept_header.to_s).to eql 'application/vnd.zion+zion;version=10.0'
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|