Skip to content

Commit

Permalink
Replace the firewall with the new main dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed Sep 20, 2018
1 parent e5f0645 commit d1defa3
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 110 deletions.
25 changes: 0 additions & 25 deletions src/clients/firewall_new.rb

This file was deleted.

27 changes: 12 additions & 15 deletions src/lib/y2firewall/clients/firewall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
require "yast"
require "yast2/execute"
require "ui/text_helpers"
require "y2firewall/dialogs/main"

Yast.import "UI"
Yast.import "Popup"
Yast.import "PackageSystem"

module Y2Firewall
module Clients
Expand All @@ -34,31 +39,23 @@ class Firewall

# Constructor
def initialize
Yast.import "UI"
Yast.import "Popup"
Yast.import "PackageSystem"

textdomain "firewall"
end

# TRANSLATORS: firewall-config and firewall-cmd are the names of software utilities,
# so they should not be translated.
NOT_SUPPORTED = N_("YaST currently does not have a module for configuring" \
" firewall. Please, either use \"firewall-config\" to configure your firewall" \
" via a user interface or \"firewall-cmd\" for the command line.").freeze
NOT_SUPPORTED = N_("YaST does not support the command line for " \
"configuring the firewall.\nInstead, please use the firewalld " \
"command line clients \"firewalld-cmd\" or \"firewall-offline-cmd\".")

def run
log_and_return do
return :abort unless Yast::PackageSystem.CheckAndInstallPackages(["firewalld"])
if !Yast::WFM.Args.empty?
$stderr.puts wrap_text(_(NOT_SUPPORTED))
false
elsif Yast::UI.TextMode()
Yast::Popup.Error(
wrap_text(_(NOT_SUPPORTED))
)
$stderr.puts _(NOT_SUPPORTED)
false
elsif Yast::PackageSystem.CheckAndInstallPackages(["firewall-config"])
Yast::Execute.locally("/usr/bin/firewall-config")
else
Dialogs::Main.new.run
end
end
end
Expand Down
50 changes: 0 additions & 50 deletions src/lib/y2firewall/clients/firewall_new.rb

This file was deleted.

39 changes: 19 additions & 20 deletions test/lib/y2firewall/clients/firewall_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,46 +27,45 @@
context "when the client is called with some argument" do
before do
allow(Yast::WFM).to receive("Args").and_return(["list"])
allow($stderr).to receive(:puts)
end

it "returns false" do
it "recommends to use the firewalld cmdline clients" do
expect($stderr).to receive(:puts).with(Y2Firewall::Clients::Firewall::NOT_SUPPORTED)

subject.run
end

it "returns false" do
expect(subject.run).to eql(false)
end
end

context "when the client is called without arguments" do
before do
allow(Yast::WFM).to receive("Args").and_return([])
allow(Yast::UI).to receive("TextMode").and_return false
end

context "and it is called in TextMode" do
before do
allow(Yast::UI).to receive("TextMode").and_return true
end

it "reports an error" do
expect(Yast::Popup).to receive("Error")

subject.run
end

it "returns false" do
allow(Yast::Popup).to receive("Error")
context "and the firewalld package is not installed" do
it "returns :abort" do
expect(Yast::PackageSystem).to receive("CheckAndInstallPackages")
.with(["firewalld"]).and_return(false)

expect(subject.run).to eq(false)
expect(subject.run).to eql(:abort)
end
end

context "and the firewall-config package is installed" do
context "and the firewalld package is installed" do
let(:main_dialog) { instance_double("Y2Firewall:::Dialogs::Main", run: true) }

before do
allow(Yast::PackageSystem).to receive("CheckAndInstallPackages")
.with(["firewall-config"]).and_return(true)
.with(["firewalld"]).and_return(true)
end

it "runs the firewall-config gui" do
expect(Yast::Execute).to receive("locally").with("/usr/bin/firewall-config")
it "runs the Main dialog" do
expect(Y2Firewall::Dialogs::Main).to receive(:new).and_return(main_dialog)
expect(main_dialog).to receive(:run)

subject.run
end
Expand Down

0 comments on commit d1defa3

Please sign in to comment.