Skip to content

Commit

Permalink
Import gpg keys from /usr/lib/rpm/gnupg/keys
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Mar 29, 2022
1 parent d4f3377 commit fd3d08b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
9 changes: 4 additions & 5 deletions service/lib/dinstaller/software.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.

require "pathname"
require "yast"
require "dinstaller/package_callbacks"
require "y2packager/product"
Expand All @@ -33,8 +32,8 @@
module DInstaller
# This class is responsible for software handling
class Software
GPG_KEYS_PATH = "/"
private_constant :GPG_KEYS_PATH
GPG_KEYS_GLOB = "/usr/lib/rpm/gnupg/keys/gpg-*"
private_constant :GPG_KEYS_GLOB

FALLBACK_REPO = "https://download.opensuse.org/tumbleweed/repo/oss/"
private_constant :FALLBACK_REPO
Expand Down Expand Up @@ -137,10 +136,10 @@ def count_packages
end

def import_gpg_keys
gpg_keys = Pathname.new(GPG_KEYS_PATH).glob("*.gpg").map(&:to_s)
gpg_keys = Dir.glob(GPG_KEYS_GLOB).map(&:to_s)
logger.info "Importing GPG keys: #{gpg_keys}"
gpg_keys.each do |path|
Yast::Pkg.ImportGPGKey(path.to_s, true)
Yast::Pkg.ImportGPGKey(path, true)
end
end

Expand Down
10 changes: 5 additions & 5 deletions service/test/dinstaller/software_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
let(:other_prod) { instance_double(Y2Packager::Product, name: "another") }
let(:base_url) { "" }
let(:destdir) { "/mnt" }
let(:gpg_path) { instance_double(Pathname, glob: []) }
let(:gpg_keys) { [] }

before do
allow(Yast::Pkg).to receive(:TargetInitialize)
allow(Yast::Pkg).to receive(:ImportGPGKey)
allow(Pathname).to receive(:new).with("/").and_return(gpg_path)
allow(Dir).to receive(:glob).with(/keys/).and_return(gpg_keys)
allow(Y2Packager::Product).to receive(:available_base_products)
.and_return(products)
allow(Yast::Packages).to receive(:Proposal).and_return({})
Expand All @@ -55,12 +55,12 @@
end

context "when GPG keys are available at /" do
before do
allow(gpg_path).to receive(:glob).with("*.gpg").and_return(["/installkey.gpg"])
let(:gpg_keys) do
["/usr/lib/gnupg/keys/gpg-key.asc"]
end

it "imports the GPG keys" do
expect(Yast::Pkg).to receive(:ImportGPGKey).with("/installkey.gpg", true)
expect(Yast::Pkg).to receive(:ImportGPGKey).with(gpg_keys.first, true)
subject.probe(progress)
end
end
Expand Down

0 comments on commit fd3d08b

Please sign in to comment.