From 7986d30e6f8454115d0d49ae71439c21917c1eed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20P=C3=A4tzold?= Date: Mon, 3 Jan 2022 21:15:12 +0100 Subject: [PATCH 1/7] IsDNSZoneMaintained returns inverted value The Function IsDNSZoneMaintained is returning true if the Zone is not maintained and otherwise around. --- src/include/dhcp-server/dns-server-dialogs.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/include/dhcp-server/dns-server-dialogs.rb b/src/include/dhcp-server/dns-server-dialogs.rb index 7390c09..2d85937 100644 --- a/src/include/dhcp-server/dns-server-dialogs.rb +++ b/src/include/dhcp-server/dns-server-dialogs.rb @@ -30,7 +30,7 @@ def IsDNSZoneMaintained(zone_name) all_zones = DnsServerAPI.GetZones # found or not? - Ops.get(all_zones, zone_name) == nil + Ops.get(all_zones, zone_name) != nil end def IsDNSZoneMaster(zone_name) From 6f2549860d9cdd4e43023ba93867140efed3fabe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20D=C3=ADaz=20Gonz=C3=A1lez?= Date: Thu, 13 Jan 2022 14:26:43 +0000 Subject: [PATCH 2/7] Add unit test for #IsDNSZoneMaintained --- test/dns_dialog_test.rb | 67 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 test/dns_dialog_test.rb diff --git a/test/dns_dialog_test.rb b/test/dns_dialog_test.rb new file mode 100644 index 0000000..c57d558 --- /dev/null +++ b/test/dns_dialog_test.rb @@ -0,0 +1,67 @@ +# Copyright (c) [2022] SUSE LLC +# +# All Rights Reserved. +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of version 2 of the GNU General Public License as published +# by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, contact SUSE LLC. +# +# 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" + +Yast.import "DnsServerAPI" + +describe "DhcpServerDnsServerDialogsInclude" do + subject(:dialog) { TestDialog.new } + + class TestDialog + include Yast::I18n + + def initialize + Yast.include self, "dhcp-server/dns-server-dialogs.rb" + end + end + + describe "#IsDNSZoneMaintained" do + before do + allow(Yast::DnsServerAPI).to receive(:GetZones).and_return(zones) + end + + let(:zones) do + { + "example.org" => { "type" => "master" }, + "forward.org" => { "type" => "forward" } + } + end + + context "when a zone name is not given" do + it "returns nil" do + expect(dialog.IsDNSZoneMaintained(nil)).to be_nil + end + end + + context "when a zone name is given" do + context "and it is included in maintained zones" do + it "returns true" do + expect(dialog.IsDNSZoneMaintained("example.org")).to eq(true) + end + end + + context "but it is NOT included in maintained zones" do + it "returns false" do + expect(dialog.IsDNSZoneMaintained("not-maintained-zone.org")).to eq(false) + end + end + end + end +end From bde8933ef9c230685e15832204778de8ccd32105 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20D=C3=ADaz=20Gonz=C3=A1lez?= Date: Thu, 13 Jan 2022 14:37:32 +0000 Subject: [PATCH 3/7] Refactor #IsDNSZoneMaintained --- src/include/dhcp-server/dns-server-dialogs.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/include/dhcp-server/dns-server-dialogs.rb b/src/include/dhcp-server/dns-server-dialogs.rb index 2d85937..9cd7656 100644 --- a/src/include/dhcp-server/dns-server-dialogs.rb +++ b/src/include/dhcp-server/dns-server-dialogs.rb @@ -27,10 +27,7 @@ def IsDNSZoneMaintained(zone_name) return nil end - all_zones = DnsServerAPI.GetZones - - # found or not? - Ops.get(all_zones, zone_name) != nil + DnsServerAPI.GetZones.keys.include?(zone_name) end def IsDNSZoneMaster(zone_name) From 486718e598fb1fa364931aa4c2ceceda1d0ec1ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20D=C3=ADaz=20Gonz=C3=A1lez?= Date: Thu, 13 Jan 2022 15:36:01 +0000 Subject: [PATCH 4/7] Rename test file --- test/{dns_dialog_test.rb => dns_server_dialog_test.rb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/{dns_dialog_test.rb => dns_server_dialog_test.rb} (100%) diff --git a/test/dns_dialog_test.rb b/test/dns_server_dialog_test.rb similarity index 100% rename from test/dns_dialog_test.rb rename to test/dns_server_dialog_test.rb From 64262bd73ebdc9255a502a84f25aad5233d935ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20D=C3=ADaz=20Gonz=C3=A1lez?= Date: Thu, 13 Jan 2022 16:00:56 +0000 Subject: [PATCH 5/7] Fix test suite Using the same "dummy" class in multiple test files makes them fail. --- test/dns_server_dialog_test.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/dns_server_dialog_test.rb b/test/dns_server_dialog_test.rb index c57d558..385b7e7 100644 --- a/test/dns_server_dialog_test.rb +++ b/test/dns_server_dialog_test.rb @@ -1,3 +1,5 @@ +#!/usr/bin/env rspec + # Copyright (c) [2022] SUSE LLC # # All Rights Reserved. @@ -22,9 +24,9 @@ Yast.import "DnsServerAPI" describe "DhcpServerDnsServerDialogsInclude" do - subject(:dialog) { TestDialog.new } + subject(:dialog) { TestDNSDialog.new } - class TestDialog + class TestDNSDialog include Yast::I18n def initialize From 51abbf50e71de32bfaaf58ee59614477c43981e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20D=C3=ADaz=20Gonz=C3=A1lez?= Date: Thu, 13 Jan 2022 16:36:20 +0000 Subject: [PATCH 6/7] Bump version and changelog --- package/yast2-dhcp-server.changes | 8 ++++++++ package/yast2-dhcp-server.spec | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/package/yast2-dhcp-server.changes b/package/yast2-dhcp-server.changes index d0366c0..8a8392b 100644 --- a/package/yast2-dhcp-server.changes +++ b/package/yast2-dhcp-server.changes @@ -1,3 +1,11 @@ +------------------------------------------------------------------- +Thu Jan 13 16:33:01 UTC 2022 - David Diaz + +- Fix DNS zone creation by fixing a maintained DNS zone check. + Reported and fixed by Daniel Pätzold + See github#yast/yast-dhcp-server#59. +- 4.3.2 + ------------------------------------------------------------------- Tue Oct 20 11:50:49 UTC 2020 - Bernhard Wiedemann diff --git a/package/yast2-dhcp-server.spec b/package/yast2-dhcp-server.spec index 87a2d95..3d0287b 100644 --- a/package/yast2-dhcp-server.spec +++ b/package/yast2-dhcp-server.spec @@ -17,7 +17,7 @@ Name: yast2-dhcp-server -Version: 4.3.1 +Version: 4.3.2 Release: 0 Summary: YaST2 - DHCP Server Configuration Group: System/YaST From 2f07d135e70c53655d390a4b92f8a648d1cea532 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20D=C3=ADaz=20Gonz=C3=A1lez?= Date: Thu, 13 Jan 2022 16:42:58 +0000 Subject: [PATCH 7/7] Fix unit tests for widgets --- test/widgets_test.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/test/widgets_test.rb b/test/widgets_test.rb index 6c5bfe2..57f3fc4 100644 --- a/test/widgets_test.rb +++ b/test/widgets_test.rb @@ -87,6 +87,7 @@ def initialize context "port is not opened" do before do + allow(Yast::Report).to receive(:Error) allow(Yast::UI).to receive(:QueryWidget).with(Id("open_port"), :Value) .and_return(false) end