master_api_key 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -91,4 +91,78 @@ RSpec.describe ApplicationController, :type => :controller do
91
91
  }.to raise_error(ArgumentError)
92
92
  end
93
93
  end
94
+
95
+ context 'with a controller with additional authorizers' do
96
+ class ExtendedApiKey < MasterApiKey::ApiKey
97
+ def allowed_id
98
+ nil
99
+ end
100
+
101
+ def allowed_filter
102
+ nil
103
+ end
104
+ end
105
+
106
+ controller do
107
+ belongs_to_api_group(:allowed_group)
108
+ authorize_with authorizers: [:first_authorizer, :second_authorizer], only:[:index]
109
+
110
+ def index
111
+ head(:ok)
112
+ end
113
+
114
+ def show
115
+ authorize_action(:first_authorizer) do
116
+ head(:ok)
117
+ end
118
+ end
119
+
120
+ def first_authorizer
121
+ @api_key.allowed_id == params.require(:id).to_i
122
+ end
123
+
124
+ def second_authorizer
125
+ @api_key.allowed_filter == params.require(:filter)
126
+ end
127
+ end
128
+
129
+ before(:each) do
130
+ @allowed_filter = 'allowed_key'
131
+ @valid_api_key = ExtendedApiKey.create!(:group => 'allowed_group')
132
+ controller.request.headers['X-API-TOKEN'] = @valid_api_key.api_token
133
+
134
+ allow(MasterApiKey::ApiKey).to receive(:find_by_api_token).with(@valid_api_key.api_token).and_return(@valid_api_key)
135
+ allow(@valid_api_key).to receive(:allowed_id).and_return(1)
136
+ allow(@valid_api_key).to receive(:allowed_filter).and_return(@allowed_filter)
137
+ end
138
+
139
+ context 'with two additional authorization factors' do
140
+ it 'should fail authorization when one of the additional authorization factors fail' do
141
+ get :index, :id => 1, :filter => 'not_allowed_filter'
142
+
143
+ expect(response).to have_http_status(403)
144
+ end
145
+
146
+ it 'should pass authorization when both authorization factors succeed' do
147
+ get :index, :id => 1, :filter => @allowed_filter
148
+
149
+ expect(response).to have_http_status(200)
150
+ end
151
+ end
152
+
153
+ context 'with one additional authorization factor' do
154
+ it 'should pass authorization when additional authorization factor succeeds' do
155
+ get :show, :id => 1
156
+
157
+ expect(response).to have_http_status(200)
158
+ end
159
+
160
+ it 'should fail authorization when additional authorization factor fails' do
161
+
162
+ get :show, :id => 2
163
+
164
+ expect(response).to have_http_status(403)
165
+ end
166
+ end
167
+ end
94
168
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: master_api_key
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Flynn Jones
@@ -73,7 +73,7 @@ cert_chain:
73
73
  7xfdQKID/bwhqUq9whTwTX2J61RCxyS+eqIRfWOYAUphZanwFD9c3uNWa+8KAhC2
74
74
  oHN/0fktfVzQYUsHnZ4=
75
75
  -----END CERTIFICATE-----
76
- date: 2016-04-18 00:00:00.000000000 Z
76
+ date: 2016-04-28 00:00:00.000000000 Z
77
77
  dependencies:
78
78
  - !ruby/object:Gem::Dependency
79
79
  name: rails
@@ -124,21 +124,21 @@ dependencies:
124
124
  - !ruby/object:Gem::Version
125
125
  version: '3.4'
126
126
  - !ruby/object:Gem::Dependency
127
- name: activerecord-jdbcmysql-adapter
127
+ name: mysql2
128
128
  requirement: !ruby/object:Gem::Requirement
129
129
  requirements:
130
130
  - - "~>"
131
131
  - !ruby/object:Gem::Version
132
- version: '1.3'
132
+ version: '0.4'
133
133
  type: :development
134
134
  prerelease: false
135
135
  version_requirements: !ruby/object:Gem::Requirement
136
136
  requirements:
137
137
  - - "~>"
138
138
  - !ruby/object:Gem::Version
139
- version: '1.3'
140
- description: This gem gives a developer a set of tools to provide authorized access
141
- their endpoints.
139
+ version: '0.4'
140
+ description: This gem gives a developer a set of tools for securing access to their
141
+ endpoints.
142
142
  email:
143
143
  - flynn.jones@outlook.com
144
144
  - pvadrevu@amplify.com
metadata.gz.sig CHANGED
Binary file