Skip to content

Commit

Permalink
Add PkgGpgCheck callback
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Sep 7, 2017
1 parent c84f544 commit 3c84363
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
14 changes: 14 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,16 @@ 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.
#
# @return [String] "I" = package should be installed; "" = no decision made.
def pkg_gpg_check(data)
log.debug("pkgGpgCheck data: #{data}")
Linuxrc.InstallInf("Insecure") == "1" ? "I" : ""
end

# After package install.
#
# return "I" for ignore
Expand Down Expand Up @@ -2664,6 +2675,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
32 changes: 32 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,36 @@
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)
end

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

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

context "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 "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
end

0 comments on commit 3c84363

Please sign in to comment.