sonar-client 0.0.5 → 0.0.6

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dd483db5d8395939220af92349ac4ee6e769a324
4
- data.tar.gz: 5fc1f42beb33dd3301c8372c7426414f310a93b4
3
+ metadata.gz: bfc392531d73c07dc38bdd9c2064d64ced271455
4
+ data.tar.gz: c59580c7f121c73586310e04623839cf3e2a0e7a
5
5
  SHA512:
6
- metadata.gz: 71c312bef170b2d717a02fa7e6e7495fd2c7f63d94f646e88f4a04b63c17f5a4b0381a5247ea09a5f05d14b7741f8f994812748c0e9a0c633672739e0a4736ac
7
- data.tar.gz: a883d0cf48e83e9a61b3b61135051a2efe84b1b38335191d80a4de85fc8a424dc47a38e99ccf0273b580c0703000c84dbb7d55f6b45a8a63a696af96837f325e
6
+ metadata.gz: a793b6cbe98628a1bf4414bdea5ec24c4f06adcf3d4b4a9066be491b241847b5adbcc0f2b37d8408bd1179cbe47b22e78f27315c99879d8e3422391edc717ccb
7
+ data.tar.gz: 8bb3e13a7914179f2a3ce8558419e782492bf84d9d8fe09e0cde218d034dfbc2d73399808ae4769140353331f48bba65c3b1e10908f3e6716a6ca07dd2cf9b6f
@@ -8,7 +8,7 @@ module Sonar
8
8
  #
9
9
  # @return [Hashie::Mash] with response of certificate
10
10
  def get_certificate(options = {})
11
- response = get("/api/#{Sonar.api_version}/certificates/#{options[:sha1]}", options)
11
+ response = get_endpoint("certificates/#{options[:sha1]}", options)
12
12
  response if response
13
13
  end
14
14
  end
data/lib/sonar/cli/cli.rb CHANGED
@@ -28,10 +28,13 @@ module Sonar
28
28
 
29
29
  desc 'search [QUERY TYPE] [QUERY TERM]', 'Search anything from Sonars'
30
30
  method_option 'record_limit', type: :numeric, aliases: '-n', desc: 'Maximum number of records to fetch'
31
+ method_option 'exact', type: :boolean, aliases: '-e', desc: 'Search for the query string exactly, do not including partial string matches'
32
+
31
33
  def search(type, term)
32
34
  @query = {}
33
35
  @query[type.to_sym] = term
34
36
  @query[:limit] = options['record_limit']
37
+ @query[:exact] = options['exact']
35
38
  resp = @client.search(@query)
36
39
 
37
40
  if resp.is_a?(Sonar::Request::RequestIterator)
@@ -56,19 +59,20 @@ module Sonar
56
59
 
57
60
  private
58
61
 
59
- def print_json(json, format)
62
+ def print_json(data, format)
60
63
  case format
61
64
  when 'pretty'
62
- ap(json)
65
+ ap(data)
63
66
  when 'lines'
64
- if json.has_key?('collection')
65
- json['collection'].each { |l| puts l.to_json }
67
+ if data.has_key?('collection')
68
+ data['collection'].each { |l| puts l.to_json }
66
69
  else
67
- puts 'Could not parse the response into lines.'
70
+ puts 'WARNING: Could not parse the response into lines, there was no collection.'
71
+ puts data.to_json
68
72
  end
69
73
  else
70
74
  # TODO: use a faster JSON generator?
71
- puts(json.to_json)
75
+ puts(data.to_json)
72
76
  end
73
77
  end
74
78
 
@@ -22,7 +22,11 @@ module Sonar
22
22
  f.puts 'format: flat'
23
23
  f.puts 'record_limit: 10000'
24
24
  end
25
+ warn = "Please set your email and API token in sonar.rc"
26
+ puts "=" * warn.size
25
27
  puts "Config file setup at: #{@path}"
28
+ puts warn
29
+ puts "=" * warn.size
26
30
  end
27
31
 
28
32
  def load_file
data/lib/sonar/request.rb CHANGED
@@ -54,7 +54,7 @@ module Sonar
54
54
  params[:connection] = connection
55
55
  resp = get(url, params)
56
56
  params[:iterator_id] = resp.iterator_id
57
- records_rcvd += resp['collection'].size
57
+ records_rcvd += resp['collection'].size rescue 0
58
58
  more = resp['more']
59
59
  yield resp
60
60
  end
