Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/spec/lib/metasploit/framework/credential_spec.rb
Views: 11784
require 'spec_helper'1require 'metasploit/framework/credential'23RSpec.describe Metasploit::Framework::Credential do45subject(:cred_detail) {6described_class.new7}89let(:public) { "public" }10let(:private) { "private" }11let(:realm) { "realm" }12let(:realm_type) { Metasploit::Model::Realm::Key::ACTIVE_DIRECTORY_DOMAIN }13let(:private_type) { :password }1415it { is_expected.to respond_to :paired }16it { is_expected.to respond_to :private }17it { is_expected.to respond_to :private_type }18it { is_expected.to respond_to :public }19it { is_expected.to respond_to :realm }20it { is_expected.to respond_to :realm_key }2122describe "#paired" do23it "defaults to true" do24expect(cred_detail.paired).to be_truthy25end26end2728context 'validations' do2930it 'is not valid without paired being set' do31expect(cred_detail).to_not be_valid32end3334context 'when not paired' do35before(:example) do36cred_detail.paired = false37end3839it 'is invalid without at least a public or a private' do40expect(cred_detail).to_not be_valid41end4243it 'is valid with just a public' do44cred_detail.public = 'root'45expect(cred_detail).to be_valid46end4748it 'is valid with just a private' do49cred_detail.private = 'toor'50expect(cred_detail).to be_valid51end52end5354context 'when paired' do55before(:example) do56cred_detail.paired = true57end5859it 'is invalid with only a public' do60cred_detail.public = 'root'61expect(cred_detail).to_not be_valid62end6364it 'is invalid with only a private' do65cred_detail.private = 'toor'66expect(cred_detail).to_not be_valid67end6869it 'is invalid with empty string for public' do70cred_detail.public = ''71cred_detail.private = 'toor'72expect(cred_detail).to_not be_valid73end7475it 'is valid with empty string for private' do76cred_detail.public = 'root'77cred_detail.private = ''78expect(cred_detail).to be_valid79end80end8182end8384describe "#to_credential" do85subject(:cred_detail) do86described_class.new(public: public, private: private, realm: realm)87end88it { is_expected.to respond_to :to_credential }89it "should return self" do90expect(cred_detail.to_credential).to eq(cred_detail)91end92end9394describe "#==" do95let(:public) { "public" }96let(:private) { "private" }97let(:realm) { "realm" }98subject(:cred_detail) do99described_class.new(public: public, private: private, realm: realm)100end101102context "when all attributes match" do103let(:other) do104described_class.new(public: public, private: private, realm: realm)105end106specify do107expect(other).to eq(cred_detail)108end109end110111context "when realm does not match" do112let(:other) do113described_class.new(public: public, private: private, realm: "")114end115specify do116expect(other).not_to eq(cred_detail)117end118end119120context "when private does not match" do121let(:other) do122described_class.new(public: public, private: "", realm: realm)123end124specify do125expect(other).not_to eq(cred_detail)126end127end128129context "when public does not match" do130let(:other) do131described_class.new(public: "", private: private, realm: realm)132end133specify do134expect(other).not_to eq(cred_detail)135end136end137context "when comparing to a different object" do138let(:other) {'a string'}139specify do140expect(other).not_to eq(cred_detail)141end142end143end144145describe '#to_h' do146subject(:cred_detail) do147described_class.new(public: public, private: private, realm: realm, realm_key: realm_type, private_type: private_type)148end149it 'returns a hash in the format expect for create_credential' do150cred_hash = {151private_data: private,152private_type: private_type,153username: public,154realm_key: realm_type,155realm_value: realm156}157expect(cred_detail.to_h).to eq cred_hash158end159end160end161162163