Skip to content

Commit fe2c583

Browse files
authored
Merge pull request #1015 from SUSE/use-headers-metadata
Use headers metadata
2 parents 7229597 + bc65f4b commit fe2c583

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

engines/scc_suma_api/app/controllers/scc_suma_api/scc_suma_api_controller.rb

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
require 'base64'
12
require 'json'
23

34
module SccSumaApi
@@ -33,11 +34,17 @@ def scc_client
3334
end
3435

3536
def is_valid?
37+
instance_data = Base64.decode64(request.headers['X-Instance-Data'].to_s)
38+
product_hash = {
39+
identifier: request.headers['X-INSTANCE-IDENTIFIER'],
40+
version: request.headers['X-INSTANCE-VERSION'],
41+
arch: request.headers['X-INSTANCE-ARCH']
42+
}
3643
verification_provider = InstanceVerification.provider.new(
3744
logger,
3845
request,
39-
params.permit(:identifier, :version, :arch, :release_type).to_h,
40-
params[:metadata]
46+
product_hash,
47+
instance_data
4148
)
4249
raise 'Unspecified error' unless verification_provider.instance_valid?
4350
end

engines/scc_suma_api/spec/requests/scc_suma_api/scc_suma_api_controller_spec.rb

+7-5
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ module SccSumaApi
1313
let(:product) { FactoryBot.create(:product, :product_sles_sap, :with_mirrored_repositories, :with_mirrored_extensions) }
1414
let(:payload) do
1515
{
16-
identifier: product.identifier,
17-
version: product.version,
18-
arch: product.arch
16+
'X-INSTANCE-IDENTIFIER' => product.identifier,
17+
'X-INSTANCE-VERSION' => product.version,
18+
'X-INSTANCE-ARCH' => product.arch
1919
}
2020
end
2121
let(:logger) { instance_double('RMT::Logger').as_null_object }
@@ -37,6 +37,8 @@ module SccSumaApi
3737
file_fixture('products/dummy_products.json'),
3838
Rails.root.join('tmp/unscoped_products.json')
3939
)
40+
41+
get '/api/scc/unscoped-products', headers: payload
4042
end
4143

4244
after { File.delete(unscoped_file) if File.exist?(unscoped_file) }
@@ -52,7 +54,7 @@ module SccSumaApi
5254

5355
context 'endpoints return unscoped products' do
5456
before do
55-
get '/api/scc/unscoped-products', params: payload
57+
get '/api/scc/unscoped-products', headers: payload
5658
end
5759

5860
its(:code) { is_expected.to eq '200' }
@@ -71,7 +73,7 @@ module SccSumaApi
7173
allow(RMT::Logger).to receive(:new).and_return(logger)
7274
File.delete(unscoped_file) if File.exist?(unscoped_file)
7375

74-
get '/api/scc/unscoped-products', params: payload
76+
get '/api/scc/unscoped-products', headers: payload
7577
end
7678

7779
its(:code) { is_expected.to eq '200' }

0 commit comments

Comments
 (0)