esp_sdk 2.2.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/CHANGELOG.md +8 -0
  4. data/Gemfile.lock +4 -1
  5. data/Rakefile +12 -1
  6. data/lib/esp/extensions/active_resource/formats/json_api_format.rb +1 -1
  7. data/lib/esp/extensions/active_resource/validations.rb +3 -2
  8. data/lib/esp/external_account_creator.rb +2 -2
  9. data/lib/esp/resources/custom_signature.rb +7 -0
  10. data/lib/esp/resources/report.rb +1 -1
  11. data/lib/esp/resources/reports/export/integration.rb +44 -0
  12. data/lib/esp/resources/team.rb +6 -0
  13. data/lib/esp/version.rb +1 -1
  14. data/lib/esp.rb +5 -0
  15. data/test/esp/extensions/active_resource/formats/json_api_format_test.rb +0 -67
  16. data/test/esp/extensions/active_resource/paginated_collection_test.rb +0 -69
  17. data/test/esp/extensions/active_resource/validations_test.rb +0 -20
  18. data/test/esp/integration/alert_integration_test.rb +96 -0
  19. data/test/esp/integration/cloud_trail_event_integration_test.rb +18 -0
  20. data/test/esp/integration/contact_request_integration_test.rb +21 -0
  21. data/test/esp/integration/custom_signature_integration_test.rb +97 -0
  22. data/test/esp/integration/dashboard_integration_test.rb +17 -0
  23. data/test/esp/integration/external_account_integration_test.rb +68 -0
  24. data/test/esp/integration/json_api_format_integration_test.rb +61 -0
  25. data/test/esp/integration/metadata_integration_test.rb +18 -0
  26. data/test/esp/integration/organization_integration_test.rb +81 -0
  27. data/test/esp/integration/paginated_collection_integration_test.rb +67 -0
  28. data/test/esp/integration/region_integration_test.rb +32 -0
  29. data/test/esp/integration/report_export_integration_integration_test.rb +24 -0
  30. data/test/esp/integration/report_integration_test.rb +71 -0
  31. data/test/esp/integration/resource_integration_test.rb +54 -0
  32. data/test/esp/integration/scan_interval_integration_test.rb +49 -0
  33. data/test/esp/integration/service_integration_test.rb +28 -0
  34. data/test/esp/integration/signature_integration_test.rb +62 -0
  35. data/test/esp/integration/stat_custom_signature_integration_test.rb +22 -0
  36. data/test/esp/integration/stat_integration_test.rb +69 -0
  37. data/test/esp/integration/stat_region_integration_test.rb +36 -0
  38. data/test/esp/integration/stat_service_integration_test.rb +36 -0
  39. data/test/esp/integration/stat_signature_integration_test.rb +36 -0
  40. data/test/esp/integration/sub_organization_integration_test.rb +79 -0
  41. data/test/esp/integration/suppression_integration_test.rb +95 -0
  42. data/test/esp/integration/suppression_region_integration_test.rb +52 -0
  43. data/test/esp/integration/suppression_signature_integration_test.rb +52 -0
  44. data/test/esp/integration/suppression_unique_identifier_integration_test.rb +30 -0
  45. data/test/esp/integration/tag_integration_test.rb +18 -0
  46. data/test/esp/integration/team_integration_test.rb +87 -0
  47. data/test/esp/integration/user_integration_test.rb +52 -0
  48. data/test/esp/integration/validations_integration_test.rb +18 -0
  49. data/test/esp/resources/alert_test.rb +0 -93
  50. data/test/esp/resources/cloud_trail_event_test.rb +0 -20
  51. data/test/esp/resources/contact_request_test.rb +0 -23
  52. data/test/esp/resources/custom_signature_test.rb +14 -85
  53. data/test/esp/resources/dashboard_test.rb +0 -19
  54. data/test/esp/resources/external_account_test.rb +0 -67
  55. data/test/esp/resources/metadata_test.rb +0 -20
  56. data/test/esp/resources/organization_test.rb +0 -80
  57. data/test/esp/resources/region_test.rb +0 -31
  58. data/test/esp/resources/report_test.rb +0 -70
  59. data/test/esp/resources/reports/export/integration_test.rb +55 -0
  60. data/test/esp/resources/resource_test.rb +0 -53
  61. data/test/esp/resources/scan_interval_test.rb +0 -50
  62. data/test/esp/resources/service_test.rb +0 -27
  63. data/test/esp/resources/signature_test.rb +0 -60
  64. data/test/esp/resources/stat_custom_signature_test.rb +0 -22
  65. data/test/esp/resources/stat_region_test.rb +1 -36
  66. data/test/esp/resources/stat_service_test.rb +1 -36
  67. data/test/esp/resources/stat_signature_test.rb +0 -36
  68. data/test/esp/resources/stat_test.rb +0 -68
  69. data/test/esp/resources/sub_organization_test.rb +0 -78
  70. data/test/esp/resources/suppression/region_test.rb +0 -50
  71. data/test/esp/resources/suppression/signature_test.rb +0 -50
  72. data/test/esp/resources/suppression/unique_identifier_test.rb +0 -30
  73. data/test/esp/resources/suppression_test.rb +0 -94
  74. data/test/esp/resources/tag_test.rb +0 -20
  75. data/test/esp/resources/team_test.rb +14 -78
  76. data/test/esp/resources/user_test.rb +0 -47
  77. data/test/factories/custom_signatures.rb +17 -7
  78. data/test/factories/teams.rb +18 -8
  79. data/test/parallel_reporter.rb +93 -0
  80. data/test/test_helper.rb +20 -4
  81. metadata +70 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8ba33c6b2844803fe17abc39fd0f2ecfdd3c86c3
