Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow SLE Micro system to access free SLES repositories #1247

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ def activate
end

def show
if @system.products.include? @product
if @product.identifier.casecmp('sles').zero?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there no positive test here we can do? It feels inefficient to say "if it's not sles maybe it's sle-micro".

# if system has SLE Micro
# it should access to SLES products
sle_micro = @system.products.any? { |p| p.identifier.downcase.include?('sle-micro') }
sle_micro_same_arch = @system.products.pluck(:arch).include?(@product.arch) if sle_micro
end
if @system.products.include?(@product) || sle_micro_same_arch
respond_with(
@product,
serializer: ::V3::ProductSerializer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ def all_allowed_paths
# to them or verify paths
all_product_versions = @system.products.map { |p| Product.where(identifier: p.identifier, arch: p.arch) }.flatten
allowed_paths = all_product_versions.map { |prod| prod.repositories.pluck(:local_path) }.flatten
# Allow SLE Micro to access all free SLES repositories
sle_micro = @system.products.any? { |p| p.identifier.downcase.include?('sle-micro') }
if sle_micro
system_products_archs = @system.products.pluck(:arch)
product_free_sles_modules_only = Product.where(
"(lower(identifier) like 'sle-module%' or lower(identifier) like 'packagehub')
and lower(identifier) not like '%sap%'
and arch = '#{system_products_archs.first}'
and free = 1"
)
end
same_arch = product_free_sles_modules_only.any? { |p| system_products_archs.include?(p.arch) } if product_free_sles_modules_only.present?
allowed_paths += product_free_sles_modules_only.map { |prod| prod.repositories.pluck(:local_path) }.flatten if same_arch

# for the SUMa PAYG offers, RMT access verification code allows access
# to the SUMa Client Tools channels and SUMa Proxy channels
# when product is SUMA_Server and PAYG or SUMA_Server and used as SCC proxy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module StrictAuthentication
RSpec.describe AuthenticationController, type: :request do
subject { response }

let(:system) { FactoryBot.create(:system, :with_activated_product) }
let(:system) { FactoryBot.create(:system, :with_activated_product_sle_micro) }

describe '#check' do
context 'without authentication' do
Expand Down Expand Up @@ -39,6 +39,36 @@ module StrictAuthentication
its(:code) { is_expected.to eq '403' }
end

context 'when requesting a file in an activated SLES repo on a SLE Micro system' do
let(:free_product) do
prod = FactoryBot.create(
:product, :module, :with_mirrored_repositories
)
prod.identifier = 'sle-module-foo'
prod.arch = system.products.first.arch
prod.save!
prod
end
let(:requested_uri) { '/repo' + free_product.repositories.first[:local_path] + '/repodata/repomd.xml' }

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

context 'when requesting a file in an activated SLES SAP repo on a SLE Micro system' do
let(:free_product) do
prod = FactoryBot.create(
:product, :module, :with_mirrored_repositories
)
prod.identifier = 'sle-module-foo-sap'
prod.arch = system.products.first.arch
prod.save!
prod
end
let(:requested_uri) { '/repo' + free_product.repositories.first[:local_path] + '/repodata/repomd.xml' }

its(:code) { is_expected.to eq '403' }
end

context 'when requesting a file in an activated repo' do
let(:requested_uri) { '/repo' + system.repositories.first[:local_path] + '/repodata/repomd.xml' }

Expand Down
16 changes: 16 additions & 0 deletions spec/factories/products.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,22 @@
friendly_version { '15 SP3' }
end

trait :product_sle_micro do
identifier { 'SLE-Micro' }
name { 'SUSE Linux Enterprise Server' }
description { 'SUSE Linux Enterprise offers a comprehensive suite of products...' }
shortname { 'SLES15-SP6' }
former_identifier { 'SUSE_SLES_MICRO' }
product_type { :base }
release_type { nil }
release_stage { 'released' }
version { '15.6' }
arch { 'x86_64' }
free { false }
cpe { 'cpe:/o:suse:sles_sap:15:sp6' }
friendly_version { '15 SP6' }
end

trait :extension do
product_type { 'extension' }
end
Expand Down
11 changes: 11 additions & 0 deletions spec/factories/systems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@
end
end

trait :with_activated_product_sle_micro do
transient do
product { create(:product, :product_sle_micro, :with_mirrored_repositories) }
subscription { nil }
end

after :create do |system, evaluator|
create(:activation, system: system, service: evaluator.product.service, subscription: evaluator.subscription)
end
end

trait :with_system_information do
system_information do
{
Expand Down
27 changes: 27 additions & 0 deletions spec/requests/api/connect/v3/systems/products_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,33 @@
end
end

context 'when SLE Micro product is activated' do
let(:system) { FactoryBot.create(:system, :with_activated_product_sle_micro) }
let(:product) { FactoryBot.create(:product, :product_sles, :with_mirrored_repositories) }
let(:payload) do
{
identifier: product.identifier,
version: product.version,
arch: system.products.first.arch
}
end
let(:serialized_json) do
V3::ProductSerializer.new(
product,
base_url: URI::HTTP.build({ scheme: response.request.scheme, host: response.request.host }).to_s
).to_json
end

describe 'response' do
subject { response }

before { get url, headers: headers, params: payload }

its(:code) { is_expected.to eq('200') }
its(:body) { is_expected.to eq(serialized_json) }
end
end

context 'with eula_url' do
subject { response }

Expand Down