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

Master bnc 1089855 #62

Merged
merged 3 commits into from
May 3, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions package/yast2-firewall.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Fri Apr 27 16:35:19 CEST 2018 - schubi@suse.de

- AutoYaST: Report whether an interface has been defined
in more than one zone (bnc#1099855).
- 4.0.25

-------------------------------------------------------------------
Sat Apr 21 07:35:42 UTC 2018 - knut.anderssen@suse.com

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


Name: yast2-firewall
Version: 4.0.24
Version: 4.0.25
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
17 changes: 17 additions & 0 deletions src/lib/y2firewall/clients/auto.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Auto < ::Installation::AutoClient
include Yast::Logger

Yast.import "HTML"
Yast.import "AutoInstall"

class << self
# @return [Boolean] whether the AutoYaST configuration has been
Expand Down Expand Up @@ -88,6 +89,7 @@ def import(profile)
enable if profile.fetch("enable_firewall", settings.enable_firewall)
start if profile.fetch("start_firewall", false)
importer.import(profile)
check_profile_for_errors
imported
end

Expand Down Expand Up @@ -150,6 +152,21 @@ def modified?

private

# Semantic AutoYaST profile check
#
# Problems will be stored in AutoInstall.issues_list.
def check_profile_for_errors
# Checking if an interface has been defined for different zones
zones = firewalld.export["zones"] || []
all_interfaces = zones.flat_map { |zone| zone["interfaces"] || [] }
double_entries = all_interfaces.select { |i| all_interfaces.count(i) > 1 }.uniq
unless double_entries.empty?
AutoInstall.issues_list.add(:invalid_value, "firewall", "interfaces",
double_entries.join(","),
_("This interface has been defined for more than one zone."))
end
end

# Depending on the profile it activates or deactivates the firewalld
# service
def activate_service
Expand Down
18 changes: 17 additions & 1 deletion test/lib/y2firewall/clients/auto_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,12 @@
end

describe "#import" do
let(:i_list) { double("IssuesList", add: nil) }

let(:arguments) do
{ "FW_MASQUERADE" => "yes", "enable_firewall" => false, "start_firewall" => false }
{ "FW_MASQUERADE" => "yes",
"enable_firewall" => false,
"start_firewall" => false }
end

it "reads the current firewalld configuration" do
Expand All @@ -118,6 +122,7 @@
context "when the current configuration was read correctly" do
before do
allow(firewalld).to receive(:read).and_return(true)
allow(Yast::AutoInstall).to receive(:issues_list).and_return(i_list)
end

it "pass its arguments to the firewalld importer" do
Expand All @@ -134,6 +139,17 @@
subject.import(arguments)
expect(subject.class.imported).to eq(true)
end

it "reports that an interface has been defined twice in zones" do
expect(firewalld).to receive(:export)
.and_return("zones" => [{ "interfaces" => ["eth0"], "name" => "public" },
{ "interfaces" => ["eth0", "eth0"], "name" => "trusted" }])
expect(i_list).to receive(:add)
.with(:invalid_value, "firewall", "interfaces",
"eth0",
"This interface has been defined for more than one zone.")
subject.import(arguments)
end
end

context "when the current configuration was not read" do
Expand Down