4
- data.tar.gz: a9f51f6b6e0abd70064f0de21ea5b365b69b2acf
3
+ metadata.gz: 5f7250441652b3030ad983a15076317a4f23f514
4
+ data.tar.gz: 20d7beccfa0aac2dcb56e27c3b636ef4360a4f25
5
5
  SHA512:
6
- metadata.gz: 15e6201640405e7dd7031147e38ff2342da257eba8ef8fd1d7a6e556f0eaf5c740c6953a2ab67522135e5cdbf57b6deed910551c302b325543d80890a3972b7b
7
- data.tar.gz: 76c3758314ca2ff6121c25305fcb8151197293a3093dd115f9b13eca919b838e995b1027fee46678b5c6ea9f196c25f0115efbdf7b5f83110f7108ac2cd24dbd
6
+ metadata.gz: 89a03a0391777f8cbde9292ab9a44ed087046e19794caf5e8f8353670da41e5433a9ee14ef17d0853e9e389942ec67ef20dbb782f322d9ac3fc9778987d630fc
7
+ data.tar.gz: ff17a934abe8abac1a91eaff1e936902d24d69bbcffbce5e4195793bd2e652abd66ac29c3616a488438ac32033007e5dcd8e1c766b5d0d8e451482c2d9ed23a3
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.0.0
1
+ 2.0.0-p647
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## Unreleased
2
+
3
+ ## 2.2.3 - 2016-05-16
4
+ ### Changed
5
+ - Some error messages changed a little bit on the API. Specifically, on region suppression, signature suppress, and custom signature suppression objects. Now when a validation trips on the related suppression object, the error message reflects that. "Reason can't be blank" changed to "Suppression region can't be blank". The message is built from the attribute which is in error, which changed from "Reason" to "Suppression.reason". Had to gsub the "." to a space to make it message friendly.
6
+ - Add the teams relation to custom signature, and the custom signatures relation to team.
7
+ - Added an endpoint, ESP::Report::Export::Integration.create, to export reports to an integration
8
+
1
9
  ## 2.2.0 - 2016-03-2
2
10
  ### Added
3
11
  - Added the ESP::ScanInterval object to use the new scan interval endpoint on the API
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- esp_sdk (2.2.0)
4
+ esp_sdk (2.3.0)
5
5
  activeresource (~> 4.0.0)
6
6
  api-auth
7
7
  rack
@@ -165,3 +165,6 @@ DEPENDENCIES
165
165
  rubocop
166
166
  shoulda
167
167
  webmock
168
+
169
+ BUNDLED WITH
170
+ 1.11.2
data/Rakefile CHANGED
@@ -6,7 +6,18 @@ require 'rdoc/task'
6
6
 
7
7
  Rake::TestTask.new do |task|
8
8
  task.libs << 'test'
