ronin-db 0.1.0.beta1-java → 0.1.0.beta3-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +1 -0
  3. data/.yardopts +1 -1
  4. data/Gemfile +1 -6
  5. data/README.md +4 -2
  6. data/gemspec.yml +9 -2
  7. data/lib/ronin/db/cli/command.rb +1 -1
  8. data/lib/ronin/db/cli/commands/add.rb +1 -1
  9. data/lib/ronin/db/cli/commands/asn.rb +3 -3
  10. data/lib/ronin/db/cli/commands/creds.rb +1 -1
  11. data/lib/ronin/db/cli/commands/edit.rb +1 -1
  12. data/lib/ronin/db/cli/commands/emails.rb +1 -1
  13. data/lib/ronin/db/cli/commands/hosts.rb +1 -1
  14. data/lib/ronin/db/cli/commands/ips.rb +4 -2
  15. data/lib/ronin/db/cli/commands/irb.rb +1 -1
  16. data/lib/ronin/db/cli/commands/list.rb +1 -1
  17. data/lib/ronin/db/cli/commands/migrate.rb +1 -1
  18. data/lib/ronin/db/cli/commands/remove.rb +1 -1
  19. data/lib/ronin/db/cli/commands/urls.rb +1 -1
  20. data/lib/ronin/db/cli/database_command.rb +1 -1
  21. data/lib/ronin/db/cli/model_command.rb +1 -1
  22. data/lib/ronin/db/cli/modifiable.rb +2 -2
  23. data/lib/ronin/db/cli/resources_command.rb +1 -1
  24. data/lib/ronin/db/cli/ruby_shell.rb +1 -1
  25. data/lib/ronin/db/cli/uri_methods.rb +1 -1
  26. data/lib/ronin/db/cli.rb +6 -1
  27. data/lib/ronin/db/config_file.rb +1 -1
  28. data/lib/ronin/db/exceptions.rb +1 -1
  29. data/lib/ronin/db/home.rb +1 -1
  30. data/lib/ronin/db/root.rb +1 -1
  31. data/lib/ronin/db/version.rb +2 -2
  32. data/lib/ronin/db.rb +3 -3
  33. data/man/ronin-db-asn.1 +1 -1
  34. data/man/ronin-db-asn.1.md +1 -1
  35. data/ronin-db.gemspec +2 -1
  36. metadata +11 -21
  37. data/spec/cli/commands/add_spec.rb +0 -220
  38. data/spec/cli/commands/edit_spec.rb +0 -12
  39. data/spec/cli/commands/irb_spec.rb +0 -26
  40. data/spec/cli/database_command_spec.rb +0 -53
  41. data/spec/cli/model_command_spec.rb +0 -237
  42. data/spec/cli/ruby_shell_spec.rb +0 -14
  43. data/spec/cli/uri_methods_spec.rb +0 -190
  44. data/spec/spec_helper.rb +0 -15
