Skip to content

Commit

Permalink
Updated testsuite
Browse files Browse the repository at this point in the history
  • Loading branch information
mchf committed Feb 18, 2020
1 parent 278abd4 commit 6574279
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/include/network/services/dns.rb
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,9 @@ def HandleResolverData(key, _event)
def ValidateHostname(key, _event)
value = UI.QueryWidget(Id(key), :Value).to_s

# empty hostname is allowed - /etc/hostname gets cleared in such case
value.empty? || Hostname.Check(value)
# 1) empty hostname is allowed - /etc/hostname gets cleared in such case
# 2) FQDN is allowed
value.empty? || Hostname.Check(value.tr('.',''))
end

# Validator for the search list
Expand Down
60 changes: 60 additions & 0 deletions test/dns_service_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env rspec

# Copyright (c) [2019] 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 "UI"

class DummyDnsService < Yast::Module
def initialize
Yast.include self, "network/services/dns.rb"
end
end

describe "NetworkServicesDnsInclude" do
subject { DummyDnsService.new }

describe "#ValidateHostname" do
it "allows empty hostname" do
allow(Yast::UI).to receive(:QueryWidget).and_return("")

expect(subject.ValidateHostname("", {})).to be true
end

it "allows valid characters in hostname" do
allow(Yast::UI).to receive(:QueryWidget).and_return("sles")

expect(subject.ValidateHostname("", {})).to be true
end

it "allows FQDN hostname if user asks for it" do
allow(Yast::UI).to receive(:QueryWidget).and_return("sles.suse.de")

expect(subject.ValidateHostname("", {})).to be true
end

it "disallows invalid characters in hostname" do
allow(Yast::UI).to receive(:QueryWidget).and_return("suse_sles")

expect(subject.ValidateHostname("", {})).to be false
end
end
end

0 comments on commit 6574279

Please sign in to comment.