drillbit 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/LICENSE.txt +19 -0
- data/README.md +2 -0
- data/Rakefile +2 -0
- data/lib/drillbit.rb +19 -0
- data/lib/drillbit/accept_header.rb +50 -0
- data/lib/drillbit/authorizable_resource.rb +160 -0
- data/lib/drillbit/authorizers/parameters.rb +24 -0
- data/lib/drillbit/authorizers/parameters/filtering.rb +50 -0
- data/lib/drillbit/authorizers/parameters/resource.rb +11 -0
- data/lib/drillbit/authorizers/query.rb +40 -0
- data/lib/drillbit/authorizers/scope.rb +30 -0
- data/lib/drillbit/configuration.rb +36 -0
- data/lib/drillbit/errors/invalid_api_request.rb +29 -0
- data/lib/drillbit/errors/invalid_subdomain.rb +29 -0
- data/lib/drillbit/errors/invalid_token.rb +22 -0
- data/lib/drillbit/matchers/accept_header.rb +16 -0
- data/lib/drillbit/matchers/generic.rb +30 -0
- data/lib/drillbit/matchers/subdomain.rb +31 -0
- data/lib/drillbit/matchers/version.rb +30 -0
- data/lib/drillbit/middleware/api_request.rb +49 -0
- data/lib/drillbit/parameters.rb +22 -0
- data/lib/drillbit/parameters/filter.rb +57 -0
- data/lib/drillbit/parameters/index.rb +31 -0
- data/lib/drillbit/parameters/page.rb +28 -0
- data/lib/drillbit/parameters/sort.rb +32 -0
- data/lib/drillbit/requests/base.rb +114 -0
- data/lib/drillbit/requests/rack.rb +50 -0
- data/lib/drillbit/requests/rails.rb +44 -0
- data/lib/drillbit/resource.rb +14 -0
- data/lib/drillbit/resource/model.rb +41 -0
- data/lib/drillbit/resource/naming.rb +33 -0
- data/lib/drillbit/resource/processors/filtering.rb +66 -0
- data/lib/drillbit/resource/processors/indexing.rb +40 -0
- data/lib/drillbit/resource/processors/paging.rb +46 -0
- data/lib/drillbit/resource/processors/sorting.rb +42 -0
- data/lib/drillbit/responses/invalid_api_request.rb +18 -0
- data/lib/drillbit/responses/invalid_subdomain.rb +18 -0
- data/lib/drillbit/responses/invalid_token.rb +20 -0
- data/lib/drillbit/serializers/json_api.rb +10 -0
- data/lib/drillbit/tokens/base64.rb +45 -0
- data/lib/drillbit/tokens/base64s/invalid.rb +14 -0
- data/lib/drillbit/tokens/base64s/null.rb +14 -0
- data/lib/drillbit/tokens/invalid.rb +26 -0
- data/lib/drillbit/tokens/json_web_token.rb +112 -0
- data/lib/drillbit/tokens/json_web_tokens/invalid.rb +14 -0
- data/lib/drillbit/tokens/json_web_tokens/null.rb +14 -0
- data/lib/drillbit/tokens/null.rb +26 -0
- data/lib/drillbit/version.rb +4 -0
- data/spec/drillbit/accept_header_spec.rb +112 -0
- data/spec/drillbit/authorizers/parameters/filtering_spec.rb +71 -0
- data/spec/drillbit/authorizers/parameters/resource_spec.rb +12 -0
- data/spec/drillbit/authorizers/parameters_spec.rb +17 -0
- data/spec/drillbit/authorizers/query_spec.rb +21 -0
- data/spec/drillbit/authorizers/scope_spec.rb +20 -0
- data/spec/drillbit/errors/invalid_api_request_spec.rb +31 -0
- data/spec/drillbit/errors/invalid_subdomain_spec.rb +31 -0
- data/spec/drillbit/errors/invalid_token_spec.rb +24 -0
- data/spec/drillbit/invalid_subdomain_spec.rb +46 -0
- data/spec/drillbit/invalid_token_spec.rb +44 -0
- data/spec/drillbit/matchers/accept_header_spec.rb +114 -0
- data/spec/drillbit/matchers/subdomain_spec.rb +78 -0
- data/spec/drillbit/matchers/version_spec.rb +86 -0
- data/spec/drillbit/middleware/api_request_spec.rb +220 -0
- data/spec/drillbit/parameters_spec.rb +49 -0
- data/spec/drillbit/requests/base_spec.rb +37 -0
- data/spec/drillbit/requests/rack_spec.rb +253 -0
- data/spec/drillbit/requests/rails_spec.rb +264 -0
- data/spec/drillbit/resource/model_spec.rb +64 -0
- data/spec/drillbit/resource/processors/filtering_spec.rb +106 -0
- data/spec/drillbit/resource/processors/indexing_spec.rb +46 -0
- data/spec/drillbit/resource/processors/paging_spec.rb +74 -0
- data/spec/drillbit/resource/processors/sorting_spec.rb +66 -0
- data/spec/drillbit/tokens/base64_spec.rb +44 -0
- data/spec/drillbit/tokens/json_web_token_spec.rb +135 -0
- data/spec/fixtures/test_rsa_key +27 -0
- data/spec/fixtures/test_rsa_key.pub +9 -0
- data/spec/spec_helper.rb +4 -0
- data/spec/support/private_keys.rb +42 -0
- metadata +244 -0
- metadata.gz.sig +0 -0
@@ -0,0 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'drillbit/resource/processors/paging'
|
4
|
+
|
5
|
+
module Drillbit
|
6
|
+
module Resource
|
7
|
+
module Processors
|
8
|
+
RSpec.describe Paging do
|
9
|
+
let(:paging_resource) { double }
|
10
|
+
let(:processed_resource) { double }
|
11
|
+
|
12
|
+
it 'can return a default page' do
|
13
|
+
paging = Paging.new(paging_resource,
|
14
|
+
'page' => {
|
15
|
+
'size' => 10,
|
16
|
+
})
|
17
|
+
|
18
|
+
allow(paging_resource).to receive(:total_pages).and_return 10
|
19
|
+
allow(paging_resource).to receive(:current_page).and_return 1
|
20
|
+
allow(paging_resource).to receive(:prev_page).and_return nil
|
21
|
+
allow(paging_resource).to receive(:next_page).and_return nil
|
22
|
+
|
23
|
+
allow(paging_resource).to receive(:page).
|
24
|
+
with(1).
|
25
|
+
and_return paging_resource
|
26
|
+
allow(paging_resource).to receive(:per).
|
27
|
+
with(10).
|
28
|
+
and_return processed_resource
|
29
|
+
|
30
|
+
expect(paging.processed).to eql processed_resource
|
31
|
+
expect(paging.meta).to eql(
|
32
|
+
'total-pages' => 10,
|
33
|
+
'current-page' => 1,
|
34
|
+
'previous-page' => nil,
|
35
|
+
'next-page' => nil,
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'can return a pageed resource' do
|
40
|
+
paging = Paging.new(paging_resource,
|
41
|
+
'page' => {
|
42
|
+
'number' => 5,
|
43
|
+
'size' => 10,
|
44
|
+
})
|
45
|
+
|
46
|
+
allow(paging_resource).to receive(:page).
|
47
|
+
with(5).
|
48
|
+
and_return paging_resource
|
49
|
+
allow(paging_resource).to receive(:per).
|
50
|
+
with(10).
|
51
|
+
and_return processed_resource
|
52
|
+
|
53
|
+
expect(paging.processed).to eql processed_resource
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'does not consider non-ideomatic page params as valid' do
|
57
|
+
paging = Paging.new(paging_resource,
|
58
|
+
'page' => {
|
59
|
+
'nombre' => 5,
|
60
|
+
'tamano' => 10,
|
61
|
+
})
|
62
|
+
|
63
|
+
expect(paging.processed).to eql paging_resource
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'does not do anything if page params are not passed in' do
|
67
|
+
paging = Paging.new(paging_resource)
|
68
|
+
|
69
|
+
expect(paging.processed).to eql paging_resource
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'drillbit/resource/processors/sorting'
|
4
|
+
|
5
|
+
module Drillbit
|
6
|
+
module Resource
|
7
|
+
module Processors
|
8
|
+
RSpec.describe Sorting do
|
9
|
+
let(:sorting_resource) { double }
|
10
|
+
|
11
|
+
it 'can return an ascending sort' do
|
12
|
+
sorting = Sorting.new(sorting_resource, 'sort' => 'my_attribute')
|
13
|
+
|
14
|
+
allow(sorting_resource).to receive(:order).
|
15
|
+
with('my_attribute' => 'asc').
|
16
|
+
and_return('sorted')
|
17
|
+
|
18
|
+
expect(sorting.processed).to eql 'sorted'
|
19
|
+
expect(sorting.meta).to eql(
|
20
|
+
'sort' => {
|
21
|
+
'my_attribute' => 'asc',
|
22
|
+
},
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'can return a descending sort' do
|
27
|
+
sorting = Sorting.new(sorting_resource, 'sort' => '-my_attribute')
|
28
|
+
|
29
|
+
allow(sorting_resource).to receive(:order).
|
30
|
+
with('my_attribute' => 'desc').
|
31
|
+
and_return('sorted')
|
32
|
+
|
33
|
+
expect(sorting.processed).to eql 'sorted'
|
34
|
+
expect(sorting.meta).to eql(
|
35
|
+
'sort' => {
|
36
|
+
'my_attribute' => 'desc',
|
37
|
+
},
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'can return multiple sorts' do
|
42
|
+
sorting = Sorting.new(sorting_resource, 'sort' => '-my_attribute,my_other_attribute')
|
43
|
+
|
44
|
+
allow(sorting_resource).to receive(:order).
|
45
|
+
with('my_attribute' => 'desc',
|
46
|
+
'my_other_attribute' => 'asc').
|
47
|
+
and_return('sorted')
|
48
|
+
|
49
|
+
expect(sorting.processed).to eql 'sorted'
|
50
|
+
expect(sorting.meta).to eql(
|
51
|
+
'sort' => {
|
52
|
+
'my_attribute' => 'desc',
|
53
|
+
'my_other_attribute' => 'asc',
|
54
|
+
},
|
55
|
+
)
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'does not do anything if sorting params are not passed in' do
|
59
|
+
sorting = Sorting.new(sorting_resource)
|
60
|
+
|
61
|
+
expect(sorting.processed).to eql sorting_resource
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'drillbit/tokens/base64'
|
4
|
+
|
5
|
+
module Drillbit
|
6
|
+
module Tokens
|
7
|
+
RSpec.describe Base64 do
|
8
|
+
it 'is valid' do
|
9
|
+
expect(Base64.new(token: 'foo')).to be_valid
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'is not blank' do
|
13
|
+
expect(Base64.new(token: 'foo')).not_to be_blank
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'can convert itself into a hash' do
|
17
|
+
token = Base64.new(token: 'foo')
|
18
|
+
|
19
|
+
expect(token.to_h).to eql([
|
20
|
+
{
|
21
|
+
'token' => 'foo',
|
22
|
+
},
|
23
|
+
{
|
24
|
+
'typ' => 'base64',
|
25
|
+
},
|
26
|
+
])
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'can convert itself into a null token' do
|
30
|
+
token = Base64.convert(raw_token: nil)
|
31
|
+
|
32
|
+
expect(token).to be_valid
|
33
|
+
expect(token).to be_blank
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'can convert itself into an invalid token' do
|
37
|
+
token = Base64.convert(raw_token: 'bla.h')
|
38
|
+
|
39
|
+
expect(token).not_to be_valid
|
40
|
+
expect(token).not_to be_blank
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'drillbit/tokens/json_web_token'
|
4
|
+
|
5
|
+
module Drillbit
|
6
|
+
module Tokens
|
7
|
+
RSpec.describe JsonWebToken do
|
8
|
+
it 'can convert an empty encrypted token' do
|
9
|
+
token = JsonWebToken.from_jwe(nil,
|
10
|
+
private_key: test_private_key)
|
11
|
+
|
12
|
+
expect(token).to be_a JsonWebTokens::Null
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'can convert an invalid encrypted token' do
|
16
|
+
token = JsonWebToken.from_jwe(invalid_jwe_token,
|
17
|
+
private_key: test_private_key)
|
18
|
+
|
19
|
+
expect(token).to be_a JsonWebTokens::Invalid
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'can verify an expired encrypted token' do
|
23
|
+
expired_jwe = valid_jwe_token('exp' => 1.day.ago.to_i,
|
24
|
+
'baz' => 'bar')
|
25
|
+
token = JsonWebToken.from_jwe(expired_jwe,
|
26
|
+
private_key: test_private_key)
|
27
|
+
|
28
|
+
expect(token).to be_a JsonWebTokens::Invalid
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'can convert an invalidly signed encrypted token' do
|
32
|
+
other_private_key = OpenSSL::PKey::RSA.new(2048)
|
33
|
+
token = JsonWebToken.from_jwe(valid_jwe_token,
|
34
|
+
private_key: other_private_key)
|
35
|
+
|
36
|
+
expect(token).to be_a JsonWebTokens::Invalid
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'can convert a valid encrypted token' do
|
40
|
+
token = JsonWebToken.from_jwe(valid_jwe_token,
|
41
|
+
private_key: test_private_key)
|
42
|
+
|
43
|
+
expect(token).to be_a JsonWebToken
|
44
|
+
expect(token.to_h).to eql([{ 'bar' => 'baz' }, { 'typ' => 'JWT', 'alg' => 'RS256' }])
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'can convert an empty signed token' do
|
48
|
+
token = JsonWebToken.from_jws(nil,
|
49
|
+
private_key: test_private_key)
|
50
|
+
|
51
|
+
expect(token).to be_a JsonWebTokens::Null
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'can verify an expired signed token' do
|
55
|
+
expired_jws = valid_jws_token('exp' => 1.day.ago.to_i,
|
56
|
+
'baz' => 'bar')
|
57
|
+
token = JsonWebToken.from_jws(expired_jws,
|
58
|
+
private_key: test_private_key)
|
59
|
+
|
60
|
+
expect(token).to be_a JsonWebTokens::Invalid
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'can convert an invalidly signed token' do
|
64
|
+
other_private_key = OpenSSL::PKey::RSA.new(2048)
|
65
|
+
token_signed_with_another_key = JsonWebToken.from_jws(valid_jws_token,
|
66
|
+
private_key: other_private_key)
|
67
|
+
invalid_token = JsonWebToken.from_jws(invalid_jws_token,
|
68
|
+
private_key: test_private_key)
|
69
|
+
|
70
|
+
expect(token_signed_with_another_key).to be_a JsonWebTokens::Invalid
|
71
|
+
expect(invalid_token).to be_a JsonWebTokens::Invalid
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'can convert a valid signed token' do
|
75
|
+
token = JsonWebToken.from_jws(valid_jws_token,
|
76
|
+
private_key: test_private_key)
|
77
|
+
|
78
|
+
expect(token).to be_a JsonWebToken
|
79
|
+
expect(token.to_h).to eql([{ 'bar' => 'baz' }, { 'typ' => 'JWT', 'alg' => 'RS256' }])
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'can transform into a JWT' do
|
83
|
+
token = JsonWebToken.new(data: { 'foo' => 'bar' },
|
84
|
+
private_key: test_private_key)
|
85
|
+
|
86
|
+
jwt = token.to_jwt
|
87
|
+
jwt_s = token.to_jwt_s
|
88
|
+
|
89
|
+
expect(jwt.to_h).to eql('foo' => 'bar')
|
90
|
+
expect(jwt_s).to eql('eyJ0eXAiOiJKV1QiLCJhbGciOiJub25lIn0.eyJmb28iOiJiYXIifQ.')
|
91
|
+
end
|
92
|
+
|
93
|
+
# rubocop:disable Metrics/LineLength
|
94
|
+
it 'can transform into a JWS and back' do
|
95
|
+
token = JsonWebToken.new(data: { 'foo' => 'bar' },
|
96
|
+
private_key: test_private_key)
|
97
|
+
|
98
|
+
jws = token.to_jws
|
99
|
+
jws_s = token.to_jws_s
|
100
|
+
|
101
|
+
expect(jws.to_h).to eql('foo' => 'bar')
|
102
|
+
expect(jws_s).to eql('eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJmb28iOiJiYXIifQ.DhPBu9Bfha08hSoy1a8Ps5YGxv2_KJCoNALH8dzd8b_VgKCPRQlIaHZwQfS5N1yfZczc2EqXIhPma4I2i-L92oDxyugZYfhMH6XUXSgB6F7SU5WtiglQ8gfgxC_u_K5htD_6zpRaHi6UTNbG8NF3RFBYK9za4GFPPWQawRQpdH2CxjyZP6pilmkynLuKx0OeQbJf1yzdgn1cDt60M8uoZZTzPgoU598ilDjYEETwyGyCi79S3A3ix8oDaJLhM8stPOHLUeglKrkwxOFglzVs7bULjzxZlygZujsHfWu16cjp_P3b4TIH_hiH0-Cjin-EVt4va2TnfGJ8HDxHxzWn7g')
|
103
|
+
|
104
|
+
converted_token = JsonWebToken.from_jws(jws_s,
|
105
|
+
private_key: test_private_key)
|
106
|
+
|
107
|
+
expect(converted_token.to_h).to eql [
|
108
|
+
{ 'foo' => 'bar' },
|
109
|
+
{ 'typ' => 'JWT', 'alg' => 'RS256' },
|
110
|
+
]
|
111
|
+
end
|
112
|
+
# rubocop:enable Metrics/LineLength
|
113
|
+
|
114
|
+
# rubocop:disable Metrics/LineLength
|
115
|
+
it 'can transform into a JWE and back' do
|
116
|
+
token = JsonWebToken.new(data: { 'foo' => 'bar' },
|
117
|
+
private_key: test_private_key)
|
118
|
+
|
119
|
+
jwe = token.to_jwe
|
120
|
+
jwe_s = token.to_jwe_s
|
121
|
+
|
122
|
+
expect(jwe.plain_text).to eql('eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJmb28iOiJiYXIifQ.DhPBu9Bfha08hSoy1a8Ps5YGxv2_KJCoNALH8dzd8b_VgKCPRQlIaHZwQfS5N1yfZczc2EqXIhPma4I2i-L92oDxyugZYfhMH6XUXSgB6F7SU5WtiglQ8gfgxC_u_K5htD_6zpRaHi6UTNbG8NF3RFBYK9za4GFPPWQawRQpdH2CxjyZP6pilmkynLuKx0OeQbJf1yzdgn1cDt60M8uoZZTzPgoU598ilDjYEETwyGyCi79S3A3ix8oDaJLhM8stPOHLUeglKrkwxOFglzVs7bULjzxZlygZujsHfWu16cjp_P3b4TIH_hiH0-Cjin-EVt4va2TnfGJ8HDxHxzWn7g')
|
123
|
+
|
124
|
+
converted_token = JsonWebToken.from_jwe(jwe_s,
|
125
|
+
private_key: test_private_key)
|
126
|
+
|
127
|
+
expect(converted_token.to_h).to eql [
|
128
|
+
{ 'foo' => 'bar' },
|
129
|
+
{ 'typ' => 'JWT', 'alg' => 'RS256' },
|
130
|
+
]
|
131
|
+
end
|
132
|
+
# rubocop:enable Metrics/LineLength
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
-----BEGIN RSA PRIVATE KEY-----
|
2
|
+
MIIEpQIBAAKCAQEAzQNhPtJl68EAoLBh92nBpDlif2M61dS+HBoRinfWT5sD3CeJ
|
3
|
+
eMPmlj9vqOdmBzBfMuoHkr3QPVjTAvsTMthoVFKVUEA28eglFABZYP99+VDIK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9TO1IpwJvYpqYU0KpJSo5G5eyxM37iQWTTCbmq2byanRLlinXs
|
8
|
+
tQIDAQAB
|
9
|
+
-----END PUBLIC KEY-----
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'json/jwt'
|
3
|
+
require 'base64'
|
4
|
+
|
5
|
+
def test_private_key
|
6
|
+
OpenSSL::PKey::RSA.new File.read(File.expand_path('../fixtures/test_rsa_key', __dir__))
|
7
|
+
end
|
8
|
+
|
9
|
+
def valid_jws_token(payload = { 'bar' => 'baz' })
|
10
|
+
@valid_jws_token ||= begin
|
11
|
+
jwt = JSON::JWT.new(payload)
|
12
|
+
jws = jwt.sign(test_private_key, :RS256)
|
13
|
+
|
14
|
+
jws.to_s
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def valid_jwe_token(payload = { 'bar' => 'baz' })
|
19
|
+
@valid_jwe_token ||= begin
|
20
|
+
jwt = JSON::JWT.new(payload)
|
21
|
+
jws = jwt.sign(test_private_key, :RS256)
|
22
|
+
jwe = jws.encrypt(test_private_key, :'RSA-OAEP', :A256GCM)
|
23
|
+
|
24
|
+
jwe.to_s
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def invalid_jws_token
|
29
|
+
@invalid_jws_token ||= valid_jws_token.tr('a', 'f')
|
30
|
+
end
|
31
|
+
|
32
|
+
def invalid_jwe_token
|
33
|
+
@invalid_jwe_token ||= valid_jwe_token.tr('a', 'f')
|
34
|
+
end
|
35
|
+
|
36
|
+
def valid_b64_token(payload = 'hereisacoollittlestring')
|
37
|
+
@valid_b64_token ||= Base64.encode64(payload).chomp
|
38
|
+
end
|
39
|
+
|
40
|
+
def invalid_b64_token
|
41
|
+
@invalid_b64_token ||= valid_b64_token.tr('abcdefghijklmnop', '$o#m$k#i$g#e$c#a')
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,244 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: drillbit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- thegranddesign
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain:
|
11
|
+
- |
|
12
|
+
-----BEGIN CERTIFICATE-----
|
13
|
+
MIIDqjCCApKgAwIBAgIBATANBgkqhkiG9w0BAQUFADBNMREwDwYDVQQDDAhydWJ5
|
14
|
+
Z2VtczEjMCEGCgmSJomT8ixkARkWE2xpdmluZ2hpZ2hvbnRoZWJsb2cxEzARBgoJ
|
15
|
+
kiaJk/IsZAEZFgNjb20wHhcNMTYwNTAxMDIzMDIzWhcNMTcwNTAxMDIzMDIzWjBN
|
16
|
+
MREwDwYDVQQDDAhydWJ5Z2VtczEjMCEGCgmSJomT8ixkARkWE2xpdmluZ2hpZ2hv
|
17
|
+
bnRoZWJsb2cxEzARBgoJkiaJk/IsZAEZFgNjb20wggEiMA0GCSqGSIb3DQEBAQUA
|
18
|
+
A4IBDwAwggEKAoIBAQC/Oxo4PMAOCC3dfzGt7DZJwoDY9MGBXoWkbWIEP91yyKIB
|
19
|
+
mWheQ1epDXkj1R6SM1+iclwgUKJQvFrSeD5i1NS9+3qRrD6gPCf3RDAbWNdUpyei
|
20
|
+
F/W4+G7eCxGC6FHv7WsBjrGWQVTjZtKYOiQCxwwkPlZSX8aBXViO8D9bZJAURocY
|
21
|
+
CbsMGeS0sPISRb0GCnI8VOIoab7GM8tdmIj4Uv0lzp4uOlKRJBss5/Sjp1mjgCvI
|
22
|
+
vuXy0X+r1l2xiXL3/uTT/Tch3lPWctEEDw9rUzNz0N5oTGK4vooq4m4AIzU1pa1Z
|
23
|
+
ZneO33rn3QVWVpOsK6NQVpBNhSism+Ju1mlvdmKFAgMBAAGjgZQwgZEwCQYDVR0T
|
24
|
+
BAIwADALBgNVHQ8EBAMCBLAwHQYDVR0OBBYEFLpr4AqEQwV9hUch3fxKvCkHUw3i
|
25
|
+
MCsGA1UdEQQkMCKBIHJ1YnlnZW1zQGxpdmluZ2hpZ2hvbnRoZWJsb2cuY29tMCsG
|
26
|
+
A1UdEgQkMCKBIHJ1YnlnZW1zQGxpdmluZ2hpZ2hvbnRoZWJsb2cuY29tMA0GCSqG
|
27
|
+
SIb3DQEBBQUAA4IBAQB5lDS+51DxC1GMpILDt++z5Isx2gSybmGKhNFFWWWo5iVW
|
28
|
+
6jLsj7H1T934Bn31sVET2cvrFGMVLKoitGgZuZPxjzkmm2+TDPbt02ThsLqjsh7W
|
29
|
+
000RFl0u7xJE8dg9y3Kmntar83Mr/Uf1F88/4mQsvGNnxGa39QP9IY4p6FkyEO3L
|
30
|
+
RRz+3xE8j0OBl1FNALFtP74/A3zmBRbCizr8En/jbQe/DISJG2o8QOyqm/64uNoy
|
31
|
+
zRIv8lqQM8QFT76rzP5SBCERwN+ltKAFbQ5/FwmZNGWYnmCP3RZMQiRnbh+9H9lh
|
32
|
+
mlbwaYZTjgsXq6cy8N38EecewgBbZYS1IYJraE/M
|
33
|
+
-----END CERTIFICATE-----
|
34
|
+
date: 2016-05-01 00:00:00.000000000 Z
|
35
|
+
dependencies:
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: erratum
|
38
|
+
requirement: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - "~>"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0.0'
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0.0'
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: json-jwt
|
52
|
+
requirement: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - "~>"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '1.5'
|
57
|
+
type: :runtime
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - "~>"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '1.5'
|
64
|
+
- !ruby/object:Gem::Dependency
|
65
|
+
name: jwt
|
66
|
+
requirement: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - "~>"
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '1.5'
|
71
|
+
type: :runtime
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - "~>"
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '1.5'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rspec
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - "~>"
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '3.4'
|
85
|
+
type: :development
|
86
|
+
prerelease: false
|
87
|
+
version_requirements: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - "~>"
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '3.4'
|
92
|
+
- !ruby/object:Gem::Dependency
|
93
|
+
name: rspeckled
|
94
|
+
requirement: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - "~>"
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0.0'
|
99
|
+
type: :development
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - "~>"
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0.0'
|
106
|
+
description: ''
|
107
|
+
email: rubygems@livinghighontheblog.com
|
108
|
+
executables: []
|
109
|
+
extensions: []
|
110
|
+
extra_rdoc_files: []
|
111
|
+
files:
|
112
|
+
- LICENSE.txt
|
113
|
+
- README.md
|
114
|
+
- Rakefile
|
115
|
+
- lib/drillbit.rb
|
116
|
+
- lib/drillbit/accept_header.rb
|
117
|
+
- lib/drillbit/authorizable_resource.rb
|
118
|
+
- lib/drillbit/authorizers/parameters.rb
|
119
|
+
- lib/drillbit/authorizers/parameters/filtering.rb
|
120
|
+
- lib/drillbit/authorizers/parameters/resource.rb
|
121
|
+
- lib/drillbit/authorizers/query.rb
|
122
|
+
- lib/drillbit/authorizers/scope.rb
|
123
|
+
- lib/drillbit/configuration.rb
|
124
|
+
- lib/drillbit/errors/invalid_api_request.rb
|
125
|
+
- lib/drillbit/errors/invalid_subdomain.rb
|
126
|
+
- lib/drillbit/errors/invalid_token.rb
|
127
|
+
- lib/drillbit/matchers/accept_header.rb
|
128
|
+
- lib/drillbit/matchers/generic.rb
|
129
|
+
- lib/drillbit/matchers/subdomain.rb
|
130
|
+
- lib/drillbit/matchers/version.rb
|
131
|
+
- lib/drillbit/middleware/api_request.rb
|
132
|
+
- lib/drillbit/parameters.rb
|
133
|
+
- lib/drillbit/parameters/filter.rb
|
134
|
+
- lib/drillbit/parameters/index.rb
|
135
|
+
- lib/drillbit/parameters/page.rb
|
136
|
+
- lib/drillbit/parameters/sort.rb
|
137
|
+
- lib/drillbit/requests/base.rb
|
138
|
+
- lib/drillbit/requests/rack.rb
|
139
|
+
- lib/drillbit/requests/rails.rb
|
140
|
+
- lib/drillbit/resource.rb
|
141
|
+
- lib/drillbit/resource/model.rb
|
142
|
+
- lib/drillbit/resource/naming.rb
|
143
|
+
- lib/drillbit/resource/processors/filtering.rb
|
144
|
+
- lib/drillbit/resource/processors/indexing.rb
|
145
|
+
- lib/drillbit/resource/processors/paging.rb
|
146
|
+
- lib/drillbit/resource/processors/sorting.rb
|
147
|
+
- lib/drillbit/responses/invalid_api_request.rb
|
148
|
+
- lib/drillbit/responses/invalid_subdomain.rb
|
149
|
+
- lib/drillbit/responses/invalid_token.rb
|
150
|
+
- lib/drillbit/serializers/json_api.rb
|
151
|
+
- lib/drillbit/tokens/base64.rb
|
152
|
+
- lib/drillbit/tokens/base64s/invalid.rb
|
153
|
+
- lib/drillbit/tokens/base64s/null.rb
|
154
|
+
- lib/drillbit/tokens/invalid.rb
|
155
|
+
- lib/drillbit/tokens/json_web_token.rb
|
156
|
+
- lib/drillbit/tokens/json_web_tokens/invalid.rb
|
157
|
+
- lib/drillbit/tokens/json_web_tokens/null.rb
|
158
|
+
- lib/drillbit/tokens/null.rb
|
159
|
+
- lib/drillbit/version.rb
|
160
|
+
- spec/drillbit/accept_header_spec.rb
|
161
|
+
- spec/drillbit/authorizers/parameters/filtering_spec.rb
|
162
|
+
- spec/drillbit/authorizers/parameters/resource_spec.rb
|
163
|
+
- spec/drillbit/authorizers/parameters_spec.rb
|
164
|
+
- spec/drillbit/authorizers/query_spec.rb
|
165
|
+
- spec/drillbit/authorizers/scope_spec.rb
|
166
|
+
- spec/drillbit/errors/invalid_api_request_spec.rb
|
167
|
+
- spec/drillbit/errors/invalid_subdomain_spec.rb
|
168
|
+
- spec/drillbit/errors/invalid_token_spec.rb
|
169
|
+
- spec/drillbit/invalid_subdomain_spec.rb
|
170
|
+
- spec/drillbit/invalid_token_spec.rb
|
171
|
+
- spec/drillbit/matchers/accept_header_spec.rb
|
172
|
+
- spec/drillbit/matchers/subdomain_spec.rb
|
173
|
+
- spec/drillbit/matchers/version_spec.rb
|
174
|
+
- spec/drillbit/middleware/api_request_spec.rb
|
175
|
+
- spec/drillbit/parameters_spec.rb
|
176
|
+
- spec/drillbit/requests/base_spec.rb
|
177
|
+
- spec/drillbit/requests/rack_spec.rb
|
178
|
+
- spec/drillbit/requests/rails_spec.rb
|
179
|
+
- spec/drillbit/resource/model_spec.rb
|
180
|
+
- spec/drillbit/resource/processors/filtering_spec.rb
|
181
|
+
- spec/drillbit/resource/processors/indexing_spec.rb
|
182
|
+
- spec/drillbit/resource/processors/paging_spec.rb
|
183
|
+
- spec/drillbit/resource/processors/sorting_spec.rb
|
184
|
+
- spec/drillbit/tokens/base64_spec.rb
|
185
|
+
- spec/drillbit/tokens/json_web_token_spec.rb
|
186
|
+
- spec/fixtures/test_rsa_key
|
187
|
+
- spec/fixtures/test_rsa_key.pub
|
188
|
+
- spec/spec_helper.rb
|
189
|
+
- spec/support/private_keys.rb
|
190
|
+
homepage:
|
191
|
+
licenses:
|
192
|
+
- MIT
|
193
|
+
metadata: {}
|
194
|
+
post_install_message:
|
195
|
+
rdoc_options: []
|
196
|
+
require_paths:
|
197
|
+
- lib
|
198
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
199
|
+
requirements:
|
200
|
+
- - ">="
|
201
|
+
- !ruby/object:Gem::Version
|
202
|
+
version: '0'
|
203
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
204
|
+
requirements:
|
205
|
+
- - ">="
|
206
|
+
- !ruby/object:Gem::Version
|
207
|
+
version: '0'
|
208
|
+
requirements: []
|
209
|
+
rubyforge_project:
|
210
|
+
rubygems_version: 2.5.1
|
211
|
+
signing_key:
|
212
|
+
specification_version: 4
|
213
|
+
summary: APIs Need Love Too
|
214
|
+
test_files:
|
215
|
+
- spec/drillbit/accept_header_spec.rb
|
216
|
+
- spec/drillbit/authorizers/parameters/filtering_spec.rb
|
217
|
+
- spec/drillbit/authorizers/parameters/resource_spec.rb
|
218
|
+
- spec/drillbit/authorizers/parameters_spec.rb
|
219
|
+
- spec/drillbit/authorizers/query_spec.rb
|
220
|
+
- spec/drillbit/authorizers/scope_spec.rb
|
221
|
+
- spec/drillbit/errors/invalid_api_request_spec.rb
|
222
|
+
- spec/drillbit/errors/invalid_subdomain_spec.rb
|
223
|
+
- spec/drillbit/errors/invalid_token_spec.rb
|
224
|
+
- spec/drillbit/invalid_subdomain_spec.rb
|
225
|
+
- spec/drillbit/invalid_token_spec.rb
|
226
|
+
- spec/drillbit/matchers/accept_header_spec.rb
|
227
|
+
- spec/drillbit/matchers/subdomain_spec.rb
|
228
|
+
- spec/drillbit/matchers/version_spec.rb
|
229
|
+
- spec/drillbit/middleware/api_request_spec.rb
|
230
|
+
- spec/drillbit/parameters_spec.rb
|
231
|
+
- spec/drillbit/requests/base_spec.rb
|
232
|
+
- spec/drillbit/requests/rack_spec.rb
|
233
|
+
- spec/drillbit/requests/rails_spec.rb
|
234
|
+
- spec/drillbit/resource/model_spec.rb
|
235
|
+
- spec/drillbit/resource/processors/filtering_spec.rb
|
236
|
+
- spec/drillbit/resource/processors/indexing_spec.rb
|
237
|
+
- spec/drillbit/resource/processors/paging_spec.rb
|
238
|
+
- spec/drillbit/resource/processors/sorting_spec.rb
|
239
|
+
- spec/drillbit/tokens/base64_spec.rb
|
240
|
+
- spec/drillbit/tokens/json_web_token_spec.rb
|
241
|
+
- spec/fixtures/test_rsa_key
|
242
|
+
- spec/fixtures/test_rsa_key.pub
|
243
|
+
- spec/spec_helper.rb
|
244
|
+
- spec/support/private_keys.rb
|