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
@@ -0,0 +1,68 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ module ESP::Integration
4
+ class ExternalAccountTest < ESP::Integration::TestCase
5
+ context ESP::ExternalAccount do
6
+ context 'live calls' do
7
+ setup do
8
+ @external_account = ESP::ExternalAccount.last
9
+ fail "Live DB does not have any external_accounts. Add a external_account and run tests again." if @external_account.blank?
10
+ end
11
+
12
+ context '#organization' do
13
+ should 'return an organization' do
14
+ org = @external_account.organization
15
+
16
+ assert_equal @external_account.organization_id, org.id
17
+ end
18
+ end
19
+
20
+ context '#sub_organization' do
21
+ should 'return a sub_organization' do
22
+ sub_org = @external_account.sub_organization
23
+
24
+ assert_equal @external_account.sub_organization_id, sub_org.id
25
+ end
26
+ end
27
+
28
+ context '#team' do
29
+ should 'return a team' do
30
+ team = @external_account.team
31
+
32
+ assert_equal ESP::Team, team.class
33
+ end
34
+ end
35
+
36
+ context '.where' do
37
+ should 'return external_account objects' do
38
+ external_accounts = ESP::ExternalAccount.where(id_eq: @external_account.id)
39
+
40
+ assert_equal ESP::ExternalAccount, external_accounts.resource_class
41
+ end
42
+ end
43
+
44
+ context '#CRUD' do
45
+ should 'be able to create, update and destroy' do
46
+ skip "There are to many dependencies to validate an external account to create or update one. Besides esp_web, esp_query has to be running and there must be valid AWS keys assigned as well."
47
+
48
+ external_account = ESP::ExternalAccount.create(name: 'bob', arn: @external_account.arn, sub_organization_id: @external_account.sub_organization_id, team_id: @external_account.team_id)
49
+
50
+ assert_predicate external_account, :new?
51
+ assert_contains external_account.errors, "The account for this ARN is already being checked by Dev"
52
+
53
+ refute_predicate @external_account, :new?
54
+ @external_account.name = @external_account.name
55
+
56
+ assert_predicate @external_account, :save
57
+
58
+ external_account = build(:external_account, id: 999)
59
+
60
+ assert_raises ActiveResource::ResourceNotFound do
61
+ external_account.destroy
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,61 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ module ESP::Integration
4
+ module Formats
5
+ class JsonAPIFormatTest < ESP::Integration::TestCase
6
+ context ActiveResource::Formats::JsonAPIFormat do
7
+ context 'live calls' do
8
+ should 'merge included objects' do
9
+ report = ESP::Report.first
10
+ alert = ESP::Alert.where(report_id: report.id, include: 'external_account.team.organization,region,signature,custom_signature').first
11
+
12
+ assert_not_nil alert.attributes['external_account']
13
+ assert_equal alert.external_account_id, alert.external_account.id
14
+ assert_not_nil alert.external_account.attributes['organization']
15
+ assert_equal alert.external_account.organization_id, alert.external_account.organization.id
16
+ assert_not_nil alert.external_account.attributes['team']
17
+ assert_equal alert.external_account.team_id, alert.external_account.team.id
18
+ assert_not_nil alert.external_account.team.attributes['organization']
19
+ assert_equal alert.external_account.team.organization_id, alert.external_account.team.organization.id
20
+ assert_not_nil alert.attributes['region']
21
+ assert_equal alert.region_id, alert.region.id
22
+ if alert.signature.present?
23
+ assert_not_nil alert.attributes['signature']
24
+ assert_equal alert.signature_id, alert.signature.id
25
+ else
26
+ assert_not_nil alert.attributes['custom_signature']
27
+ assert_equal alert.custom_signature_id, alert.custom_signature.id
28
+ end
29
+ end
30
+
31
+ should 'assign foreign key for a belongs_to relationship' do
32
+ user = ESP::User.last
33
+
34
+ assert_not_nil user.organization_id
35
+ end
36
+
37
+ should 'assign foreign key for a has_many relationship' do
38
+ user = ESP::User.last
39
+
40
+ assert_not_nil user.sub_organization_ids
41
+ end
42
+ end
43
+ end
44
+
45
+ context ActiveResource::ConnectionError do
46
+ context 'live calls' do
47
+ context "with ESP::Team" do
48
+ context '.initialize' do
49
+ should 'parse the error and return a descriptive error message' do
50
+ error = assert_raises ActiveResource::BadRequest do
51
+ ESP::Team.create
52
+ end
53
+ assert_equal 'Failed. Response code = 400. Response message = param is missing or the value is empty: attributes.', error.message
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,18 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ module ESP::Integration
4
+ class MetadataTest < ESP::Integration::TestCase
5
+ context ESP::Metadata do
6
+ context 'live calls' do
7
+ context '.for_alert' do
8
+ should 'return metadata for alert id' do
9
+ report = ESP::Report.all.detect { |r| r.status == 'complete' }
10
+ metadata = ESP::Metadata.for_alert(report.alerts.last.id)
11
+
12
+ assert_equal ESP::Metadata, metadata.class
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,81 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ module ESP::Integration
4
+ class OrganizationTest < ESP::Integration::TestCase
5
+ context ESP::Organization do
6
+ context 'live calls' do
7
+ setup do
8
+ @organization = ESP::Organization.last
9
+ fail "Live DB does not have any sub organizations. Add a sub organization and run tests again." if @organization.blank?
10
+ end
11
+
12
+ context '#teams' do
13
+ should 'return teams' do
14
+ teams = @organization.teams
15
+
16
+ assert_equal ESP::Team, teams.resource_class
17
+ end
18
+ end
19
+
20
+ context '#sub_organizations' do
21
+ should 'return a sub_organization' do
22
+ sub_organizations = @organization.sub_organizations
23
+
24
+ assert_equal ESP::SubOrganization, sub_organizations.resource_class
25
+ end
26
+ end
27
+
28
+ context '#users' do
29
+ should 'return an array of users' do
30
+ users = @organization.users
31
+
32
+ assert_equal ESP::User, users.resource_class
33
+ end
34
+ end
35
+
36
+ context '#reports' do
37
+ should 'return an array of reports' do
38
+ reports = @organization.reports
39
+
40
+ assert_equal ESP::Report, reports.resource_class
41
+ end
42
+ end
43
+
44
+ context '#external_accounts' do
45
+ should 'return an array of external_accounts' do
46
+ external_accounts = @organization.external_accounts
47
+
48
+ assert_equal ESP::ExternalAccount, external_accounts.resource_class
49
+ end
50
+ end
51
+
52
+ context '#custom_signatures' do
53
+ should 'return an array of custom_signatures' do
54
+ custom_signatures = @organization.custom_signatures
55
+
56
+ assert_equal ESP::CustomSignature, custom_signatures.resource_class
57
+ end
58
+ end
59
+
60
+ context '.where' do
61
+ should 'return organization objects' do
62
+ organizations = ESP::Organization.where(id_eq: @organization.id)
63
+
64
+ assert_equal ESP::Organization, organizations.resource_class
65
+ end
66
+ end
67
+
68
+ context '#CRUD' do
69
+ should 'be able to update' do
70
+ @organization.name = @organization.name
71
+ @organization.save
72
+
73
+ assert_nothing_raised do
74
+ ESP::Organization.find(@organization.id)
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,67 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ module ESP::Integration
4
+ class PaginatedCollectionTest < ESP::Integration::TestCase
5
+ context ActiveResource::PaginatedCollection do
6
+ context 'live calls' do
7
+ should 'always return the correct page and update itself when using the ! methods' do
8
+ report = ESP::Report.all.detect { |r| r.status == 'complete' }
9
+ alerts = report.alerts
10
+ last_page_number = alerts.last_page_number
11
+
12
+ assert_equal '1', alerts.current_page_number
13
+ first_id = alerts.first.id
14
+
15
+ alerts.next_page!
16
+ assert_equal '2', alerts.current_page_number
17
+ refute_equal first_id, alerts.first.id
18
+ first_id = alerts.first.id
19
+
20
+ alerts.last_page!
21
+ assert_equal last_page_number, alerts.current_page_number
22
+ refute_equal first_id, alerts.first.id
23
+ first_id = alerts.first.id
24
+
25
+ alerts.previous_page!
26
+ assert_equal last_page_number.to_i - 1, alerts.current_page_number.to_i
27
+ refute_equal first_id, alerts.first.id
28
+ assert_equal 20, alerts.count # make sure the size did not get messed up while on the last page
29
+ first_id = alerts.first.id
30
+
31
+ alerts.page!(3)
32
+ assert_equal '3', alerts.current_page_number
33
+ refute_equal first_id, alerts.first.id
34
+ end
35
+
36
+ should 'always return the correct page when not using the ! methods' do
37
+ report = ESP::Report.all.detect { |r| r.status == 'complete' }
38
+ alerts = report.alerts
39
+ last_page_number = alerts.last_page_number
40
+
41
+ assert_equal '1', alerts.current_page_number
42
+ first_id = alerts.first.id
43
+
44
+ page = alerts.next_page
45
+ assert_equal '2', page.current_page_number
46
+ refute_equal first_id, page.first.id
47
+ first_id = page.first.id
48
+
49
+ page = page.last_page
50
+ assert_equal last_page_number, page.current_page_number
51
+ refute_equal first_id, page.first.id
52
+ first_id = page.first.id
53
+
54
+ page = page.previous_page
55
+ assert_equal last_page_number.to_i - 1, page.current_page_number.to_i
56
+ refute_equal first_id, page.first.id
57
+ assert_equal 20, page.count # make sure the size did not get messed up while on the last page
58
+ first_id = page.first.id
59
+
60
+ page = alerts.page(3)
61
+ assert_equal '3', page.current_page_number
62
+ refute_equal first_id, page.first.id
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,32 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ module ESP::Integration
4
+ class RegionTest < ESP::Integration::TestCase
5
+ context ESP::Region do
6
+ context 'live calls' do
7
+ setup do
8
+ @region = ESP::Region.last
9
+ fail "Live DB does not have any regions. Add a region and run tests again." if @region.blank?
10
+ end
11
+
12
+ context '.where' do
13
+ should 'return region objects' do
14
+ regions = ESP::Region.where(id_eq: @region.id)
15
+
16
+ assert_equal ESP::Region, regions.resource_class
17
+ end
18
+ end
19
+
20
+ context '#CRUD' do
21
+ should 'be able to read' do
22
+ assert_not_nil @region
23
+
24
+ region = ESP::Region.find(@region.id)
25
+
26
+ assert_not_nil region
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,24 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ module ESP::Integration
4
+ class Report
5
+ module Export
6
+ class IntegrationTest < ESP::Integration::TestCase
7
+ context ESP::Report::Export::Integration do
8
+ context 'live calls' do
9
+ context '#create' do
10
+ should 'return regions' do
11
+ report = ESP::Report.last
12
+ fail "Live DB does not have any reports. Add a report with stats and run tests again." if report.blank?
13
+
14
+ response = ESP::Report::Export::Integration.create(integration_id: 1, report_ids: [report.id])
15
+
16
+ assert_predicate response.errors, :blank?
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,71 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ module ESP::Integration
4
+ class ReportTest < ESP::Integration::TestCase
5
+ context ESP::Report 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
+ end
11
+
12
+ context '#organization' do
13
+ should 'return an organization' do
14
+ org = @report.organization
15
+
16
+ assert_equal @report.organization_id, org.id
17
+ end
18
+ end
19
+
20
+ context '#sub_organization' do
21
+ should 'return a sub_organization' do
22
+ sub_org = @report.sub_organization
23
+
24
+ assert_equal @report.sub_organization_id, sub_org.id
25
+ end
26
+ end
27
+
28
+ context '#team' do
29
+ should 'return a team' do
30
+ team = @report.team
31
+
32
+ assert_equal ESP::Team, team.class
33
+ end
34
+ end
35
+
36
+ context '#alerts' do
37
+ should 'return an array of alerts' do
38
+ alerts = @report.alerts
39
+
40
+ assert_equal ESP::Alert, alerts.resource_class
41
+ end
42
+ end
43
+
44
+ context '#stat' do
45
+ should 'return a stat' do
46
+ stat = @report.stat
47
+
48
+ assert_equal ESP::Stat, stat.class
49
+ end
50
+ end
51
+
52
+ context '.where' do
53
+ should 'return report objects' do
54
+ reports = ESP::Report.where(id_eq: @report.id)
55
+
56
+ assert_equal ESP::Report, reports.resource_class
57
+ end
58
+ end
59
+
60
+ context '.create' do
61
+ should 'return an error if a bad team_id is passed' do
62
+ assert_nothing_raised do
63
+ r = ESP::Report.create(team_id: 999)
64
+ assert_equal "Couldn't find Team", r.errors.full_messages.first
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,54 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ module ESP::Integration
4
+ class ResourceTest < ESP::Integration::TestCase
5
+ context ESP::Resource do
6
+ context 'live calls' do
7
+ setup do
8
+ @team = ESP::Team.last
9
+ fail "Live DB does not have any teams. Add a team and run tests again." if @team.blank?
10
+ end
11
+
12
+ context 'with ESP::Team' do
13
+ context '.find' do
14
+ should 'find a team' do
15
+ t = ESP::Team.find(@team.id)
16
+
17
+ assert_equal ESP::Team, t.class
18
+ assert_equal @team.id, t.id
19
+ end
20
+
21
+ should 'find teams' do
22
+ t = ESP::Team.find(:all, params: { id: @team.id })
23
+
24
+ assert_equal ESP::Team, t.resource_class
25
+ assert_equal 1, t.count
26
+ end
27
+ end
28
+
29
+ context '.where' do
30
+ should 'return teams' do
31
+ teams = ESP::Team.where(id: @team.id)
32
+
33
+ assert_equal ESP::Team, teams.resource_class
34
+ assert_equal 1, teams.count
35
+ end
36
+
37
+ should 'return included object on first call' do
38
+ teams = ESP::Team.where(id: @team.id, include: 'organization')
39
+
40
+ assert_equal ESP::Organization, teams.first.attributes['organization'].class
41
+ end
42
+
43
+ should 'return multiple included objects on first call' do
44
+ teams = ESP::Team.where(id: @team.id, include: 'sub_organization, organization')
45
+
46
+ assert_equal ESP::Organization, teams.first.attributes['organization'].class
47
+ assert_equal ESP::SubOrganization, teams.first.attributes['sub_organization'].class
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,49 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ module ESP::Integration
4
+ class ScanIntervalTest < ESP::Integration::TestCase
5
+ context ESP::ScanInterval do
6
+ context 'live calls' do
7
+ setup do
8
+ @external_account = ESP::ExternalAccount.last
9
+ @service = ESP::Service.last
10
+ fail "Live DB does not have any external_accounts. Add an external_account and run tests again." if @external_account.blank?
11
+ fail "Live DB does not have any services. Add an service and run tests again." if @service.blank?
12
+ end
13
+
14
+ context '#CRUD' do
15
+ should 'be able to create, update and destroy' do
16
+ @scan_interval = ESP::ScanInterval.new(interval: 15, service_id: @service.id, external_account_id: @external_account.id)
17
+
18
+ # Create
19
+ assert_predicate @scan_interval, :new?
20
+ @scan_interval.save
21
+ refute_predicate @scan_interval, :new?
22
+
23
+ # Update
24
+ @scan_interval.interval = 30
25
+ @scan_interval.save
26
+ assert_nothing_raised do
27
+ ESP::ScanInterval.find(@scan_interval.id.to_i)
28
+ end
29
+
30
+ # Service Relationship
31
+ service = @scan_interval.service
32
+ assert_equal service.id, @service.id
33
+
34
+ # External Account Relationship
35
+ external_account = @scan_interval.external_account
36
+ assert_equal external_account.id, @external_account.id
37
+
38
+ # Destroy
39
+ @scan_interval.destroy
40
+
41
+ assert_raises ActiveResource::ResourceNotFound do
42
+ ESP::ScanInterval.find(@scan_interval.id.to_i)
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,28 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ module ESP::Integration
4
+ class ServiceTest < ESP::Integration::TestCase
5
+ context ESP::Service do
6
+ context 'live calls' do
7
+ setup do
8
+ @service = ESP::Service.last
9
+ fail "Live DB does not have any services. Add a service and run tests again." if @service.blank?
10
+ end
11
+
12
+ context '#signatures' do
13
+ should 'return an array of signatures' do
14
+ signatures = @service.signatures
15
+
16
+ assert_equal ESP::Signature, signatures.resource_class
17
+ end
18
+ end
19
+
20
+ context '#CRUD' do
21
+ should 'be able to read' do
22
+ assert_not_nil @service, @service.inspect
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,62 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ module ESP::Integration
4
+ class SignatureTest < ESP::Integration::TestCase
5
+ context ESP::Signature do
6
+ context 'live calls' do
7
+ setup do
8
+ @signature = ESP::Signature.where(name_cont: 'heartbleed').last
9
+ fail "Live DB does not have any signatures. Add a signature and run tests again." if @signature.blank?
10
+ end
11
+
12
+ context '#service' do
13
+ should 'return a service' do
14
+ service = @signature.service
15
+
16
+ assert_equal @signature.service_id, service.id
17
+ assert_equal ESP::Service, service.class
18
+ end
19
+ end
20
+
21
+ context '#run' do
22
+ should 'return alerts' do
23
+ skip "Can't run sigs on CI" if ENV['CI_SERVER']
24
+ external_account_id = ESP::ExternalAccount.last.id
25
+
26
+ alerts = @signature.run(external_account_id: external_account_id, region: 'us_east_1')
27
+
28
+ assert_equal ESP::Alert, alerts.resource_class
29
+ end
30
+
31
+ should 'return errors' do
32
+ external_account_id = 999_999_999_999
33
+
34
+ @signature.run(external_account_id: external_account_id, region: 'us_east_1')
35
+
36
+ assert_equal "Couldn't find ExternalAccount", @signature.errors.full_messages.first
37
+ end
38
+ end
39
+
40
+ context '.where' do
41
+ should 'return signature objects' do
42
+ signatures = ESP::Signature.where(id_eq: @signature.id)
43
+
44
+ assert_equal ESP::Signature, signatures.resource_class
45
+ end
46
+ end
47
+
48
+ context '#CRUD' do
49
+ should 'be able to read' do
50
+ signature = ESP::Signature.last
51
+
52
+ assert_not_nil signature
53
+
54
+ signature = ESP::Signature.find(signature.id)
55
+
56
+ assert_not_nil signature
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,22 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ module ESP::Integration
4
+ class Stat
5
+ class CustomSignatureTest < ESP::Integration::TestCase
6
+ context ESP::StatCustomSignature do
7
+ context 'live calls' do
8
+ context '.for_stat' do
9
+ should 'return tags for stat id' do
10
+ report = ESP::Report.all.detect { |r| r.status == 'complete' }
11
+ fail "make sure you have a complete report" unless report.present?
12
+ stat_id = report.stat.id
13
+ stats = ESP::StatCustomSignature.for_stat(stat_id)
14
+
15
+ assert_equal ESP::StatCustomSignature, stats.resource_class
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end