@@ -1,220 +0,0 @@
1
- require 'spec_helper'
2
- require 'ronin/db/cli/commands/add'
3
-
4
- describe Ronin::DB::CLI::Commands::Add do
5
- describe "options" do
6
- before { subject.parse_options(argv) }
7
-
8
- describe "--adapter" do
9
- let(:adapter) { 'sqlite3' }
10
- let(:argv) { ['--adapter', adapter] }
11
-
12
- it "must set #config[:adapter]" do
13
- expect(subject.config[:adapter]).to eq(adapter)
14
- end
15
- end
16
-
17
- describe "--sqlite3" do
18
- let(:database) { '/path/to/file.sqlite3' }
19
- let(:argv) { ['--sqlite3', database] }
20
-
21
- it "must set #config[:adapter] to 'sqlite3'" do
22
- expect(subject.config[:adapter]).to eq('sqlite3')
23
- end
24
-
25
- it "must set #config[:database] to the given path" do
26
- expect(subject.config[:database]).to eq(database)
27
- end
28
-
29
- context "when the argument is a relative path" do
30
- let(:database) { 'file.sqlite3' }
31
-
32
- it "must expand the relative path before setting #config[:database]" do
33
- expect(subject.config[:database]).to eq(File.expand_path(database))
34
- end
35
- end
36
- end
37
-
38
- describe "--mysql2" do
39
- let(:argv) { ['--mysql2'] }
40
-
41
- it "must set #config[:adapter] to 'mysql2'" do
42
- expect(subject.config[:adapter]).to eq('mysql2')
43
- end
44
- end
45
-
46
- describe "--postgresql" do
47
- let(:argv) { ['--postgresql'] }
48
-
49
- it "must set #config[:adapter] to 'postgresql'" do
50
- expect(subject.config[:adapter]).to eq('postgresql')
51
- end
52
- end
53
-
54
- describe "--host" do
55
- let(:host) { 'example.com' }
56
- let(:argv) { ['--host', host] }
57
-
58
- it "must set #config[:host]" do
59
- expect(subject.config[:host]).to eq(host)
60
- end
61
- end
62
-
63
- describe "--port" do
64
- let(:port) { 1234 }
65
- let(:argv) { ['--port', port.to_s] }
66
-
67
- it "must set #config[:port]" do
68
- expect(subject.config[:port]).to eq(port)
69
- end
70
- end
71
-
72
- describe "--username" do
73
- let(:username) { 'foo' }
74
- let(:argv) { ['--username', username] }
75
-
76
- it "must set #config[:username]" do
77
- expect(subject.config[:username]).to eq(username)
78
- end
79
- end
80
-
81
- describe "--password" do
82
- let(:password) { 'secret' }
83
- let(:argv) { ['--password', password] }
84
-
85
- it "must set #config[:password]" do
86
- expect(subject.config[:password]).to eq(password)
87
- end
88
- end
89
-
90
- describe "--database" do
91
- let(:database) { 'foo' }
92
- let(:argv) { ['--database', database] }
93
-
94
- it "must set #config[:database]" do
95
- expect(subject.config[:database]).to eq(database)
96
- end
97
- end
98
- end
99
-
100
- describe "#initialize" do
101
- it "must initialize #config to an empty Hash" do
102
- expect(subject.config).to eq({})
103
- end
104
- end
105
-
106
- describe "#run" do
107
- let(:adapter) { 'sqlite3' }
108
- let(:database) { '/path/to/test.sqlite3' }
109
- let(:name) { 'test' }
110
-
111
- let(:config_file_hash) { {} }
112
-
113
- context "when given a URI argument" do
114
- let(:uri) { "#{adapter}:#{database}" }
115
-
116
- it "must parse the URI, call ConfigFile.edit, and add #config to it with the given NAME argument" do
117
- expect(Ronin::DB::ConfigFile).to receive(:edit).and_yield(config_file_hash)
118
-
119
- subject.run(name,uri)
120
-
121
- expect(config_file_hash[name]).to eq(
122
- {
123
- adapter: adapter,
124
- database: database
125
- }
126
- )
127
- end
128
- end
129
-
130
- context "when given options instead of a URI argument" do
131
- let(:argv) do
132
- [
133
- '--adapter', adapter,
134
- '--database', database
135
- ]
136
- end
137
-
138
- before { subject.parse_options(argv) }
139
-
140
- it "must call ConfigFile.edit and add #config to it with the given NAME argument" do
141
- expect(Ronin::DB::ConfigFile).to receive(:edit).and_yield(config_file_hash)
142
-
143
- subject.run(name)
144
-
145
- expect(config_file_hash[name]).to eq(
146
- {
147
- adapter: adapter,
148
- database: database
149
- }
150
- )
151
- end
152
- end
153
-
154
- context "when #config[:adapter] is not set" do
155
- let(:argv) { ['--database', '/path/to/db.sqlite3'] }
156
-
157
- before { subject.parse_options(argv) }
158
-
159
- it "must print an error message and exit with 1" do
160
- expect {
161
- subject.run(name)
162
- }.to output("add: must specify a URI or the --adapter option#{$/}").to_stderr.and(raise_error(SystemExit))
163
- end
164
- end
165
-
166
- context "when #config[:database] is not set" do
167
- let(:argv) { ['--adapter', 'sqlite3'] }
168
-
169
- before { subject.parse_options(argv) }
170
-
171
- it "must print an error message and exit with 1" do
172
- expect {
173
- subject.run(name)
174
- }.to output("add: must specify a URI or the --database option#{$/}").to_stderr.and(raise_error(SystemExit))
175
- end
176
- end
177
- end
178
-
179
- describe "#read_password" do
180
- let(:password) { 'secret' }
181
-
182
- it "must call #ask_secret with 'Password' and set config[:password]" do
183
- expect(subject).to receive(:ask_secret).with('Password').and_return(password)
184
-
185
- subject.read_password
186
-
187
- expect(subject.config[:password]).to eq(password)
188
- end
189
- end
190
-
191
- describe "#validate_config!" do
192
- context "when #config[:adapter] is not set" do
193
- before do
194
- subject.config[:database] = '/path/to/db.sqlite3'
195
- end
196
-
197
- it "must print an error message and exit with 1" do
198
- expect(subject).to receive(:exit).with(1)
199
-
200
- expect {
201
- subject.validate_config!
202
- }.to output("add: must specify a URI or the --adapter option#{$/}").to_stderr
203
- end
204
- end
205
-
206
- context "when #config[:database] is not set" do
207
- before do
208
- subject.config[:adapter] = 'sqlite3'
209
- end
210
-
211
- it "must print an error message and exit with 1" do
212
- expect(subject).to receive(:exit).with(1)
213
-
214
- expect {
215
- subject.validate_config!
216
- }.to output("add: must specify a URI or the --database option#{$/}").to_stderr
217
- end
218
- end
219
- end
220
- end
@@ -1,12 +0,0 @@
1
- require 'spec_helper'
2
- require 'ronin/db/cli/commands/edit'
3
-
4
- describe Ronin::DB::CLI::Commands::Edit do
5
- describe "#run" do
6
- it "must edit the ConfigFile::PATH" do
7
- expect(subject).to receive(:edit).with(Ronin::DB::ConfigFile::PATH)
8
-
9
- subject.run
10
- end
11
- end
12
- end
@@ -1,26 +0,0 @@
1
- require 'spec_helper'
2
- require 'ronin/db/cli/commands/irb'
3
-
4
- describe Ronin::DB::CLI::Commands::Irb do
5
- describe "#run" do
6
- it "must call #connet, then #load_models, then CLI::RubyShell.start" do
7
- expect(subject).to receive(:connect)
8
- expect(subject).to receive(:load_models)
9
- expect(Ronin::DB::CLI::RubyShell).to receive(:start)
10
-
11
- subject.run
12
- end
13
-
14
- context "when #options[:no_connect] is set" do
15
- before { subject.options[:no_connect] = true }
16
-
17
- it "must not call #connet or #load_models" do
18
- expect(subject).to_not receive(:connect)
19
- expect(subject).to_not receive(:load_models)
20
- expect(Ronin::DB::CLI::RubyShell).to receive(:start)
21
-
22
- subject.run
23
- end
24
- end
25
- end
26
- end
@@ -1,53 +0,0 @@
1
- require 'spec_helper'
2
- require 'ronin/db/cli/database_command'
3
-
4
- describe Ronin::DB::CLI::DatabaseCommand do
5
- describe "#config" do
6
- context "when neither options[:db] nor options[:db_uri] are set" do
7
- it "must default to connecting to the :default database" do
8
- expect(subject.config).to eq(Ronin::DB.config[:default])
9
- end
10
- end
11
-
12
- context "when options[:db] is set" do
13
- let(:db_name) { :test }
14
- let(:config) do
15
- {
16
- db_name => {
17
- adapter: 'sqlite3',
18
- database: '/path/to/db.sqlite3'
19
- }
20
- }
21
- end
22
-
23
- before do
24
- allow(Ronin::DB).to receive(:config).and_return(config)
25
-
26
- subject.options[:db] = db_name
27
- end
28
-
29
- it "must return the database configuration for options[:db]" do
30
- expect(subject.config).to eq(Ronin::DB.config[db_name])
31
- end
32
- end
33
-
34
- context "when options[:db_uri] is set" do
35
- let(:db_uri) { "postgres://user:password@host:1234/database" }
36
- let(:parsed_uri) { subject.parse_uri(subject.options[:db_uri]) }
37
-
38
- before { subject.options[:db_uri] = db_uri }
39
-
40
- it "must return the parsed URI for options[:db_uri]" do
41
- expect(subject.config).to eq(parsed_uri)
42
- end
43
- end
44
- end
45
-
46
- describe "#connect" do
47
- it "must call ActiveRecord::Base.establish_connection with #config" do
48
- expect(ActiveRecord::Base).to receive(:establish_connection).with(subject.config)
49
-
50
- subject.connect
51
- end
52
- end
53
- end
@@ -1,237 +0,0 @@
1
- require 'spec_helper'
2
- require 'ronin/db/cli/model_command'
3
- require 'ronin/db/ip_address'
4
- require 'ronin/db/host_name'
5
-
6
- describe Ronin::DB::CLI::ModelCommand do
7
- it "must inherit from Ronin::DB::CLI::DatabaseCommand" do
8
- expect(described_class).to be < Ronin::DB::CLI::DatabaseCommand
9
- end
10
-
11
- describe ".model_file" do
12
- subject { test_class }
13
-
14
- context "and when model_file is not set in the class" do
15
- module TestModelCommand
16
- class WithNoModelFileSet < Ronin::DB::CLI::ModelCommand
17
- end
18
- end
19
-
20
- let(:test_class) { TestModelCommand::WithNoModelFileSet }
21
-
22
- it do
23
- expect {
24
- subject.model_file
25
- }.to raise_error(NotImplementedError,"#{subject} did not define model_file")
26
- end
27
- end
28
-
29
- context "and when model_file is set in the class" do
30
- module TestModelCommand
31
- class WithModelFileSet < Ronin::DB::CLI::ModelCommand
32
- model_file 'ronin/db/test'
33
- end
34
- end
35
-
36
- let(:test_class) { TestModelCommand::WithModelFileSet }
37
-
38
- it "must return the set model_file" do
39
- expect(subject.model_file).to eq('ronin/db/test')
40
- end
41
- end
42
-
43
- context "but when the model_file was set in the superclass" do
44
- module TestModelCommand
45
- class InheritsItsModelFile < WithModelFileSet
46
- end
47
- end
48
-
49
- let(:test_class) { TestModelCommand::InheritsItsModelFile }
50
-
51
- it "must return the model_file set in the superclass" do
52
- expect(subject.model_file).to eq('ronin/db/test')
53
- end
54
-
55
- context "but the model_file is overridden in the sub-class" do
56
- module TestModelCommand
57
- class OverridesItsInheritedModelFile < WithModelFileSet
58
- model_file 'ronin/db/test2'
59
- end
60
- end
61
-
62
- let(:test_class) do
63
- TestModelCommand::OverridesItsInheritedModelFile
64
- end
65
-
66
- it "must return the model_file set in the sub-class" do
67
- expect(subject.model_file).to eq('ronin/db/test2')
68
- end
69
-
70
- it "must not modify the superclass'es model_file" do
71
- expect(subject.superclass.model_file).to eq('ronin/db/test')
72
- end
73
- end
74
- end
75
- end
76
-
77
- describe ".model_name" do
78
- subject { test_class }
79
-
80
- context "and when model_name is not set in the class" do
81
- module TestModelCommand
82
- class WithNoModelNameSet < Ronin::DB::CLI::ModelCommand
83
- end
84
- end
85
-
86
- let(:test_class) { TestModelCommand::WithNoModelNameSet }
87
-
88
- it do
89
- expect {
90
- subject.model_name
91
- }.to raise_error(NotImplementedError,"#{subject} did not define model_name")
92
- end
93
- end
94
-
95
- context "and when model_name is set in the class" do
96
- module TestModelCommand
97
- class WithModelNameSet < Ronin::DB::CLI::ModelCommand
98
- model_name 'Test'
99
- end
100
- end
101
-
102
- let(:test_class) { TestModelCommand::WithModelNameSet }
103
-
104
- it "must return the set model_name" do
105
- expect(subject.model_name).to eq('Test')
106
- end
107
- end
108
-
109
- context "but when the model_name was set in the superclass" do
110
- module TestModelCommand
111
- class InheritsItsModelName < WithModelNameSet
112
- end
113
- end
114
-
115
- let(:test_class) { TestModelCommand::InheritsItsModelName }
116
-
117
- it "must return the model_name set in the superclass" do
118
- expect(subject.model_name).to eq('Test')
119
- end
120
-
121
- context "but the model_name is overridden in the sub-class" do
122
- module TestModelCommand
123
- class OverridesItsInheritedModelName < WithModelNameSet
124
- model_name 'Test2'
125
- end
126
- end
127
-
128
- let(:test_class) do
129
- TestModelCommand::OverridesItsInheritedModelName
130
- end
131
-
132
- it "must return the model_name set in the sub-class" do
133
- expect(subject.model_name).to eq('Test2')
134
- end
135
-
136
- it "must not modify the superclass'es model_name" do
137
- expect(subject.superclass.model_name).to eq('Test')
138
- end
139
- end
140
- end
141
- end
142
-
143
- describe ".model_name" do
144
- end
145
-
146
- module TestModelCommand
147
- class TestCommand < Ronin::DB::CLI::ModelCommand
148
- model_file 'ronin/db/ip_address'
149
- model_name 'IPAddress'
150
- end
151
- end
152
-
153
- let(:test_command) { TestModelCommand::TestCommand }
154
- subject { test_command.new }
155
-
156
- describe "#initialize" do
157
- it "must initialize #query_method_calls to an empty Array" do
158
- expect(subject.query_method_calls).to eq([])
159
- end
160
- end
161
-
162
- describe "#model" do
163
- it "must resolve the class for the model within Ronin::DB::" do
164
- expect(subject.model).to be(Ronin::DB.const_get(subject.class.model_name))
165
- end
166
- end
167
-
168
- describe "#query" do
169
- let(:host) { 'example.com' }
170
- let(:ipv4) { '93.184.216.34' }
171
- let(:ipv6) { '2606:2800:220:1:248:1893:25c8:1946' }
172
-
173
- before do
174
- host_name = Ronin::DB::HostName.create(name: host)
175
-
176
- Ronin::DB::IPAddress.create(address: '127.0.0.1', version: 4)
177
- Ronin::DB::IPAddress.create(
178
- address: ipv4,
179
- version: 4,
180
- host_names: [host_name]
181
- )
182
- Ronin::DB::IPAddress.create(
183
- address: ipv6,
184
- version: 6,
185
- host_names: [host_name]
186
- )
187
- Ronin::DB::IPAddress.create(address: '::1', version: 6)
188
- end
189
-
190
- context "when #query_method_calls is empty" do
191
- it "must return a ActiveRecord_Relation object" do
192
- expect(subject.query).to be_kind_of(
193
- subject.model.const_get('ActiveRecord_Relation')
194
- )
195
- end
196
- end
197
-
198
- context "when #query_method_calls contains a :where method call" do
199
- before do
200
- subject.query_method_calls << [:where, [], {version: 4}]
201
- end
202
-
203
- it "must invoke #where with the given arguments on the query" do
204
- expect(subject.query).to eq(
205
- Ronin::DB::IPAddress.where(version: 4)
206
- )
207
- end
208
- end
209
-
210
- context "when #query_method_calls contains a scoped query method call" do
211
- before do
212
- subject.query_method_calls << [:with_host_name, [host]]
213
- end
214
-
215
- it "must invoke the scoped query method on the query" do
216
- expect(subject.query).to eq(
217
- Ronin::DB::IPAddress.with_host_name(host)
218
- )
219
- end
220
- end
221
-
222
- after do
223
- Ronin::DB::IPAddress.destroy_all
224
- Ronin::DB::HostName.destroy_all
225
- end
226
- end
227
-
228
- describe "#print_record" do
229
- let(:record) { Ronin::DB::IPAddress.new(address: '127.0.0.1') }
230
-
231
- it "must print the record using #puts" do
232
- expect {
233
- subject.print_record(record)
234
- }.to output("#{record}#{$/}").to_stdout
235
- end
236
- end
237
- end
@@ -1,14 +0,0 @@
1
- require 'spec_helper'
2
- require 'ronin/db/cli/ruby_shell'
3
-
4
- describe Ronin::DB::CLI::RubyShell do
5
- describe "#initialize" do
6
- it "must default #name to 'ronin-db'" do
7
- expect(subject.name).to eq('ronin-db')
8
- end
9
-
10
- it "must default #context to Ronin::DB" do
11
- expect(subject.context).to be(Ronin::DB)
12
- end
13
- end
14
- end