Skip to content

Commit a4809ef

Browse files
committed
Merge pull request #4 from wvu-r7/pr/2969
Specs 'n' stuff
2 parents 427fece + 355cda0 commit a4809ef

File tree

2 files changed

+46
-7
lines changed

2 files changed

+46
-7
lines changed

lib/rex/text.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ module Text
3232
#
3333
##
3434

35+
TLDs = ['com', 'net', 'org', 'gov', 'biz', 'edu']
3536
States = ["AK", "AL", "AR", "AZ", "CA", "CO", "CT", "DE", "FL", "GA", "HI",
3637
"IA", "ID", "IL", "IN", "KS", "KY", "LA", "MA", "MD", "ME", "MI", "MN",
3738
"MO", "MS", "MT", "NC", "ND", "NE", "NH", "NJ", "NM", "NV", "NY", "OH",
@@ -1581,8 +1582,7 @@ def self.rand_hostname
15811582
(rand(5) + 1).times {
15821583
host.push(Rex::Text.rand_text_alphanumeric(rand(10) + 1))
15831584
}
1584-
d = ['com', 'net', 'org', 'gov']
1585-
host.push(d[rand(d.size)])
1585+
host.push(TLDs[rand(TLDs.size)])
15861586
host.join('.').downcase
15871587
end
15881588

@@ -1617,16 +1617,12 @@ def self.rand_name_female
16171617

16181618
# Generate a random mail address
16191619
def self.rand_mail_address
1620-
d = ['com', 'net', 'org', 'gov', 'biz', 'edu']
1621-
16221620
mail_address = ''
16231621
mail_address << Rex::Text.rand_name
16241622
mail_address << '.'
16251623
mail_address << Rex::Text.rand_surname
16261624
mail_address << '@'
1627-
mail_address << Rex::Text.rand_text_alpha(rand(5) + 4).downcase
1628-
mail_address << '.'
1629-
mail_address << d[rand(d.size)]
1625+
mail_address << Rex::Text.rand_hostname
16301626
end
16311627

16321628

spec/lib/rex/text_spec.rb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,49 @@
7171
end
7272
end
7373

74+
context ".rand_surname" do
75+
it "should return a random surname" do
76+
described_class::Surnames.should include(described_class.rand_surname)
77+
end
78+
end
79+
80+
context ".rand_name" do
81+
it "should return a random name" do
82+
names = described_class::Names_Female + described_class::Names_Male
83+
names.should include(described_class.rand_name)
84+
end
85+
end
86+
87+
context ".rand_name_female" do
88+
it "should return a random female name" do
89+
described_class::Names_Female.should include(described_class.rand_name_female)
90+
end
91+
end
92+
93+
context ".rand_name_male" do
94+
it "should return a random male name" do
95+
described_class::Names_Male.should include(described_class.rand_name_male)
96+
end
97+
end
98+
99+
context ".rand_mail_address" do
100+
it "should return a random mail address" do
101+
names = described_class::Names_Female + described_class::Names_Male
102+
surnames = described_class::Surnames
103+
tlds = described_class::TLDs
104+
105+
# XXX: This is kinda dirty
106+
mail_address = described_class.rand_mail_address.split("@").map { |x| x.split(".") }
107+
name, surname = mail_address.first.first, mail_address.first.last
108+
domain, tld = "example", mail_address.last.last # Poor man's stubbing to preserve TLD
109+
110+
names.should include(name)
111+
surnames.should include(surname)
112+
domain.should eq("example")
113+
tlds.should include(tld)
114+
end
115+
end
116+
74117
end
75118
end
76119

0 commit comments

Comments
 (0)