Sha256: a2aa91e3977401e0685434948186741c92c1e6891d2be14e9b387ce2ad820c4c

Contents?: true

Size: 1.92 KB

Versions: 2

Compression:

Stored size: 1.92 KB

Contents

require 'spec_helper'
require 'ronin/wordlist'

require 'tempfile'

describe Wordlist do
  let(:words) { %w[foo bar baz] }

  before(:all) do
    Tempfile.open('ronin-support-wordlist') do |file|
      words.each { |word| file.puts word }

      @path = file.path
    end
  end

  subject { described_class.new(words) }

  describe "parse" do
    subject { described_class }

    let(:words) { ('aa'..'zz').to_a }
    let(:text)  {
      words.each_slice(100).map { |w| w.shuffle.join(' ') }.join("\n")
    }

    it "should parse unique words" do
      subject.parse(text).to_a =~ words
    end

    it "should sort the unique words" do
      subject.parse(text).to_a == words.sort
    end

    it "should yield unique words when they are seen" do
      seen = []

      subject.parse(text) { |word| seen << word }

      seen.should =~ words
    end
  end

  describe "#initialize" do
    it "should accept a list of words" do
      subject.to_a.should == words
    end

    it "should accept a path to a wordlist file" do
      file = described_class.new(@path)

      file.to_a.should == words
    end
  end

  describe "#each_word" do
    it "should raise a TypeError for non-String / non-Enumerable objects" do
      wordlist = described_class.new(Object.new)

      lambda {
        wordlist.each_word { |word| }
      }.should raise_error(TypeError)
    end
  end

  describe "#each" do
    it "should rewind file lists" do
      subject.each { |word| }

      subject.to_a.should == words
    end

    it "should apply additional mutation rules" do
      wordlist = described_class.new(words)
      wordlist.mutations['o'] = ['0']

      wordlist.to_a.should =~ %w[foo f0o fo0 f00 bar baz]
    end
  end

  describe "#each_n_words" do
    it "should enumerate over every combination of N words" do
      subject.each_n_words(2).to_a.should == %w[
        foofoo foobar foobaz
        barfoo barbar barbaz
        bazfoo bazbar bazbaz
      ]
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ronin-support-0.4.1 spec/wordlist_spec.rb
ronin-support-0.4.0 spec/wordlist_spec.rb