metasploit-framework/spec/lib/metasploit/framework/credential_collection_spec.rb

86 lines
2.3 KiB
Ruby
Raw Normal View History

require 'spec_helper'
require 'metasploit/framework/credential_collection'
describe Metasploit::Framework::CredentialCollection do
describe "#each" do
subject(:collection) do
described_class.new(
2014-06-05 16:37:48 +00:00
username: username,
password: password,
user_file: user_file,
2014-06-05 16:51:11 +00:00
pass_file: pass_file,
userpass_file: userpass_file,
)
end
2014-06-05 16:37:48 +00:00
let(:username) { "user" }
let(:password) { "pass" }
let(:user_file) { nil }
2014-06-05 16:51:11 +00:00
let(:pass_file) { nil }
let(:userpass_file) { nil }
2014-06-05 16:37:48 +00:00
specify do
expect { |b| collection.each(&b) }.to yield_with_args(Metasploit::Framework::Credential)
end
2014-06-05 16:37:48 +00:00
context "when given a user_file and password" do
let(:username) { nil }
let(:user_file) do
filename = "foo"
stub_file = StringIO.new("asdf\njkl\n")
File.stub(:open).with(filename,/^r/).and_yield stub_file
filename
end
specify do
expect { |b| collection.each(&b) }.to yield_successive_args(
Metasploit::Framework::Credential.new(public: "asdf", private: password),
Metasploit::Framework::Credential.new(public: "jkl", private: password),
)
end
end
2014-06-05 16:51:11 +00:00
context "when given a pass_file and username" do
let(:password) { nil }
let(:pass_file) do
filename = "foo"
stub_file = StringIO.new("asdf\njkl\n")
File.stub(:open).with(filename,/^r/).and_return stub_file
filename
end
specify do
expect { |b| collection.each(&b) }.to yield_successive_args(
Metasploit::Framework::Credential.new(public: username, private: "asdf"),
Metasploit::Framework::Credential.new(public: username, private: "jkl"),
)
end
end
2014-06-05 16:54:59 +00:00
context "when given a userspass_file" do
let(:username) { nil }
let(:password) { nil }
let(:userpass_file) do
filename = "foo"
stub_file = StringIO.new("asdf jkl\nfoo bar\n")
File.stub(:open).with(filename,/^r/).and_yield stub_file
filename
end
specify do
expect { |b| collection.each(&b) }.to yield_successive_args(
Metasploit::Framework::Credential.new(public: "asdf", private: "jkl"),
Metasploit::Framework::Credential.new(public: "foo", private: "bar"),
)
end
end
end
end