Skip to content

Commit

Permalink
Merge branch 'SLE-15-SP3' into merge-SLE-15-SP3
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Jan 20, 2022
2 parents c6a01a0 + 66682fd commit fddb9ca
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 53 deletions.
7 changes: 7 additions & 0 deletions package/autoyast2.changes
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Thu Jan 20 07:58:35 UTC 2022 - Imobach Gonzalez Sosa <igonzalezsosa@suse.com>

- Fix handling of add-on signature settings, introduced when fixing
bsc#1192437 (bsc#1194881).
- 4.4.26

-------------------------------------------------------------------
Thu Jan 13 11:58:37 UTC 2022 - Imobach Gonzalez Sosa <igonzalezsosa@suse.com>

Expand Down
2 changes: 1 addition & 1 deletion package/autoyast2.spec
Expand Up @@ -22,7 +22,7 @@
%endif

Name: autoyast2
Version: 4.4.25
Version: 4.4.26
Release: 0
Summary: YaST2 - Automated Installation
License: GPL-2.0-only
Expand Down
33 changes: 10 additions & 23 deletions src/lib/autoinstall/pkg_gpg_check_handler.rb
Expand Up @@ -31,12 +31,13 @@ class PkgGpgCheckHandler
# @option data [String] "Localpath" Path to RPM file.
# @option data [String] "RepoMediaUrl" Media URL.
# (it should match `media_url` key in AutoYaST profile).
# @param [Hash] profile AutoYaST profile.
def initialize(data, profile)
# @param signature_handling [Hash] Signature handling settings (from AutoYaST general section)
# @param addons [Array<Hash>] Defined add-ons to check for signature settings
def initialize(data, signature_handling = {}, addons = [])
@result = data["CheckPackageResult"]
@package = data["Package"]
@path = data["Localpath"]
@config = get_addon_config(profile, data["RepoMediaUrl"])
@config = get_addon_config(signature_handling, addons, data["RepoMediaUrl"])
log.info format("Signature handling settings: #{@config}")
end

Expand Down Expand Up @@ -143,27 +144,13 @@ def handle_error
# If the add-on has its own specific configuration, those settings
# will override to general settings.
#
# @param [Yast::ProfileHash] profile AutoYaST profile
# @param signature_handling [Hash] General signature handling options
# @param addons [Array<Hash>] List of add-ons
# @param [String] url Repository URL
# @return [Yast::ProfileHash] Signature handling settings for the given add-on.
def get_addon_config(profile, url)
config = addons_config(profile).find { |c| c["media_url"] == url }
addon_config = Yast::ProfileHash.new(config || {})

general_config = profile.fetch_as_hash("general")
general_config.fetch_as_hash("signature-handling")
.merge(addon_config.fetch_as_hash("signature-handling"))
end

# Get add-ons configuration
#
# This is just a helper method that returns the //add-ons/add_on_products section
# of an AutoYaST profile.
#
# @param [Yast::ProfileHash] profile AutoYaST profile.
# @return [Array<Hash>] Add-ons section from profile.
def addons_config(profile)
profile.fetch_as_hash("add-on").fetch_as_array("add_on_products")
# @return [Hash] Signature handling settings for the given add-on.
def get_addon_config(signature_handling, addons, url)
addon_config = addons.find { |a| a["media_url"] == url } || {}
signature_handling.merge(addon_config.fetch("signature-handling", {}))
end

# Find the key ID for the package
Expand Down
9 changes: 7 additions & 2 deletions src/modules/AutoInstall.rb
Expand Up @@ -22,8 +22,10 @@ def main
Yast.import "Profile"
Yast.import "Mode"
Yast.import "Stage"
Yast.import "AutoinstConfig"
Yast.import "AutoInstallRules"
Yast.import "AutoinstConfig"
Yast.import "AutoinstGeneral"
Yast.import "AddOnProduct"
Yast.import "Report"
Yast.import "TFTP"