9
- task.test_files = FileList['test/*_test.rb', 'test/**/*_test.rb']
9
+ task.test_files = FileList['test/*_test.rb', 'test/**/*_test.rb'] - FileList["test/esp/integration/**/*_test.rb"]
10
+ end
11
+
12
+ namespace "test" do
13
+ Rake::TestTask.new("integration") do |t|
14
+ t.pattern = "test/esp/integration/**/*_test.rb"
15
+ end
16
+
17
+ Rake::TestTask.new("all") do |task|
18
+ task.libs << 'test'
19
+ task.test_files = FileList['test/*_test.rb', 'test/**/*_test.rb']
20
+ end
10
21
  end
11
22
 
12
23
  task default: [:test]
@@ -37,7 +37,7 @@ module ActiveResource # :nodoc: all
37
37
  end
38
38
 
39
39
  def decode(json)
40
- # ap ActiveSupport::JSON.decode(json), index: false, indent: -2
40
+ # pp ActiveSupport::JSON.decode(json), index: false, indent: -2
41
41
  Formats.remove_root(parse_json_api(ActiveSupport::JSON.decode(json)))
42
42
  end
43
43
 
@@ -35,8 +35,9 @@ module ActiveResource # :nodoc: all
35
35
  raw_errors.each do |error|
36
36
  next unless error['meta']
37
37
  error['meta'].map do |attr, message|
38
- errors[attr] ||= []
39
- errors[attr] << message
38
+ friendly_attr = attr.tr('.', ' ')
39
+ errors[friendly_attr] ||= []
40
+ errors[friendly_attr] << message
40
41
  end
41
42
  end
42
43
  end
@@ -30,11 +30,11 @@ module ESP # :nodoc: all
30
30
  def create
31
31
  fail ESP::AddExternalAccountError, aws.errors.full_messages.join(', ') unless aws.valid?
32
32
 
33
- puts "adding AWS account #{aws.owner_id} to ESP as #{team_name}" # rubocop:disable Rails/Output
33
+ puts "adding AWS account #{aws.owner_id} to ESP as #{team_name}" unless ESP.env.test? # rubocop:disable Rails/Output
34
34
  aws_role_object = aws.create_and_attach_role!(external_account_id)
35
35
  sleep 10
36
36
 
37
- puts "aws_role_arn = #{aws_role_object.role.arn}, external_id = #{external_account_id}, nickname = #{team_name}, esp_suborg_id = #{sub_organization.id}, esp_team_id = #{team.id}" # rubocop:disable Rails/Output
37
+ puts "aws_role_arn = #{aws_role_object.role.arn}, external_id = #{external_account_id}, nickname = #{team_name}, esp_suborg_id = #{sub_organization.id}, esp_team_id = #{team.id}" unless ESP.env.test? # rubocop:disable Rails/Output
38
38
  external_account = ESP::ExternalAccount.create(arn: aws_role_object.role.arn, external_id: external_account_id, name: team_name, sub_organization_id: sub_organization.id, team_id: team.id)
39
39
  fail ESP::AddExternalAccountError, "On External Account: #{external_account.errors.full_messages.join(', ')}" unless external_account.errors.blank?
40
40
  external_account
@@ -4,6 +4,13 @@ module ESP
4
4
  # The organization this custom signature belongs to.
5
5
  belongs_to :organization, class_name: 'ESP::Organization'
6
6
 
7
+ ##
8
+ # The collection of teams that belong to the custom_signature.
9
+ def teams
10
+ return attributes['teams'] if attributes['teams'].present?
11
+ Team.where(custom_signatures_id_eq: id)
12
+ end
13
+
7
14
  # Run a custom signature that has not been saved. Useful for debugging a custom signature.
8
15
  # Returns a collection of alerts.
9
16
  # Throws an error if not successful.
@@ -53,7 +53,7 @@ module ESP
53
53
  # ==== Example
54
54
  #
55
55
  # report = ESP::Report.find(345)
56
- # alerts = report.alerts(status: 'fail', signature_severity: 'High')
56
+ # alerts = report.alerts(status_eq: 'fail', signature_risk_level_in: ['High'])
57
57
  def alerts(arguments = {})
58
58
  ESP::Alert.where(arguments.merge(report_id: id))
59
59
  end
