Skip to content

Commit

Permalink
Allow extension no CSP specific
Browse files Browse the repository at this point in the history
Prepare the condition for any CSPs

Rename method to be generic
  • Loading branch information
jesusbv committed Nov 21, 2024
1 parent 50d74dc commit 91552ef
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ def payg_billing_code?(iid, identifier)
return true if (identifier.casecmp('sles_sap').zero? && SLES4SAP_PRODUCT_IDENTIFIER.include?(instance_billing_info[:marketplace_code]))
end

def basic?
false
def allowed_extension?
# method to check if a product (extension) meet the criteria
# to be acivated on SCC or not, i.e. LTSS in Azure Basic VM
true
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

it 'class instance verification provider' do
expect(InstanceVerification::Providers::Example).to receive(:new)
.with(be_a(ActiveSupport::Logger), be_a(ActionDispatch::Request), payload, nil).and_call_original
.with(be_a(ActiveSupport::Logger), be_a(ActionDispatch::Request), payload, nil).and_call_original.at_least(:once)
allow(File).to receive(:directory?)
allow(Dir).to receive(:mkdir)
allow(FileUtils).to receive(:touch)
Expand Down Expand Up @@ -71,13 +71,17 @@
end

context 'when verification provider returns false' do
# let(:plugin_double) { instance_double('InstanceVerification::Providers::Example') }

before do
stub_request(:post, scc_activate_url)
.to_return(
status: 200,
body: { error: 'Unexpected instance verification error has occurred' }.to_json,
headers: {}
)
)
# allow(InstanceVerification::Providers::Example).to receive(:new).and_return(plugin_double)
# allow(plugin_double).to receive(:allowed_extension?).and_return(true)
post url, params: payload, headers: headers
end

Expand Down Expand Up @@ -113,7 +117,7 @@

it 'class instance verification provider' do
expect(InstanceVerification::Providers::Example).to receive(:new)
.with(be_a(ActiveSupport::Logger), be_a(ActionDispatch::Request), payload, nil).and_call_original
.with(be_a(ActiveSupport::Logger), be_a(ActionDispatch::Request), payload, nil).and_call_original.at_least(:once)
allow(File).to receive(:directory?)
allow(Dir).to receive(:mkdir)
allow(FileUtils).to receive(:touch)
Expand All @@ -123,7 +127,7 @@

context 'when system has hw_info' do
let(:instance_data) { 'dummy_instance_data' }
let(:system) { FactoryBot.create(:system, :payg, :with_system_information_az, instance_data: instance_data) }
let(:system) { FactoryBot.create(:system, :payg, :with_system_information, instance_data: instance_data) }
let(:serialized_service_json) do
V3::ServiceSerializer.new(
product.service,
Expand Down Expand Up @@ -188,7 +192,7 @@
let(:instance_data) { 'dummy_instance_data' }
let(:system) do
FactoryBot.create(
:system, :payg, :with_system_information_az, :with_activated_product, product: base_product, instance_data: instance_data
:system, :payg, :with_system_information, :with_activated_product, product: base_product, instance_data: instance_data
)
end
let(:serialized_service_json) do
Expand Down Expand Up @@ -340,8 +344,9 @@

before do
allow(InstanceVerification::Providers::Example).to receive(:new)
.with(nil, nil, nil, instance_data).and_return(plugin_double)
.and_return(plugin_double)
allow(plugin_double).to receive(:parse_instance_data).and_return({ InstanceId: 'foo' })
allow(plugin_double).to receive(:allowed_extension?).and_return(true)

allow(InstanceVerification).to receive(:update_cache).with('127.0.0.1', system.login, product.id)
FactoryBot.create(:subscription, product_classes: product_classes)
Expand Down Expand Up @@ -380,8 +385,9 @@

before do
allow(InstanceVerification::Providers::Example).to receive(:new)
.with(nil, nil, nil, instance_data).and_return(plugin_double)
.and_return(plugin_double)
allow(plugin_double).to receive(:parse_instance_data).and_return({ InstanceId: 'foo' })
allow(plugin_double).to receive(:allowed_extension?).and_return(true)

allow(InstanceVerification).to receive(:update_cache).with('127.0.0.1', system.login, product.id)
FactoryBot.create(:subscription, product_classes: product_classes)
Expand Down Expand Up @@ -414,7 +420,7 @@

it 'class instance verification provider' do
expect(InstanceVerification::Providers::Example).to receive(:new)
.with(be_a(ActiveSupport::Logger), be_a(ActionDispatch::Request), payload, nil).and_call_original
.and_call_original.at_least(:once)
allow(File).to receive(:directory?)
allow(Dir).to receive(:mkdir)
allow(FileUtils).to receive(:touch)
Expand Down Expand Up @@ -514,8 +520,9 @@

before do
allow(InstanceVerification::Providers::Example).to receive(:new)
.with(nil, nil, nil, instance_data).and_return(plugin_double)
.and_return(plugin_double)
allow(plugin_double).to receive(:parse_instance_data).and_return({ InstanceId: 'foo' })
allow(plugin_double).to receive(:allowed_extension?).and_return(true)

FactoryBot.create(:subscription, product_classes: product_classes)
stub_request(:post, scc_activate_url)
Expand Down
7 changes: 2 additions & 5 deletions engines/scc_proxy/lib/scc_proxy/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -373,11 +373,8 @@ def has_no_regcode?(auth_header)
protected

def scc_activate_product
if (@system.system_information &&
JSON.parse(@system.system_information)['cloud_provider'].casecmp('microsoft').zero? &&
@product.product_class.downcase.include?('ltss') &&
InstanceVerification.provider.new(logger, request, nil, @system.instance_data).basic?
)
product_hash = @product.attributes.symbolize_keys.slice(:identifier, :version, :arch)
unless InstanceVerification.provider.new(logger, request, product_hash, @system.instance_data).allowed_extension?
error = ActionController::TranslatedError.new(N_('Product not supported for this instance'))
error.status = :forbidden
raise error
Expand Down

0 comments on commit 91552ef

Please sign in to comment.