Skip to content

Commit

Permalink
Merge pull request #1015 from SUSE/use-headers-metadata
Browse files Browse the repository at this point in the history
Use headers metadata
  • Loading branch information
digitaltom authored Jul 6, 2023
2 parents 7229597 + bc65f4b commit fe2c583
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'base64'
require 'json'

module SccSumaApi
Expand Down Expand Up @@ -33,11 +34,17 @@ def scc_client
end

def is_valid?
instance_data = Base64.decode64(request.headers['X-Instance-Data'].to_s)
product_hash = {
identifier: request.headers['X-INSTANCE-IDENTIFIER'],
version: request.headers['X-INSTANCE-VERSION'],
arch: request.headers['X-INSTANCE-ARCH']
}
verification_provider = InstanceVerification.provider.new(
logger,
request,
params.permit(:identifier, :version, :arch, :release_type).to_h,
params[:metadata]
product_hash,
instance_data
)
raise 'Unspecified error' unless verification_provider.instance_valid?
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ module SccSumaApi
let(:product) { FactoryBot.create(:product, :product_sles_sap, :with_mirrored_repositories, :with_mirrored_extensions) }
let(:payload) do
{
identifier: product.identifier,
version: product.version,
arch: product.arch
'X-INSTANCE-IDENTIFIER' => product.identifier,
'X-INSTANCE-VERSION' => product.version,
'X-INSTANCE-ARCH' => product.arch
}
end
let(:logger) { instance_double('RMT::Logger').as_null_object }
Expand All @@ -37,6 +37,8 @@ module SccSumaApi
file_fixture('products/dummy_products.json'),
Rails.root.join('tmp/unscoped_products.json')
)

get '/api/scc/unscoped-products', headers: payload
end

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

context 'endpoints return unscoped products' do
before do
get '/api/scc/unscoped-products', params: payload
get '/api/scc/unscoped-products', headers: payload
end

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

get '/api/scc/unscoped-products', params: payload
get '/api/scc/unscoped-products', headers: payload
end

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

0 comments on commit fe2c583

Please sign in to comment.