Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid crash if failed to resolve the IP from install.inf (bsc#1161217) #1028

Merged
merged 4 commits into from Jan 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions package/yast2-network.changes
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Wed Jan 22 16:43:21 UTC 2020 - Ancor Gonzalez Sosa <ancor@suse.com>

- Do not crash if install.inf contains an IP address that cannot
be resolved to a name (bsc#1161217)
- 4.2.47

-------------------------------------------------------------------
Tue Jan 21 07:24:03 UTC 2020 - Knut Anderssen <kanderssen@suse.com>

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


Name: yast2-network
Version: 4.2.46
Version: 4.2.47
Release: 0
Summary: YaST2 - Network Configuration
License: GPL-2.0-only
Expand Down
4 changes: 3 additions & 1 deletion src/lib/y2network/sysconfig/hostname_reader.rb
Expand Up @@ -92,7 +92,9 @@ def hostname_from_install_inf
end

host, _domain = *Yast::Hostname.SplitFQ(fqdn)
host.empty? ? nil : host
return nil if host.nil? || host.empty?

host
end

# Reads the (transient) hostname known to the resolver
Expand Down
Expand Up @@ -17,13 +17,13 @@
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.

require_relative "../test_helper"
require_relative "../../test_helper"
require "y2network/sysconfig/hostname_reader"

describe Y2Network::Sysconfig::HostnameReader do
subject(:reader) { described_class.new }

describe "#hostname" do
describe "#config" do
let(:install_inf_hostname) { "linuxrc" }
let(:dhcp_hostname) { "dhcp" }
let(:system_hostname) { "system" }
Expand All @@ -34,25 +34,37 @@
allow(reader).to receive(:hostname_from_dhcp).and_return(dhcp_hostname)
allow(reader).to receive(:hostname_from_system).and_return(system_hostname)
allow(reader).to receive(:hostname_from_resolver).and_return(resolver_hostname)

allow(Yast::Stage).to receive(:initial).and_return(installation)
end

context "during installation" do
let(:install_inf_exists?) { true }
RSpec.shared_examples "installer and static" do
it "reads the installer hostname from /etc/install.conf" do
expect(reader.config.installer).to eq("linuxrc")
end

before do
allow(Yast::Stage).to receive(:initial).and_return(true)
it "reads the static hostname from the system" do
expect(reader.config.static).to eq("system")
end
end

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

it "reads the hostname from /etc/install.conf" do
expect(reader.hostname_from_install_inf).to eq("linuxrc")
include_examples "installer and static"

it "reads the transient hostname from DHCP" do
expect(reader.config.transient).to eq("dhcp")
end
end

context "when the /etc/install.inf file does not exists" do
let(:install_inf_hostname) { nil }
context "in an installed system" do
let(:installation) { false }

it "returns nil" do
expect(reader.hostname_from_install_inf).to be_nil
end
include_examples "installer and static"

it "reads the transient hostname from the resolver" do
expect(reader.config.transient).to eq("system.suse.de")
end
end
end
Expand All @@ -77,18 +89,19 @@
end

context "when an IP address is used instead of a hostname" do
let(:hostname) { "foo1.bar.cz" }
let(:hostname) { "192.168.1.1" }
let(:resolved_hostname) { "foo1.bar.cz" }

before do
allow(Yast::NetHwDetection).to receive(:ResolveIP).and_return(hostname)
allow(Yast::NetHwDetection).to receive(:ResolveIP).and_return(resolved_hostname)
end

it "returns the associated hostname" do
expect(reader.hostname_from_install_inf).to eq("foo1")
end

context "and it is not resolvable to an IP" do
let(:hostname) { nil }
let(:resolved_hostname) { nil }

it "returns nil" do
expect(reader.hostname_from_install_inf).to be_nil
Expand Down