Skip to content

Commit

Permalink
Merge pull request #622 from yast/pkg-gpg-check
Browse files Browse the repository at this point in the history
Handle GPG check during installation
  • Loading branch information
imobachgs committed Sep 7, 2017
2 parents c84f544 + b6c09f4 commit 15ad29f
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 1 deletion.
23 changes: 23 additions & 0 deletions library/packages/src/modules/PackageCallbacks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def main
Yast.import "Progress"
Yast.import "FileUtils"
Yast.import "SignatureCheckCallbacks"
Yast.import "Linuxrc"

@_provide_popup = false
@_package_popup = false
Expand Down Expand Up @@ -402,6 +403,24 @@ def ProgressPackage(percent)
true
end

# Handle GPG check result (pkgGpgCheck)
#
# If insecure mode is set to '1', the check result is ignored. Otherwise, no decision is made.
# When running on an installed system, it always return "".
#
# @param data [Hash] Output from `pkgGpgCheck` callback.
# @option data [Integer] "CheckPackageResult" Check result code according to libzypp.
# @option data [String] "Package" Package's name.
# @option data [String] "Localpath" Path to RPM file.
# @option data [String] "RepoMediaUrl" Media URL.
# @return [String] "I" if the package should be accepted; otherwise
# a blank string is returned (so no decision is made).
def pkg_gpg_check(data)
log.debug("pkgGpgCheck data: #{data}")
insecure = Stage.initial && Linuxrc.InstallInf("Insecure") == "1"
insecure ? "I" : ""
end

# After package install.
#
# return "I" for ignore
Expand Down Expand Up @@ -2664,6 +2683,9 @@ def SetProvideCallbacks
Pkg.CallbackDonePackage(
fun_ref(method(:DonePackage), "string (integer, string)")
)
Pkg.CallbackPkgGpgCheck(
fun_ref(method(:pkg_gpg_check), "string(map)")
)

nil
end
Expand Down Expand Up @@ -2877,6 +2899,7 @@ def RestoreProvideCallbacks
Pkg.CallbackStartPackage(nil)
Pkg.CallbackProgressPackage(nil)
Pkg.CallbackDonePackage(nil)
Pkg.CallbackPkgGpgCheck(nil)

nil
end
Expand Down
46 changes: 46 additions & 0 deletions library/packages/test/package_callbacks_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,50 @@
expect(cds).to eq []
end
end

describe "#pkp_gpg_check" do
let(:data) { { "CheckResult" => 1 } }

before do
allow(Yast::Linuxrc).to receive(:InstallInf).with("Insecure").and_return(insecure)
allow(Yast::Stage).to receive(:initial).and_return(initial)
end

context "during installation" do
let(:initial) { true }

context "and when insecure is not set" do
let(:insecure) { nil }

it "returns ''" do
expect(subject.pkg_gpg_check(data)).to eq("")
end
end

context "and when Insecure is set to '1'" do
let(:insecure) { "1" }

it "returns 'I'" do
expect(subject.pkg_gpg_check(data)).to eq("I")
end
end

context "and when Insecure is set but different to '1'" do
let(:insecure) { "0" }

it "returns ''" do
expect(subject.pkg_gpg_check(data)).to eq("")
end
end
end

context "on an installed system" do
let(:initial) { false }
let(:insecure) { "1" }

it "returns ''" do
expect(subject.pkg_gpg_check(data)).to eq("")
end
end
end
end
7 changes: 7 additions & 0 deletions package/yast2.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Thu Sep 7 12:15:56 UTC 2017 - igonzalezsosa@suse.com

- Fix handling of PGP signatures when running in insecure mode
(bsc#1054663)
- 4.0.4

-------------------------------------------------------------------
Mon Sep 4 11:32:04 UTC 2017 - ancor@suse.com

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


Name: yast2
Version: 4.0.3
Version: 4.0.4
Release: 0
Summary: YaST2 - Main Package
License: GPL-2.0
Expand Down

0 comments on commit 15ad29f

Please sign in to comment.