sonar-client 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/sonar +1 -1
- data/lib/sonar/cli/cli.rb +5 -0
- data/lib/sonar/version.rb +1 -1
- data/spec/sonar/cli_spec.rb +15 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 820db139f2824907be22a0f34c228fa5d9175f33
|
4
|
+
data.tar.gz: 5d3f107c6d8e627891c4de9e3b2e4886dcb19d8e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1ceabcd6de7dfbf8e8d985413ed05e3c873a4e94df64ef3be6ffbb01330a6f455df8f9104c7b4b165b8d7cbad591ac518f7ea4f84465a48cf9f87531dd43f5b
|
7
|
+
data.tar.gz: d3b32283cb878fbad817379ce73d3ecf520701295a133c755d3c5c0adfa5731b4d484369f411b36e663083d53e517c94b57bddd3e0e30be83eb8827ca1447128
|
data/bin/sonar
CHANGED
data/lib/sonar/cli/cli.rb
CHANGED
@@ -35,13 +35,18 @@ module Sonar
|
|
35
35
|
@query[:exact] = options['exact']
|
36
36
|
resp = @client.search(@query)
|
37
37
|
|
38
|
+
errors = 0
|
38
39
|
if resp.is_a?(Sonar::Request::RequestIterator)
|
39
40
|
resp.each do |data|
|
41
|
+
errors += 1 if data.key?('errors') || data.key?('error')
|
40
42
|
print_json(cleanup_data(data), options['format'])
|
41
43
|
end
|
42
44
|
else
|
45
|
+
errors += 1 if resp.key?('errors') || resp.key?('error')
|
43
46
|
print_json(cleanup_data(resp), options['format'])
|
44
47
|
end
|
48
|
+
|
49
|
+
return errors
|
45
50
|
end
|
46
51
|
|
47
52
|
desc 'types', 'List all Sonar query types'
|
data/lib/sonar/version.rb
CHANGED
data/spec/sonar/cli_spec.rb
CHANGED
@@ -7,9 +7,13 @@ describe Sonar::CLI do
|
|
7
7
|
Sonar::RCFile.instance.path = "#{fixtures_path}/sonar-stock.rc"
|
8
8
|
end
|
9
9
|
it 'warns user of missing config values when trying to search' do
|
10
|
-
output =
|
10
|
+
output, _ = run_command('search rdns 8.8.8.8')
|
11
11
|
expect(output).to match(/Could not authenticate/)
|
12
12
|
end
|
13
|
+
it 'exits non-zero when errors are encountered' do
|
14
|
+
_, ret = run_command('search rdns 8.8.8.8')
|
15
|
+
expect(ret).to eq(1)
|
16
|
+
end
|
13
17
|
end
|
14
18
|
|
15
19
|
context "with a valid profile" do
|
@@ -17,7 +21,7 @@ describe Sonar::CLI do
|
|
17
21
|
Sonar::RCFile.instance.path = "#{fixtures_path}/sonar.rc"
|
18
22
|
end
|
19
23
|
it "should return the profile" do
|
20
|
-
output =
|
24
|
+
output, _ = run_command('profile')
|
21
25
|
expect(output).to match(/email@asdfasdfasfd.com/)
|
22
26
|
end
|
23
27
|
|
@@ -28,11 +32,11 @@ describe Sonar::CLI do
|
|
28
32
|
)
|
29
33
|
end
|
30
34
|
it 'strips whitespace from values' do
|
31
|
-
output =
|
35
|
+
output, _ = run_command('search rdns 8.8.8.8')
|
32
36
|
expect(output).to eq('{"collection":[{"address":"192.168.1.1"}],"more":"false"}')
|
33
37
|
end
|
34
38
|
it 'can return lines format' do
|
35
|
-
output =
|
39
|
+
output, _ = run_command('search --format lines rdns 8.8.8.8')
|
36
40
|
expect(output).to eq('{"address":"192.168.1.1"}')
|
37
41
|
end
|
38
42
|
end
|
@@ -43,7 +47,7 @@ describe Sonar::CLI do
|
|
43
47
|
)
|
44
48
|
end
|
45
49
|
it 'parses the nested values in an array' do
|
46
|
-
output =
|
50
|
+
output, _ = run_command('search sslcert 152a0a633aaf13f02c428ac1a3e672e895512bfd')
|
47
51
|
expect(JSON.parse(output)['collection'].first['details'].first['subject']['ST']).to eq('California')
|
48
52
|
end
|
49
53
|
end
|
@@ -54,7 +58,7 @@ describe Sonar::CLI do
|
|
54
58
|
)
|
55
59
|
end
|
56
60
|
xit 'parses the nested value as a string' do
|
57
|
-
output =
|
61
|
+
output, _ = run_command('search processed 8.8.8.')
|
58
62
|
expect(JSON.parse(output)['collection'].first['value']['ip']).to eq('8.8.8.8')
|
59
63
|
end
|
60
64
|
end
|
@@ -66,7 +70,7 @@ describe Sonar::CLI do
|
|
66
70
|
)
|
67
71
|
end
|
68
72
|
it 'matches exactly with --exact' do
|
69
|
-
output =
|
73
|
+
output, _ = run_command('search fdns 208.118.227.20 --exact')
|
70
74
|
expect(JSON.parse(output)['collection'].size).to be >= 1
|
71
75
|
expect(JSON.parse(output)['collection'].any? { |c| c['name'] == '208.118.227.20' }).to be(true)
|
72
76
|
end
|
@@ -78,7 +82,7 @@ describe Sonar::CLI do
|
|
78
82
|
)
|
79
83
|
end
|
80
84
|
it 'matches exactly without --exact' do
|
81
|
-
output =
|
85
|
+
output, _ = run_command('search fdns 208.118.227.20')
|
82
86
|
expect(JSON.parse(output)['collection'].size).to be > 1
|
83
87
|
end
|
84
88
|
end
|
@@ -86,6 +90,8 @@ describe Sonar::CLI do
|
|
86
90
|
end
|
87
91
|
|
88
92
|
def run_command(args)
|
89
|
-
|
93
|
+
ret = 0
|
94
|
+
output, _ = capture(:stdout) { ret = Sonar::CLI.start(args.split) }.strip
|
95
|
+
[output, ret]
|
90
96
|
end
|
91
97
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sonar-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Deardorff & HD Moore
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday_middleware
|