File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed
lib/ronin/support/network Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -141,6 +141,11 @@ module Network
141
141
#
142
142
class Host
143
143
144
+ # A regular expression for matching host names.
145
+ #
146
+ # @since 1.2.0
147
+ REGEX = /\A (?:(?:[a-zA-Z\d ](?:[-a-zA-Z\d ]*[a-zA-Z\d ])?)\. )*(?:[a-zA-Z](?:[-a-zA-Z\d ]*[a-zA-Z\d ])?)\. ?\z /
148
+
144
149
# The host name.
145
150
#
146
151
# @return [String]
Original file line number Diff line number Diff line change 18
18
19
19
subject { described_class . new ( hostname ) }
20
20
21
+ describe "REGEX" do
22
+ subject { described_class ::REGEX }
23
+
24
+ it "must match a local hostname" do
25
+ expect ( subject =~ 'localhost' ) . to be_truthy
26
+ end
27
+
28
+ it "must match a domain name" do
29
+ expect ( subject =~ 'example.com' ) . to be_truthy
30
+ end
31
+
32
+ it "must match a sub-domain name" do
33
+ expect ( subject =~ 'www.example.com' ) . to be_truthy
34
+ end
35
+ end
36
+
21
37
describe "#initialize" do
22
38
it "must set #name" do
23
39
expect ( subject . name ) . to eq ( hostname )
You can’t perform that action at this time.
0 commit comments