controls 1.7.4 → 1.7.5
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 +4 -4
- data/.travis.yml +3 -0
- data/apiary.apib +22 -22
- data/lib/controls/client.rb +2 -1
- data/lib/controls/client/security_controls.rb +3 -2
- data/lib/controls/version.rb +1 -1
- data/spec/controls/client/assessments_spec.rb +2 -0
- data/spec/controls/client/assets_spec.rb +52 -0
- data/spec/controls/client/security_controls_spec.rb +29 -0
- data/spec/matchers.rb +5 -4
- data/spec/spec_helper.rb +2 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c245dec5cdf4115335c576ae0019c5f7a25835e
|
4
|
+
data.tar.gz: 38bbd0e485cc4713699eb4b6749192596b0a7f73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79b1f36d95c8832c9f51fa9a6947a39d50bbf1e3fef4b4fda3c8f38988a90ede0abe35e49f1d6ce3fbe8d92df8ceb2e3bb94a4e77a0634964fa9c48a6862604c
|
7
|
+
data.tar.gz: a7534a3fccc7a0ffee58b73a510a17809afccb12c89d37b8c3e251bfb0e1efdef986d8396395203a17085a74aba6b360d3684b06ede233e4c28e69e2d4b7e18c
|
data/.travis.yml
CHANGED
data/apiary.apib
CHANGED
@@ -8,25 +8,6 @@ Notes API is a *short texts saving* service similar to its physical paper presen
|
|
8
8
|
## Assessment Collection [/assessments]
|
9
9
|
### Assessments [GET]
|
10
10
|
|
11
|
-
+ Response 200 (application/json)
|
12
|
-
|
13
|
-
{
|
14
|
-
"id": 1,
|
15
|
-
"assessing": false,
|
16
|
-
"highRiskAssetCount": 0,
|
17
|
-
"mediumRiskAssetCount": 24,
|
18
|
-
"lowRiskAssetCount": 0,
|
19
|
-
"totalAssetCount": 24,
|
20
|
-
"overallRiskScore": 4.004146038088617,
|
21
|
-
"timestamp": 1393184605912
|
22
|
-
}
|
23
|
-
|
24
|
-
## Assessment [/assessments/{assessment_id}]
|
25
|
-
### Assessment by ID [GET]
|
26
|
-
|
27
|
-
+ Parameters
|
28
|
-
+ assessment_id (optional, integer, `1`) ... The ID of the assessment to retreive.
|
29
|
-
|
30
11
|
+ Response 200 (application/json)
|
31
12
|
|
32
13
|
[
|
@@ -42,6 +23,25 @@ Notes API is a *short texts saving* service similar to its physical paper presen
|
|
42
23
|
}
|
43
24
|
]
|
44
25
|
|
26
|
+
## Assessment [/assessments/{assessment_id}]
|
27
|
+
### Assessment by ID [GET]
|
28
|
+
|
29
|
+
+ Parameters
|
30
|
+
+ assessment_id (optional, integer, `1`) ... The ID of the assessment to retreive.
|
31
|
+
|
32
|
+
+ Response 200 (application/json)
|
33
|
+
|
34
|
+
{
|
35
|
+
"id": 1,
|
36
|
+
"assessing": false,
|
37
|
+
"highRiskAssetCount": 0,
|
38
|
+
"mediumRiskAssetCount": 24,
|
39
|
+
"lowRiskAssetCount": 0,
|
40
|
+
"totalAssetCount": 24,
|
41
|
+
"overallRiskScore": 4.004146038088617,
|
42
|
+
"timestamp": 1393184605912
|
43
|
+
}
|
44
|
+
|
45
45
|
# Group Search
|
46
46
|
## Assets [/assets/search?query={query}]
|
47
47
|
### Asset Search [GET]
|
@@ -51,12 +51,12 @@ Notes API is a *short texts saving* service similar to its physical paper presen
|
|
51
51
|
|
52
52
|
+ Response 200 (application/json)
|
53
53
|
|
54
|
-
|
55
|
-
{
|
54
|
+
{
|
55
|
+
"resources": {
|
56
56
|
"uuid": "db899a57-347c-4df9-9ce2-6932dc4adf38>",
|
57
57
|
"riskScore": 5.554266115196547,
|
58
58
|
"riskLevel": "MEDIUM",
|
59
59
|
"hostName": "CMMNCTR2K7R2-U",
|
60
60
|
"ipaddress": "10.4.19.25"
|
61
61
|
}
|
62
|
-
|
62
|
+
}
|
data/lib/controls/client.rb
CHANGED
@@ -121,6 +121,7 @@ module Controls
|
|
121
121
|
# @return [Array,Hash] an array or hash of parsed JSON data
|
122
122
|
def put(path, body = {}, headers = {}, &block)
|
123
123
|
headers = connection_options[:headers].merge(headers)
|
124
|
+
headers['content-type'] = 'application/json'
|
124
125
|
url = URI.escape(File.join(api_endpoint, path))
|
125
126
|
resp = middleware.put(url, body, headers, &block)
|
126
127
|
@_last_request = {
|
@@ -132,7 +133,7 @@ module Controls
|
|
132
133
|
fail exception('Invalid content-type error')
|
133
134
|
end
|
134
135
|
|
135
|
-
|
136
|
+
resp.status
|
136
137
|
rescue Faraday::Error::ConnectionFailed => e
|
137
138
|
if e.message =~ /^SSL_connect/
|
138
139
|
warn(*SSL_WARNING)
|
@@ -36,9 +36,10 @@ module Controls
|
|
36
36
|
# @param [Array[Hash{String=>String,Boolean}]] controls a list of controls to update
|
37
37
|
# @return [void]
|
38
38
|
def update_security_controls(controls)
|
39
|
-
|
40
|
-
if controls.is_a? Array
|
39
|
+
if controls.kind_of? Array
|
41
40
|
put '/security_controls', controls.to_json
|
41
|
+
elsif controls.is_a? Controls::SecurityControl
|
42
|
+
put "/security_controls/#{controls.name}", controls.to_json
|
42
43
|
elsif controls.is_a? Hash
|
43
44
|
put "/security_controls/#{controls['name']}", controls.to_json
|
44
45
|
end
|
data/lib/controls/version.rb
CHANGED
@@ -0,0 +1,52 @@
|
|
1
|
+
require_relative '../../spec_helper.rb'
|
2
|
+
|
3
|
+
describe '/api/assets' do
|
4
|
+
before do
|
5
|
+
login_to_environment
|
6
|
+
end
|
7
|
+
|
8
|
+
context 'GET /api/assets' do
|
9
|
+
it 'returns a paginated asset collection' do
|
10
|
+
assets = Controls.assets
|
11
|
+
|
12
|
+
expect(assets).to be_kind_of(Controls::AssetCollection)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'respects pageable parameters' do
|
16
|
+
asset_collection = Controls.assets(
|
17
|
+
'page.sort' => 'os',
|
18
|
+
'page.size' => 20,
|
19
|
+
'page.sort.dir' => 'DESC'
|
20
|
+
)
|
21
|
+
expect(asset_collection).to be_kind_of(Controls::AssetCollection)
|
22
|
+
|
23
|
+
sort = asset_collection.sort.first
|
24
|
+
expect(sort.ascending?).to be_false
|
25
|
+
expect(sort.direction).to eq('DESC')
|
26
|
+
expect(sort.property).to eq('os')
|
27
|
+
|
28
|
+
operating_systems = asset_collection.resources.map(&:operating_system)
|
29
|
+
expect(operating_systems).to eq(operating_systems.sort.reverse)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'returns a 400 Bad Request on a bad page.sort parameter' do
|
33
|
+
asset_collection = expect {
|
34
|
+
Controls.assets(
|
35
|
+
'page.sort' => 'asdfghjkl;'
|
36
|
+
)
|
37
|
+
}.not_to raise_error, "expected: 200 OK\ngot: 500 Internal Server Error"
|
38
|
+
expect(asset_collection).to be_kind_of(Controls::Error)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'GET /api/assets/search?query=Windows' do
|
43
|
+
it 'returns only assets with Windows assets' do
|
44
|
+
asset_collection = Controls.asset_search('Windows')
|
45
|
+
expect(asset_collection).to be_kind_of(Controls::AssetCollection)
|
46
|
+
|
47
|
+
asset_collection.resources.map(&:operating_system).each do |operating_system|
|
48
|
+
expect(operating_system).to match(/^windows/i)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative '../../spec_helper.rb'
|
2
|
+
|
3
|
+
describe '/api/security_controls' do
|
4
|
+
before do
|
5
|
+
login_to_environment
|
6
|
+
end
|
7
|
+
|
8
|
+
context 'GET /api/security_controls' do
|
9
|
+
it 'returns a list of security controls' do
|
10
|
+
security_controls = Controls.security_controls
|
11
|
+
|
12
|
+
security_controls.each do |security_control|
|
13
|
+
enabled_is_boolean = [TrueClass, FalseClass].include?(security_control.enabled.class)
|
14
|
+
expect(enabled_is_boolean).to be_true
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'GET /api/security_controls/desktops-with-antivirus-deployed' do
|
20
|
+
it 'returns a single security control' do
|
21
|
+
security_control = Controls.security_controls('desktops-with-antivirus-deployed')
|
22
|
+
|
23
|
+
expect(security_control.name).to eq('desktops-with-antivirus-deployed')
|
24
|
+
|
25
|
+
enabled_is_boolean = [TrueClass, FalseClass].include?(security_control.enabled.class)
|
26
|
+
expect(enabled_is_boolean).to be_true
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/spec/matchers.rb
CHANGED
@@ -3,19 +3,20 @@ require 'rspec/expectations'
|
|
3
3
|
# Assessment Matchers
|
4
4
|
RSpec::Matchers.define :match_assessment_format do
|
5
5
|
match do |resource|
|
6
|
-
# Reverses the coercion
|
7
6
|
[
|
8
7
|
resource.high_risk_asset_count,
|
9
8
|
resource.id,
|
10
9
|
resource.low_risk_asset_count,
|
11
10
|
resource.medium_risk_asset_count,
|
12
|
-
resource.timestamp.to_i,
|
11
|
+
resource.timestamp.to_i, # Reverses the coercion
|
13
12
|
resource.total_asset_count
|
14
13
|
].each do |attribute|
|
15
14
|
expect(attribute.class).to eq(Fixnum)
|
16
15
|
end
|
17
16
|
|
18
|
-
|
19
|
-
|
17
|
+
assessing_is_boolean = [TrueClass, FalseClass].include?(resource.assessing.class)
|
18
|
+
risk_score_is_float = [Float].include?(resource.overall_risk_score.class)
|
19
|
+
expect(assessing_is_boolean).to be_true
|
20
|
+
expect(risk_score_is_float).to be_true
|
20
21
|
end
|
21
22
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -5,6 +5,8 @@ module SpecHelpers
|
|
5
5
|
def login_to_environment
|
6
6
|
# Allow self-signed certs in continuous integration
|
7
7
|
Controls.verify_ssl = false
|
8
|
+
Controls.api_endpoint = ENV['CONTROLS_API_ENDPOINT']
|
9
|
+
Controls.web_endpoint = ENV['CONTROLS_WEB_ENDPOINT']
|
8
10
|
Controls.login(ENV['CONTROLS_USERNAME'], ENV['CONTROLS_PASSWORD'])
|
9
11
|
end
|
10
12
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: controls
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.7.
|
4
|
+
version: 1.7.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Erran Carey
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dish
|
@@ -136,6 +136,8 @@ files:
|
|
136
136
|
- lib/controls/response.rb
|
137
137
|
- lib/controls/version.rb
|
138
138
|
- spec/controls/client/assessments_spec.rb
|
139
|
+
- spec/controls/client/assets_spec.rb
|
140
|
+
- spec/controls/client/security_controls_spec.rb
|
139
141
|
- spec/matchers.rb
|
140
142
|
- spec/spec_helper.rb
|
141
143
|
homepage: ''
|
@@ -164,6 +166,8 @@ specification_version: 4
|
|
164
166
|
summary: This gem interfaces to Rapid7's **controls**insight API.
|
165
167
|
test_files:
|
166
168
|
- spec/controls/client/assessments_spec.rb
|
169
|
+
- spec/controls/client/assets_spec.rb
|
170
|
+
- spec/controls/client/security_controls_spec.rb
|
167
171
|
- spec/matchers.rb
|
168
172
|
- spec/spec_helper.rb
|
169
173
|
has_rdoc:
|