@@ -0,0 +1,44 @@
1
+ module ESP
2
+ class Report
3
+ module Export
4
+ class Integration < ESP::Resource
5
+ self.prefix += "reports/export/"
6
+ # Not Implemented. You cannot search for Reports::Export::Integration.
7
+ def self.where(*)
8
+ fail ESP::NotImplementedError
9
+ end
10
+
11
+ # Not Implemented. You cannot search for Reports::Export::Integration.
12
+ def self.find(*)
13
+ fail ESP::NotImplementedError
14
+ end
15
+
16
+ # Not Implemented. You cannot update a Reports::Export::Integration.
17
+ def update
18
+ fail ESP::NotImplementedError
19
+ end
20
+
21
+ # Not Implemented. You cannot destroy a Reports::Export::Integration.
22
+ def destroy
23
+ fail ESP::NotImplementedError
24
+ end
25
+
26
+ # :singleton-method: create
27
+ # Enqueue reports to be exported to the given integration
28
+ # Returns a Report::Export::Integration object if successful
29
+ # ==== Attribute
30
+ #
31
+ # See {API documentation}[http://api-docs.evident.io?ruby#report-export] for valid arguments
32
+ #
33
+ # If not successful, returns a Report::Export::Integration object with the errors object populated.
34
+
35
+ protected
36
+
37
+ # A success message gets returned, so just return the response instead of parsing for attributes
38
+ def load_attributes_from_response(response)
39
+ response
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -16,6 +16,12 @@ module ESP
16
16
  # The collection of reports that belong to the team.
17
17
  has_many :reports, class_name: 'ESP::Report'
18
18
 
19
+ ##
20
+ # The collection of custom_signatures that belong to the team.
21
+ def custom_signatures
22
+ CustomSignature.where(teams_id_eq: id)
23
+ end
24
+
19
25
  # Enqueue a report to be run for this team.
20
26
  # Returns a Report object with a status of 'queued' and an id
21
27
  # Periodically check the API
data/lib/esp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module ESP
2
- VERSION = '2.2.0'
2
+ VERSION = '2.3.0'
3
3
  end
data/lib/esp.rb CHANGED
@@ -114,4 +114,9 @@ module ESP
114
114
  autoload :StatService, File.expand_path(File.dirname(__FILE__) + '/esp/resources/stat_service')
115
115
  autoload :ExternalAccountCreator, File.expand_path(File.dirname(__FILE__) + '/../lib/esp/external_account_creator')
116
116
  autoload :AWSClients, File.expand_path(File.dirname(__FILE__) + '/../lib/esp/aws_clients')
117
+ class Report
118
+ module Export
119
+ autoload :Integration, File.expand_path(File.dirname(__FILE__) + '/esp/resources/reports/export/integration')
120
+ end
121
+ end
117
122
  end
@@ -51,51 +51,6 @@ module ActiveResource
51
51
  end
52
52
  end
53
53
  end
54
-
55
- context 'live calls' do
56
- setup do
57
- skip "Make sure you run the live calls locally to ensure proper integration" if ENV['CI_SERVER']
58
- WebMock.allow_net_connect!
59
- end
60
-
61
- teardown do
62
- WebMock.disable_net_connect!
63
- end
64
-
65
- should 'merge included objects' do
66
- alert = ESP::Alert.find(1, include: 'external_account.team.organization,region,signature,custom_signature')
67
-
68
- assert_not_nil alert.attributes['external_account']
69
- assert_equal alert.external_account_id, alert.external_account.id
70
- assert_not_nil alert.external_account.attributes['organization']
71
- assert_equal alert.external_account.organization_id, alert.external_account.organization.id
72
- assert_not_nil alert.external_account.attributes['team']
73
- assert_equal alert.external_account.team_id, alert.external_account.team.id
74
- assert_not_nil alert.external_account.team.attributes['organization']
75
- assert_equal alert.external_account.team.organization_id, alert.external_account.team.organization.id
76
- assert_not_nil alert.attributes['region']
77
- assert_equal alert.region_id, alert.region.id
78
- if alert.signature.present?
79
- assert_not_nil alert.attributes['signature']
80
- assert_equal alert.signature_id, alert.signature.id
81
- else
82
- assert_not_nil alert.attributes['custom_signature']
83
- assert_equal alert.custom_signature_id, alert.custom_signature.id
84
- end
85
- end
86
-
87
- should 'assign foreign key for a belongs_to relationship' do
88
- user = ESP::User.last
89
-
90
- assert_not_nil user.organization_id
91
- end
92
-
93
- should 'assign foreign key for a has_many relationship' do
94
- user = ESP::User.last
95
-
96
- assert_not_nil user.sub_organization_ids
97
- end
98
- end
99
54
  end
