Skip to content

Commit

Permalink
Land #130, factorygirl updates to factorybot
Browse files Browse the repository at this point in the history
  • Loading branch information
busterb committed Mar 27, 2018
2 parents 7c45be1 + 661d33e commit 4b13e2f
Show file tree
Hide file tree
Showing 52 changed files with 358 additions and 370 deletions.
10 changes: 2 additions & 8 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ source "https://rubygems.org"
# development dependencies will be added by default to the :development group.
gemspec

# This isn't in gemspec because metasploit-framework has its own patched version of 'net/ssh' that it needs to use
# instead of this gem.
# Metasploit::Credential::SSHKey validation and helper methods
gem 'net-ssh'

group :development do
# Entity-Relationship diagrams for developers that need to access database using SQL directly.
gem 'rails-erd'
Expand All @@ -27,10 +22,9 @@ group :development, :test do
# Uploads simplecov reports to coveralls.io
gem 'coveralls', require: false
# supplies factories for producing model instance for specs
# Version 4.1.0 or newer is needed to support generate calls without the 'FactoryGirl.' in factory definitions syntax.
gem 'factory_girl'
gem 'factory_bot'
# auto-load factories from spec/factories
gem 'factory_girl_rails'
gem 'factory_bot_rails'
# jquery-rails is used by the dummy application
gem 'jquery-rails'
# add matchers from shoulda, such as validates_presence_of, which are useful for testing validations, and have_db_*
Expand Down
4 changes: 2 additions & 2 deletions lib/metasploit/credential/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ class Metasploit::Credential::Engine < Rails::Engine
after: 'factory_girl.set_factory_paths',
# before metasploit_data_models because it prepends
before: 'metasploit_data_models.prepend_factory_path' do
if defined? FactoryGirl
if defined? FactoryBot
relative_definition_file_path = config.generators.options[:factory_girl][:dir]
definition_file_path = root.join(relative_definition_file_path)

# unshift so that projects that use metasploit-credential can modify metasploit_credential_* factories
FactoryGirl.definition_file_paths.unshift definition_file_path
FactoryBot.definition_file_paths.unshift definition_file_path
end
end
end
12 changes: 3 additions & 9 deletions metasploit-credential.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,8 @@ Gem::Specification.new do |s|

s.add_runtime_dependency 'rex-socket'

if RUBY_PLATFORM =~ /java/
s.add_runtime_dependency 'jdbc-postgres'
s.add_runtime_dependency 'activerecord-jdbcpostgresql-adapter'
s.add_runtime_dependency 'net-ssh'

s.platform = Gem::Platform::JAVA
else
s.add_runtime_dependency 'pg'

s.platform = Gem::Platform::RUBY
end
s.add_runtime_dependency 'pg', '~> 0.15'
s.platform = Gem::Platform::RUBY
end
2 changes: 1 addition & 1 deletion spec/factories/metasploit/credential/blank_usernames.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :metasploit_credential_blank_username,
class: Metasploit::Credential::BlankUsername do
initialize_with { Metasploit::Credential::BlankUsername.where(username: "").first_or_create }
Expand Down
12 changes: 6 additions & 6 deletions spec/factories/metasploit/credential/cores.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :metasploit_credential_core,
class: Metasploit::Credential::Core do
transient do
Expand All @@ -9,20 +9,20 @@

association :public, factory: :metasploit_credential_public

origin { FactoryGirl.build(origin_factory) }
private { FactoryGirl.build(private_factory) }
realm { FactoryGirl.build(realm_factory) }
origin { FactoryBot.build(origin_factory) }
private { FactoryBot.build(private_factory) }
realm { FactoryBot.build(realm_factory) }

