esp_sdk 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/CHANGELOG.md +6 -1
- data/Gemfile.lock +11 -1
- data/README.md +287 -28
- data/bin/esp +15 -0
- data/esp_sdk.gemspec +2 -0
- data/lib/esp/aws_clients.rb +60 -0
- data/lib/esp/commands/add_external_account.rb +57 -0
- data/lib/esp/commands/commands_tasks.rb +106 -0
- data/lib/esp/commands/console.rb +68 -0
- data/lib/esp/extensions/active_resource/formats/json_api_format.rb +12 -4
- data/lib/esp/extensions/active_resource/paginated_collection.rb +5 -5
- data/lib/esp/extensions/active_resource/validations.rb +1 -1
- data/lib/esp/external_account_creator.rb +77 -0
- data/lib/esp/resources/alert.rb +30 -34
- data/lib/esp/resources/cloud_trail_event.rb +5 -0
- data/lib/esp/resources/contact_request.rb +6 -5
- data/lib/esp/resources/custom_signature.rb +32 -56
- data/lib/esp/resources/dashboard.rb +8 -1
- data/lib/esp/resources/external_account.rb +27 -19
- data/lib/esp/resources/organization.rb +27 -3
- data/lib/esp/resources/region.rb +15 -3
- data/lib/esp/resources/report.rb +28 -24
- data/lib/esp/resources/resource.rb +26 -10
- data/lib/esp/resources/service.rb +5 -0
- data/lib/esp/resources/signature.rb +28 -12
- data/lib/esp/resources/stat.rb +21 -2
- data/lib/esp/resources/stat_custom_signature.rb +30 -4
- data/lib/esp/resources/stat_region.rb +29 -3
- data/lib/esp/resources/stat_service.rb +29 -3
- data/lib/esp/resources/stat_signature.rb +29 -3
- data/lib/esp/resources/sub_organization.rb +27 -3
- data/lib/esp/resources/suppression/region.rb +14 -32
- data/lib/esp/resources/suppression/signature.rb +14 -40
- data/lib/esp/resources/suppression/unique_identifier.rb +8 -6
- data/lib/esp/resources/suppression.rb +43 -5
- data/lib/esp/resources/tag.rb +5 -0
- data/lib/esp/resources/team.rb +33 -9
- data/lib/esp/resources/user.rb +29 -3
- data/lib/esp/version.rb +1 -1
- data/lib/esp.rb +25 -5
- data/test/esp/aws_clients_test.rb +101 -0
- data/test/esp/extensions/active_resource/formats/json_api_format_test.rb +26 -12
- data/test/esp/extensions/active_resource/paginated_collection_test.rb +93 -72
- data/test/esp/extensions/active_resource/validations_test.rb +2 -12
- data/test/esp/external_account_creator_test.rb +153 -0
- data/test/esp/resources/alert_test.rb +71 -33
- data/test/esp/resources/cloud_trail_event_test.rb +9 -1
- data/test/esp/resources/contact_request_test.rb +8 -0
- data/test/esp/resources/custom_signature_test.rb +8 -0
- data/test/esp/resources/dashboard_test.rb +8 -0
- data/test/esp/resources/external_account_test.rb +8 -0
- data/test/esp/resources/metadata_test.rb +1 -1
- data/test/esp/resources/organization_test.rb +8 -0
- data/test/esp/resources/region_test.rb +12 -4
- data/test/esp/resources/report_test.rb +13 -4
- data/test/esp/resources/resource_test.rb +208 -64
- data/test/esp/resources/service_test.rb +8 -0
- data/test/esp/resources/signature_test.rb +15 -9
- data/test/esp/resources/stat_custom_signature_test.rb +9 -1
- data/test/esp/resources/stat_region_test.rb +23 -1
- data/test/esp/resources/stat_service_test.rb +23 -1
- data/test/esp/resources/stat_signature_test.rb +23 -1
- data/test/esp/resources/stat_test.rb +52 -8
- data/test/esp/resources/sub_organization_test.rb +8 -0
- data/test/esp/resources/suppression/region_test.rb +10 -2
- data/test/esp/resources/suppression/signature_test.rb +10 -2
- data/test/esp/resources/suppression/unique_identifier_test.rb +10 -2
- data/test/esp/resources/suppression_test.rb +74 -14
- data/test/esp/resources/tag_test.rb +9 -1
- data/test/esp/resources/team_test.rb +8 -0
- data/test/esp/resources/user_test.rb +49 -19
- data/test/esp_test.rb +19 -1
- data/test/factories/alerts.rb +70 -0
- data/test/factories/organizations.rb +2 -2
- data/test/factories/regions.rb +1 -1
- data/test/factories/sub_organizations.rb +1 -1
- data/test/factories/suppressions.rb +109 -3
- data/test/factories/users.rb +65 -2
- data/test/test_helper.rb +9 -8
- metadata +41 -69
- data/bin/esp_console +0 -67
- data/rdoc/ActiveResource/Formats.html +0 -178
- data/rdoc/ActiveResource/PaginatedCollection.html +0 -912
- data/rdoc/ActiveResource.html +0 -182
- data/rdoc/ESP/Alert.html +0 -808
- data/rdoc/ESP/CloudTrailEvent.html +0 -377
- data/rdoc/ESP/ContactRequest.html +0 -368
- data/rdoc/ESP/CustomSignature.html +0 -748
- data/rdoc/ESP/Dashboard.html +0 -357
- data/rdoc/ESP/ExternalAccount.html +0 -567
- data/rdoc/ESP/Metadata.html +0 -411
- data/rdoc/ESP/Organization.html +0 -592
- data/rdoc/ESP/Region.html +0 -401
- data/rdoc/ESP/Report.html +0 -624
- data/rdoc/ESP/Service.html +0 -382
- data/rdoc/ESP/Signature.html +0 -557
- data/rdoc/ESP/Stat.html +0 -1780
- data/rdoc/ESP/StatCustomSignature.html +0 -1601
- data/rdoc/ESP/StatRegion.html +0 -1600
- data/rdoc/ESP/StatService.html +0 -1600
- data/rdoc/ESP/StatSignature.html +0 -1600
- data/rdoc/ESP/SubOrganization.html +0 -542
- data/rdoc/ESP/Suppression/Region.html +0 -456
- data/rdoc/ESP/Suppression/Signature.html +0 -472
- data/rdoc/ESP/Suppression/UniqueIdentifier.html +0 -419
- data/rdoc/ESP/Suppression.html +0 -651
- data/rdoc/ESP/Tag.html +0 -373
- data/rdoc/ESP/Team.html +0 -586
- data/rdoc/ESP/User.html +0 -485
- data/rdoc/ESP.html +0 -549
- data/rdoc/README_md.html +0 -503
- data/rdoc/created.rid +0 -31
- data/rdoc/images/add.png +0 -0
- data/rdoc/images/arrow_up.png +0 -0
- data/rdoc/images/brick.png +0 -0
- data/rdoc/images/brick_link.png +0 -0
- data/rdoc/images/bug.png +0 -0
- data/rdoc/images/bullet_black.png +0 -0
- data/rdoc/images/bullet_toggle_minus.png +0 -0
- data/rdoc/images/bullet_toggle_plus.png +0 -0
- data/rdoc/images/date.png +0 -0
- data/rdoc/images/delete.png +0 -0
- data/rdoc/images/find.png +0 -0
- data/rdoc/images/loadingAnimation.gif +0 -0
- data/rdoc/images/macFFBgHack.png +0 -0
- data/rdoc/images/package.png +0 -0
- data/rdoc/images/page_green.png +0 -0
- data/rdoc/images/page_white_text.png +0 -0
- data/rdoc/images/page_white_width.png +0 -0
- data/rdoc/images/plugin.png +0 -0
- data/rdoc/images/ruby.png +0 -0
- data/rdoc/images/tag_blue.png +0 -0
- data/rdoc/images/tag_green.png +0 -0
- data/rdoc/images/transparent.png +0 -0
- data/rdoc/images/wrench.png +0 -0
- data/rdoc/images/wrench_orange.png +0 -0
- data/rdoc/images/zoom.png +0 -0
- data/rdoc/index.html +0 -136
- data/rdoc/js/darkfish.js +0 -155
- data/rdoc/js/jquery.js +0 -4
- data/rdoc/js/navigation.js +0 -142
- data/rdoc/js/search.js +0 -94
- data/rdoc/js/search_index.js +0 -1
- data/rdoc/js/searcher.js +0 -228
- data/rdoc/rdoc.css +0 -595
- data/rdoc/table_of_contents.html +0 -942
@@ -0,0 +1,153 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
require_relative '../../lib/esp/aws_clients'
|
3
|
+
require_relative '../../lib/esp/external_account_creator'
|
4
|
+
|
5
|
+
module ESP
|
6
|
+
class ExternalAccountCreatorTest < ActiveSupport::TestCase
|
7
|
+
context ESP::ExternalAccountCreator do
|
8
|
+
context "#create" do
|
9
|
+
setup do
|
10
|
+
@external_account_creator = ExternalAccountCreator.new
|
11
|
+
|
12
|
+
@external_account_creator.aws.stubs(:owner_id).returns('012345678912')
|
13
|
+
|
14
|
+
role = mock
|
15
|
+
role.stubs(:arn).returns('arn')
|
16
|
+
aws_role_object = mock
|
17
|
+
aws_role_object.stubs(:role).returns(role)
|
18
|
+
@external_account_creator.aws.stubs(:create_and_attach_role!).returns(aws_role_object)
|
19
|
+
|
20
|
+
@team_stub = stub_request(:put, /teams.json*/).to_return(body: json_list(:team, 1))
|
21
|
+
@sub_organization_stub = stub_request(:put, /sub_organizations.json*/).to_return(body: json_list(:sub_organization, 1))
|
22
|
+
|
23
|
+
@external_account_creator.stubs(:sleep).returns(0)
|
24
|
+
|
25
|
+
@external_account_stub = stub_request(:post, /external_accounts.json*/).to_return(body: json(:external_account))
|
26
|
+
end
|
27
|
+
|
28
|
+
should "fail if aws is not valid" do
|
29
|
+
@external_account_creator.aws.unstub(:owner_id)
|
30
|
+
@external_account_creator.aws.stubs(:owner_id).returns('abc')
|
31
|
+
|
32
|
+
exception = assert_raises AddExternalAccountError do
|
33
|
+
@external_account_creator.create
|
34
|
+
end
|
35
|
+
|
36
|
+
assert_match(/wrong length/, exception.message)
|
37
|
+
assert_equal AddExternalAccountError::EXIT_CODES['12 characters'], exception.exit_code
|
38
|
+
end
|
39
|
+
|
40
|
+
should "create and attach aws role" do
|
41
|
+
@external_account_creator.create
|
42
|
+
|
43
|
+
assert_received(@external_account_creator.aws, :create_and_attach_role!) do |expect|
|
44
|
+
expect.with do |external_account_id|
|
45
|
+
assert_equal @external_account_creator.send(:external_account_id), external_account_id
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context "#organization" do
|
51
|
+
setup do
|
52
|
+
stub_request(:get, /organizations.json*/).to_return(body: json_list(:empty, 1))
|
53
|
+
remove_request_stub(@sub_organization_stub)
|
54
|
+
stub_request(:put, /sub_organizations.json*/).to_return(body: json_list(:empty, 1))
|
55
|
+
end
|
56
|
+
|
57
|
+
should "fail if organization is not returned" do
|
58
|
+
exception = assert_raises AddExternalAccountError do
|
59
|
+
@external_account_creator.create
|
60
|
+
end
|
61
|
+
|
62
|
+
assert_match(/Organization not found/, exception.message)
|
63
|
+
assert_equal AddExternalAccountError::EXIT_CODES['organization not found'], exception.exit_code
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context "#sub_organization" do
|
68
|
+
setup do
|
69
|
+
stub_request(:get, /organizations.json*/).to_return(body: json_list(:organization, 1))
|
70
|
+
remove_request_stub(@sub_organization_stub)
|
71
|
+
end
|
72
|
+
|
73
|
+
should "fail if sub_organization is not found or created" do
|
74
|
+
stub_request(:put, /sub_organizations.json*/).to_return(body: json_list(:empty, 1))
|
75
|
+
stub_request(:post, /sub_organizations.json*/).to_return(status: 422, body: json(:error, :active_record))
|
76
|
+
|
77
|
+
exception = assert_raises AddExternalAccountError do
|
78
|
+
@external_account_creator.create
|
79
|
+
end
|
80
|
+
|
81
|
+
assert_match(/On Sub Organization/, exception.message)
|
82
|
+
assert_equal AddExternalAccountError::EXIT_CODES['sub organization'], exception.exit_code
|
83
|
+
end
|
84
|
+
|
85
|
+
should "create sub organization if sub_organization is not found" do
|
86
|
+
stub_request(:put, /sub_organizations.json*/).to_return(body: json_list(:empty, 1))
|
87
|
+
sub_org_stub = stub_request(:post, /sub_organizations.json*/).to_return(status: 422, body: json(:sub_organization))
|
88
|
+
|
89
|
+
@external_account_creator.create
|
90
|
+
|
91
|
+
assert_requested sub_org_stub
|
92
|
+
assert_not_nil @external_account_creator.send(:sub_organization)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context "#team" do
|
97
|
+
setup do
|
98
|
+
stub_request(:get, /sub_organizations.json*/).to_return(body: json_list(:sub_organization, 1))
|
99
|
+
remove_request_stub(@team_stub)
|
100
|
+
end
|
101
|
+
|
102
|
+
should "fail if team is not found or created" do
|
103
|
+
stub_request(:put, /teams.json*/).to_return(body: json_list(:empty, 1))
|
104
|
+
stub_request(:post, /teams.json*/).to_return(status: 422, body: json(:error, :active_record))
|
105
|
+
|
106
|
+
exception = assert_raises AddExternalAccountError do
|
107
|
+
@external_account_creator.create
|
108
|
+
end
|
109
|
+
|
110
|
+
assert_match(/On Team/, exception.message)
|
111
|
+
assert_equal AddExternalAccountError::EXIT_CODES['team'], exception.exit_code
|
112
|
+
end
|
113
|
+
|
114
|
+
should "create team if team is not found" do
|
115
|
+
stub_request(:put, /teams.json*/).to_return(body: json_list(:empty, 1))
|
116
|
+
team_stub = stub_request(:post, /teams.json*/).to_return(status: 422, body: json(:team))
|
117
|
+
|
118
|
+
@external_account_creator.create
|
119
|
+
|
120
|
+
assert_requested team_stub
|
121
|
+
assert_not_nil @external_account_creator.send(:team)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
should "fail if external account is not created" do
|
126
|
+
remove_request_stub @external_account_stub
|
127
|
+
stub_request(:post, /external_accounts.json*/).to_return(status: 422, body: json(:error, :active_record))
|
128
|
+
|
129
|
+
exception = assert_raises AddExternalAccountError do
|
130
|
+
@external_account_creator.create
|
131
|
+
end
|
132
|
+
|
133
|
+
assert_match(/On External Account/, exception.message)
|
134
|
+
assert_equal AddExternalAccountError::EXIT_CODES['external account'], exception.exit_code
|
135
|
+
end
|
136
|
+
|
137
|
+
should "create and return external_account" do
|
138
|
+
external_account = @external_account_creator.create
|
139
|
+
|
140
|
+
assert_requested(:post, /external_accounts.json*/) do |req|
|
141
|
+
body = JSON.parse(req.body)
|
142
|
+
assert_equal @external_account_creator.aws.create_and_attach_role!.role.arn, body['data']['attributes']['arn']
|
143
|
+
assert_equal @external_account_creator.send(:external_account_id), body['data']['attributes']['external_id']
|
144
|
+
assert_equal @external_account_creator.send(:team_name), body['data']['attributes']['name']
|
145
|
+
assert_equal @external_account_creator.send(:sub_organization).id, body['data']['attributes']['sub_organization_id']
|
146
|
+
assert_equal @external_account_creator.send(:team).id, body['data']['attributes']['team_id']
|
147
|
+
end
|
148
|
+
assert_not_nil external_account
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
@@ -106,34 +106,21 @@ module ESP
|
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
109
|
-
context '
|
110
|
-
should 'call the api for the alert' do
|
111
|
-
alert = build(:alert)
|
112
|
-
stubbed_metadata = stub_request(:get, %r{alerts/#{alert.id}/metadata.json*}).to_return(body: json(:metadata))
|
113
|
-
|
114
|
-
alert.metadata
|
115
|
-
|
116
|
-
assert_requested(stubbed_metadata)
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
context '.for_report' do
|
109
|
+
context '.where' do
|
121
110
|
should 'throw an error if report_id is not supplied' do
|
122
111
|
error = assert_raises ArgumentError do
|
123
|
-
ESP::Alert.
|
112
|
+
ESP::Alert.where(status: 'complete')
|
124
113
|
end
|
125
114
|
assert_equal 'You must supply a report id.', error.message
|
126
115
|
end
|
127
116
|
|
128
|
-
should 'call the api and
|
129
|
-
stub_request(:
|
117
|
+
should 'call the api and return alerts when report_id is supplied' do
|
118
|
+
stub_alert = stub_request(:put, %r{reports/5/alerts.json*}).to_return(body: json_list(:alert, 2))
|
130
119
|
|
131
|
-
|
120
|
+
alert = ESP::Alert.where(report_id: 5)
|
132
121
|
|
133
|
-
assert_requested(
|
134
|
-
|
135
|
-
end
|
136
|
-
assert_equal ESP::Alert, alerts.resource_class
|
122
|
+
assert_requested(stub_alert)
|
123
|
+
assert_equal ESP::Alert, alert.resource_class
|
137
124
|
end
|
138
125
|
end
|
139
126
|
|
@@ -243,7 +230,7 @@ module ESP
|
|
243
230
|
setup do
|
244
231
|
skip "Make sure you run the live calls locally to ensure proper integration" if ENV['CI_SERVER']
|
245
232
|
WebMock.allow_net_connect!
|
246
|
-
@report = ESP::Report.
|
233
|
+
@report = ESP::Report.all.detect { |r| r.status == 'complete' }
|
247
234
|
skip "Live DB does not have any reports. Add a report and run tests again." if @report.blank?
|
248
235
|
@alert = @report.alerts.last
|
249
236
|
end
|
@@ -252,31 +239,82 @@ module ESP
|
|
252
239
|
WebMock.disable_net_connect!
|
253
240
|
end
|
254
241
|
|
255
|
-
context '#
|
256
|
-
should 'return
|
242
|
+
context '#external_account' do
|
243
|
+
should 'return an external_account' do
|
244
|
+
external_account = @alert.external_account
|
245
|
+
|
246
|
+
assert_equal ESP::ExternalAccount, external_account.class
|
247
|
+
assert_equal @alert.external_account_id, external_account.id
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
context '#region' do
|
252
|
+
should 'return a region' do
|
253
|
+
region = @alert.region
|
254
|
+
|
255
|
+
assert_equal ESP::Region, region.class
|
256
|
+
assert_equal @alert.region_id, region.id
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
context '#signature' do
|
261
|
+
should 'return a signature' do
|
262
|
+
signature = @alert.signature
|
263
|
+
|
264
|
+
assert_equal ESP::Signature, signature.class
|
265
|
+
assert_equal @alert.signature_id, signature.id
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
context '#custom_signature' do
|
270
|
+
should 'return a custom_signature' do
|
257
271
|
assert_nothing_raised do
|
258
|
-
@alert.
|
272
|
+
@alert.attributes['custom_signature_id'] ||= 1
|
273
|
+
@alert.custom_signature
|
259
274
|
end
|
260
275
|
end
|
261
276
|
end
|
262
277
|
|
263
|
-
context '
|
264
|
-
should 'return
|
265
|
-
|
266
|
-
|
278
|
+
context '#suppression' do
|
279
|
+
should 'return a suppression' do
|
280
|
+
assert_nothing_raised do
|
281
|
+
@alert.attributes['suppression_id'] ||= 1
|
282
|
+
@alert.suppression
|
283
|
+
end
|
284
|
+
end
|
285
|
+
end
|
267
286
|
|
268
|
-
|
287
|
+
context '#cloud_trail_events' do
|
288
|
+
should 'return cloud_trail_events' do
|
289
|
+
assert_nothing_raised do
|
290
|
+
@alert.cloud_trail_events
|
291
|
+
end
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
295
|
+
context '#tags' do
|
296
|
+
should 'return tags' do
|
297
|
+
assert_nothing_raised do
|
298
|
+
@alert.tags
|
299
|
+
end
|
269
300
|
end
|
270
301
|
end
|
271
302
|
|
272
303
|
context '.find' do
|
273
304
|
should 'return an alert by id' do
|
274
|
-
|
275
|
-
alert_id = report.alerts.last.id
|
276
|
-
alert = ESP::Alert.find(alert_id.to_i)
|
305
|
+
alert = ESP::Alert.find(@alert.id.to_i)
|
277
306
|
|
278
307
|
assert_equal ESP::Alert, alert.class
|
279
|
-
assert_equal
|
308
|
+
assert_equal @alert.id, alert.id
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
312
|
+
context '.where' do
|
313
|
+
should 'return alert objects' do
|
314
|
+
alerts = ESP::Alert.where(report_id: @report.id, id_eq: @alert.id)
|
315
|
+
|
316
|
+
assert_equal ESP::Alert, alerts.resource_class
|
317
|
+
assert_equal @alert.id, alerts.first.id
|
280
318
|
end
|
281
319
|
end
|
282
320
|
end
|
@@ -3,6 +3,14 @@ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
|
3
3
|
module ESP
|
4
4
|
class CloudTrailEventTest < ActiveSupport::TestCase
|
5
5
|
context ESP::CloudTrailEvent do
|
6
|
+
context '.where' do
|
7
|
+
should 'not be implemented' do
|
8
|
+
assert_raises ESP::NotImplementedError do
|
9
|
+
ESP::CloudTrailEvent.where(id_eq: 2)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
6
14
|
context '#create' do
|
7
15
|
should 'not be implemented' do
|
8
16
|
assert_raises ESP::NotImplementedError do
|
@@ -86,7 +94,7 @@ module ESP
|
|
86
94
|
|
87
95
|
context '.for_alert' do
|
88
96
|
should 'return events for alert id' do
|
89
|
-
report = ESP::Report.
|
97
|
+
report = ESP::Report.all.detect { |r| r.status == 'complete' }
|
90
98
|
events = ESP::CloudTrailEvent.for_alert(report.alerts.last.id)
|
91
99
|
|
92
100
|
assert_equal ESP::CloudTrailEvent, events.resource_class
|
@@ -11,6 +11,14 @@ module ESP
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
+
context '.where' do
|
15
|
+
should 'not be implemented' do
|
16
|
+
assert_raises ESP::NotImplementedError do
|
17
|
+
ESP::ContactRequest.where(id_eq: 2)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
14
22
|
context '#update' do
|
15
23
|
should 'not be implemented' do
|
16
24
|
s = ESP::ContactRequest.new
|
@@ -211,6 +211,14 @@ module ESP
|
|
211
211
|
end
|
212
212
|
end
|
213
213
|
|
214
|
+
context '.where' do
|
215
|
+
should 'return custom_signature objects' do
|
216
|
+
custom_signatures = ESP::CustomSignature.where(id_eq: @custom_signature.id)
|
217
|
+
|
218
|
+
assert_equal ESP::CustomSignature, custom_signatures.resource_class
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
214
222
|
context '#CRUD' do
|
215
223
|
should 'be able to create, update and destroy' do
|
216
224
|
custom_signature = ESP::CustomSignature.new(@custom_signature.attributes)
|
@@ -11,6 +11,14 @@ module ESP
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
+
context '.where' do
|
15
|
+
should 'not be implemented' do
|
16
|
+
assert_raises ESP::NotImplementedError do
|
17
|
+
ESP::Dashboard.where(id_eq: 2)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
14
22
|
context '#create' do
|
15
23
|
should 'not be implemented' do
|
16
24
|
assert_raises ESP::NotImplementedError do
|
@@ -98,6 +98,14 @@ module ESP
|
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
101
|
+
context '.where' do
|
102
|
+
should 'return external_account objects' do
|
103
|
+
external_accounts = ESP::ExternalAccount.where(id_eq: @external_account.id)
|
104
|
+
|
105
|
+
assert_equal ESP::ExternalAccount, external_accounts.resource_class
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
101
109
|
context '#CRUD' do
|
102
110
|
should 'be able to create, update and destroy' do
|
103
111
|
skip "There are to many dependencies to validate an external account to create or update one. Besides esp_web, esp_query has to be running and there must be valid AWS keys assigned as well."
|
@@ -86,7 +86,7 @@ module ESP
|
|
86
86
|
|
87
87
|
context '.for_alert' do
|
88
88
|
should 'return metadata for alert id' do
|
89
|
-
report = ESP::Report.
|
89
|
+
report = ESP::Report.all.detect { |r| r.status == 'complete' }
|
90
90
|
metadata = ESP::Metadata.for_alert(report.alerts.last.id)
|
91
91
|
|
92
92
|
assert_equal ESP::Metadata, metadata.class
|
@@ -159,6 +159,14 @@ module ESP
|
|
159
159
|
end
|
160
160
|
end
|
161
161
|
|
162
|
+
context '.where' do
|
163
|
+
should 'return organization objects' do
|
164
|
+
organizations = ESP::Organization.where(id_eq: @organization.id)
|
165
|
+
|
166
|
+
assert_equal ESP::Organization, organizations.resource_class
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
162
170
|
context '#CRUD' do
|
163
171
|
should 'be able to update' do
|
164
172
|
@organization.name = @organization.name
|
@@ -61,19 +61,27 @@ module ESP
|
|
61
61
|
setup do
|
62
62
|
skip "Make sure you run the live calls locally to ensure proper integration" if ENV['CI_SERVER']
|
63
63
|
WebMock.allow_net_connect!
|
64
|
+
@region = ESP::Region.last
|
65
|
+
skip "Live DB does not have any regions. Add a region and run tests again." if @region.blank?
|
64
66
|
end
|
65
67
|
|
66
68
|
teardown do
|
67
69
|
WebMock.disable_net_connect!
|
68
70
|
end
|
69
71
|
|
72
|
+
context '.where' do
|
73
|
+
should 'return region objects' do
|
74
|
+
regions = ESP::Region.where(id_eq: @region.id)
|
75
|
+
|
76
|
+
assert_equal ESP::Region, regions.resource_class
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
70
80
|
context '#CRUD' do
|
71
81
|
should 'be able to read' do
|
72
|
-
region
|
73
|
-
|
74
|
-
assert_not_nil region
|
82
|
+
assert_not_nil @region
|
75
83
|
|
76
|
-
region = ESP::Region.find(region.id)
|
84
|
+
region = ESP::Region.find(@region.id)
|
77
85
|
|
78
86
|
assert_not_nil region
|
79
87
|
end
|
@@ -60,12 +60,13 @@ module ESP
|
|
60
60
|
context '#alerts' do
|
61
61
|
should 'call the api for the report and the passed in params' do
|
62
62
|
report = build(:report)
|
63
|
-
stub_request(:
|
63
|
+
stub_request(:put, %r{reports/#{report.id}/alerts.json*}).to_return(body: json_list(:alert, 2))
|
64
64
|
|
65
65
|
report.alerts(status: 'pass')
|
66
66
|
|
67
|
-
assert_requested(:
|
68
|
-
|
67
|
+
assert_requested(:put, %r{reports/#{report.id}/alerts.json*}) do |req|
|
68
|
+
body = JSON.parse(req.body)
|
69
|
+
assert_equal 'pass', body['filter']['status']
|
69
70
|
end
|
70
71
|
end
|
71
72
|
end
|
@@ -118,7 +119,7 @@ module ESP
|
|
118
119
|
setup do
|
119
120
|
skip "Make sure you run the live calls locally to ensure proper integration" if ENV['CI_SERVER']
|
120
121
|
WebMock.allow_net_connect!
|
121
|
-
@report = ESP::Report.
|
122
|
+
@report = ESP::Report.all.detect { |r| r.status == 'complete' }
|
122
123
|
skip "Live DB does not have any reports. Add a report and run tests again." if @report.blank?
|
123
124
|
end
|
124
125
|
|
@@ -166,6 +167,14 @@ module ESP
|
|
166
167
|
end
|
167
168
|
end
|
168
169
|
|
170
|
+
context '.where' do
|
171
|
+
should 'return report objects' do
|
172
|
+
reports = ESP::Report.where(id_eq: @report.id)
|
173
|
+
|
174
|
+
assert_equal ESP::Report, reports.resource_class
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
169
178
|
context '.create' do
|
170
179
|
should 'return an error if a bad team_id is passed' do
|
171
180
|
assert_nothing_raised do
|