esp_sdk 2.0.0 → 2.1.0
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 +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
|
@@ -39,14 +39,6 @@ module ESP
|
|
|
39
39
|
end
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
-
context '.where' do
|
|
43
|
-
should 'not be implemented yet' do
|
|
44
|
-
assert_raise ESP::NotImplementedError do
|
|
45
|
-
ESP::Team.where(id: 1)
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
|
|
50
42
|
context '#serializable_hash' do
|
|
51
43
|
should 'format per json api standard' do
|
|
52
44
|
t = build(:team)
|
|
@@ -101,90 +93,242 @@ module ESP
|
|
|
101
93
|
assert_equal({ "0" => "3", "1" => "4" }, query['filter']['id_in'])
|
|
102
94
|
end
|
|
103
95
|
end
|
|
104
|
-
end
|
|
105
96
|
|
|
106
|
-
|
|
107
|
-
|
|
97
|
+
should 'not put page parameter inside filter parameter' do
|
|
98
|
+
stub_request(:get, /teams.json*/).to_return(body: json_list(:team, 2))
|
|
108
99
|
|
|
109
|
-
|
|
100
|
+
ESP::Team.find(:all, params: { id: 3, page: { number: 2, size: 3 } })
|
|
110
101
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
102
|
+
assert_requested(:get, /teams.json*/) do |req|
|
|
103
|
+
query = Rack::Utils.parse_nested_query(CGI.unescape(req.uri.query))
|
|
104
|
+
assert_equal true, query.key?('filter')
|
|
105
|
+
assert_equal '2', query['page']['number']
|
|
106
|
+
end
|
|
115
107
|
end
|
|
116
|
-
end
|
|
117
108
|
|
|
118
|
-
|
|
119
|
-
|
|
109
|
+
should 'add the include option to param' do
|
|
110
|
+
stub_request(:get, /teams.json*/).to_return(body: json_list(:team, 2))
|
|
120
111
|
|
|
121
|
-
|
|
112
|
+
ESP::Team.find(:all, include: 'organization')
|
|
122
113
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
114
|
+
assert_requested(:get, /teams.json*/) do |req|
|
|
115
|
+
query = Rack::Utils.parse_nested_query(CGI.unescape(req.uri.query))
|
|
116
|
+
assert_equal true, query.key?('include')
|
|
117
|
+
assert_equal 'organization', query['include']
|
|
118
|
+
end
|
|
127
119
|
end
|
|
128
|
-
end
|
|
129
120
|
|
|
130
|
-
|
|
131
|
-
|
|
121
|
+
should 'add the include option to param when finding by id' do
|
|
122
|
+
stub_request(:get, %r{teams/2.json*}).to_return(body: json_list(:team, 2))
|
|
132
123
|
|
|
133
|
-
|
|
124
|
+
ESP::Team.find(2, include: 'organization')
|
|
134
125
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
126
|
+
assert_requested(:get, %r{teams/2.json*}) do |req|
|
|
127
|
+
query = Rack::Utils.parse_nested_query(CGI.unescape(req.uri.query))
|
|
128
|
+
assert_equal true, query.key?('include')
|
|
129
|
+
assert_equal 'organization', query['include']
|
|
130
|
+
end
|
|
139
131
|
end
|
|
140
|
-
end
|
|
141
132
|
|
|
142
|
-
|
|
143
|
-
|
|
133
|
+
should 'not ransackize the filter parameter if it is passed' do
|
|
134
|
+
stub_request(:get, /teams.json*/).to_return(body: json_list(:team, 2))
|
|
144
135
|
|
|
145
|
-
|
|
136
|
+
ESP::Team.find(:all, params: { filter: { id_eq: 3 }, page: { number: 2, size: 3 } })
|
|
146
137
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
138
|
+
assert_requested(:get, /teams.json*/) do |req|
|
|
139
|
+
query = Rack::Utils.parse_nested_query(CGI.unescape(req.uri.query))
|
|
140
|
+
assert_equal true, query.key?('filter')
|
|
141
|
+
assert_equal true, query['filter'].key?('id_eq')
|
|
142
|
+
end
|
|
151
143
|
end
|
|
152
|
-
end
|
|
153
144
|
|
|
154
|
-
|
|
155
|
-
|
|
145
|
+
should 'add the from attribute to PaginatedCollection objects when from is supplied' do
|
|
146
|
+
stub_request(:get, /teams.json*/).to_return(body: json_list(:team, 2))
|
|
156
147
|
|
|
157
|
-
|
|
148
|
+
teams = ESP::Team.find(:all, from: "#{Team.prefix}teams.json", params: { filter: { id_eq: 3 }, page: { number: 2, size: 3 } })
|
|
158
149
|
|
|
159
|
-
|
|
150
|
+
assert_equal '/api/v2/teams.json', teams.from
|
|
151
|
+
end
|
|
160
152
|
end
|
|
161
|
-
end
|
|
162
153
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
154
|
+
context '.where' do
|
|
155
|
+
should 'call the index method when finding by single id using put' do
|
|
156
|
+
stub_request(:put, /teams.json/).to_return(body: json_list(:team, 1))
|
|
157
|
+
|
|
158
|
+
ESP::Team.where(id: 3)
|
|
159
|
+
|
|
160
|
+
assert_requested(:put, /teams.json/)
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
should 'build body inside filter param and ad _eq when single value' do
|
|
164
|
+
stub_request(:put, /teams.json*/).to_return(body: json_list(:team, 2))
|
|
165
|
+
|
|
166
|
+
ESP::Team.where(id: 3)
|
|
167
|
+
|
|
168
|
+
assert_requested(:put, /teams.json*/) do |req|
|
|
169
|
+
body = JSON.parse req.body
|
|
170
|
+
assert_equal true, body.key?('filter')
|
|
171
|
+
assert_equal true, body['filter'].key?('id_eq')
|
|
172
|
+
assert_equal 3, body['filter']['id_eq']
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
should 'build body inside filter param and ad _in when multiple values' do
|
|
177
|
+
stub_request(:put, /teams.json*/).to_return(body: json_list(:team, 2))
|
|
178
|
+
|
|
179
|
+
ESP::Team.where(id: [3, 4])
|
|
180
|
+
|
|
181
|
+
assert_requested(:put, /teams.json*/) do |req|
|
|
182
|
+
body = JSON.parse req.body
|
|
183
|
+
assert_equal true, body.key?('filter')
|
|
184
|
+
assert_equal true, body['filter'].key?('id_in')
|
|
185
|
+
assert_equal([3, 4], body['filter']['id_in'])
|
|
186
|
+
end
|
|
187
|
+
end
|
|
170
188
|
|
|
171
|
-
|
|
172
|
-
|
|
189
|
+
should 'not put page parameter inside filter parameter' do
|
|
190
|
+
stub_request(:put, /teams.json*/).to_return(body: json_list(:team, 2))
|
|
191
|
+
|
|
192
|
+
ESP::Team.where(id: 3, page: { number: 2, size: 3 })
|
|
193
|
+
|
|
194
|
+
assert_requested(:put, /teams.json*/) do |req|
|
|
195
|
+
body = JSON.parse req.body
|
|
196
|
+
assert_equal true, body.key?('filter')
|
|
197
|
+
assert_equal 2, body['page']['number']
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
should 'add the include option to param' do
|
|
202
|
+
stub_request(:put, /teams.json*/).to_return(body: json_list(:team, 2))
|
|
203
|
+
|
|
204
|
+
ESP::Team.where(id: 1, include: 'organization')
|
|
205
|
+
|
|
206
|
+
assert_requested(:put, /teams.json*/) do |req|
|
|
207
|
+
body = JSON.parse req.body
|
|
208
|
+
assert_equal true, body.key?('include')
|
|
209
|
+
assert_equal 'organization', body['include']
|
|
210
|
+
end
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
should 'add the sorts option to the params' do
|
|
214
|
+
stub_request(:put, /teams.json*/).to_return(body: json_list(:team, 2))
|
|
215
|
+
|
|
216
|
+
ESP::Team.where(name_cont: 'Team', sorts: 'created_at')
|
|
217
|
+
|
|
218
|
+
assert_requested(:put, /teams.json*/) do |req|
|
|
219
|
+
body = JSON.parse req.body
|
|
220
|
+
assert_equal true, body.key?('filter')
|
|
221
|
+
assert_equal 'Team', body['filter']['name_cont']
|
|
222
|
+
assert_equal 'created_at', body['filter']['sorts']
|
|
223
|
+
end
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
should 'add the combinator option to the params' do
|
|
227
|
+
stub_request(:put, /teams.json*/).to_return(body: json_list(:team, 2))
|
|
228
|
+
|
|
229
|
+
ESP::Team.where(name_cont: 'Team', id_eq: 3, m: :or)
|
|
230
|
+
|
|
231
|
+
assert_requested(:put, /teams.json*/) do |req|
|
|
232
|
+
body = JSON.parse req.body
|
|
233
|
+
assert_equal true, body.key?('filter')
|
|
234
|
+
assert_equal 'Team', body['filter']['name_cont']
|
|
235
|
+
assert_equal 3, body['filter']['id_eq']
|
|
236
|
+
assert_equal 'or', body['filter']['m']
|
|
237
|
+
end
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
should 'add _eq to attribute if predicate is not already appended' do
|
|
241
|
+
stub_request(:put, /teams.json*/).to_return(body: json_list(:team, 2))
|
|
242
|
+
|
|
243
|
+
ESP::Team.where(id: 3)
|
|
244
|
+
|
|
245
|
+
assert_requested(:put, /teams.json*/) do |req|
|
|
246
|
+
body = JSON.parse req.body
|
|
247
|
+
assert_equal true, body.key?('filter')
|
|
248
|
+
assert_equal true, body['filter'].key?("id_eq")
|
|
249
|
+
end
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
should 'add _in to array attribute if predicate is not already appended' do
|
|
253
|
+
stub_request(:put, /teams.json*/).to_return(body: json_list(:team, 2))
|
|
254
|
+
|
|
255
|
+
ESP::Team.where(id: [3])
|
|
256
|
+
|
|
257
|
+
assert_requested(:put, /teams.json*/) do |req|
|
|
258
|
+
body = JSON.parse req.body
|
|
259
|
+
assert_equal true, body.key?('filter')
|
|
260
|
+
assert_equal true, body['filter'].key?("id_in")
|
|
261
|
+
end
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
ESP::Resource::PREDICATES.split('|').each do |predicate|
|
|
265
|
+
next if predicate == 'm' # This is a special case
|
|
266
|
+
should "not ransackize attributes that already have ransack predicate #{predicate} appended" do
|
|
267
|
+
stub_request(:put, /teams.json*/).to_return(body: json_list(:team, 2))
|
|
268
|
+
|
|
269
|
+
args = { page: { number: 2, size: 3 } }
|
|
270
|
+
args["id_#{predicate}"] = 3
|
|
271
|
+
ESP::Team.where(args)
|
|
272
|
+
|
|
273
|
+
assert_requested(:put, /teams.json*/) do |req|
|
|
274
|
+
body = JSON.parse req.body
|
|
275
|
+
assert_equal true, body.key?('filter')
|
|
276
|
+
assert_equal true, body['filter'].key?("id_#{predicate}")
|
|
277
|
+
end
|
|
278
|
+
end
|
|
279
|
+
end
|
|
173
280
|
end
|
|
174
281
|
|
|
175
|
-
context '
|
|
176
|
-
|
|
177
|
-
|
|
282
|
+
context 'live calls' do
|
|
283
|
+
setup do
|
|
284
|
+
skip "Make sure you run the live calls locally to ensure proper integration" if ENV['CI_SERVER']
|
|
285
|
+
WebMock.allow_net_connect!
|
|
286
|
+
@team = ESP::Team.last
|
|
287
|
+
skip "Live DB does not have any teams. Add a team and run tests again." if @team.blank?
|
|
288
|
+
end
|
|
178
289
|
|
|
179
|
-
|
|
180
|
-
|
|
290
|
+
teardown do
|
|
291
|
+
WebMock.disable_net_connect!
|
|
181
292
|
end
|
|
182
293
|
|
|
183
|
-
|
|
184
|
-
|
|
294
|
+
context 'with ESP::Team' do
|
|
295
|
+
context '.find' do
|
|
296
|
+
should 'find a team' do
|
|
297
|
+
t = ESP::Team.find(@team.id)
|
|
298
|
+
|
|
299
|
+
assert_equal ESP::Team, t.class
|
|
300
|
+
assert_equal @team.id, t.id
|
|
301
|
+
end
|
|
302
|
+
|
|
303
|
+
should 'find teams' do
|
|
304
|
+
t = ESP::Team.find(:all, params: { id: @team.id })
|
|
305
|
+
|
|
306
|
+
assert_equal ESP::Team, t.resource_class
|
|
307
|
+
assert_equal 1, t.count
|
|
308
|
+
end
|
|
309
|
+
end
|
|
310
|
+
|
|
311
|
+
context '.where' do
|
|
312
|
+
should 'return teams' do
|
|
313
|
+
teams = ESP::Team.where(id: @team.id)
|
|
185
314
|
|
|
186
|
-
|
|
187
|
-
|
|
315
|
+
assert_equal ESP::Team, teams.resource_class
|
|
316
|
+
assert_equal 1, teams.count
|
|
317
|
+
end
|
|
318
|
+
|
|
319
|
+
should 'return included object on first call' do
|
|
320
|
+
teams = ESP::Team.where(id: @team.id, include: 'organization')
|
|
321
|
+
|
|
322
|
+
assert_equal ESP::Organization, teams.first.attributes['organization'].class
|
|
323
|
+
end
|
|
324
|
+
|
|
325
|
+
should 'return multiple included objects on first call' do
|
|
326
|
+
teams = ESP::Team.where(id: @team.id, include: 'sub_organization, organization')
|
|
327
|
+
|
|
328
|
+
assert_equal ESP::Organization, teams.first.attributes['organization'].class
|
|
329
|
+
assert_equal ESP::SubOrganization, teams.first.attributes['sub_organization'].class
|
|
330
|
+
end
|
|
331
|
+
end
|
|
188
332
|
end
|
|
189
333
|
end
|
|
190
334
|
end
|
|
@@ -4,6 +4,14 @@ module ESP
|
|
|
4
4
|
class ServiceTest < ActiveSupport::TestCase
|
|
5
5
|
context ESP::Service do
|
|
6
6
|
context '#signatures' do
|
|
7
|
+
context '.where' do
|
|
8
|
+
should 'not be implemented' do
|
|
9
|
+
assert_raises ESP::NotImplementedError do
|
|
10
|
+
Tag.where(id_eq: 2)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
7
15
|
should 'call the api' do
|
|
8
16
|
s = build(:service)
|
|
9
17
|
stub_request(:get, /signatures.json*/).to_return(body: json_list(:signature, 2))
|
|
@@ -123,6 +123,8 @@ module ESP
|
|
|
123
123
|
setup do
|
|
124
124
|
skip "Make sure you run the live calls locally to ensure proper integration" if ENV['CI_SERVER']
|
|
125
125
|
WebMock.allow_net_connect!
|
|
126
|
+
@signature = ESP::Signature.where(name_cont: 'heartbleed').last
|
|
127
|
+
skip "Live DB does not have any signatures. Add a signature and run tests again." if @signature.blank?
|
|
126
128
|
end
|
|
127
129
|
|
|
128
130
|
teardown do
|
|
@@ -131,32 +133,36 @@ module ESP
|
|
|
131
133
|
|
|
132
134
|
context '#service' do
|
|
133
135
|
should 'return a service' do
|
|
134
|
-
|
|
136
|
+
service = @signature.service
|
|
135
137
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
assert_equal signature.service_id, service.id
|
|
138
|
+
assert_equal @signature.service_id, service.id
|
|
139
139
|
assert_equal ESP::Service, service.class
|
|
140
140
|
end
|
|
141
141
|
end
|
|
142
142
|
|
|
143
143
|
context '#run' do
|
|
144
144
|
should 'return alerts' do
|
|
145
|
-
signature = ESP::Signature.first
|
|
146
145
|
external_account_id = ESP::ExternalAccount.last.id
|
|
147
146
|
|
|
148
|
-
alerts = signature.run(external_account_id: external_account_id, region: 'us_east_1')
|
|
147
|
+
alerts = @signature.run(external_account_id: external_account_id, region: 'us_east_1')
|
|
149
148
|
|
|
150
149
|
assert_equal ESP::Alert, alerts.resource_class
|
|
151
150
|
end
|
|
152
151
|
|
|
153
152
|
should 'return errors' do
|
|
154
|
-
signature = ESP::Signature.first
|
|
155
153
|
external_account_id = 999_999_999_999
|
|
156
154
|
|
|
157
|
-
signature
|
|
155
|
+
@signature.run(external_account_id: external_account_id, region: 'us_east_1')
|
|
156
|
+
|
|
157
|
+
assert_equal "Couldn't find ExternalAccount", @signature.errors.full_messages.first
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
context '.where' do
|
|
162
|
+
should 'return signature objects' do
|
|
163
|
+
signatures = ESP::Signature.where(id_eq: @signature.id)
|
|
158
164
|
|
|
159
|
-
assert_equal
|
|
165
|
+
assert_equal ESP::Signature, signatures.resource_class
|
|
160
166
|
end
|
|
161
167
|
end
|
|
162
168
|
|
|
@@ -5,6 +5,14 @@ module ESP
|
|
|
5
5
|
class CustomSignatureTest < ActiveSupport::TestCase
|
|
6
6
|
context ESP::StatCustomSignature do
|
|
7
7
|
context '.for_stat' do
|
|
8
|
+
context '.where' do
|
|
9
|
+
should 'not be implemented' do
|
|
10
|
+
assert_raises ESP::NotImplementedError do
|
|
11
|
+
StatCustomSignature.where(id_eq: 2)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
8
16
|
should 'throw an error if stat id is not supplied' do
|
|
9
17
|
error = assert_raises ArgumentError do
|
|
10
18
|
ESP::StatCustomSignature.for_stat
|
|
@@ -100,7 +108,7 @@ module ESP
|
|
|
100
108
|
|
|
101
109
|
context '.for_stat' do
|
|
102
110
|
should 'return tags for stat id' do
|
|
103
|
-
report = ESP::Report.find(:first, params: {
|
|
111
|
+
report = ESP::Report.find(:first, params: { id_eq: 1 })
|
|
104
112
|
skip "make sure you have a complete report" unless report.present?
|
|
105
113
|
stat_id = report.stat.id
|
|
106
114
|
stats = ESP::StatCustomSignature.for_stat(stat_id)
|
|
@@ -4,6 +4,14 @@ module ESP
|
|
|
4
4
|
class Stat
|
|
5
5
|
class RegionTest < ActiveSupport::TestCase
|
|
6
6
|
context ESP::StatRegion do
|
|
7
|
+
context '.where' do
|
|
8
|
+
should 'not be implemented' do
|
|
9
|
+
assert_raises ESP::NotImplementedError do
|
|
10
|
+
StatRegion.where(id_eq: 2)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
7
15
|
context '.for_stat' do
|
|
8
16
|
should 'throw an error if stat id is not supplied' do
|
|
9
17
|
error = assert_raises ArgumentError do
|
|
@@ -97,9 +105,23 @@ module ESP
|
|
|
97
105
|
WebMock.disable_net_connect!
|
|
98
106
|
end
|
|
99
107
|
|
|
108
|
+
context '#regions' do
|
|
109
|
+
should 'return regions' do
|
|
110
|
+
report = ESP::Report.all.detect { |r| r.status == 'complete' }
|
|
111
|
+
skip "Live DB does not have any reports. Add a report with stats and run tests again." if report.blank?
|
|
112
|
+
stat = ESP::Stat.for_report(report.id)
|
|
113
|
+
regions = stat.regions
|
|
114
|
+
|
|
115
|
+
region = regions.first.region
|
|
116
|
+
|
|
117
|
+
assert_equal ESP::Region, region.class
|
|
118
|
+
assert_equal regions.first.region.code, region.code
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
100
122
|
context '.for_stat' do
|
|
101
123
|
should 'return tags for stat id' do
|
|
102
|
-
report = ESP::Report.find(:first, params: {
|
|
124
|
+
report = ESP::Report.find(:first, params: { id_eq: 1 })
|
|
103
125
|
skip "make sure you have a complete report" unless report.present?
|
|
104
126
|
stat_id = report.stat.id
|
|
105
127
|
stats = ESP::StatRegion.for_stat(stat_id)
|
|
@@ -4,6 +4,14 @@ module ESP
|
|
|
4
4
|
class Stat
|
|
5
5
|
class ServiceTest < ActiveSupport::TestCase
|
|
6
6
|
context ESP::StatService do
|
|
7
|
+
context '.where' do
|
|
8
|
+
should 'not be implemented' do
|
|
9
|
+
assert_raises ESP::NotImplementedError do
|
|
10
|
+
StatService.where(id_eq: 2)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
7
15
|
context '.for_stat' do
|
|
8
16
|
should 'throw an error if stat id is not supplied' do
|
|
9
17
|
error = assert_raises ArgumentError do
|
|
@@ -97,9 +105,23 @@ module ESP
|
|
|
97
105
|
WebMock.disable_net_connect!
|
|
98
106
|
end
|
|
99
107
|
|
|
108
|
+
context '#services' do
|
|
109
|
+
should 'return signatures' do
|
|
110
|
+
report = ESP::Report.all.detect { |r| r.status == 'complete' }
|
|
111
|
+
skip "Live DB does not have any reports. Add a report with stats and run tests again." if report.blank?
|
|
112
|
+
stat = ESP::Stat.for_report(report.id)
|
|
113
|
+
services = stat.services
|
|
114
|
+
|
|
115
|
+
service = services.first.service
|
|
116
|
+
|
|
117
|
+
assert_equal ESP::Service, service.class
|
|
118
|
+
assert_equal services.first.service.name, service.name
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
100
122
|
context '.for_stat' do
|
|
101
123
|
should 'return tags for stat id' do
|
|
102
|
-
report = ESP::Report.find(:first, params: {
|
|
124
|
+
report = ESP::Report.find(:first, params: { id_eq: 1 })
|
|
103
125
|
skip "make sure you have a complete report" unless report.present?
|
|
104
126
|
stat_id = report.stat.id
|
|
105
127
|
stats = ESP::StatService.for_stat(stat_id)
|
|
@@ -4,6 +4,14 @@ module ESP
|
|
|
4
4
|
class Stat
|
|
5
5
|
class SignatureTest < ActiveSupport::TestCase
|
|
6
6
|
context ESP::StatSignature do
|
|
7
|
+
context '.where' do
|
|
8
|
+
should 'not be implemented' do
|
|
9
|
+
assert_raises ESP::NotImplementedError do
|
|
10
|
+
StatSignature.where(id_eq: 2)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
7
15
|
context '.for_stat' do
|
|
8
16
|
should 'throw an error if stat id is not supplied' do
|
|
9
17
|
error = assert_raises ArgumentError do
|
|
@@ -98,9 +106,23 @@ module ESP
|
|
|
98
106
|
WebMock.disable_net_connect!
|
|
99
107
|
end
|
|
100
108
|
|
|
109
|
+
context '#signatures' do
|
|
110
|
+
should 'return signatures' do
|
|
111
|
+
report = ESP::Report.all.detect { |r| r.status == 'complete' }
|
|
112
|
+
skip "Live DB does not have any reports. Add a report with stats and run tests again." if report.blank?
|
|
113
|
+
stat = ESP::Stat.for_report(report.id)
|
|
114
|
+
signatures = stat.signatures
|
|
115
|
+
|
|
116
|
+
signature = signatures.first.signature
|
|
117
|
+
|
|
118
|
+
assert_equal ESP::Signature, signature.class
|
|
119
|
+
assert_equal signatures.first.signature.name, signature.name
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
101
123
|
context '.for_stat' do
|
|
102
124
|
should 'return tags for stat id' do
|
|
103
|
-
report = ESP::Report.find(:first, params: {
|
|
125
|
+
report = ESP::Report.find(:first, params: { id_eq: 1 })
|
|
104
126
|
skip "make sure you have a complete report" unless report.present?
|
|
105
127
|
stat_id = report.stat.id
|
|
106
128
|
stats = ESP::StatSignature.for_stat(stat_id)
|
|
@@ -3,6 +3,14 @@ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
|
|
3
3
|
module ESP
|
|
4
4
|
class StatTest < ActiveSupport::TestCase
|
|
5
5
|
context ESP::Stat do
|
|
6
|
+
context '.where' do
|
|
7
|
+
should 'not be implemented' do
|
|
8
|
+
assert_raises ESP::NotImplementedError do
|
|
9
|
+
Stat.where(id_eq: 2)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
6
14
|
context '#report' do
|
|
7
15
|
should 'call the api' do
|
|
8
16
|
stat = build(:stat, report_id: 3)
|
|
@@ -127,22 +135,58 @@ module ESP
|
|
|
127
135
|
setup do
|
|
128
136
|
skip "Make sure you run the live calls locally to ensure proper integration" if ENV['CI_SERVER']
|
|
129
137
|
WebMock.allow_net_connect!
|
|
130
|
-
@
|
|
131
|
-
skip "Live DB does not have any
|
|
138
|
+
@report = ESP::Report.all.detect { |r| r.status == 'complete' }
|
|
139
|
+
skip "Live DB does not have any reports. Add a report with stats and run tests again." if @report.blank?
|
|
140
|
+
@stat = ESP::Stat.for_report(@report.id)
|
|
132
141
|
end
|
|
133
142
|
|
|
134
143
|
teardown do
|
|
135
144
|
WebMock.disable_net_connect!
|
|
136
145
|
end
|
|
137
146
|
|
|
138
|
-
context '
|
|
139
|
-
should 'return
|
|
140
|
-
report =
|
|
141
|
-
|
|
147
|
+
context '#report' do
|
|
148
|
+
should 'return a report' do
|
|
149
|
+
report = @stat.report
|
|
150
|
+
|
|
151
|
+
assert_equal @stat.report_id, report.id
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
context '#regions' do
|
|
156
|
+
should 'return regions' do
|
|
157
|
+
regions = @stat.regions
|
|
158
|
+
|
|
159
|
+
assert_equal ESP::StatRegion, regions.resource_class
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
context '#services' do
|
|
164
|
+
should 'return services' do
|
|
165
|
+
services = @stat.services
|
|
166
|
+
|
|
167
|
+
assert_equal ESP::StatService, services.resource_class
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
context '#signatures' do
|
|
172
|
+
should 'return signatures' do
|
|
173
|
+
signatures = @stat.signatures
|
|
174
|
+
|
|
175
|
+
assert_equal ESP::StatSignature, signatures.resource_class
|
|
176
|
+
end
|
|
177
|
+
end
|
|
142
178
|
|
|
143
|
-
|
|
179
|
+
context '#custom_signautures' do
|
|
180
|
+
should 'return custom_signautures' do
|
|
181
|
+
custom_signatures = @stat.custom_signatures
|
|
144
182
|
|
|
145
|
-
assert_equal
|
|
183
|
+
assert_equal ESP::StatCustomSignature, custom_signatures.resource_class
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
context 'for_report' do
|
|
188
|
+
should 'return the stat for the report' do
|
|
189
|
+
assert_equal @report.id, @stat.report_id
|
|
146
190
|
end
|
|
147
191
|
end
|
|
148
192
|
|
|
@@ -97,6 +97,14 @@ module ESP
|
|
|
97
97
|
end
|
|
98
98
|
end
|
|
99
99
|
|
|
100
|
+
context '.where' do
|
|
101
|
+
should 'return sub_organization objects' do
|
|
102
|
+
sub_organizations = ESP::SubOrganization.where(id_eq: @sub_organization.id)
|
|
103
|
+
|
|
104
|
+
assert_equal ESP::SubOrganization, sub_organizations.resource_class
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
100
108
|
context '#CRUD' do
|
|
101
109
|
should 'be able to create, update and destroy' do
|
|
102
110
|
sub_organization = ESP::SubOrganization.new(name: 'bob', organization_id: @sub_organization.organization_id)
|
|
@@ -4,6 +4,14 @@ module ESP
|
|
|
4
4
|
class Suppression
|
|
5
5
|
class RegionTest < ActiveSupport::TestCase
|
|
6
6
|
context ESP::Suppression::Region do
|
|
7
|
+
context '.where' do
|
|
8
|
+
should 'not be implemented' do
|
|
9
|
+
assert_raises ESP::NotImplementedError do
|
|
10
|
+
ESP::Suppression::Region.where(id_eq: 2)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
7
15
|
context '#find' do
|
|
8
16
|
should 'not be implemented' do
|
|
9
17
|
assert_raises ESP::NotImplementedError do
|
|
@@ -91,7 +99,7 @@ module ESP
|
|
|
91
99
|
|
|
92
100
|
context 'for_alert' do
|
|
93
101
|
should 'return error when reason is not supplied' do
|
|
94
|
-
alert_id = ESP::Report.
|
|
102
|
+
alert_id = ESP::Report.all.detect { |r| r.status == 'complete' }.alerts.last.id
|
|
95
103
|
|
|
96
104
|
suppression = ESP::Suppression::Region.create(alert_id: alert_id)
|
|
97
105
|
|
|
@@ -99,7 +107,7 @@ module ESP
|
|
|
99
107
|
end
|
|
100
108
|
|
|
101
109
|
should 'return suppression' do
|
|
102
|
-
alert_id = ESP::Report.
|
|
110
|
+
alert_id = ESP::Report.all.detect { |r| r.status == 'complete' }.alerts.last.id
|
|
103
111
|
|
|
104
112
|
suppression = ESP::Suppression::Region.create(alert_id: alert_id, reason: 'test')
|
|
105
113
|
|