2014-04-22 16:05:58 +00:00
|
|
|
require 'spec_helper'
|
2014-06-04 18:01:09 +00:00
|
|
|
require 'metasploit/framework/credential'
|
2014-04-22 16:05:58 +00:00
|
|
|
|
2014-06-04 18:01:09 +00:00
|
|
|
describe Metasploit::Framework::Credential do
|
2014-04-22 16:05:58 +00:00
|
|
|
|
|
|
|
subject(:cred_detail) {
|
|
|
|
described_class.new
|
|
|
|
}
|
|
|
|
|
2014-07-31 23:10:48 +00:00
|
|
|
let(:public) { "public" }
|
|
|
|
let(:private) { "private" }
|
|
|
|
let(:realm) { "realm" }
|
|
|
|
let(:realm_type) { Metasploit::Model::Realm::Key::ACTIVE_DIRECTORY_DOMAIN }
|
|
|
|
let(:private_type) { :password }
|
|
|
|
|
2014-04-22 16:05:58 +00:00
|
|
|
it { should respond_to :paired }
|
|
|
|
it { should respond_to :private }
|
2014-07-07 18:07:28 +00:00
|
|
|
it { should respond_to :private_type }
|
2014-04-22 16:05:58 +00:00
|
|
|
it { should respond_to :public }
|
|
|
|
it { should respond_to :realm }
|
2014-07-07 18:07:28 +00:00
|
|
|
it { should respond_to :realm_key }
|
2014-04-22 16:05:58 +00:00
|
|
|
|
2014-05-08 18:34:31 +00:00
|
|
|
describe "#paired" do
|
|
|
|
it "defaults to true" do
|
2014-08-25 23:13:38 +00:00
|
|
|
expect(cred_detail.paired).to be_truthy
|
2014-05-08 18:34:31 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-04-22 16:05:58 +00:00
|
|
|
context 'validations' do
|
|
|
|
|
|
|
|
it 'is not valid without paired being set' do
|
|
|
|
expect(cred_detail).to_not be_valid
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when not paired' do
|
|
|
|
before(:each) do
|
|
|
|
cred_detail.paired = false
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is invalid without at least a public or a private' do
|
|
|
|
expect(cred_detail).to_not be_valid
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is valid with just a public' do
|
|
|
|
cred_detail.public = 'root'
|
|
|
|
expect(cred_detail).to be_valid
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is valid with just a private' do
|
|
|
|
cred_detail.private = 'toor'
|
|
|
|
expect(cred_detail).to be_valid
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when paired' do
|
|
|
|
before(:each) do
|
|
|
|
cred_detail.paired = true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is invalid with only a public' do
|
|
|
|
cred_detail.public = 'root'
|
|
|
|
expect(cred_detail).to_not be_valid
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is invalid with only a private' do
|
|
|
|
cred_detail.private = 'toor'
|
|
|
|
expect(cred_detail).to_not be_valid
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is invalid with empty string for public' do
|
|
|
|
cred_detail.public = ''
|
|
|
|
cred_detail.private = 'toor'
|
|
|
|
expect(cred_detail).to_not be_valid
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is valid with empty string for private' do
|
|
|
|
cred_detail.public = 'root'
|
|
|
|
cred_detail.private = ''
|
|
|
|
expect(cred_detail).to be_valid
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-06-05 16:37:48 +00:00
|
|
|
end
|
|
|
|
|
2014-07-31 23:10:48 +00:00
|
|
|
describe "#to_credential" do
|
2014-06-26 16:05:59 +00:00
|
|
|
subject(:cred_detail) do
|
|
|
|
described_class.new(public: public, private: private, realm: realm)
|
|
|
|
end
|
|
|
|
it { should respond_to :to_credential }
|
|
|
|
it "should return self" do
|
|
|
|
cred_detail.to_credential.should eq(cred_detail)
|
|
|
|
end
|
|
|
|
end
|
2014-07-07 18:07:28 +00:00
|
|
|
|
2014-06-05 16:37:48 +00:00
|
|
|
describe "#==" do
|
|
|
|
let(:public) { "public" }
|
|
|
|
let(:private) { "private" }
|
|
|
|
let(:realm) { "realm" }
|
|
|
|
subject(:cred_detail) do
|
|
|
|
described_class.new(public: public, private: private, realm: realm)
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when all attributes match" do
|
|
|
|
let(:other) do
|
|
|
|
described_class.new(public: public, private: private, realm: realm)
|
|
|
|
end
|
|
|
|
specify do
|
|
|
|
expect(other).to eq(cred_detail)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when realm does not match" do
|
|
|
|
let(:other) do
|
|
|
|
described_class.new(public: public, private: private, realm: "")
|
|
|
|
end
|
|
|
|
specify do
|
|
|
|
expect(other).not_to eq(cred_detail)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when private does not match" do
|
|
|
|
let(:other) do
|
|
|
|
described_class.new(public: public, private: "", realm: realm)
|
|
|
|
end
|
|
|
|
specify do
|
|
|
|
expect(other).not_to eq(cred_detail)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when public does not match" do
|
|
|
|
let(:other) do
|
|
|
|
described_class.new(public: "", private: private, realm: realm)
|
|
|
|
end
|
|
|
|
specify do
|
|
|
|
expect(other).not_to eq(cred_detail)
|
|
|
|
end
|
|
|
|
end
|
2014-07-23 21:17:09 +00:00
|
|
|
context "when comparing to a different object" do
|
|
|
|
let(:other) {'a string'}
|
|
|
|
specify do
|
|
|
|
expect(other).not_to eq(cred_detail)
|
|
|
|
end
|
|
|
|
end
|
2014-04-22 16:05:58 +00:00
|
|
|
end
|
2014-07-31 23:10:48 +00:00
|
|
|
|
2014-08-01 14:45:51 +00:00
|
|
|
describe '#to_h' do
|
2014-07-31 23:10:48 +00:00
|
|
|
subject(:cred_detail) do
|
|
|
|
described_class.new(public: public, private: private, realm: realm, realm_key: realm_type, private_type: private_type)
|
|
|
|
end
|
|
|
|
it 'returns a hash in the format expect for create_credential' do
|
|
|
|
cred_hash = {
|
|
|
|
private_data: private,
|
|
|
|
private_type: private_type,
|
|
|
|
username: public,
|
|
|
|
realm_key: realm_type,
|
|
|
|
realm_value: realm
|
|
|
|
}
|
2014-08-01 14:45:51 +00:00
|
|
|
expect(cred_detail.to_h).to eq cred_hash
|
2014-07-31 23:10:48 +00:00
|
|
|
end
|
|
|
|
end
|
2014-05-08 18:34:31 +00:00
|
|
|
end
|