workspace {
case origin
when Metasploit::Credential::Origin::Import
FactoryGirl.build(:mdm_workspace)
FactoryBot.build(:mdm_workspace)
when Metasploit::Credential::Origin::Manual
user = origin.user

# an admin can use workspaces it is not a member of
if user.admin
FactoryGirl.build(:mdm_workspace)
FactoryBot.build(:mdm_workspace)
else
origin.user.workspaces.sample
end
Expand Down
4 changes: 2 additions & 2 deletions spec/factories/metasploit/credential/importer/cores.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
long_form_headers = 'username,private_type,private_data,realm_key,realm_value,host_address,service_port,service_name,service_protocol,status,access_level,last_attempted_at'
short_form_headers = 'username,private_data'
login_status = Metasploit::Model::Login::Status::ALL.select {|x| x != Metasploit::Model::Login::Status::UNTRIED }.sample
Expand All @@ -7,7 +7,7 @@

factory :metasploit_credential_core_importer,
class: Metasploit::Credential::Importer::Core do
origin { FactoryGirl.build :metasploit_credential_origin_import }
origin { FactoryBot.build :metasploit_credential_origin_import }
input { generate(:well_formed_csv_compliant_header) }
end

Expand Down
6 changes: 3 additions & 3 deletions spec/factories/metasploit/credential/importer/pwdumps.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FactoryGirl.define do
FactoryBot.define do
factory :metasploit_credential_importer_pwdump,
class: Metasploit::Credential::Importer::Pwdump do
filename "pwdump-import-#{Time.now.to_i}"
origin {FactoryGirl.build :metasploit_credential_origin_import }
input { FactoryGirl.generate(:wellformed_pwdump) }
origin {FactoryBot.build :metasploit_credential_origin_import }
input { FactoryBot.generate(:wellformed_pwdump) }
end

# Represents a file that should do an error-free import
Expand Down
16 changes: 8 additions & 8 deletions spec/factories/metasploit/credential/importer/zips.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

require 'zip'

FactoryGirl.define do
FactoryBot.define do
factory :metasploit_credential_importer_zip,
class: Metasploit::Credential::Importer::Zip do
input { generate :metasploit_credential_importer_zip_file }
origin {FactoryGirl.build :metasploit_credential_origin_import }
origin {FactoryBot.build :metasploit_credential_origin_import }
end


Expand All @@ -29,12 +29,12 @@

# Create keys
key_data = 5.times.collect do
FactoryGirl.build(:metasploit_credential_ssh_key).data
FactoryBot.build(:metasploit_credential_ssh_key).data
end

# associate keys with usernames
csv_hash = key_data.inject({}) do |hash, data|
username = FactoryGirl.generate(:metasploit_credential_public_username)
username = FactoryBot.generate(:metasploit_credential_public_username)
hash[username] = data
hash
end
Expand Down Expand Up @@ -77,12 +77,12 @@

# Create keys
key_data = 5.times.collect do
FactoryGirl.build(:metasploit_credential_ssh_key).data
FactoryBot.build(:metasploit_credential_ssh_key).data
end

# associate keys with usernames
csv_hash = key_data.inject({}) do |hash, data|
username = FactoryGirl.generate(:metasploit_credential_public_username)
username = FactoryBot.generate(:metasploit_credential_public_username)
hash[username] = data
hash
end
Expand Down Expand Up @@ -121,12 +121,12 @@

# Create keys
key_data = 5.times.collect do
FactoryGirl.build(:metasploit_credential_ssh_key).data
FactoryBot.build(:metasploit_credential_ssh_key).data
end

# associate keys with usernames
csv_hash = key_data.inject({}) do |hash, data|
username = FactoryGirl.generate(:metasploit_credential_public_username)
username = FactoryBot.generate(:metasploit_credential_public_username)
hash[username] = data
hash
end
Expand Down
6 changes: 3 additions & 3 deletions spec/factories/metasploit/credential/logins.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FactoryGirl.define do
FactoryBot.define do
factory :metasploit_credential_login,
class: Metasploit::Credential::Login do
transient do
host {
FactoryGirl.build(
FactoryBot.build(
:mdm_host, workspace: workspace
)
}
Expand All @@ -20,7 +20,7 @@
end
}
service {
FactoryGirl.build(
FactoryBot.build(
:mdm_service,
host: host
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'digest/sha1'

FactoryGirl.define do
FactoryBot.define do
factory :metasploit_credential_nonreplayable_hash,
class: Metasploit::Credential::NonreplayableHash,
parent: :metasploit_credential_password_hash do
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/metasploit/credential/ntlm_hashes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
klass = Metasploit::Credential::NTLMHash

factory :metasploit_credential_ntlm_hash,
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/metasploit/credential/origin/imports.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :metasploit_credential_origin_import,
class: Metasploit::Credential::Origin::Import do
association :task, factory: :mdm_task
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/metasploit/credential/origin/manuals.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :metasploit_credential_origin_manual,
class: Metasploit::Credential::Origin::Manual do
association :user, factory: :mdm_user
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/metasploit/credential/origin/services.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :metasploit_credential_origin_service,
class: Metasploit::Credential::Origin::Service do
transient do
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/metasploit/credential/origin/sessions.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :metasploit_credential_origin_session,
class: Metasploit::Credential::Origin::Session do
association :session, factory: :mdm_session
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/metasploit/credential/password_hashes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :metasploit_credential_password_hash,
# no need to declare metasploit_credential_private as the :parent because :metasploit_credential_password_hash
# uses its own data sequence to differentiate password hashes from other private data and #type is
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/metasploit/credential/passwords.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :metasploit_credential_password,
# no need to declare metasploit_credential_private as the :parent because :metasploit_credential_password uses
# its own data sequence to differentiate passwords from other private data and #type is automatically
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/metasploit/credential/postgres_md5.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
klass = Metasploit::Credential::PostgresMD5

factory :metasploit_credential_postgres_md5,
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/metasploit/credential/privates.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

FactoryGirl.define do
FactoryBot.define do
factory :metasploit_credential_private,
class: Metasploit::Credential::Private do
data { generate :metasploit_credential_private_data }
Expand Down
4 changes: 2 additions & 2 deletions spec/factories/metasploit/credential/publics.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :metasploit_credential_public,
class: Metasploit::Credential::Username do
transient do
Expand All @@ -17,7 +17,7 @@
}
end

initialize_with { FactoryGirl.build(public_factory, username: username) }
initialize_with { FactoryBot.build(public_factory, username: username) }
end

sequence :metasploit_credential_public_username do |n|
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/metasploit/credential/realms.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do

factory :metasploit_credential_realm,
class: Metasploit::Credential::Realm do
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/metasploit/credential/replayable_hashes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :metasploit_credential_replayable_hash,
class: Metasploit::Credential::ReplayableHash,
parent: :metasploit_credential_password_hash
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/metasploit/credential/ssh_keys.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :metasploit_credential_ssh_key,
class: Metasploit::Credential::SSHKey do
transient do
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/metasploit/credential/usernames.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :metasploit_credential_username,
class: Metasploit::Credential::Username do
username { generate :metasploit_credential_public_username }
Expand Down
Loading

0 comments on commit 4b13e2f

Please sign in to comment.