data/lib/sonar/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Sonar
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -0,0 +1,3 @@
1
+ email: YOUR_EMAIL
2
+ access_token: SONAR_TOKEN
3
+ api_url: https://sonar.labs.rapid7.com
@@ -5,9 +5,9 @@ describe Sonar::Search do
5
5
  let(:client) { Sonar::Client.new }
6
6
 
7
7
  context "sha1 #get_certificate" do
8
- it "should find the Rapid7 certificate by sha1" do
8
+ it "should find the link to certificate by sha1" do
9
9
  res = client.get_certificate(sha1: "1e80c24b97c928bb1db7d4d3c05475a6a40a1186")
10
- expect(res.subject.CN).to eq("www.rapid7.com")
10
+ expect(res._links.self.href).to match(/certificates/)
11
11
  end
12
12
  end
13
13
  end
@@ -2,6 +2,16 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  describe Sonar::CLI do
5
+ context 'with an invalid stock sonar.rc profile' do
6
+ before do
7
+ Sonar::RCFile.instance.path = "#{fixtures_path}/sonar-stock.rc"
8
+ end
9
+ it 'warns user of missing config values when trying to search' do
10
+ output = run_command('search rdns 8.8.8.8')
11
+ expect(output).to match(/Could not authenticate/)
12
+ end
13
+ end
14
+
5
15
  context "with a valid profile" do
6
16
  before do
7
17
  Sonar::RCFile.instance.path = "#{fixtures_path}/sonar.rc"
@@ -43,11 +53,36 @@ describe Sonar::CLI do
43
53
  Sonar::Client.new.search(processed: '8.8.8.')
44
54
  )
45
55
  end
46
- it 'parses the nested value as a string' do
56
+ xit 'parses the nested value as a string' do
47
57
  output = run_command('search processed 8.8.8.')
48
58
  expect(JSON.parse(output)['collection'].first['value']['ip']).to eq('8.8.8.8')
49
59
  end
50
60
  end
61
+ describe 'searching with #exact --exact option' do
62
+ context 'client that returns fdns for rapid7 IP exact' do
63
+ before do
64
+ allow_any_instance_of(Sonar::Client).to receive(:search).and_return(
65
+ Sonar::Client.new.search(fdns: '208.118.227.20', exact: true)
66
+ )
67
+ end
68
+ it 'matches exactly with --exact' do
69
+ output = run_command('search fdns 208.118.227.20 --exact')
70
+ expect(JSON.parse(output)['collection'].size).to eq(1)
71
+ expect(JSON.parse(output)['collection'].first['name']).to eq('208.118.227.20')
72
+ end
73
+ end
74
+ context 'client that returns fdns for rapid7 IP' do
75
+ before do
76
+ allow_any_instance_of(Sonar::Client).to receive(:search).and_return(
77
+ Sonar::Client.new.search(fdns: '208.118.227.20')
78
+ )
79
+ end
80
+ it 'matches exactly without --exact' do
81
+ output = run_command('search fdns 208.118.227.20')
82
+ expect(JSON.parse(output)['collection'].size).to be > 1
83
+ end
84
+ end
85
+ end
51
86
  end
52
87
 
53
88
  def run_command(args)
@@ -98,7 +98,7 @@ describe Sonar::Search do
98
98
  let(:resp) { client.search(fdns: '208.118.227.10') }
99
99
 
100
100
  it "finds fdnsip rapid7.com at 208.118.227.10" do
101
- expect(resp['collection'].any? { |x| x['address'] == 'rapid7.com' }).to be(true)
101
+ expect(resp['collection'].any? { |x| x['address'] =~ 'rapid7' }).to be(true)
102
102
  end
103
103
  end
104
104
 
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.0.5
4
+ version: 0.0.6
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: 2015-04-14 00:00:00.000000000 Z
11
+ date: 2015-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday_middleware
@@ -247,6 +247,7 @@ files:
247
247
  - lib/sonar/user.rb
248
248
  - lib/sonar/version.rb
249
249
  - sonar-client.gemspec
250
+ - spec/fixtures/sonar-stock.rc
250
251
  - spec/fixtures/sonar.rc
251
252
  - spec/sonar/certificate_spec.rb
252
253
  - spec/sonar/cli_spec.rb
@@ -280,6 +281,7 @@ signing_key:
280
281
  specification_version: 4
281
282
  summary: API Wrapper for Sonar
282
283
  test_files:
284
+ - spec/fixtures/sonar-stock.rc
283
285
  - spec/fixtures/sonar.rc
284
286
  - spec/sonar/certificate_spec.rb
285
287
  - spec/sonar/cli_spec.rb