100
55
 
101
56
  context ActiveResource::ConnectionError do
@@ -118,28 +73,6 @@ module ActiveResource
118
73
  end
119
74
  end
120
75
  end
121
-
122
- context 'live calls' do
123
- setup do
124
- skip "Make sure you run the live calls locally to ensure proper integration" if ENV['CI_SERVER']
125
- WebMock.allow_net_connect!
126
- end
127
-
128
- teardown do
129
- WebMock.disable_net_connect!
130
- end
131
-
132
- context "with ESP::Team" do
133
- context '.initialize' do
134
- should 'parse the error and return a descriptive error message' do
135
- error = assert_raises ActiveResource::BadRequest do
136
- ESP::Team.create
137
- end
138
- assert_equal 'Failed. Response code = 400. Response message = param is missing or the value is empty: attributes.', error.message
139
- end
140
- end
141
- end
142
- end
143
76
  end
144
77
  end
145
78
  end
@@ -382,75 +382,6 @@ module ActiveResource
382
382
  end
383
383
  end
384
384
  end
385
-
386
- context 'live calls' do
387
- setup do
388
- skip "Make sure you run the live calls locally to ensure proper integration" if ENV['CI_SERVER']
389
- WebMock.allow_net_connect!
390
- end
391
-
392
- teardown do
393
- WebMock.disable_net_connect!
394
- end
395
-
396
- should 'always return the correct page and update itself when using the ! methods' do
397
- report = ESP::Report.all.detect { |r| r.status == 'complete' }
398
- alerts = report.alerts
399
- last_page_number = alerts.last_page_number
400
-
401
- assert_equal '1', alerts.current_page_number
402
- first_id = alerts.first.id
403
-
404
- alerts.next_page!
405
- assert_equal '2', alerts.current_page_number
406
- refute_equal first_id, alerts.first.id
407
- first_id = alerts.first.id
408
-
409
- alerts.last_page!
410
- assert_equal last_page_number, alerts.current_page_number
411
- refute_equal first_id, alerts.first.id
412
- first_id = alerts.first.id
413
-
414
- alerts.previous_page!
415
- assert_equal alerts.last_page_number.to_i - 1, alerts.current_page_number.to_i
416
- refute_equal first_id, alerts.first.id
417
- assert_equal 20, alerts.count # make sure the size did not get messed up while on the last page
418
- first_id = alerts.first.id
419
-
420
- alerts.page!(4)
421
- assert_equal '4', alerts.current_page_number
422
- refute_equal first_id, alerts.first.id
423
- end
424
-
425
- should 'always return the correct page and when not using the ! methods' do
426
- report = ESP::Report.all.detect { |r| r.status == 'complete' }
427
- alerts = report.alerts
428
- last_page_number = alerts.last_page_number
429
-
430
- assert_equal '1', alerts.current_page_number
431
- first_id = alerts.first.id
432
-
433
- page = alerts.next_page
434
- assert_equal '2', page.current_page_number
435
- refute_equal first_id, page.first.id
436
- first_id = page.first.id
437
-
438
- page = page.last_page
439
- assert_equal last_page_number, page.current_page_number
440
- refute_equal first_id, page.first.id
441
- first_id = page.first.id
442
-
443
- page = page.previous_page
444
- assert_equal page.last_page_number.to_i - 1, page.current_page_number.to_i
445
- refute_equal first_id, page.first.id
446
- assert_equal 20, page.count # make sure the size did not get messed up while on the last page
447
- first_id = page.first.id
448
-
449
- page = alerts.page(4)
450
- assert_equal '4', page.current_page_number
451
- refute_equal first_id, page.first.id
452
- end
453
- end
454
385
  end
455
386
  end
456
387
  end
@@ -24,26 +24,6 @@ module ActiveResource
24
24
  end
25
25
  end
26
26
  end
