Skip to content

Commit

Permalink
Merge pull request #18 from yast/fix_empty_dns
Browse files Browse the repository at this point in the history
Fix empty dns
  • Loading branch information
jreidinger committed Oct 20, 2016
2 parents 92d990b + e4aeb68 commit 0d7d068
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 20 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ before_install:
# disable rvm, use system Ruby
- rvm reset
- wget https://raw.githubusercontent.com/yast/yast-devtools/master/travis-tools/travis_setup.sh
- sh ./travis_setup.sh -p "rake yast2-devtools yast2-testsuite yast2 yast2-perl-bindings" -g "rspec:3.3.0 yast-rake gettext"
- sh ./travis_setup.sh -p "rake yast2-devtools yast2-testsuite yast2 yast2-perl-bindings" -g "rspec:3.3.0 yast-rake gettext simplecov coveralls"
script:
- rake check:syntax
- rake check:pot
- make -f Makefile.cvs
- make
- sudo make install
- make check
- COVERAGE=1 rake test:unit

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

[![Travis Build](https://travis-ci.org/yast/yast-dhcp-server.svg?branch=master)](https://travis-ci.org/yast/yast-dhcp-server)
[![Jenkins Build](http://img.shields.io/jenkins/s/https/ci.opensuse.org/yast-dhcp-server-master.svg)](https://ci.opensuse.org/view/Yast/job/yast-dhcp-server-master/)

[![Coverage Status](https://coveralls.io/repos/github/yast/yast-dhcp-server/badge.svg?branch=master)](https://coveralls.io/github/yast/yast-dhcp-server?branch=master)
8 changes: 8 additions & 0 deletions package/yast2-dhcp-server.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
-------------------------------------------------------------------
Thu Oct 20 07:31:59 UTC 2016 - jreidinger@suse.com

- allow empty string in primary name server field for dynamic DNS
option to allow what is suggested in documentation for local DNS
servers (bsc#736496)
- 3.2.1

-------------------------------------------------------------------
Thu Oct 6 11:25:00 UTC 2016 - jreidinger@suse.com

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


Name: yast2-dhcp-server
Version: 3.2.0
Version: 3.2.1
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
28 changes: 15 additions & 13 deletions src/include/dhcp-server/widgets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -702,27 +702,29 @@ def DDNSZonesInit(id)
# @param [String] id string widget id
# @param [Hash] event map event that is handled
# @return [Boolean] true if validation succeeded
def DNSZonesValidate(id, event)
event = deep_copy(event)
if !Convert.to_boolean(UI.QueryWidget(Id("ddns_enable"), :Value))
return true
end
ret = true
Builtins.foreach(["zone", "zone_ip", "reverse_zone", "reverse_ip"]) do |w|
value = Convert.to_string(UI.QueryWidget(Id(w), :Value))
def DNSZonesValidate(_id, _event)
return true if !UI.QueryWidget(Id("ddns_enable"), :Value)

["zone", "zone_ip", "reverse_zone", "reverse_ip"].each do |w|
value = UI.QueryWidget(Id(w), :Value)
if (w == "zone" || w == "reverse_zone") &&
Builtins.regexpmatch(value, "^.*\\.$")
value = Builtins.regexpsub(value, "^(.*)\\.$", "\\1")
end
if !(Hostname.CheckFQ(value) ||
Builtins.contains(["zone_ip", "reverse_ip"], w) && IP.Check4(value))
ip_field = ["zone_ip", "reverse_ip"].include?(w)
# for primary dns ip can be used
valid_ip = ip_field && IP.Check4(value)
# for dns also empty value can be used
default_ip = ip_field && value.empty?

if !(Hostname.CheckFQ(value) || valid_ip || default_ip)
UI.SetFocus(Id(w))
Report.Error(Hostname.ValidFQ)
ret = false
raise Break
return false
end
end
ret

true
end


Expand Down
25 changes: 25 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
ENV["Y2DIR"] = File.expand_path("../../src", __FILE__)

require "yast"
require "yast/rspec"


if ENV["COVERAGE"]
require "simplecov"
SimpleCov.start do
add_filter "/test/"
end

# for coverage we need to load all ruby files
src_location = File.expand_path("../../src", __FILE__)
Dir["#{src_location}/{module,lib}/**/*.rb"].each { |f| require_relative f }

# use coveralls for on-line code coverage reporting at Travis CI
if ENV["TRAVIS"]
require "coveralls"
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
SimpleCov::Formatter::HTMLFormatter,
Coveralls::SimpleCov::Formatter
]
end
end
73 changes: 73 additions & 0 deletions test/widgets_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
require_relative "test_helper"

Yast.import "UI"

module Yast
class Test < Yast::Client
def initialize
Yast.include self, "dhcp-server/widgets.rb"
end
end
end



describe "Yast::DhcpServerWidgetsInclude" do
subject { Yast::Test.new }

describe "#DNSZonesValidate" do
before do
allow(Yast::UI).to receive(:QueryWidget).with(Id("ddns_enable"), :Value)
.and_return(true)

allow(Yast::UI).to receive(:QueryWidget).with(Id("zone_ip"), :Value)
.and_return("127.0.0.1")
allow(Yast::UI).to receive(:QueryWidget).with(Id("reverse_ip"), :Value)
.and_return("127.0.0.1")
allow(Yast::UI).to receive(:QueryWidget).with(Id("zone"), :Value)
.and_return("test.suse.cz")
allow(Yast::UI).to receive(:QueryWidget).with(Id("reverse_zone"), :Value)
.and_return("test2.suse.cz")
end

it "returns true if dynanic dns is not enabled" do
allow(Yast::UI).to receive(:QueryWidget).with(Id("ddns_enable"), :Value)
.and_return(false)
# add one failing to test that it do not fail
allow(Yast::UI).to receive(:QueryWidget).with(Id("zone_ip"), :Value)
.and_return("666.666.666.666")

expect(subject.DNSZonesValidate("ddns_enable", {})).to eq true
end

it "returns false and report error if zone_ip is invalid IPv4" do
allow(Yast::UI).to receive(:QueryWidget).with(Id("zone_ip"), :Value)
.and_return("666.666.666.666")
expect(Yast::Report).to receive(:Error)

expect(subject.DNSZonesValidate("ddns_enable", {})).to eq false
end

it "returns false and report error if zone is not FQDN" do
allow(Yast::UI).to receive(:QueryWidget).with(Id("zone"), :Value)
.and_return("bla***bla")
expect(Yast::Report).to receive(:Error)

expect(subject.DNSZonesValidate("ddns_enable", {})).to eq false
end

it "returns true even if zone contains trailing comma" do
allow(Yast::UI).to receive(:QueryWidget).with(Id("zone"), :Value)
.and_return("test.suse.cz.")

expect(subject.DNSZonesValidate("ddns_enable", {})).to eq true
end

it "returns true if zone_ip is empty" do
allow(Yast::UI).to receive(:QueryWidget).with(Id("zone_ip"), :Value)
.and_return("")

expect(subject.DNSZonesValidate("ddns_enable", {})).to eq true
end
end
end
4 changes: 0 additions & 4 deletions test/yapi_dhcpd_test.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/usr/bin/env rspec

require 'rspec'
ENV["Y2DIR"] = File.expand_path("../../src", __FILE__)
require "yast"

module Yast
import "YaPI::DHCPD"
import "Service"
Expand Down

0 comments on commit 0d7d068

Please sign in to comment.