Skip to content

Commit f86d1af

Browse files
authored
add WordlistFile specs (#13)
1 parent 8ceb9db commit f86d1af

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

lib/ronin/wordlists/wordlist_file.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ def initialize(path, url: nil)
7373
# @raise [DownloadFailed]
7474
# Failed to download the wordlist file.
7575
#
76+
# @return [WordlistFile]
77+
# The wordlist file.
78+
#
7679
def self.download(url,dest=Dir.pwd)
7780
dest_path = begin
7881
Core::System.download(url,dest)

spec/wordlist_file_spec.rb

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
require 'spec_helper'
2+
require 'ronin/wordlists/wordlist_file'
3+
require 'ronin/core/system'
4+
5+
describe Ronin::Wordlists::WordlistFile do
6+
subject { described_class.new(path, url: url) }
7+
8+
let(:path) { File.expand_path(File.join(__dir__, '..', 'spec', 'fixtures', 'wordlists')) }
9+
let(:url) { "www.example.com" }
10+
11+
describe "#initialzie" do
12+
it "must initialize #path, #name and #url" do
13+
expect(subject.path).to eq(path)
14+
expect(subject.name).to eq("wordlists")
15+
expect(subject.url).to eq("www.example.com")
16+
end
17+
end
18+
19+
describe ".download" do
20+
context "when download succeed" do
21+
let(:download_result) { described_class.download("valid.com") }
22+
23+
before do
24+
allow(Ronin::Core::System).to receive(:download).and_return("/some/path")
25+
end
26+
27+
it "must return new WordlistFile" do
28+
expect(download_result).to be_kind_of(described_class)
29+
expect(download_result.path).to eq("/some/path")
30+
expect(download_result.url).to eq("valid.com")
31+
end
32+
end
33+
34+
context "when download failed" do
35+
before do
36+
allow(Ronin::Core::System).to receive(:download).and_raise(Ronin::Wordlists::DownloadFailed, "error message")
37+
end
38+
39+
it "must raise a DownloadFailed error" do
40+
expect {
41+
described_class.download("invalid.com")
42+
}.to raise_error(Ronin::Wordlists::DownloadFailed, "error message")
43+
end
44+
end
45+
end
46+
47+
describe "#type" do
48+
it "must return :file" do
49+
expect(subject.type).to eq(:file)
50+
end
51+
end
52+
53+
describe "#filename" do
54+
it "must return paths basename" do
55+
expect(subject.filename).to eq("wordlists")
56+
end
57+
end
58+
59+
describe "#update" do
60+
context "if #url is not nil" do
61+
it "must download wordlist from url" do
62+
expect(described_class).to receive(:download).with(subject.url, subject.path)
63+
64+
subject.update
65+
end
66+
end
67+
end
68+
69+
describe "#delete" do
70+
it "must delete the wordlist" do
71+
expect(File).to receive(:unlink).with(subject.path)
72+
73+
subject.delete
74+
end
75+
end
76+
77+
describe "#to_s" do
78+
it "must return path as string" do
79+
expect(subject.to_s).to eq(path)
80+
end
81+
end
82+
end

0 commit comments

Comments
 (0)