27
-
28
- context 'live calls' do
29
- setup do
30
- skip "Make sure you run the live calls locally to ensure proper integration" if ENV['CI_SERVER']
31
- WebMock.allow_net_connect!
32
- end
33
-
34
- teardown do
35
- WebMock.disable_net_connect!
36
- end
37
-
38
- context "#load_remote_errors" do
39
- should 'should parse the response and put error messages in the errors object' do
40
- team = ESP::Team.create(name: 'bob')
41
-
42
- assert_contains team.errors.full_messages, "Organization can't be blank"
43
- assert_contains team.errors.full_messages, "Organization can't be blank"
44
- end
45
- end
46
- end
47
27
  end
48
28
  end
49
29
  end
@@ -0,0 +1,96 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ module ESP::Integration
4
+ class AlertTest < ESP::Integration::TestCase
5
+ context ESP::Alert do
6
+ context 'live calls' do
7
+ setup do
8
+ @report = ESP::Report.all.detect { |r| r.status == 'complete' }
9
+ fail "Live DB does not have any reports. Add a report and run tests again." if @report.blank?
10
+ @alert = @report.alerts.last
11
+ end
12
+
13
+ context '#external_account' do
14
+ should 'return an external_account' do
15
+ external_account = @alert.external_account
16
+
17
+ assert_equal ESP::ExternalAccount, external_account.class
18
+ assert_equal @alert.external_account_id, external_account.id
19
+ end
20
+ end
21
+
22
+ context '#region' do
23
+ should 'return a region' do
24
+ region = @alert.region
25
+
26
+ assert_equal ESP::Region, region.class
27
+ assert_equal @alert.region_id, region.id
28
+ end
29
+ end
30
+
31
+ context '#signature' do
32
+ should 'return a signature' do
33
+ @alert.attributes['signature_id'] ||= 1
34
+ signature = @alert.signature
35
+
36
+ assert_equal ESP::Signature, signature.class
37
+ assert_equal @alert.signature_id, signature.id
38
+ end
39
+ end
40
+
41
+ context '#custom_signature' do
42
+ should 'return a custom_signature' do
43
+ @alert.attributes['custom_signature_id'] ||= 1
44
+ custom_signature = @alert.custom_signature
45
+
46
+ assert_equal ESP::CustomSignature, custom_signature.class
47
+ assert_equal @alert.custom_signature_id.to_s, custom_signature.id.to_s
48
+ end
49
+ end
50
+
51
+ context '#suppression' do
52
+ should 'return a suppression' do
53
+ assert_nothing_raised do
54
+ @alert.attributes['suppression_id'] ||= 1
55
+ @alert.suppression
56
+ end
57
+ end
58
+ end
59
+
60
+ context '#cloud_trail_events' do
61
+ should 'return cloud_trail_events' do
62
+ assert_nothing_raised do
63
+ @alert.cloud_trail_events
64
+ end
65
+ end
66
+ end
67
+
68
+ context '#tags' do
69
+ should 'return tags' do
70
+ assert_nothing_raised do
71
+ @alert.tags
72
+ end
73
+ end
74
+ end
75
+
76
+ context '.find' do
77
+ should 'return an alert by id' do
78
+ alert = ESP::Alert.find(@alert.id.to_i)
79
+
80
+ assert_equal ESP::Alert, alert.class
81
+ assert_equal @alert.id, alert.id
82
+ end
83
+ end
84
+
85
+ context '.where' do
86
+ should 'return alert objects' do
87
+ alerts = ESP::Alert.where(report_id: @report.id, id_eq: @alert.id)
88
+
89
+ assert_equal ESP::Alert, alerts.resource_class
90
+ assert_equal @alert.id, alerts.first.id
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,18 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ module ESP::Integration
4
+ class CloudTrailEventTest < ESP::Integration::TestCase
5
+ context ESP::CloudTrailEvent do
6
+ context 'live calls' do
7
+ context '.for_alert' do
8
+ should 'return events for alert id' do
9
+ report = ESP::Report.all.detect { |r| r.status == 'complete' }
10
+ events = ESP::CloudTrailEvent.for_alert(report.alerts.last.id)
11
+
12
+ assert_equal ESP::CloudTrailEvent, events.resource_class
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,21 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ module ESP::Integration
4
+ class ContactRequestTest < ESP::Integration::TestCase
5
+ context ESP::ContactRequest do
6
+ context 'live calls' do
7
+ context '#CRUD' do
8
+ should 'be able to create, update and destroy' do
9
+ 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...')
10
+
11
+ assert_predicate contact_request, :new?
12
+
13
+ contact_request.save
14
+
15
+ refute_predicate contact_request, :new?
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,97 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ module ESP::Integration
4
+ class CustomSignatureTest < ESP::Integration::TestCase
5
+ context ESP::CustomSignature do
6
+ context 'live calls' do
7
+ setup do
8
+ @custom_signature = ESP::CustomSignature.last
9
+ fail "Live DB does not have any custom_signatures. Add a custom_signature and run tests again." if @custom_signature.blank?
10
+ end
11
+
12
+ context '#organization' do
13
+ should 'return an organization' do
14
+ organization = @custom_signature.organization
15
+
16
+ assert_equal @custom_signature.organization_id, organization.id
17
+ assert_equal ESP::Organization, organization.class
18
+ end
19
+ end
20
+
21
+ context '#teams' do
22
+ should 'return list of teams' do
23
+ team = @custom_signature.teams
24
+
25
+ assert_equal ESP::Team, team.resource_class
26
+ end
27
+ end
28
+
29
+ context '.run' do
30
+ should 'return alerts' do
31
+ skip "Can't run sigs on CI" if ENV['CI_SERVER']
32
+ external_account_id = ESP::ExternalAccount.last.id
33
+ alerts = ESP::CustomSignature.run(external_account_id: external_account_id, regions: 'us_east_1', language: @custom_signature.language, signature: @custom_signature.signature)
34
+
35
+ assert_equal ESP::Alert, alerts.resource_class
36
+ end
37
+
38
+ should 'return errors' do
39
+ signature = ESP::CustomSignature.run(external_account_id: 999_999_999_999, regions: 'us_east_1', language: @custom_signature.language, signature: @custom_signature.signature)
40
+
41
+ assert_equal "Couldn't find ExternalAccount", signature.errors.full_messages.first
42
+ end
43
+ end
44
+
45
+ context '#run' do
46
+ should 'return alerts' do
47
+ skip "Can't run sigs on CI" if ENV['CI_SERVER']
48
+ external_account_id = ESP::ExternalAccount.last.id
49
+ alerts = @custom_signature.run(external_account_id: external_account_id, regions: ['us_east_1'])
50
+
51
+ assert_equal ESP::Alert, alerts.resource_class
52
+ end
53
+
54
+ should 'return errors' do
55
+ @custom_signature.run(external_account_id: 999_999_999_999)
56
+
57
+ assert_equal "Couldn't find ExternalAccount", @custom_signature.errors.full_messages.first
58
+ end
59
+ end
60
+
61
+ context '.where' do
62
+ should 'return custom_signature objects' do
63
+ custom_signatures = ESP::CustomSignature.where(id_eq: @custom_signature.id)
64
+
65
+ assert_equal ESP::CustomSignature, custom_signatures.resource_class
66
+ end
67
+ end
68
+
69
+ context '#CRUD' do
70
+ should 'be able to create, update and destroy' do
71
+ skip "Can't run sigs on CI" if ENV['CI_SERVER']
72
+ custom_signature = ESP::CustomSignature.new(@custom_signature.attributes)
73
+
74
+ assert_predicate custom_signature, :new?
75
+
76
+ custom_signature.save
77
+
78
+ refute_predicate custom_signature, :new?
79
+
80
+ custom_signature.identifier = 'new identifier'
81
+ custom_signature.save
82
+
83
+ assert_nothing_raised do
84
+ ESP::CustomSignature.find(custom_signature.id)
85
+ end
86
+
87
+ custom_signature.destroy
88
+
89
+ assert_raises ActiveResource::ResourceNotFound do
90
+ ESP::CustomSignature.find(custom_signature.id)
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,17 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ module ESP::Integration
4
+ class DashboardTest < ESP::Integration::TestCase
5
+ context ESP::Dashboard do
6
+ context 'live calls' do
7
+ context '.recent' do
8
+ should 'return an array of contact_requests' do
9
+ dashboards = ESP::Dashboard.recent
10
+
11
+ assert_equal ESP::Dashboard, dashboards.resource_class
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end