Skip to content

Commit 0aafff9

Browse files
committed
Added Ronin::Wordlists::Mixin (closes #20).
1 parent 5760956 commit 0aafff9

File tree

2 files changed

+176
-0
lines changed

2 files changed

+176
-0
lines changed

lib/ronin/wordlists/mixin.rb

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# frozen_string_literal: true
2+
#
3+
# ronin-wordlists - A library and tool for managing wordlists.
4+
#
5+
# Copyright (c) 2023-2024 Hal Brodigan (postmodern.mod3@gmail.com)
6+
#
7+
# ronin-wordlists is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU Lesser General Public License as published
9+
# by the Free Software Foundation, either version 3 of the License, or
10+
# (at your option) any later version.
11+
#
12+
# ronin-wordlists is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU Lesser General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU Lesser General Public License
18+
# along with ronin-wordlists. If not, see <https://www.gnu.org/licenses/>.
19+
#
20+
21+
require 'ronin/wordlists'
22+
23+
module Ronin
24+
module Wordlists
25+
#
26+
# Wordlist helper methods.
27+
#
28+
module Mixin
29+
#
30+
# Downloads a new wordlist.
31+
#
32+
# @param [String, URI::HTTP] url
33+
# The URL of the wordlist to download.
34+
#
35+
# @api public
36+
#
37+
# @see Wordlists.download
38+
#
39+
def wordlists_download(url)
40+
Wordlists.download(url)
41+
end
42+
43+
alias download_wordlist wordlists_download
44+
45+
#
46+
# Finds a wordlist.
47+
#
48+
# @param [String] name
49+
# The wordlist file name.
50+
#
51+
# @return [String, nil]
52+
# The path to the wordlist file.
53+
#
54+
# @api public
55+
#
56+
# @see Wordlists.find
57+
#
58+
def wordlists_find(name)
59+
Wordlists.find(name)
60+
end
61+
62+
alias find_wordlist wordlists_find
63+
64+
#
65+
# Lists all wordlists on the system.
66+
#
67+
# @param [String] pattern
68+
# Optional glob pattern to search for within the wordlist directory.
69+
#
70+
# @return [Set<String>]
71+
# The wordlist files within the wordlist directories.
72+
#
73+
# @api public
74+
#
75+
# @see Wordlists.list
76+
#
77+
def wordlists_list(pattern='*')
78+
Wordlists.list(pattern)
79+
end
80+
81+
alias list_wordlists wordlists_list
82+
83+
#
84+
# Opens a wordlist.
85+
#
86+
# @param [String] name
87+
# The wordlist file name.
88+
#
89+
# @return [Wordlist::File]
90+
# The opened wordlist file.
91+
#
92+
# @raise [WordlistNotFound]
93+
# No wordlist with the given name.
94+
#
95+
# @api public
96+
#
97+
# @see Wordlists.open
98+
#
99+
def wordlists_open(name)
100+
Wordlists.open(name)
101+
end
102+
103+
alias open_wordlist wordlists_open
104+
end
105+
end
106+
end

spec/mixin_spec.rb

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
require 'spec_helper'
2+
require 'ronin/wordlists/mixin'
3+
4+
describe Ronin::Wordlists::Mixin do
5+
class TestWordlistsMixin
6+
include Ronin::Wordlists::Mixin
7+
end
8+
9+
subject { TestWordlistsMixin.new }
10+
11+
describe "#wordlists_download" do
12+
let(:url) { 'http://example.com/path/to/wordlist.txt' }
13+
14+
it "must call Ronin::Wordlists.download with the given URL" do
15+
expect(Ronin::Wordlists).to receive(:download).with(url)
16+
17+
subject.wordlists_download(url)
18+
end
19+
end
20+
21+
describe "#wordlists_find" do
22+
let(:name) { 'subdomains-100' }
23+
let(:path) { "/path/to/#{name}.txt" }
24+
25+
it "must call Ronin::Wordlists.find with the given name" do
26+
expect(Ronin::Wordlists).to receive(:find).with(name).and_return(path)
27+
28+
expect(subject.wordlists_find(name)).to eq(path)
29+
end
30+
end
31+
32+
describe "#wordlists_list" do
33+
let(:wordlists) do
34+
Set[
35+
double('wordlist1'),
36+
double('wordlist2'),
37+
double('wordlist3')
38+
]
39+
end
40+
41+
context "when given no arguments" do
42+
it "must call Ronin::Wordlists.list('*')" do
43+
expect(Ronin::Wordlists).to receive(:list).with('*').and_return(wordlists)
44+
45+
expect(subject.wordlists_list).to eq(wordlists)
46+
end
47+
end
48+
49+
context "when given a glob pattern" do
50+
let(:pattern) { 'wordlist*' }
51+
52+
it "must call Ronin::Wordlists.list() with the glob pattern" do
53+
expect(Ronin::Wordlists).to receive(:list).with(pattern).and_return(wordlists)
54+
55+
expect(subject.wordlists_list(pattern)).to eq(wordlists)
56+
end
57+
end
58+
end
59+
60+
describe "#wordlists_open" do
61+
let(:name) { 'subdomains-100' }
62+
let(:wordlist) { double('opened Wordlist') }
63+
64+
it "must call Ronin::Wordlists.open with the given name" do
65+
expect(Ronin::Wordlists).to receive(:open).with(name).and_return(wordlist)
66+
67+
expect(subject.wordlists_open(name)).to eq(wordlist)
68+
end
69+
end
70+
end

0 commit comments

Comments
 (0)