Expand Down Expand Up @@ -334,7 +336,10 @@ def PXELocalBoot
# a blank string is returned (so no decision is made).
def pkg_gpg_check(data)
log.debug("pkgGpgCheck data: #{data}")
accept = PkgGpgCheckHandler.new(data, Profile.current).accept?
checker = PkgGpgCheckHandler.new(
data, Yast::AutoinstGeneral.signature_handling, Yast::AddOnProduct.add_on_products
)
accept = checker.accept?
log.info("PkgGpgCheckerHandler for #{data["Package"]} returned #{accept}")
accept ? "I" : ""
end
Expand Down
8 changes: 5 additions & 3 deletions test/AutoInstall_test.rb
Expand Up @@ -24,12 +24,14 @@ def self.new_from_hashes(_hash)

describe "#pkg_gpg_check" do
let(:data) { { "CheckPackageResult" => Yast::PkgGpgCheckHandler::CHK_OK } }
let(:profile) { {} }
let(:checker) { double("checker") }
let(:signature_handling) { { "accept_unsigned_file" => true } }

before do
allow(Yast::Profile).to receive(:current).and_return(profile)
allow(Yast::PkgGpgCheckHandler).to receive(:new).with(data, profile).and_return(checker)
allow(Yast::AutoinstGeneral).to receive(:signature_handling)
.and_return(signature_handling)
allow(Yast::PkgGpgCheckHandler).to receive(:new)
.with(data, signature_handling, []).and_return(checker)
allow(checker).to receive(:accept?).and_return(accept?)
end

Expand Down
42 changes: 18 additions & 24 deletions test/lib/pkg_gpg_check_handler_test.rb
Expand Up @@ -8,7 +8,9 @@
Yast.import "Profile"

describe Yast::PkgGpgCheckHandler do
subject(:handler) { Yast::PkgGpgCheckHandler.new(data, profile) }
subject(:handler) do
Yast::PkgGpgCheckHandler.new(data, signature_handling, addons)
end

let(:data) do
Yast::ProfileHash.new(
Expand All @@ -19,10 +21,8 @@
)
end
let(:result) { Yast::PkgGpgCheckHandler::CHK_OK }
let(:profile) do
Yast::ProfileHash.new("general" => { "signature-handling" => signature_handling })
end
let(:signature_handling) { {} }
let(:addons) { [] }

describe "#accept?" do
context "when signature is OK" do
Expand Down Expand Up @@ -212,8 +212,8 @@
end
end

# Using '<all>' element in profile instead of just 'true'.
context "and all packages with non trusted keys are allowed" do
# Using '<all>' element in profile instead of just 'true'.
let(:signature_handling) { { "accept_non_trusted_gpg_key" => { "all" => true } } }

it "returns true" do
Expand Down Expand Up @@ -270,24 +270,16 @@
context "when the add-on has specific settings" do
let(:result) { Yast::PkgGpgCheckHandler::CHK_NOTFOUND }

let(:profile) do
Yast::ProfileHash.new(
"general" => {
"signature-handling" => {
"accept_unsigned_file" => true,
"accept_unknown_gpg_key" => true
}
},
"add-on" => {
"add_on_products" => [
{
"media_url" => "http://dl.opensuse.org/repos/YaST:/Head",
"name" => "yast_head",
"signature-handling" => { "accept_unsigned_file" => false }
}
]
}
)
let(:signature_handling) do
{ "accept_unsigned_file" => true, "accept_unknown_gpg_key" => true }
end

let(:addons) do
[
{ "media_url" => "http://dl.opensuse.org/repos/YaST:/Head",
"name" => "yast_head",
"signature-handling" => { "accept_unsigned_file" => false } }
]
end

it "honors the add-on settings" do
Expand All @@ -296,7 +288,9 @@

it "honors general settings which are not overridden" do
gpg_handler = Yast::PkgGpgCheckHandler.new(
data.merge("CheckPackageResult" => Yast::PkgGpgCheckHandler::CHK_NOKEY), profile
data.merge("CheckPackageResult" => Yast::PkgGpgCheckHandler::CHK_NOKEY),
signature_handling,
addons
)
expect(gpg_handler.accept?).to eq(true)
end
Expand Down

0 comments on commit fddb9ca

Please sign in to comment.