diff --git a/engines/registry/app/models/access_scope.rb b/engines/registry/app/models/access_scope.rb index f66d760ef..b15c0b17b 100644 --- a/engines/registry/app/models/access_scope.rb +++ b/engines/registry/app/models/access_scope.rb @@ -94,7 +94,7 @@ def allowed_paths(system = nil) } allowed_non_free_product_classes.each do |non_free_prod_class| activation_state = SccProxy.scc_check_subscription_expiration( - auth_header, system.login, system.system_token, system.proxy_byos_mode, non_free_prod_class + auth_header, system, non_free_prod_class ) unless activation_state[:is_active] Rails.logger.info( diff --git a/engines/registry/spec/app/models/access_scope_spec.rb b/engines/registry/spec/app/models/access_scope_spec.rb index 90af1c45e..0d3c84a22 100644 --- a/engines/registry/spec/app/models/access_scope_spec.rb +++ b/engines/registry/spec/app/models/access_scope_spec.rb @@ -215,20 +215,15 @@ allow(SccProxy).to receive(:scc_check_subscription_expiration) .with( header_expected, - system.login, - system.system_token, - system.proxy_byos_mode, + system, 'SLES15-SP4-LTSS-X86' ).and_return(scc_response) end - # rubocop:disable RSpec/ExampleLength it 'returns no actions allowed' do expect(SccProxy).to receive(:scc_check_subscription_expiration).with( header_expected, - system.login, - system.system_token, - system.proxy_byos_mode, + system, 'SLES15-SP4-LTSS-X86' ) yaml_string = access_policy_content @@ -248,7 +243,6 @@ } ) end - # rubocop:enable RSpec/ExampleLength end end diff --git a/engines/scc_proxy/lib/scc_proxy/engine.rb b/engines/scc_proxy/lib/scc_proxy/engine.rb index ac6d5da56..e3faad42e 100644 --- a/engines/scc_proxy/lib/scc_proxy/engine.rb +++ b/engines/scc_proxy/lib/scc_proxy/engine.rb @@ -201,16 +201,16 @@ def parse_error(error_message, token = nil, email = nil) error_message end - def get_scc_activations(headers, system_token, mode, login) + def get_scc_activations(headers, system) auth = headers['HTTP_AUTHORIZATION'] if headers && headers.include?('HTTP_AUTHORIZATION') uri = URI.parse(SYSTEMS_ACTIVATIONS_URL) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true - uri.query = URI.encode_www_form({ byos_mode: mode }) - scc_request = Net::HTTP::Get.new(uri.path, headers(auth, system_token)) + uri.query = URI.encode_www_form({ byos_mode: system.proxy_byos_mode }) + scc_request = Net::HTTP::Get.new(uri.path, headers(auth, system.system_token)) response = http.request(scc_request) unless response.code_type == Net::HTTPOK - Rails.logger.info "Could not get the system (#{login}) activations, error: #{response.message} #{response.code}" + Rails.logger.info "Could not get the system (#{system.login}) activations, error: #{response.message} #{response.code}" raise ActionController::TranslatedError.new(response.body) end JSON.parse(response.body) @@ -271,10 +271,8 @@ def activations_fail_state(scc_systems_activations, headers, product = nil) end end - def scc_check_subscription_expiration(headers, login, system_token, mode, product = nil) - scc_systems_activations = SccProxy.get_scc_activations( - headers, system_token, mode, login - ) + def scc_check_subscription_expiration(headers, system, product = nil) + scc_systems_activations = SccProxy.get_scc_activations(headers, system) return { is_active: false, message: 'No activations.' } if scc_systems_activations.empty? no_status_products_ids = scc_systems_activations.map do |act| @@ -443,9 +441,7 @@ def scc_deactivate_product elsif @system.hybrid? && @product.extension? # check if product is on SCC and # if it is -> de-activate it - scc_hybrid_system_activations = SccProxy.get_scc_activations( - headers, @system.system_token, @system.proxy_byos_mode, @system.login - ) + scc_hybrid_system_activations = SccProxy.get_scc_activations(headers, @system) if scc_hybrid_system_activations.map { |act| act['service']['product']['id'] == @product.id }.present? # if product is found on SCC, regardless of the state # it is OK to remove it from SCC diff --git a/engines/zypper_auth/lib/zypper_auth/engine.rb b/engines/zypper_auth/lib/zypper_auth/engine.rb index 915d20683..d5622f994 100644 --- a/engines/zypper_auth/lib/zypper_auth/engine.rb +++ b/engines/zypper_auth/lib/zypper_auth/engine.rb @@ -50,9 +50,7 @@ def verify_instance(request, logger, system) end def handle_scc_subscription(request, system, verification_provider) - result = SccProxy.scc_check_subscription_expiration( - request.headers, system.login, system.system_token, system.proxy_byos_mode - ) + result = SccProxy.scc_check_subscription_expiration(request.headers, system) return true if result[:is_active] ZypperAuth.zypper_auth_message(request, system, verification_provider, result[:message]) diff --git a/engines/zypper_auth/spec/requests/strict_authentication/authentication_controller_spec.rb b/engines/zypper_auth/spec/requests/strict_authentication/authentication_controller_spec.rb index 2a3ed4084..f0ab69371 100644 --- a/engines/zypper_auth/spec/requests/strict_authentication/authentication_controller_spec.rb +++ b/engines/zypper_auth/spec/requests/strict_authentication/authentication_controller_spec.rb @@ -245,20 +245,16 @@ before do stub_request(:get, scc_systems_activations_url).to_return(status: 200, body: [body_active].to_json, headers: {}) - # allow(SccProxy).to receive(:get_scc_activations).and_return(status: 200, body: [body_active].to_json, headers: {}) expect(URI).to receive(:encode_www_form).with({ byos_mode: 'hybrid' }) allow(File).to receive(:directory?).and_return(true) allow(Dir).to receive(:mkdir) allow(FileUtils).to receive(:touch) - # get '/api/auth/check', headers: headers end it 'returns true' do result = SccProxy.scc_check_subscription_expiration( headers, - system_hybrid.login, - system_hybrid.system_token, - system_hybrid.proxy_byos_mode, + system_hybrid, system_hybrid.activations.first.product.product_class + '-LTSS' ) expect(result[:is_active]).to be(true) @@ -297,9 +293,7 @@ it 'returns false, expired' do result = SccProxy.scc_check_subscription_expiration( headers, - system_hybrid.login, - system_hybrid.system_token, - system_hybrid.proxy_byos_mode, + system_hybrid, system_hybrid.activations.first.product.product_class + '-LTSS' ) expect(result[:is_active]).to eq(false) @@ -339,9 +333,7 @@ it 'returns product not activated' do result = SccProxy.scc_check_subscription_expiration( headers, - system_hybrid.login, - system_hybrid.system_token, - system_hybrid.proxy_byos_mode, + system_hybrid, system_hybrid.activations.first.product.product_class + '-LTSS' ) expect(result[:is_active]).to eq(false) @@ -381,9 +373,7 @@ it 'returns unexpected error' do result = SccProxy.scc_check_subscription_expiration( headers, - system_hybrid.login, - system_hybrid.system_token, - system_hybrid.proxy_byos_mode, + system_hybrid, system_hybrid.activations.first.product.product_class + '-LTSS' ) expect(result[:is_active]).to eq(false)