metasploit-erd 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe Metasploit::ERD do
4
+ context 'CONSTANTS' do
5
+ context 'VERSION' do
6
+ subject(:version) do
7
+ described_class::VERSION
8
+ end
9
+
10
+ it 'is Metasploit::ERD::Version.full' do
11
+ expect(version).to eq(Metasploit::ERD::Version.full)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,26 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+
3
+ # require before 'metasploit/erd' so coverage is shown for files required by 'metasploit/erd'
4
+ require 'simplecov'
5
+ require 'coveralls'
6
+
7
+ if ENV['TRAVIS'] == 'true'
8
+ # don't generate local report as it is inaccessible on travis-ci, which is why coveralls is being used.
9
+ SimpleCov.formatter = Coveralls::SimpleCov::Formatter
10
+ else
11
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
12
+ # either generate the local report
13
+ SimpleCov::Formatter::HTMLFormatter
14
+ ]
15
+ end
16
+
17
+ require 'metasploit/erd'
18
+
19
+ # Requires supporting ruby files with custom matchers and macros, etc,
20
+ # in spec/support/ and its subdirectories.
21
+ spec_pathname = Pathname.new(__FILE__).realpath.parent
22
+ glob_pathname = spec_pathname.join('support', '**', '*.rb')
23
+
24
+ Dir[glob_pathname].each do |f|
25
+ require f
26
+ end
@@ -0,0 +1,12 @@
1
+ shared_context 'ActiveRecord::Base connection' do
2
+ before(:each) do
3
+ ActiveRecord::Base.establish_connection(
4
+ adapter: 'sqlite3',
5
+ database: ':memory:'
6
+ )
7
+ end
8
+
9
+ after(:each) do
10
+ ActiveRecord::Base.connection.disconnect!
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ shared_context 'ActiveRecord::Base.descendants cleaner' do
2
+ before(:each) do
3
+ expect(ActiveRecord::Base.direct_descendants).to be_empty
4
+ end
5
+
6
+ after(:each) do
7
+ # `ActiveSupport::DescendantsTracker.clear` will not clear ActiveRecord::Base subclasses because
8
+ # ActiveSupport::Dependencies is loaded
9
+ ActiveRecord::Base.direct_descendants.clear
10
+ end
11
+ end
@@ -0,0 +1,284 @@
1
+ shared_examples_for 'Metasploit::ERD::Clusterable' do
2
+ include_context 'ActiveRecord::Base connection'
3
+
4
+ #
5
+ # Methods
6
+ #
7
+
8
+ def migrate
9
+ ActiveRecord::Migration.verbose = false
10
+
11
+ ActiveRecord::Migration.create_table :dummy_factories do |t|
12
+ t.timestamps
13
+ end
14
+
15
+ ActiveRecord::Migration.create_table :dummy_widgets do |t|
16
+ t.references :factory
17
+
18
+ t.timestamps
19
+ end
20
+ end
21
+
22
+ #
23
+ # lets
24
+ #
25
+
26
+ let(:dummy_module) {
27
+ Module.new do
28
+ def self.table_name_prefix
29
+ 'dummy_'
30
+ end
31
+ end
32
+ }
33
+
34
+ let(:dummy_factory) {
35
+ Class.new(ActiveRecord::Base) do
36
+ has_many :widgets,
37
+ class_name: 'Dummy::Widget',
38
+ inverse_of: :factory
39
+ end
40
+ }
41
+
42
+ let(:dummy_widget) {
43
+ Class.new(ActiveRecord::Base) do
44
+ belongs_to :factory,
45
+ class_name: 'Dummy::Factory',
46
+ inverse_of: :widgets
47
+ end
48
+ }
49
+
50
+ #
51
+ # Callbacks
52
+ #
53
+
54
+ before(:each) do
55
+ migrate
56
+
57
+ stub_const('Dummy', dummy_module)
58
+ stub_const('Dummy::Factory', dummy_factory)
59
+ stub_const('Dummy::Widget', dummy_widget)
60
+ end
61
+
62
+ context '#diagram' do
63
+ subject(:diagram) {
64
+ entity.diagram(*arguments)
65
+ }
66
+
67
+ let(:arguments) {
68
+ []
69
+ }
70
+
71
+ it { should be_a Metasploit::ERD::Diagram }
72
+
73
+ context 'Metasploit::ERD::Diagram#create' do
74
+ subject(:create) {
75
+ diagram.create
76
+ }
77
+
78
+ #
79
+ # lets
80
+ #
81
+
82
+ let(:arguments) {
83
+ [
84
+ {
85
+ directory: directory
86
+ }
87
+ ]
88
+ }
89
+
90
+ let(:directory) {
91
+ spec_pathname.join('tmp')
92
+ }
93
+
94
+ let(:spec_pathname) {
95
+ Pathname.new(__FILE__).parent.parent.parent.parent.parent.parent
96
+ }
97
+
98
+ #
99
+ # Callbacks
100
+ #
101
+
102
+ before(:each) do
103
+ if directory.exist?
104
+ directory.rmtree
105
+ end
106
+ end
107
+
108
+ after(:each) do
109
+ directory.rmtree
110
+ end
111
+
112
+ context 'directory' do
113
+ context 'with existing' do
114
+ before(:each) do
115
+ directory.mkpath
116
+ end
117
+
118
+ it 'returns path where diagram was written' do
119
+ expect(create).to be_a String
120
+ end
121
+ end
122
+
123
+ context 'without existing' do
124
+ it 'creates directory' do
125
+ expect {
126
+ create
127
+ }.to change(directory, :directory?).to(true)
128
+ end
129
+
130
+ it 'returns path where diagram was written' do
131
+ expect(create).to be_a String
132
+ end
133
+ end
134
+ end
135
+
136
+ end
137
+
138
+ context 'Metasploit::ERD::Diagram#domain' do
139
+ subject(:domain) {
140
+ diagram.domain
141
+ }
142
+
143
+ it 'is #domain' do
144
+ entity_domain = entity.domain
145
+ allow(entity).to receive(:domain).and_return(entity_domain)
146
+
147
+ expect(domain).to eq(entity_domain)
148
+ end
149
+ end
150
+
151
+ context 'Metasploit::ERD::Diagram#options' do
152
+ subject(:options) {
153
+ diagram.options
154
+ }
155
+
156
+ context 'with :basename' do
157
+ let(:arguments) {
158
+ [
159
+ argument_options
160
+ ]
161
+ }
162
+
163
+ let(:argument_options) {
164
+ {
165
+ basename: argument_basename
166
+ }
167
+ }
168
+
169
+ context 'with nil' do
170
+ let(:argument_basename) {
171
+ nil
172
+ }
173
+
174
+ it 'is not retained' do
175
+ expect(options).not_to have_key(:basename)
176
+ end
177
+ end
178
+
179
+ context 'without nil' do
180
+ let(:argument_basename) {
181
+ 'basename.extra.extension'
182
+ }
183
+
184
+ it 'is not retained' do
185
+ expect(options).not_to have_key(:basename)
186
+ end
187
+
188
+ context '[:filename]' do
189
+ subject(:filename) {
190
+ options[:filename]
191
+ }
192
+
193
+ it 'ends with :basename' do
194
+ expect(filename).to end_with(argument_basename)
195
+ end
196
+ end
197
+
198
+ context '[:directory]' do
199
+ let(:argument_options) {
200
+ super().merge(
201
+ directory: argument_directory
202
+ )
203
+ }
204
+
205
+ context 'with nil' do
206
+ let(:argument_directory) {
207
+ nil
208
+ }
209
+
210
+ it 'is not retained' do
211
+ expect(options).not_to have_key(:directory)
212
+ end
213
+
214
+ context '[:filename]' do
215
+ subject(:filename) {
216
+ options[:filename]
217
+ }
218
+
219
+ it 'uses Dir.pwd for the directory' do
220
+ expect(File.dirname(filename)).to eq(Dir.pwd)
221
+ end
222
+ end
223
+ end
224
+
225
+ context 'without nil' do
226
+ let(:argument_directory) {
227
+ '/a/directory'
228
+ }
229
+
230
+ it 'is not retained' do
231
+ expect(options).not_to have_key(:directory)
232
+ end
233
+
234
+ context '[:filename]' do
235
+ subject(:filename) {
236
+ options[:filename]
237
+ }
238
+
239
+ it 'uses :directory for the directory' do
240
+ expect(File.dirname(filename)).to eq(argument_directory)
241
+ end
242
+ end
243
+ end
244
+ end
245
+ end
246
+ end
247
+
248
+ context '[:directory]' do
249
+ it 'is not retained' do
250
+ expect(options).not_to have_key(:directory)
251
+ end
252
+ end
253
+
254
+ context '[:title]' do
255
+ subject(:title) {
256
+ options[:title]
257
+ }
258
+
259
+ it { should be_a String }
260
+ end
261
+ end
262
+ end
263
+
264
+ context '#domain' do
265
+ subject(:domain) do
266
+ entity.domain
267
+ end
268
+
269
+ it 'creates RailsERD::Domain from #cluster Metasploit::ERD::Cluster#class_set' do
270
+ # ensures entity's class defined cluster
271
+ cluster = entity.cluster
272
+ class_set = cluster.class_set
273
+
274
+ expect(entity).to receive(:cluster).and_return(cluster)
275
+ expect(cluster).to receive(:class_set).and_return(class_set)
276
+ expect(RailsERD::Domain).to receive(:new).with(
277
+ class_set,
278
+ hash_including(warn: false)
279
+ )
280
+
281
+ domain
282
+ end
283
+ end
284
+ end
metadata ADDED
@@ -0,0 +1,187 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: metasploit-erd
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Luke Imhoff
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '2.14'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '2.14'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activerecord
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '3.2'
62
+ - - <
63
+ - !ruby/object:Gem::Version
64
+ version: 4.0.0
65
+ type: :runtime
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '3.2'
72
+ - - <
73
+ - !ruby/object:Gem::Version
74
+ version: 4.0.0
75
+ - !ruby/object:Gem::Dependency
76
+ name: activesupport
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '3.2'
82
+ - - <
83
+ - !ruby/object:Gem::Version
84
+ version: 4.0.0
85
+ type: :runtime
86
+ prerelease: false
87
+ version_requirements: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '3.2'
92
+ - - <
93
+ - !ruby/object:Gem::Version
94
+ version: 4.0.0
95
+ - !ruby/object:Gem::Dependency
96
+ name: rails-erd
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: '1.1'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ~>
107
+ - !ruby/object:Gem::Version
108
+ version: '1.1'
109
+ description: Traces the belongs_to associations on ActiveRecord::Base descendants
110
+ to find the minimum cluster in which all foreign keys are fulfilled in the Entity-Relationship
111
+ Diagram.
112
+ email:
113
+ - luke_imhoff@rapid7.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .coveralls.yml
119
+ - .gitignore
120
+ - .rspec
121
+ - .simplecov
122
+ - .travis.yml
123
+ - .yardopts
124
+ - Gemfile
125
+ - LICENSE
126
+ - README.md
127
+ - Rakefile
128
+ - lib/metasploit/erd.rb
129
+ - lib/metasploit/erd/cluster.rb
130
+ - lib/metasploit/erd/clusterable.rb
131
+ - lib/metasploit/erd/diagram.rb
132
+ - lib/metasploit/erd/entity.rb
133
+ - lib/metasploit/erd/entity/class.rb
134
+ - lib/metasploit/erd/entity/namespace.rb
135
+ - lib/metasploit/erd/relationship.rb
136
+ - lib/metasploit/erd/version.rb
137
+ - lib/tasks/yard.rake
138
+ - metasploit-erd.gemspec
139
+ - spec/metasploit/erd/cluster_spec.rb
140
+ - spec/metasploit/erd/diagram_spec.rb
141
+ - spec/metasploit/erd/entity/class_spec.rb
142
+ - spec/metasploit/erd/entity/namespace_spec.rb
143
+ - spec/metasploit/erd/relationship_spec.rb
144
+ - spec/metasploit/erd/version_spec.rb
145
+ - spec/metasploit/erd_spec.rb
146
+ - spec/spec_helper.rb
147
+ - spec/support/shared/contexts/active_record_base_connection.rb
148
+ - spec/support/shared/contexts/active_record_base_descendants_cleaner.rb
149
+ - spec/support/shared/examples/metasploit/erd/clusterable.rb
150
+ homepage: https://github.com/rapid7/metasploit-erd
151
+ licenses:
152
+ - BSD-3-clause
153
+ metadata: {}
154
+ post_install_message:
155
+ rdoc_options: []
156
+ require_paths:
157
+ - lib
158
+ required_ruby_version: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - ! '>='
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ required_rubygems_version: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ! '>='
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ requirements: []
169
+ rubyforge_project:
170
+ rubygems_version: 2.2.2
171
+ signing_key:
172
+ specification_version: 4
173
+ summary: Extensions to rails-erd to find clusters of models to generate subdomains
174
+ specific to each model
175
+ test_files:
176
+ - spec/metasploit/erd/cluster_spec.rb
177
+ - spec/metasploit/erd/diagram_spec.rb
178
+ - spec/metasploit/erd/entity/class_spec.rb
179
+ - spec/metasploit/erd/entity/namespace_spec.rb
180
+ - spec/metasploit/erd/relationship_spec.rb
181
+ - spec/metasploit/erd/version_spec.rb
182
+ - spec/metasploit/erd_spec.rb
183
+ - spec/spec_helper.rb
184
+ - spec/support/shared/contexts/active_record_base_connection.rb
185
+ - spec/support/shared/contexts/active_record_base_descendants_cleaner.rb
186
+ - spec/support/shared/examples/metasploit/erd/clusterable.rb
187
+ has_rdoc: