Skip to content

Commit

Permalink
Merge eb2e16b into 70d6da0
Browse files Browse the repository at this point in the history
  • Loading branch information
wfeldt committed Oct 26, 2022
2 parents 70d6da0 + eb2e16b commit 060dfbb
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 7 deletions.
6 changes: 6 additions & 0 deletions package/yast2-packager.changes
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Tue Oct 25 10:20:48 UTC 2022 - Steffen Winterfeldt <snwint@suse.com>

- support 'repo' scheme for add-ons (jsc#SLE-22578, jsc#SLE-24584)
- 4.5.6

-------------------------------------------------------------------
Thu May 26 12:40:24 UTC 2022 - Ladislav Slezák <lslezak@suse.cz>

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-packager.spec
Expand Up @@ -17,7 +17,7 @@


Name: yast2-packager
Version: 4.5.5
Version: 4.5.6
Release: 0
Summary: YaST2 - Package Library
License: GPL-2.0-or-later
Expand Down
40 changes: 34 additions & 6 deletions src/modules/AddOnProduct.rb
Expand Up @@ -5,6 +5,8 @@
require "packager/product_patterns"
require "y2packager/resolvable"
require "y2packager/repository"
require "uri"
require "yast2/rel_url"

# Yast namespace
module Yast
Expand Down Expand Up @@ -388,23 +390,49 @@ def GetBaseProductURL
end

# Returns an absolute URL from base + relative url.
# Relative URL needs to start with 'reulrl://' othewise
# it is not considered being relative and it's returned
# as it is (just the relative_url parameter).
#
# Relative URL needs to start with 'relurl://' or 'repo:/', otherwise it
# is not considered being relative and it's returned as it is (just the
# relative_url parameter).
#
# 'repo' URLs are resolved relative to the installation medium, not base_url.
#
# @param [String] base_url
# @param [String] url URL relative to the base
# @param [String] url URL relative to base_url resp. installation medium
#
# @example
# AddOnProduct::GetAbsoluteURL (
# "http://www.example.org/some%20dir/another%20dir",
# "relurl://../AnotherProduct/"
# ) -> "http://www.example.org/some%20dir/AnotherProduct/"
#
# AddOnProduct::GetAbsoluteURL (
# "username:password@ftp://www.example.org/dir/",
# "ftp://username:password@www.example.org/dir/",
# "relurl://./Product_CD1/"
# ) -> "username:password@ftp://www.example.org/dir/Product_CD1/"
# ) -> "ftp://username:password@www.example.org/dir/Product_CD1/"
#
# with /etc/install.inf containing the line 'ZyppRepoURL: hd:/?device=/dev/sda'
# AddOnProduct::GetAbsoluteURL (
# "ftp://username:password@www.example.org/dir/",
# "repo:/Product_CD1"
# ) -> "hd:/Product_CD1?device=/dev/sda"
def GetAbsoluteURL(base_url, url)
url_parsed = URI(url)

if url_parsed.scheme == "repo"
base_url = InstURL.installInf2Url("")
if base_url.empty?
log.error "no ZyppRepoURL in /etc/install.inf"
else
rel_url = "relurl:" + url_parsed.path
url = Yast2::RelURL.from_installation_repository(rel_url).absolute_url.to_s
log.info("base url + relative path: #{URL.HidePassword(base_url)} + #{url_parsed.path}")
log.info("absolute url: #{URL.HidePassword(url)}")
end

return url
end

if !Builtins.regexpmatch(url, "^relurl://")
Builtins.y2debug("Not a relative URL: %1", URL.HidePassword(url))
return url
Expand Down
42 changes: 42 additions & 0 deletions test/addon_product_test.rb
Expand Up @@ -793,4 +793,46 @@
end
end
end

describe "#GetAbsoluteURL" do
it "resolves a relurl with .." do
base = "http://www.example.org/some%20dir/another%20dir"
rel = "relurl://../AnotherProduct/"
expect(subject.GetAbsoluteURL(base, rel))
.to eq "http://www.example.org/some%20dir/AnotherProduct/"
end

it "resolves a relurl, with a misleading non-ftp base" do
# scheme: username
# opaque: password@ftp://www.example.org/dir/
base = "username:password@ftp://www.example.org/dir/"
rel = "relurl://./Product_CD1/"
expect(subject.GetAbsoluteURL(base, rel))
.to eq "username:password@ftp://www.example.org/dir/Product_CD1/"
end

it "resolves a relurl, preserving user:pass" do
base = "ftp://username:password@www.example.org/dir/"
rel = "relurl://./Product_CD1/"
expect(subject.GetAbsoluteURL(base, rel))
.to eq "ftp://username:password@www.example.org/dir/Product_CD1/"
end

it "resolves a repo:, ignoring base_url, using InstURL, masking password" do
base = "urn:whatever"
rel = "repo:/foo.xml"
inst_url = "ftp://username:password@www.example.org/dir/"
expected = "ftp://username:password@www.example.org/dir/foo.xml"

expect(Yast::InstURL).to receive(:installInf2Url).with("").and_return(inst_url)

expect(Yast2::RelURL).to receive(:from_installation_repository)
.with("relurl:/foo.xml")
.and_return(double(absolute_url: expected))
expect(subject.log).to receive(:info).with(/base url.*PASSWORD/)
expect(subject.log).to receive(:info).with(/absolute url.*PASSWORD/)
expect(subject.GetAbsoluteURL(base, rel))
.to eq expected
end
end
end

0 comments on commit 060dfbb

Please sign in to comment.