sonar-client 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +4 -0
- data/lib/sonar.rb +1 -0
- data/lib/sonar/client.rb +54 -4
- data/lib/sonar/registration.rb +12 -0
- data/lib/sonar/version.rb +1 -1
- data/spec/sonar/cli_spec.rb +2 -2
- data/spec/sonar/registration_spec.rb +32 -0
- data/spec/spec_helper.rb +2 -2
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28d19291140201d88ac436b2d42ab047c477acde
|
4
|
+
data.tar.gz: 3f3115c49a108f3d175f0ea670348ec89835e37e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25251c5d02b60a2afaad1af4ddac7cdf1e85e13fee30b4e89def0f95f1d5aee0de867bbcf6a1665128a6a44c81b75e6e5f5f1a1c5ffa98800921e95974179bfa
|
7
|
+
data.tar.gz: b6cb3e46073c83cd24de84c9abf9a27d4b348e28a8d889309d1f0640a77d2785504be243d8b9ecf88f9640c375d6a779f5c31f5f2fe43b958a3d02eb2b41719d
|
data/Gemfile
CHANGED
data/lib/sonar.rb
CHANGED
data/lib/sonar/client.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
require 'faraday'
|
3
|
+
require 'faraday_middleware'
|
2
4
|
require 'forwardable'
|
3
5
|
require 'sonar/request'
|
4
6
|
require 'sonar/certificate'
|
5
7
|
require 'sonar/search'
|
6
8
|
require 'sonar/user'
|
7
9
|
require 'sonar/cli/cli'
|
10
|
+
require 'sonar/registration'
|
8
11
|
|
9
12
|
module Sonar
|
10
13
|
class Client
|
@@ -14,6 +17,7 @@ module Sonar
|
|
14
17
|
include Certificate
|
15
18
|
include Search
|
16
19
|
include User
|
20
|
+
include Registration
|
17
21
|
|
18
22
|
attr_accessor :api_url, :api_version, :access_token, :email
|
19
23
|
|
@@ -22,10 +26,10 @@ module Sonar
|
|
22
26
|
#
|
23
27
|
# @params options[Hash]
|
24
28
|
def initialize(options = {})
|
25
|
-
@api_url = options
|
26
|
-
@api_version = options
|
27
|
-
@access_token = options
|
28
|
-
@email = options
|
29
|
+
@api_url = options.fetch(:api_url, default_api_url)
|
30
|
+
@api_version = options.fetch(:api_version, default_api_version )
|
31
|
+
@access_token = options.fetch(:access_token, default_access_token)
|
32
|
+
@email = options.fetch(:email, default_email)
|
29
33
|
end
|
30
34
|
|
31
35
|
##
|
@@ -72,6 +76,52 @@ module Sonar
|
|
72
76
|
|
73
77
|
private
|
74
78
|
|
79
|
+
# Returns the default value for the api url
|
80
|
+
#
|
81
|
+
# @return [String] the URL for the Sonar API
|
82
|
+
def default_api_url
|
83
|
+
begin
|
84
|
+
Sonar.api_url
|
85
|
+
rescue NoMethodError
|
86
|
+
'https://sonar.labs.rapid7.com'
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# Returns the default value for the api version
|
91
|
+
#
|
92
|
+
# @return [String] the Sonar API version to use
|
93
|
+
def default_api_version
|
94
|
+
begin
|
95
|
+
Sonar.api_version
|
96
|
+
rescue NoMethodError
|
97
|
+
'v2'
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# Returns the default value for the access token
|
102
|
+
#
|
103
|
+
# @return [String] if {Sonar} has a value configured
|
104
|
+
# @return [nil]
|
105
|
+
def default_access_token
|
106
|
+
begin
|
107
|
+
Sonar.access_token
|
108
|
+
rescue NoMethodError
|
109
|
+
''
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
# Returns the default value for the email address
|
114
|
+
#
|
115
|
+
# @return [String] if {Sonar} has a value configured
|
116
|
+
# @return [nil]
|
117
|
+
def default_email
|
118
|
+
begin
|
119
|
+
Sonar.email
|
120
|
+
rescue NoMethodError
|
121
|
+
''
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
75
125
|
def default_headers
|
76
126
|
{
|
77
127
|
accept: 'application/json',
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Sonar
|
3
|
+
module Registration
|
4
|
+
|
5
|
+
# Takes a Metasploit Product Key and attempts
|
6
|
+
# to register a Sonar account with it.
|
7
|
+
def register_metasploit(product_key)
|
8
|
+
post_params = { product_key: product_key.dup }
|
9
|
+
post_to_sonar('metasploit_verify', post_params)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/sonar/version.rb
CHANGED
data/spec/sonar/cli_spec.rb
CHANGED
@@ -67,8 +67,8 @@ describe Sonar::CLI do
|
|
67
67
|
end
|
68
68
|
it 'matches exactly with --exact' do
|
69
69
|
output = run_command('search fdns 208.118.227.20 --exact')
|
70
|
-
expect(JSON.parse(output)['collection'].size).to
|
71
|
-
expect(JSON.parse(output)['collection'].
|
70
|
+
expect(JSON.parse(output)['collection'].size).to be >= 1
|
71
|
+
expect(JSON.parse(output)['collection'].any? { |c| c['name'] == '208.118.227.20' }).to be(true)
|
72
72
|
end
|
73
73
|
end
|
74
74
|
context 'client that returns fdns for rapid7 IP' do
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Sonar::Registration do
|
5
|
+
let(:client) { Sonar::Client.new }
|
6
|
+
|
7
|
+
context 'POSTing a valid product key' do
|
8
|
+
let (:resp) { client.register_metasploit("1e80c24b97c928bb1db7d4d3c05475a6a40a1186") }
|
9
|
+
|
10
|
+
xit 'responds that the license is valid' do
|
11
|
+
expect(resp).to have_key('valid')
|
12
|
+
expect(resp['valid']).to be(true)
|
13
|
+
end
|
14
|
+
xit 'responds with a user email' do
|
15
|
+
expect(resp).to have_key('email')
|
16
|
+
expect(resp['email']).to match(/@/)
|
17
|
+
end
|
18
|
+
xit 'responds with an api_key' do
|
19
|
+
expect(resp).to have_key('api_key')
|
20
|
+
expect(resp['api_key']).to match(/KEY/)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'POSTing an invalid product key' do
|
25
|
+
let (:resp) { client.register_metasploit("DDXXXX") }
|
26
|
+
|
27
|
+
xit 'responds that the license is invalid' do
|
28
|
+
expect(resp).to have_key('valid')
|
29
|
+
expect(resp['valid']).to be(false)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -66,6 +66,6 @@ def fixtures_path
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def reset_sonar_config
|
69
|
-
Sonar.
|
70
|
-
Sonar.
|
69
|
+
Sonar.remove_class_variable(:@@api_url) if Sonar.class_variable_defined?(:@@api_url)
|
70
|
+
Sonar.remove_class_variable(:@@api_version) if Sonar.class_variable_defined?(:@@api_version)
|
71
71
|
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.0.
|
4
|
+
version: 0.0.8
|
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-
|
11
|
+
date: 2015-11-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday_middleware
|
@@ -242,6 +242,7 @@ files:
|
|
242
242
|
- lib/sonar/cli/cli.rb
|
243
243
|
- lib/sonar/cli/rcfile.rb
|
244
244
|
- lib/sonar/client.rb
|
245
|
+
- lib/sonar/registration.rb
|
245
246
|
- lib/sonar/request.rb
|
246
247
|
- lib/sonar/search.rb
|
247
248
|
- lib/sonar/user.rb
|
@@ -252,6 +253,7 @@ files:
|
|
252
253
|
- spec/sonar/certificate_spec.rb
|
253
254
|
- spec/sonar/cli_spec.rb
|
254
255
|
- spec/sonar/client_spec.rb
|
256
|
+
- spec/sonar/registration_spec.rb
|
255
257
|
- spec/sonar/search_spec.rb
|
256
258
|
- spec/sonar/user_spec.rb
|
257
259
|
- spec/sonar_spec.rb
|
@@ -286,6 +288,7 @@ test_files:
|
|
286
288
|
- spec/sonar/certificate_spec.rb
|
287
289
|
- spec/sonar/cli_spec.rb
|
288
290
|
- spec/sonar/client_spec.rb
|
291
|
+
- spec/sonar/registration_spec.rb
|
289
292
|
- spec/sonar/search_spec.rb
|
290
293
|
- spec/sonar/user_spec.rb
|
291
294
|
- spec/sonar_spec.rb
|