Skip to content

Commit

Permalink
Merge pull request #99 from yast/skip-registered-add-ons
Browse files Browse the repository at this point in the history
Do not export registered add-ons
  • Loading branch information
imobachgs authored Jul 19, 2020
2 parents 184ec0e + 223db0d commit c503f65
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 10 deletions.
7 changes: 7 additions & 0 deletions package/yast2-add-on.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Thu Jul 16 10:17:01 UTC 2020 - Imobach Gonzalez Sosa <igonzalezsosa@suse.com>

- Do not export registered add-ons, as they should be included
in the <suse_register/> section of the profile (bsc#1174202).
- 4.3.2

-------------------------------------------------------------------
Wed Jun 10 14:04:00 UTC 2020 - Josef Reidinger <jreidinger@suse.com>

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-add-on.spec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


Name: yast2-add-on
Version: 4.3.1
Version: 4.3.2
Release: 0
Summary: YaST2 - Add-On media installation code
License: GPL-2.0-only
Expand Down
59 changes: 53 additions & 6 deletions src/modules/AddOnOthers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,65 @@ def Read
# </add_on_others>
# </add-on>
def Export
others = @add_on_others.map do |p|
{ "media_url" => p["url"],
"alias" => p["alias"],
"priority" => p["priority"],
"name" => p["name"],
"product_dir" => p["product_dir"] }
others = @add_on_others.each_with_object([]) do |addon, all|
next if registered_addon?(addon)

all << {
"media_url" => addon["url"],
"alias" => addon["alias"],
"priority" => addon["priority"],
"name" => addon["name"],
"product_dir" => addon["product_dir"]
}
end
{ "add_on_others" => others }
end

publish function: :Export, type: "map ()"
publish function: :Read, type: "map()"

private

# Determine whether an addon corresponds to a registered product
#
# @param addon [Hash] Addon data
# @return [Boolean]
def registered_addon?(addon)
return false unless addon["url"]

url = normalize_url(addon["url"])
registered_repositories_urls.include?(url)
end

# Returns the URLs corresponding to registered products repositories
#
# @return [Array<URI>]
def registered_repositories_urls
return @registered_repositories_urls if @registered_repositories_urls

begin
require "registration/registration"
rescue LoadError
return []
end
activated_products = Registration::Registration.new.activated_products
repositories = activated_products.map(&:repositories).flatten
@registered_repositories_urls = repositories.map { |r| normalize_url(r["url"]) }
end

# Normalizes the URL to make the comparison easier
#
# It removes the query, the fragment and the trailing '/' character is found.
#
# @param url [URI,String] URL to normalize
# @return [URI]
def normalize_url(url)
uri = URI(url)
uri.fragment = nil
uri.query = nil
uri.path = uri.path.delete_suffix("/")
uri
end
end

AddOnOthers = AddOnOthersClass.new
Expand Down
37 changes: 34 additions & 3 deletions test/addon_others_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

let(:repo_hash) do
{ "alias" => "user defined",
"url" => "http://xxx.url",
"url" => "http://xxx.url?foo=bar",
"name" => "user_defined",
"priority" => 19,
"product_dir" => "/" }
Expand All @@ -57,6 +57,8 @@
.and_return(installed_products)
allow(Yast::Pkg).to receive(:SourceGetCurrent).with(true)
.and_return([0, 1, 2, 3, 4])
allow(subject).to receive(:require).with("registration/registration")
.and_raise(LoadError)
end

describe "#Read" do
Expand All @@ -72,7 +74,6 @@
end

describe "#Export" do

context "installed products and add-ons are available" do
let(:ret) do
{ "media_url" => repo_hash["url"],
Expand All @@ -82,12 +83,42 @@
"product_dir" => repo_hash["product_dir"] }
end

it "returns an array of user defined repos in AY format" do
before do
allow(Yast::Pkg).to receive(:SourceGeneralData).with(4)
.and_return(repo_hash)
end

it "returns an array of user defined repos in AY format" do
Yast::AddOnOthers.Read()
expect(Yast::AddOnOthers.Export).to eq("add_on_others" => [ret])
end

context "when an add-on is registered" do
let(:registration_module) do
double("Registration::Registration", new: registration)
end

let(:registration) do
instance_double("Registration::Registration", activated_products: [product])
end

let(:product) do
double("SUSE::Connect::Remote::Product", repositories: [scc_repo])
end

let(:scc_repo) do
{ "url" => "http://xxx.url" }
end

before do
allow(subject).to receive(:require).with("registration/registration")
stub_const("Registration::Registration", registration_module)
end

it "does not export such an addon" do
expect(Yast::AddOnOthers.Export).to eq("add_on_others" => [])
end
end
end
end
end

0 comments on commit c503f65

Please sign in to comment.