Skip to content

Commit 8fd5810

Browse files
committed
swagger parser updated for the new security obj
1 parent c5252f3 commit 8fd5810

4 files changed

Lines changed: 42 additions & 8 deletions

File tree

lib/3scale_toolbox/commands/import_command/openapi/update_service_oidc_conf_step.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def add_flow_settings(settings)
2929
# only applies to oauth2 sec type
3030
return if api_spec.security.nil? || api_spec.security[:type] != 'oauth2'
3131

32-
settings.merge!(api_spec.security[:flows])
32+
settings.merge!(api_spec.security[:flows] || {})
3333
end
3434
end
3535
end

lib/3scale_toolbox/openapi/swagger.rb

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ module OpenAPI
2121
# * :type -> string
2222
# * :name -> string
2323
# * :in_f -> string
24-
# * :flow -> symbol (:implicit_flow_enabled, :direct_access_grants_enabled, :service_accounts_enabled, :standard_flow_enabled)
24+
# * :flows -> hash
25+
# * :implicit_flow_enabled -> bool
26+
# * :direct_access_grants_enabled -> bool
27+
# * :service_accounts_enabled -> bool
28+
# * :standard_flow_enabled -> bool
2529
# * :scopes -> array of string
2630
# * Swagger.service_backend_version -> string ('1','2','oidc')
2731
# * Swagger.set_server_url -> def(spec, url)
@@ -150,7 +154,7 @@ def parse_global_security_reqs
150154
type: sec_def['type'],
151155
name: sec_def['name'],
152156
in_f: sec_def['in'],
153-
flow: convert_flow(sec_def['flow']),
157+
flows: parse_flows(sec_def['flow']),
154158
scopes: sec_item
155159
}
156160
end
@@ -171,6 +175,21 @@ def security_definitions
171175
raw['securityDefinitions'] || {}
172176
end
173177

178+
def parse_flows(flow_name)
179+
return nil if flow_name.nil?
180+
181+
basic_flows_object.merge!({ convert_flow(flow_name) => true })
182+
end
183+
184+
def basic_flows_object
185+
{
186+
standard_flow_enabled: false,
187+
implicit_flow_enabled: false,
188+
service_accounts_enabled: false,
189+
direct_access_grants_enabled: false
190+
}
191+
end
192+
174193
def convert_flow(flow_name)
175194
return nil if flow_name.nil?
176195

spec/unit/commands/import_command/openapi/update_service_oidc_conf_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@
6565

6666
let(:security) { { id: 'oidc', type: 'oauth2', flows: flows } }
6767

68+
context 'no flows' do
69+
let(:flows) { nil }
70+
71+
it 'service is not updated' do
72+
# if service.update_oidc is called, this test should fail
73+
subject
74+
end
75+
end
76+
6877
context 'flow implicit' do
6978
let(:flows) { basic_empty_flow.merge(implicit_flow_enabled: true) }
7079
let(:expected_implicit_flow) { true }

spec/unit/openapi/swagger_spec.rb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
let(:validate) { true }
66
subject { described_class.build(raw_specification, validate: validate) }
77
let(:content) { basic_swagger_content }
8+
let(:basic_empty_flow) do
9+
{
10+
standard_flow_enabled: false, implicit_flow_enabled: false,
11+
service_accounts_enabled: false, direct_access_grants_enabled: false
12+
}
13+
end
814

915
context 'missing info' do
1016
let(:content) do
@@ -217,7 +223,7 @@
217223
end
218224

219225
it 'flow matches' do
220-
expect(subject.security[:flow]).to be_nil
226+
expect(subject.security[:flows]).to be_nil
221227
end
222228

223229
it 'scopes matches' do
@@ -249,7 +255,7 @@
249255
end
250256

251257
it 'flow matches' do
252-
expect(subject.security[:flow]).to be(:implicit_flow_enabled)
258+
expect(subject.security[:flows]).to eq(basic_empty_flow.merge(implicit_flow_enabled: true))
253259
end
254260

255261
it 'scopes matches' do
@@ -281,7 +287,7 @@
281287
end
282288

283289
it 'flow matches' do
284-
expect(subject.security[:flow]).to be(:direct_access_grants_enabled)
290+
expect(subject.security[:flows]).to eq(basic_empty_flow.merge(direct_access_grants_enabled: true))
285291
end
286292

287293
it 'scopes matches' do
@@ -313,7 +319,7 @@
313319
end
314320

315321
it 'flow matches' do
316-
expect(subject.security[:flow]).to be(:service_accounts_enabled)
322+
expect(subject.security[:flows]).to eq(basic_empty_flow.merge(service_accounts_enabled: true))
317323
end
318324

319325
it 'scopes matches' do
@@ -345,7 +351,7 @@
345351
end
346352

347353
it 'flow matches' do
348-
expect(subject.security[:flow]).to be(:standard_flow_enabled)
354+
expect(subject.security[:flows]).to eq(basic_empty_flow.merge(standard_flow_enabled: true))
349355
end
350356

351357
it 'scopes matches' do

0 commit comments

Comments
 (0)