esp_sdk 1.1.0 → 2.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -2
- data/.rubocop.yml +53 -6
- data/.ruby-version +1 -1
- data/.travis.yml +8 -2
- data/Gemfile.lock +171 -0
- data/Guardfile +47 -0
- data/README.md +230 -5
- data/Rakefile +14 -1
- data/assets/logo.png +0 -0
- data/bin/esp_console +71 -0
- data/esp_sdk.gemspec +27 -18
- data/lib/esp/exceptions.rb +3 -0
- data/lib/esp/extensions/active_resource/formats/json_api_format.rb +105 -0
- data/lib/esp/extensions/active_resource/paginated_collection.rb +198 -0
- data/lib/esp/extensions/active_resource/validations.rb +45 -0
- data/lib/esp/resources/alert.rb +135 -0
- data/lib/esp/resources/cloud_trail_event.rb +45 -0
- data/lib/esp/resources/concerns/stat_totals.rb +79 -0
- data/lib/esp/resources/contact_request.rb +42 -0
- data/lib/esp/resources/custom_signature.rb +224 -0
- data/lib/esp/resources/dashboard.rb +31 -0
- data/lib/esp/resources/external_account.rb +89 -0
- data/lib/esp/resources/organization.rb +61 -0
- data/lib/esp/resources/region.rb +46 -0
- data/lib/esp/resources/report.rb +100 -0
- data/lib/esp/resources/resource.rb +66 -0
- data/lib/esp/resources/service.rb +31 -0
- data/lib/esp/resources/signature.rb +106 -0
- data/lib/esp/resources/stat.rb +124 -0
- data/lib/esp/resources/stat_custom_signature.rb +121 -0
- data/lib/esp/resources/stat_region.rb +121 -0
- data/lib/esp/resources/stat_service.rb +121 -0
- data/lib/esp/resources/stat_signature.rb +121 -0
- data/lib/esp/resources/sub_organization.rb +69 -0
- data/lib/esp/resources/suppression/region.rb +99 -0
- data/lib/esp/resources/suppression/signature.rb +107 -0
- data/lib/esp/resources/suppression/unique_identifier.rb +60 -0
- data/lib/esp/resources/suppression.rb +86 -0
- data/lib/esp/resources/tag.rb +45 -0
- data/lib/esp/resources/team.rb +79 -0
- data/lib/esp/resources/user.rb +46 -0
- data/lib/esp/version.rb +3 -0
- data/lib/esp.rb +95 -0
- data/lib/esp_sdk.rb +9 -45
- data/lib/tasks/rubocop.rake +2 -0
- data/lib/tasks/testing.rake +3 -0
- data/rdoc/ActiveResource/Formats.html +176 -0
- data/rdoc/ActiveResource/PaginatedCollection.html +910 -0
- data/rdoc/ActiveResource.html +180 -0
- data/rdoc/ESP/Alert.html +771 -0
- data/rdoc/ESP/CloudTrailEvent.html +375 -0
- data/rdoc/ESP/ContactRequest.html +366 -0
- data/rdoc/ESP/CustomSignature.html +746 -0
- data/rdoc/ESP/Dashboard.html +355 -0
- data/rdoc/ESP/ExternalAccount.html +565 -0
- data/rdoc/ESP/Organization.html +590 -0
- data/rdoc/ESP/Region.html +399 -0
- data/rdoc/ESP/Report.html +622 -0
- data/rdoc/ESP/Service.html +380 -0
- data/rdoc/ESP/Signature.html +555 -0
- data/rdoc/ESP/Stat.html +1778 -0
- data/rdoc/ESP/StatCustomSignature.html +1599 -0
- data/rdoc/ESP/StatRegion.html +1598 -0
- data/rdoc/ESP/StatService.html +1598 -0
- data/rdoc/ESP/StatSignature.html +1598 -0
- data/rdoc/ESP/SubOrganization.html +540 -0
- data/rdoc/ESP/Suppression/Region.html +454 -0
- data/rdoc/ESP/Suppression/Signature.html +470 -0
- data/rdoc/ESP/Suppression/UniqueIdentifier.html +417 -0
- data/rdoc/ESP/Suppression.html +649 -0
- data/rdoc/ESP/Tag.html +371 -0
- data/rdoc/ESP/Team.html +584 -0
- data/rdoc/ESP/User.html +483 -0
- data/rdoc/ESP.html +546 -0
- data/rdoc/README_md.html +501 -0
- data/rdoc/created.rid +30 -0
- 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 +134 -0
- data/rdoc/js/darkfish.js +155 -0
- data/rdoc/js/jquery.js +4 -0
- data/rdoc/js/navigation.js +142 -0
- data/rdoc/js/search.js +94 -0
- data/rdoc/js/search_index.js +1 -0
- data/rdoc/js/searcher.js +228 -0
- data/rdoc/rdoc.css +595 -0
- data/rdoc/table_of_contents.html +927 -0
- data/test/esp/extensions/active_resource/formats/json_api_format_test.rb +109 -0
- data/test/esp/extensions/active_resource/paginated_collection_test.rb +435 -0
- data/test/esp/extensions/active_resource/validations_test.rb +59 -0
- data/test/esp/resources/alert_test.rb +263 -0
- data/test/esp/resources/cloud_trail_event_test.rb +98 -0
- data/test/esp/resources/contact_request_test.rb +73 -0
- data/test/esp/resources/custom_signature_test.rb +241 -0
- data/test/esp/resources/dashboard_test.rb +71 -0
- data/test/esp/resources/external_account_test.rb +125 -0
- data/test/esp/resources/organization_test.rb +175 -0
- data/test/esp/resources/region_test.rb +84 -0
- data/test/esp/resources/report_test.rb +180 -0
- data/test/esp/resources/resource_test.rb +183 -0
- data/test/esp/resources/service_test.rb +64 -0
- data/test/esp/resources/signature_test.rb +177 -0
- data/test/esp/resources/stat_custom_signature_test.rb +115 -0
- data/test/esp/resources/stat_region_test.rb +114 -0
- data/test/esp/resources/stat_service_test.rb +114 -0
- data/test/esp/resources/stat_signature_test.rb +115 -0
- data/test/esp/resources/stat_test.rb +159 -0
- data/test/esp/resources/sub_organization_test.rb +127 -0
- data/test/esp/resources/suppression/region_test.rb +115 -0
- data/test/esp/resources/suppression/signature_test.rb +117 -0
- data/test/esp/resources/suppression/unique_identifier_test.rb +79 -0
- data/test/esp/resources/suppression_test.rb +226 -0
- data/test/esp/resources/tag_test.rb +98 -0
- data/test/esp/resources/team_test.rb +140 -0
- data/test/esp/resources/user_test.rb +113 -0
- data/test/esp_test.rb +139 -0
- data/test/factories/alerts.rb +234 -0
- data/test/factories/cloud_trail_events.rb +16 -0
- data/test/factories/contact_requests.rb +14 -0
- data/test/factories/custom_signatures.rb +30 -0
- data/test/factories/dashboards.rb +91 -0
- data/test/factories/errors.rb +24 -0
- data/test/factories/external_accounts.rb +44 -0
- data/test/factories/organizations.rb +48 -0
- data/test/factories/regions.rb +9 -0
- data/test/factories/reports.rb +56 -0
- data/test/factories/services.rb +12 -0
- data/test/factories/signatures.rb +28 -0
- data/test/factories/stat_custom_signatures.rb +97 -0
- data/test/factories/stat_regions.rb +97 -0
- data/test/factories/stat_services.rb +97 -0
- data/test/factories/stat_signautures.rb +97 -0
- data/test/factories/stats.rb +129 -0
- data/test/factories/sub_organizations.rb +34 -0
- data/test/factories/suppression/regions.rb +90 -0
- data/test/factories/suppression/signatures.rb +117 -0
- data/test/factories/suppression/unique_identifiers.rb +111 -0
- data/test/factories/suppressions.rb +71 -0
- data/test/factories/tags.rb +12 -0
- data/test/factories/teams.rb +32 -0
- data/test/factories/users.rb +54 -0
- data/test/json_strategy.rb +25 -0
- data/test/test_helper.rb +44 -5
- metadata +387 -119
- data/bin/esp_repl +0 -60
- data/lib/esp_sdk/api.rb +0 -33
- data/lib/esp_sdk/client.rb +0 -62
- data/lib/esp_sdk/configure.rb +0 -40
- data/lib/esp_sdk/end_points/base.rb +0 -102
- data/lib/esp_sdk/end_points/contact_requests.rb +0 -6
- data/lib/esp_sdk/end_points/custom_signatures.rb +0 -41
- data/lib/esp_sdk/end_points/dashboard.rb +0 -35
- data/lib/esp_sdk/end_points/external_accounts.rb +0 -9
- data/lib/esp_sdk/end_points/organizations.rb +0 -6
- data/lib/esp_sdk/end_points/reports.rb +0 -6
- data/lib/esp_sdk/end_points/services.rb +0 -6
- data/lib/esp_sdk/end_points/signatures.rb +0 -39
- data/lib/esp_sdk/end_points/sub_organizations.rb +0 -6
- data/lib/esp_sdk/end_points/teams.rb +0 -6
- data/lib/esp_sdk/end_points/users.rb +0 -6
- data/lib/esp_sdk/exceptions.rb +0 -8
- data/lib/esp_sdk/extensions/rest_client/request.rb +0 -9
- data/lib/esp_sdk/repl.rb +0 -61
- data/lib/esp_sdk/version.rb +0 -3
- data/test/esp_sdk/api_test.rb +0 -36
- data/test/esp_sdk/client_test.rb +0 -129
- data/test/esp_sdk/configure_test.rb +0 -65
- data/test/esp_sdk/end_points/.keep +0 -0
- data/test/esp_sdk/end_points/base_test.rb +0 -230
- data/test/esp_sdk/end_points/custom_signatures_test.rb +0 -90
- data/test/esp_sdk/end_points/dashboard_test.rb +0 -55
- data/test/esp_sdk/end_points/external_accounts_test.rb +0 -20
- data/test/esp_sdk/end_points/signatures_test.rb +0 -83
- data/test/esp_sdk/exceptions_test.rb +0 -41
- data/test/esp_sdk_test.rb +0 -70
@@ -0,0 +1,263 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
2
|
+
|
3
|
+
module ESP
|
4
|
+
class AlertTest < ActiveSupport::TestCase
|
5
|
+
context ESP::Alert do
|
6
|
+
context '#create' do
|
7
|
+
should 'not be implemented' do
|
8
|
+
assert_raises ESP::NotImplementedError do
|
9
|
+
ESP::Alert.create(name: 'test')
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context '#update' do
|
15
|
+
should 'not be implemented' do
|
16
|
+
cloud_trail_event = build(:cloud_trail_event)
|
17
|
+
assert_raises ESP::NotImplementedError do
|
18
|
+
cloud_trail_event.save
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context '#destroy' do
|
24
|
+
should 'not be implemented' do
|
25
|
+
cloud_trail_event = build(:cloud_trail_event)
|
26
|
+
assert_raises ESP::NotImplementedError do
|
27
|
+
cloud_trail_event.destroy
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context '#external_account' do
|
33
|
+
should 'call the api' do
|
34
|
+
alert = build(:alert, external_account_id: 3)
|
35
|
+
stubbed_external_account = stub_request(:get, %r{external_accounts/#{alert.external_account_id}.json*}).to_return(body: json(:external_account))
|
36
|
+
|
37
|
+
alert.external_account
|
38
|
+
|
39
|
+
assert_requested(stubbed_external_account)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context '#region' do
|
44
|
+
should 'call the api' do
|
45
|
+
alert = build(:alert, region_id: 3)
|
46
|
+
stubbed_region = stub_request(:get, %r{regions/#{alert.region_id}.json*}).to_return(body: json(:region))
|
47
|
+
|
48
|
+
alert.region
|
49
|
+
|
50
|
+
assert_requested(stubbed_region)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context '#signature' do
|
55
|
+
should 'call the api' do
|
56
|
+
alert = build(:alert, signature_id: 3)
|
57
|
+
stubbed_signature = stub_request(:get, %r{signatures/#{alert.signature_id}.json*}).to_return(body: json(:signature))
|
58
|
+
|
59
|
+
alert.signature
|
60
|
+
|
61
|
+
assert_requested(stubbed_signature)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context '#custom_signature' do
|
66
|
+
should 'call the api' do
|
67
|
+
alert = build(:alert, custom_signature_id: 3)
|
68
|
+
stubbed_custom_signature = stub_request(:get, %r{custom_signatures/#{alert.custom_signature_id}.json*}).to_return(body: json(:custom_signature))
|
69
|
+
|
70
|
+
alert.custom_signature
|
71
|
+
|
72
|
+
assert_requested(stubbed_custom_signature)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context '#suppression' do
|
77
|
+
should 'call the api' do
|
78
|
+
alert = build(:alert, suppression_id: 3)
|
79
|
+
stubbed_suppression = stub_request(:get, %r{suppressions/#{alert.suppression_id}.json*}).to_return(body: json(:suppression))
|
80
|
+
|
81
|
+
alert.suppression
|
82
|
+
|
83
|
+
assert_requested(stubbed_suppression)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context '#cloud_trail_events' do
|
88
|
+
should 'call the api for the alert' do
|
89
|
+
alert = build(:alert)
|
90
|
+
stubbed_events = stub_request(:get, %r{alerts/#{alert.id}/cloud_trail_events.json*}).to_return(body: json_list(:cloud_trail_event, 2))
|
91
|
+
|
92
|
+
alert.cloud_trail_events
|
93
|
+
|
94
|
+
assert_requested(stubbed_events)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context '#tags' do
|
99
|
+
should 'call the api for the alert' do
|
100
|
+
alert = build(:alert)
|
101
|
+
stubbed_tags = stub_request(:get, %r{alerts/#{alert.id}/tags.json*}).to_return(body: json_list(:tag, 2))
|
102
|
+
|
103
|
+
alert.tags
|
104
|
+
|
105
|
+
assert_requested(stubbed_tags)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
context '.for_report' do
|
110
|
+
should 'throw an error if report_id is not supplied' do
|
111
|
+
error = assert_raises ArgumentError do
|
112
|
+
ESP::Alert.for_report
|
113
|
+
end
|
114
|
+
assert_equal 'You must supply a report id.', error.message
|
115
|
+
end
|
116
|
+
|
117
|
+
should 'call the api and pass params' do
|
118
|
+
stub_request(:get, %r{reports/5/alerts.json*}).to_return(body: json_list(:alert, 2))
|
119
|
+
|
120
|
+
alerts = ESP::Alert.for_report(5, status: 'pass')
|
121
|
+
|
122
|
+
assert_requested(:get, %r{reports/5/alerts.json*}) do |req|
|
123
|
+
assert_equal "filter[status]=pass", URI.unescape(req.uri.query)
|
124
|
+
end
|
125
|
+
assert_equal ESP::Alert, alerts.resource_class
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
context '.find' do
|
130
|
+
should 'throw an error if report_id is not supplied' do
|
131
|
+
error = assert_raises ArgumentError do
|
132
|
+
ESP::Alert.find(:all, params: { id: 3 })
|
133
|
+
end
|
134
|
+
assert_equal 'You must supply a report id.', error.message
|
135
|
+
end
|
136
|
+
|
137
|
+
should 'call the show api and return an alert if searching by id' do
|
138
|
+
stub_alert = stub_request(:get, %r{alerts/5.json*}).to_return(body: json(:alert))
|
139
|
+
|
140
|
+
alert = ESP::Alert.find(5)
|
141
|
+
|
142
|
+
assert_requested(stub_alert)
|
143
|
+
assert_equal ESP::Alert, alert.class
|
144
|
+
end
|
145
|
+
|
146
|
+
should 'call the api and return alerts when report_id is supplied' do
|
147
|
+
stub_alert = stub_request(:get, %r{reports/5/alerts.json*}).to_return(body: json_list(:alert, 2))
|
148
|
+
|
149
|
+
alert = ESP::Alert.find(:all, params: { report_id: 5 })
|
150
|
+
|
151
|
+
assert_requested(stub_alert)
|
152
|
+
assert_equal ESP::Alert, alert.resource_class
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
context '#suppress_signature' do
|
157
|
+
should 'throw an error if reason is not supplied' do
|
158
|
+
alert = build(:alert)
|
159
|
+
|
160
|
+
error = assert_raises ArgumentError do
|
161
|
+
alert.suppress_signature
|
162
|
+
end
|
163
|
+
assert_equal 'You must specify the reason.', error.message
|
164
|
+
end
|
165
|
+
|
166
|
+
should 'call Suppression::Signature.create' do
|
167
|
+
alert = build(:alert)
|
168
|
+
Suppression::Signature.stubs(:create)
|
169
|
+
|
170
|
+
alert.suppress_signature('the reason')
|
171
|
+
|
172
|
+
assert_received(Suppression::Signature, :create) do |expects|
|
173
|
+
expects.with do |params|
|
174
|
+
assert_equal alert.id, params[:alert_id]
|
175
|
+
assert_equal 'the reason', params[:reason]
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
context '#suppress_region' do
|
182
|
+
should 'throw an error if reason is not supplied' do
|
183
|
+
alert = build(:alert)
|
184
|
+
|
185
|
+
error = assert_raises ArgumentError do
|
186
|
+
alert.suppress_region
|
187
|
+
end
|
188
|
+
assert_equal 'You must specify the reason.', error.message
|
189
|
+
end
|
190
|
+
|
191
|
+
should 'call Suppression::Region.create' do
|
192
|
+
alert = build(:alert)
|
193
|
+
Suppression::Region.stubs(:create)
|
194
|
+
|
195
|
+
alert.suppress_region('the reason')
|
196
|
+
|
197
|
+
assert_received(Suppression::Region, :create) do |expects|
|
198
|
+
expects.with do |params|
|
199
|
+
assert_equal alert.id, params[:alert_id]
|
200
|
+
assert_equal 'the reason', params[:reason]
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
context '#suppress_unique_identifier' do
|
207
|
+
should 'throw an error if reason is not supplied' do
|
208
|
+
alert = build(:alert)
|
209
|
+
|
210
|
+
error = assert_raises ArgumentError do
|
211
|
+
alert.suppress_unique_identifier
|
212
|
+
end
|
213
|
+
assert_equal 'You must specify the reason.', error.message
|
214
|
+
end
|
215
|
+
|
216
|
+
should 'call Suppression::UniqueIdentifier.create' do
|
217
|
+
alert = build(:alert)
|
218
|
+
Suppression::UniqueIdentifier.stubs(:create)
|
219
|
+
|
220
|
+
alert.suppress_unique_identifier('the reason')
|
221
|
+
|
222
|
+
assert_received(Suppression::UniqueIdentifier, :create) do |expects|
|
223
|
+
expects.with do |params|
|
224
|
+
assert_equal alert.id, params[:alert_id]
|
225
|
+
assert_equal 'the reason', params[:reason]
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
context 'live calls' do
|
232
|
+
setup do
|
233
|
+
skip "Make sure you run the live calls locally to ensure proper integration" if ENV['CI_SERVER']
|
234
|
+
WebMock.allow_net_connect!
|
235
|
+
end
|
236
|
+
|
237
|
+
teardown do
|
238
|
+
WebMock.disable_net_connect!
|
239
|
+
end
|
240
|
+
|
241
|
+
context '.for_report' do
|
242
|
+
should 'return events for report id' do
|
243
|
+
report = ESP::Report.last
|
244
|
+
alerts = ESP::Alert.for_report(report.id)
|
245
|
+
|
246
|
+
assert_equal ESP::Alert, alerts.resource_class
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
context '.find' do
|
251
|
+
should 'return an alert by id' do
|
252
|
+
report = ESP::Report.last
|
253
|
+
alert_id = report.alerts.last.id
|
254
|
+
alert = ESP::Alert.find(alert_id.to_i)
|
255
|
+
|
256
|
+
assert_equal ESP::Alert, alert.class
|
257
|
+
assert_equal alert_id, alert.id
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|
261
|
+
end
|
262
|
+
end
|
263
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
2
|
+
|
3
|
+
module ESP
|
4
|
+
class CloudTrailEventTest < ActiveSupport::TestCase
|
5
|
+
context ESP::CloudTrailEvent do
|
6
|
+
context '#create' do
|
7
|
+
should 'not be implemented' do
|
8
|
+
assert_raises ESP::NotImplementedError do
|
9
|
+
ESP::CloudTrailEvent.create(name: 'test')
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context '#update' do
|
15
|
+
should 'not be implemented' do
|
16
|
+
cloud_trail_event = build(:cloud_trail_event)
|
17
|
+
assert_raises ESP::NotImplementedError do
|
18
|
+
cloud_trail_event.save
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context '#destroy' do
|
24
|
+
should 'not be implemented' do
|
25
|
+
cloud_trail_event = build(:cloud_trail_event)
|
26
|
+
assert_raises ESP::NotImplementedError do
|
27
|
+
cloud_trail_event.destroy
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context '.for_alert' do
|
33
|
+
should 'throw an error if alert id is not supplied' do
|
34
|
+
error = assert_raises ArgumentError do
|
35
|
+
ESP::CloudTrailEvent.for_alert
|
36
|
+
end
|
37
|
+
assert_equal 'You must supply an alert id.', error.message
|
38
|
+
end
|
39
|
+
|
40
|
+
should 'call the api' do
|
41
|
+
stub_event = stub_request(:get, %r{alerts/5/cloud_trail_events.json*}).to_return(body: json_list(:cloud_trail_event, 2))
|
42
|
+
|
43
|
+
events = ESP::CloudTrailEvent.for_alert(5)
|
44
|
+
|
45
|
+
assert_requested(stub_event)
|
46
|
+
assert_equal ESP::CloudTrailEvent, events.resource_class
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context '.find' do
|
51
|
+
should 'throw an error if alert_id is not supplied' do
|
52
|
+
error = assert_raises ArgumentError do
|
53
|
+
ESP::CloudTrailEvent.find(:all, params: { id: 3 })
|
54
|
+
end
|
55
|
+
assert_equal 'You must supply an alert id.', error.message
|
56
|
+
end
|
57
|
+
|
58
|
+
should 'call the show api and return an event if searching by id' do
|
59
|
+
stub_event = stub_request(:get, %r{cloud_trail_events/5.json*}).to_return(body: json(:cloud_trail_event))
|
60
|
+
|
61
|
+
event = ESP::CloudTrailEvent.find(5)
|
62
|
+
|
63
|
+
assert_requested(stub_event)
|
64
|
+
assert_equal ESP::CloudTrailEvent, event.class
|
65
|
+
end
|
66
|
+
|
67
|
+
should 'call the api and return events when alert_id is supplied' do
|
68
|
+
stub_event = stub_request(:get, %r{alerts/5/cloud_trail_events.json*}).to_return(body: json_list(:cloud_trail_event, 2))
|
69
|
+
|
70
|
+
events = ESP::CloudTrailEvent.find(:all, params: { alert_id: 5 })
|
71
|
+
|
72
|
+
assert_requested(stub_event)
|
73
|
+
assert_equal ESP::CloudTrailEvent, events.resource_class
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context 'live calls' do
|
78
|
+
setup do
|
79
|
+
skip "Make sure you run the live calls locally to ensure proper integration" if ENV['CI_SERVER']
|
80
|
+
WebMock.allow_net_connect!
|
81
|
+
end
|
82
|
+
|
83
|
+
teardown do
|
84
|
+
WebMock.disable_net_connect!
|
85
|
+
end
|
86
|
+
|
87
|
+
context '.for_alert' do
|
88
|
+
should 'return events for alert id' do
|
89
|
+
report = ESP::Report.last
|
90
|
+
events = ESP::CloudTrailEvent.for_alert(report.alerts.last.id)
|
91
|
+
|
92
|
+
assert_equal ESP::CloudTrailEvent, events.resource_class
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
2
|
+
|
3
|
+
module ESP
|
4
|
+
class ContactRequestTest < ActiveSupport::TestCase
|
5
|
+
context ESP::ContactRequest do
|
6
|
+
context '#find' do
|
7
|
+
should 'not be implemented' do
|
8
|
+
assert_raises ESP::NotImplementedError do
|
9
|
+
ESP::ContactRequest.find(4)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context '#update' do
|
15
|
+
should 'not be implemented' do
|
16
|
+
s = ESP::ContactRequest.new
|
17
|
+
assert_raises ESP::NotImplementedError do
|
18
|
+
s.update
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context '#destroy' do
|
24
|
+
should 'not be implemented' do
|
25
|
+
s = ESP::ContactRequest.new
|
26
|
+
assert_raises ESP::NotImplementedError do
|
27
|
+
s.destroy
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context '#create' do
|
33
|
+
should 'call the api' do
|
34
|
+
stub_request(:post, /contact_requests.json*/).to_return(body: json(:contact_request))
|
35
|
+
|
36
|
+
contact_request = ESP::ContactRequest.create(user_id: 5, request_type: 'feature', title: 'My great feature idea', description: 'This is my idea for a really useful feature...')
|
37
|
+
|
38
|
+
assert_requested(:post, /contact_requests.json*/) do |req|
|
39
|
+
body = JSON.parse(req.body)
|
40
|
+
assert_equal 5, body['data']['attributes']['user_id']
|
41
|
+
assert_equal 'feature', body['data']['attributes']['request_type']
|
42
|
+
assert_equal 'My great feature idea', body['data']['attributes']['title']
|
43
|
+
assert_equal 'This is my idea for a really useful feature...', body['data']['attributes']['description']
|
44
|
+
end
|
45
|
+
assert_equal ESP::ContactRequest, contact_request.class
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'live calls' do
|
50
|
+
setup do
|
51
|
+
skip "Make sure you run the live calls locally to ensure proper integration" if ENV['CI_SERVER']
|
52
|
+
WebMock.allow_net_connect!
|
53
|
+
end
|
54
|
+
|
55
|
+
teardown do
|
56
|
+
WebMock.disable_net_connect!
|
57
|
+
end
|
58
|
+
|
59
|
+
context '#CRUD' do
|
60
|
+
should 'be able to create, update and destroy' do
|
61
|
+
contact_request = ESP::ContactRequest.new(user_id: 5, request_type: 'feature', title: 'My great feature idea', description: 'This is my idea for a really useful feature...')
|
62
|
+
|
63
|
+
assert_predicate contact_request, :new?
|
64
|
+
|
65
|
+
contact_request.save
|
66
|
+
|
67
|
+
refute_predicate contact_request, :new?
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,241 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
2
|
+
|
3
|
+
module ESP
|
4
|
+
class CustomSignatureTest < ActiveSupport::TestCase
|
5
|
+
context ESP::CustomSignature do
|
6
|
+
context '#organization' do
|
7
|
+
should 'call the api' do
|
8
|
+
custom_signature = build(:custom_signature, organization_id: 4)
|
9
|
+
stubbed_organization = stub_request(:get, %r{organizations/#{custom_signature.organization_id}.json*}).to_return(body: json(:organization))
|
10
|
+
|
11
|
+
custom_signature.organization
|
12
|
+
|
13
|
+
assert_requested(stubbed_organization)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context '.run_sanity_test!' do
|
18
|
+
should 'call the api and pass params' do
|
19
|
+
custom_signature = build(:custom_signature, external_account_id: 3)
|
20
|
+
stub_request(:post, %r{custom_signatures/run.json*}).to_return(body: json_list(:alert, 2))
|
21
|
+
|
22
|
+
alerts = ESP::CustomSignature.run!(external_account_id: 3, regions: 'param2', language: custom_signature.language, signature: custom_signature.signature)
|
23
|
+
|
24
|
+
assert_requested(:post, %r{custom_signatures/run.json*}) do |req|
|
25
|
+
body = JSON.parse req.body
|
26
|
+
assert_equal false, body['data'].key?('id')
|
27
|
+
assert_equal ['param2'], body['data']['attributes']['regions']
|
28
|
+
assert_equal custom_signature.language, body['data']['attributes']['language']
|
29
|
+
assert_equal custom_signature.signature, body['data']['attributes']['signature']
|
30
|
+
end
|
31
|
+
assert_equal ESP::Alert, alerts.resource_class
|
32
|
+
end
|
33
|
+
|
34
|
+
should 'throw an error if an error is returned' do
|
35
|
+
custom_signature = build(:custom_signature, external_account_id: 3)
|
36
|
+
error = ActiveResource::BadRequest.new('')
|
37
|
+
error_response = json(:error)
|
38
|
+
response = mock(body: error_response, code: '400')
|
39
|
+
error.stubs(:response).returns(response)
|
40
|
+
ActiveResource::Connection.any_instance.expects(:post).raises(error)
|
41
|
+
stub_request(:post, %r{custom_signatures/run.json*}).to_return(body: json_list(:alert, 2))
|
42
|
+
|
43
|
+
error = assert_raises ActiveResource::ResourceInvalid do
|
44
|
+
ESP::CustomSignature.run!(external_account_id: 3, regions: 'param2', language: custom_signature.language, signature: custom_signature.signature)
|
45
|
+
end
|
46
|
+
assert_equal "Failed. Response code = 400. Response message = #{JSON.parse(error_response)['errors'].first['title']}.", error.message
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context '.run_sanity_test' do
|
51
|
+
should 'call the api and pass params' do
|
52
|
+
custom_signature = build(:custom_signature, external_account_id: 3)
|
53
|
+
stub_request(:post, %r{custom_signatures/run.json*}).to_return(body: json_list(:alert, 2))
|
54
|
+
|
55
|
+
alerts = ESP::CustomSignature.run(external_account_id: 3, regions: 'param2', language: custom_signature.language, signature: custom_signature.signature)
|
56
|
+
|
57
|
+
assert_requested(:post, %r{custom_signatures/run.json*}) do |req|
|
58
|
+
body = JSON.parse req.body
|
59
|
+
assert_equal false, body['data'].key?('id')
|
60
|
+
assert_equal ['param2'], body['data']['attributes']['regions']
|
61
|
+
assert_equal custom_signature.language, body['data']['attributes']['language']
|
62
|
+
assert_equal custom_signature.signature, body['data']['attributes']['signature']
|
63
|
+
end
|
64
|
+
assert_equal ESP::Alert, alerts.resource_class
|
65
|
+
end
|
66
|
+
|
67
|
+
should 'not throw an error if an error is returned' do
|
68
|
+
custom_signature = build(:custom_signature, external_account_id: 3)
|
69
|
+
error = ActiveResource::BadRequest.new('')
|
70
|
+
error_response = json(:error)
|
71
|
+
response = mock(body: error_response, code: '400')
|
72
|
+
error.stubs(:response).returns(response)
|
73
|
+
ActiveResource::Connection.any_instance.expects(:post).raises(error)
|
74
|
+
stub_request(:post, %r{custom_signatures/run.json*}).to_return(body: json_list(:alert, 2))
|
75
|
+
|
76
|
+
assert_nothing_raised do
|
77
|
+
result = ESP::CustomSignature.run(external_account_id: 3, regions: 'param2', language: custom_signature.language, signature: custom_signature.signature)
|
78
|
+
assert_equal JSON.parse(error_response)['errors'].first['title'], result.errors.full_messages.first
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context '#run!' do
|
84
|
+
should 'call the api and pass params' do
|
85
|
+
custom_signature = build(:custom_signature, external_account_id: 3)
|
86
|
+
stub_request(:post, %r{custom_signatures/#{custom_signature.id}/run.json*}).to_return(body: json_list(:alert, 2))
|
87
|
+
|
88
|
+
alerts = custom_signature.run!(regions: 'param2')
|
89
|
+
|
90
|
+
assert_requested(:post, %r{custom_signatures/#{custom_signature.id}/run.json*}) do |req|
|
91
|
+
body = JSON.parse req.body
|
92
|
+
assert_equal custom_signature.id, body['data']['id']
|
93
|
+
assert_equal ['param2'], body['data']['attributes']['regions']
|
94
|
+
end
|
95
|
+
assert_equal ESP::Alert, alerts.resource_class
|
96
|
+
end
|
97
|
+
|
98
|
+
should 'throw an error if an error is returned' do
|
99
|
+
custom_signature = build(:custom_signature, external_account_id: 3)
|
100
|
+
error = ActiveResource::BadRequest.new('')
|
101
|
+
error_response = json(:error)
|
102
|
+
response = mock(body: error_response, code: '400')
|
103
|
+
error.stubs(:response).returns(response)
|
104
|
+
ActiveResource::Connection.any_instance.expects(:post).raises(error)
|
105
|
+
stub_request(:post, %r{custom_signatures/#{custom_signature.id}/run.json*}).to_return(body: json_list(:alert, 2))
|
106
|
+
|
107
|
+
error = assert_raises ActiveResource::ResourceInvalid do
|
108
|
+
custom_signature.run!(regions: 'param2')
|
109
|
+
end
|
110
|
+
assert_equal "Failed. Response code = 400. Response message = #{JSON.parse(error_response)['errors'].first['title']}.", error.message
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
context '#run' do
|
115
|
+
should 'call the api and pass params' do
|
116
|
+
custom_signature = build(:custom_signature, external_account_id: 3)
|
117
|
+
stub_request(:post, %r{custom_signatures/#{custom_signature.id}/run.json*}).to_return(body: json_list(:alert, 2))
|
118
|
+
|
119
|
+
alerts = custom_signature.run(regions: 'param2')
|
120
|
+
|
121
|
+
assert_requested(:post, %r{custom_signatures/#{custom_signature.id}/run.json*}) do |req|
|
122
|
+
body = JSON.parse req.body
|
123
|
+
assert_equal custom_signature.id, body['data']['id']
|
124
|
+
assert_equal ['param2'], body['data']['attributes']['regions']
|
125
|
+
end
|
126
|
+
assert_equal ESP::Alert, alerts.resource_class
|
127
|
+
end
|
128
|
+
|
129
|
+
should 'not throw an error if an error is returned' do
|
130
|
+
custom_signature = build(:custom_signature, external_account_id: 3)
|
131
|
+
error = ActiveResource::BadRequest.new('')
|
132
|
+
error_response = json(:error)
|
133
|
+
response = mock(body: error_response, code: '400')
|
134
|
+
error.stubs(:response).returns(response)
|
135
|
+
ActiveResource::Connection.any_instance.expects(:post).raises(error)
|
136
|
+
stub_request(:post, %r{custom_signatures/#{custom_signature.id}/run.json*}).to_return(body: json_list(:alert, 2))
|
137
|
+
|
138
|
+
assert_nothing_raised do
|
139
|
+
custom_signature.run(regions: 'param2')
|
140
|
+
assert_equal JSON.parse(error_response)['errors'].first['title'], custom_signature.errors.full_messages.first
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
context '#suppress' do
|
146
|
+
should 'call the api' do
|
147
|
+
stub_request(:post, %r{suppressions/signatures.json*}).to_return(body: json(:suppression_signature))
|
148
|
+
custom_signature = build(:custom_signature)
|
149
|
+
|
150
|
+
suppression = custom_signature.suppress(regions: ['us_east_1'], external_account_ids: [5], reason: 'because')
|
151
|
+
|
152
|
+
assert_requested(:post, %r{suppressions/signatures.json*}) do |req|
|
153
|
+
body = JSON.parse(req.body)
|
154
|
+
assert_equal 'because', body['data']['attributes']['reason']
|
155
|
+
assert_equal [custom_signature.id], body['data']['attributes']['custom_signature_ids']
|
156
|
+
assert_equal ['us_east_1'], body['data']['attributes']['regions']
|
157
|
+
assert_equal [5], body['data']['attributes']['external_account_ids']
|
158
|
+
end
|
159
|
+
assert_equal ESP::Suppression::Signature, suppression.class
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
context 'live calls' do
|
164
|
+
setup do
|
165
|
+
skip "Make sure you run the live calls locally to ensure proper integration" if ENV['CI_SERVER']
|
166
|
+
WebMock.allow_net_connect!
|
167
|
+
@custom_signature = ESP::CustomSignature.last
|
168
|
+
skip "Live DB does not have any custom_signatures. Add a custom_signature and run tests again." if @custom_signature.blank?
|
169
|
+
end
|
170
|
+
|
171
|
+
teardown do
|
172
|
+
WebMock.disable_net_connect!
|
173
|
+
end
|
174
|
+
|
175
|
+
context '#organization' do
|
176
|
+
should 'return an organization' do
|
177
|
+
organization = @custom_signature.organization
|
178
|
+
|
179
|
+
assert_equal @custom_signature.organization_id, organization.id
|
180
|
+
assert_equal ESP::Organization, organization.class
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
context '.run' do
|
185
|
+
should 'return alerts' do
|
186
|
+
external_account_id = ESP::ExternalAccount.last.id
|
187
|
+
alerts = ESP::CustomSignature.run(external_account_id: external_account_id, regions: 'us_east_1', language: @custom_signature.language, signature: @custom_signature.signature)
|
188
|
+
|
189
|
+
assert_equal ESP::Alert, alerts.resource_class
|
190
|
+
end
|
191
|
+
|
192
|
+
should 'return errors' do
|
193
|
+
signature = ESP::CustomSignature.run(external_account_id: 999, regions: 'us_east_1', language: @custom_signature.language, signature: @custom_signature.signature)
|
194
|
+
|
195
|
+
assert_equal "Couldn't find ExternalAccount", signature.errors.full_messages.first
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
context '#run' do
|
200
|
+
should 'return alerts' do
|
201
|
+
external_account_id = ESP::ExternalAccount.last.id
|
202
|
+
alerts = @custom_signature.run(external_account_id: external_account_id, regions: ['us_east_1'])
|
203
|
+
|
204
|
+
assert_equal ESP::Alert, alerts.resource_class
|
205
|
+
end
|
206
|
+
|
207
|
+
should 'return errors' do
|
208
|
+
@custom_signature.run(external_account_id: 999)
|
209
|
+
|
210
|
+
assert_equal "Couldn't find ExternalAccount", @custom_signature.errors.full_messages.first
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
context '#CRUD' do
|
215
|
+
should 'be able to create, update and destroy' do
|
216
|
+
custom_signature = ESP::CustomSignature.new(@custom_signature.attributes)
|
217
|
+
|
218
|
+
assert_predicate custom_signature, :new?
|
219
|
+
|
220
|
+
custom_signature.save
|
221
|
+
|
222
|
+
refute_predicate custom_signature, :new?
|
223
|
+
|
224
|
+
custom_signature.identifier = 'new identifier'
|
225
|
+
custom_signature.save
|
226
|
+
|
227
|
+
assert_nothing_raised do
|
228
|
+
ESP::CustomSignature.find(custom_signature.id)
|
229
|
+
end
|
230
|
+
|
231
|
+
custom_signature.destroy
|
232
|
+
|
233
|
+
assert_raises ActiveResource::ResourceNotFound do
|
234
|
+
ESP::CustomSignature.find(custom_signature.id)
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|