Merge pull request #92 from rapid7/feature/MSP-9912/metamodule-refactor-ssh-key

Feature/msp 9912/metamodule refactor ssh key
bug/bundler_fix
dmaloney-r7 2014-06-27 11:48:57 -05:00
commit 0a6a5a0a12
10 changed files with 60 additions and 2 deletions

View File

@ -0,0 +1,14 @@
# Adds associations to `Metasploit::Credential::Core` which are inverses of association on models under
# {BruteForce::Reuse}.
module Metasploit::Credential::Core::ToCredential
extend ActiveSupport::Concern
included do
def to_credential
Metasploit::Framework::Credential.new(public: public.try(:username), private: private.try(:data), realm: realm.try(:value) )
end
end
end

View File

@ -61,7 +61,11 @@ module Metasploit
def ==(other)
other.public == self.public && other.private == self.private && other.realm == self.realm
end
def to_credential
self
end
private
def at_realm

View File

@ -101,7 +101,8 @@ module Metasploit
consecutive_error_count = 0
total_error_count = 0
cred_details.each do |credential|
cred_details.each do |raw_credential|
credential = raw_credential.to_credential
result = attempt_login(credential)
result.freeze

View File

@ -74,6 +74,19 @@ describe Metasploit::Framework::Credential do
end
describe ".to_credential" do
let(:public) { "public" }
let(:private) { "private" }
let(:realm) { "realm" }
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
describe "#==" do
let(:public) { "public" }
let(:private) { "private" }

View File

@ -0,0 +1,5 @@
require 'spec_helper'
describe Metasploit::Credential::Core do
it_should_behave_like 'Metasploit::Credential::Core::ToCredential'
end

View File

@ -0,0 +1,21 @@
require 'metasploit/framework/credential'
shared_examples_for 'Metasploit::Credential::Core::ToCredential' do
context "methods" do
context ".to_credential" do
subject(:crednetial_core) do
FactoryGirl.create(:metasploit_credential_core)
end
it { should respond_to :to_credential }
it "should return a Metasploit::Framework::Credential" do
expect(
crednetial_core.to_credential
).to be_a Metasploit::Framework::Credential
end
end
end
end