esp_sdk 2.4.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,13 +1,13 @@
1
1
  module ESP
2
2
  class Dashboard < ESP::Resource
3
- # Not Implemented. You cannot search for Suppression::Region.
3
+ # Not Implemented. You cannot search for a Dashboard.
4
4
  #
5
5
  # Regular ARELlike methods are disabled.
6
6
  def self.find(*)
7
7
  fail ESP::NotImplementedError, 'Regular ARELlike methods are disabled. Use the .recent method.'
8
8
  end
9
9
 
10
- # Not Implemented. You cannot search for Suppression::Region.
10
+ # Not Implemented. You cannot search for a Dashboard.
11
11
  #
12
12
  # Regular ARELlike methods are disabled.
13
13
  def self.where(*)
@@ -1,5 +1,9 @@
1
1
  module ESP
2
2
  class Report < ESP::Resource
3
+ module Export
4
+ autoload :Integration, File.expand_path(File.dirname(__FILE__) + '/reports/export/integration')
5
+ end
6
+
3
7
  ##
4
8
  # The organization the report belongs to.
5
9
  belongs_to :organization, class_name: 'ESP::Organization'
@@ -16,7 +20,7 @@ module ESP
16
20
  # The external_account the report belongs to.
17
21
  belongs_to :external_account, class_name: 'ESP::ExternalAccount'
18
22
 
19
- # Not Implemented. You cannot create or update a Report.
23
+ # Not Implemented. You cannot update a Report.
20
24
  def update
21
25
  fail ESP::NotImplementedError
22
26
  end
@@ -1,5 +1,9 @@
1
1
  module ESP
2
2
  class Suppression < ESP::Resource
3
+ autoload :UniqueIdentifier, File.expand_path(File.dirname(__FILE__) + '/suppression/unique_identifier')
4
+ autoload :Signature, File.expand_path(File.dirname(__FILE__) + '/suppression/signature')
5
+ autoload :Region, File.expand_path(File.dirname(__FILE__) + '/suppression/region')
6
+
3
7
  ##
4
8
  # The organization this sub organization belongs to.
5
9
  belongs_to :organization, class_name: 'ESP::Organization'
@@ -1,3 +1,3 @@
1
1
  module ESP
2
- VERSION = '2.4.0'.freeze
2
+ VERSION = '2.5.0'.freeze
3
3
  end
@@ -0,0 +1,95 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ module ESP::Integration
4
+ class CustomSignatureDefinitionTest < ESP::Integration::TestCase
5
+ context ESP::CustomSignature::Definition do
6
+ context 'live calls' do
7
+ context '#custom_signature' do
8
+ should 'return a custom_signature' do
9
+ archived_definition = ESP::CustomSignature::Definition.where(status_eq: 'archived').last
10
+ fail 'Missing definition' if archived_definition.blank?
11
+
12
+ custom_signature = archived_definition.custom_signature
13
+
14
+ assert_equal archived_definition.custom_signature_id, custom_signature.id
15
+ assert_equal ESP::CustomSignature, custom_signature.class
16
+ end
17
+ end
18
+
19
+ context '#results' do
20
+ should 'return list of results' do
21
+ archived_definition = ESP::CustomSignature::Definition.where(status_eq: 'archived').last
22
+ fail 'Missing definition' if archived_definition.blank?
23
+
24
+ results = archived_definition.results
25
+
26
+ assert_equal ESP::CustomSignature::Result, results.resource_class
27
+ end
28
+ end
29
+
30
+ context '.where' do
31
+ should 'return definition objects' do
32
+ archived_definition = ESP::CustomSignature::Definition.where(status_eq: 'archived').last
33
+ fail 'Missing definition' if archived_definition.blank?
34
+
35
+ definitions = ESP::CustomSignature::Definition.where(id_eq: archived_definition.id)
36
+
37
+ assert_equal ESP::CustomSignature::Definition, definitions.resource_class
38
+ end
39
+ end
40
+
41
+ context '.archive' do
42
+ should 'archive definition' do
43
+ definition = ESP::CustomSignature::Definition.where(status_eq: 'active').last
44
+ fail 'Missing definition' if definition.blank?
45
+
46
+ definition.archive
47
+
48
+ assert_equal 'archived', definition.status
49
+ end
50
+ end
51
+
52
+ context '.activate' do
53
+ should 'activate definition' do
54
+ custom_signature = ESP::CustomSignature.last
55
+ fail 'Missing custom signature' if custom_signature.blank?
56
+ definition = ESP::CustomSignature::Definition.create(custom_signature_id: custom_signature.id)
57
+
58
+ assert_equal 'editable', definition.status
59
+
60
+ definition.activate
61
+
62
+ assert_equal 'validating', definition.status
63
+ end
64
+ end
65
+
66
+ context '#CRUD' do
67
+ should 'be able to create, update and destroy' do
68
+ custom_signature = ESP::CustomSignature.last
69
+ fail 'Missing custom signature' if custom_signature.blank?
70
+ definition = ESP::CustomSignature::Definition.new(custom_signature_id: custom_signature.id)
71
+
72
+ assert_predicate definition, :new?
73
+
74
+ definition.save
75
+
76
+ refute_predicate definition, :new?
77
+
78
+ definition.code = 'ABC123'
79
+ definition.save
80
+
81
+ assert_nothing_raised do
82
+ ESP::CustomSignature::Definition.find(definition.id)
83
+ end
84
+
85
+ definition.destroy
86
+
87
+ assert_raises ActiveResource::ResourceNotFound do
88
+ ESP::CustomSignature::Definition.find(definition.id)
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
@@ -26,38 +26,6 @@ module ESP::Integration
26
26
  end
27
27
  end
28
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
29
  context '.where' do
62
30
  should 'return custom_signature objects' do
63
31
  custom_signatures = ESP::CustomSignature.where(id_eq: @custom_signature.id)
@@ -68,7 +36,6 @@ module ESP::Integration
68
36
 
69
37
  context '#CRUD' do
70
38
  should 'be able to create, update and destroy' do
71
- skip "Can't run sigs on CI" if ENV['CI_SERVER']
72
39
  custom_signature = ESP::CustomSignature.new(@custom_signature.attributes)
73
40
 
74
41
  assert_predicate custom_signature, :new?
@@ -0,0 +1,59 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ module ESP::Integration
4
+ class CustomSignatureResultAlertTest < ESP::Integration::TestCase
5
+ context ESP::CustomSignature::Result::Alert do
6
+ context 'live calls' do
7
+ context '#for_result' do
8
+ should 'return alerts' do
9
+ result = ESP::CustomSignature::Result.first
10
+ fail 'Missing result' if result.blank?
11
+
12
+ alerts = ESP::CustomSignature::Result::Alert.for_result(result.id)
13
+
14
+ assert_equal ESP::CustomSignature::Result::Alert, alerts.resource_class
15
+ end
16
+ end
17
+
18
+ context '#custom_signature' do
19
+ should 'return a custom_signature' do
20
+ result = ESP::CustomSignature::Result.first
21
+ fail 'Missing result' if result.blank?
22
+ alert = ESP::CustomSignature::Result::Alert.for_result(result.id).first
23
+
24
+ custom_signature = alert.custom_signature
25
+
26
+ assert_equal ESP::CustomSignature, custom_signature.class
27
+ assert_equal alert.custom_signature_id, custom_signature.id
28
+ end
29
+ end
30
+
31
+ context '#external_account' do
32
+ should 'return a external_account' do
33
+ result = ESP::CustomSignature::Result.first
34
+ fail 'Missing result' if result.blank?
35
+ alert = ESP::CustomSignature::Result::Alert.for_result(result.id).first
36
+
37
+ external_account = alert.external_account
38
+
39
+ assert_equal ESP::ExternalAccount, external_account.class
40
+ assert_equal alert.external_account_id, external_account.id
41
+ end
42
+ end
43
+
44
+ context '#region' do
45
+ should 'return a region' do
46
+ result = ESP::CustomSignature::Result.first
47
+ fail 'Missing result' if result.blank?
48
+ alert = ESP::CustomSignature::Result::Alert.for_result(result.id).first
49
+
50
+ region = alert.region
51
+
52
+ assert_equal ESP::Region, region.class
53
+ assert_equal alert.region_id, region.id
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,83 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ module ESP::Integration
4
+ class CustomSignatureResultTest < ESP::Integration::TestCase
5
+ context ESP::CustomSignature::Result do
6
+ context 'live calls' do
7
+ context '#definition' do
8
+ should 'return a definition' do
9
+ result = ESP::CustomSignature::Result.last
10
+ fail 'Missing result' if result.blank?
11
+
12
+ definition = result.definition
13
+
14
+ assert_equal ESP::CustomSignature::Definition, definition.class
15
+ assert_equal result.definition_id, definition.id
16
+ end
17
+ end
18
+
19
+ context '#region' do
20
+ should 'return a region' do
21
+ result = ESP::CustomSignature::Result.last
22
+ fail 'Missing result' if result.blank?
23
+
24
+ region = result.region
25
+
26
+ assert_equal ESP::Region, region.class
27
+ assert_equal result.region_id, region.id
28
+ end
29
+ end
30
+
31
+ context '#external_account' do
32
+ should 'return a external_account' do
33
+ result = ESP::CustomSignature::Result.last
34
+ fail 'Missing result' if result.blank?
35
+
36
+ external_account = result.external_account
37
+
38
+ assert_equal ESP::ExternalAccount, external_account.class
39
+ assert_equal result.external_account_id, external_account.id
40
+ end
41
+ end
42
+
43
+ context '#alerts' do
44
+ should 'return list of alerts' do
45
+ result = ESP::CustomSignature::Result.last
46
+ fail 'Missing result' if result.blank?
47
+
48
+ alerts = result.alerts
49
+
50
+ assert_equal ESP::CustomSignature::Result::Alert, alerts.resource_class
51
+ end
52
+ end
53
+
54
+ context '.where' do
55
+ should 'return result objects' do
56
+ result = ESP::CustomSignature::Result.last
57
+ fail 'Missing result' if result.blank?
58
+
59
+ results = ESP::CustomSignature::Result.where(id_eq: result.id)
60
+
61
+ assert_equal ESP::CustomSignature::Result, results.resource_class
62
+ end
63
+ end
64
+
65
+ context '#create' do
66
+ should 'be able to create' do
67
+ custom_signature = ESP::CustomSignature.create(name: 'ABC', identifier: 'ABC', risk_level: 'High')
68
+ refute_predicate custom_signature, :new?
69
+ definition = custom_signature.definitions.first
70
+ fail 'Missing definition' if definition.blank?
71
+ result = ESP::CustomSignature::Result.new(custom_signature_definition_id: definition.id, external_account_id: 1, region_id: 1, code: 'abc', language: 'ruby')
72
+
73
+ assert_predicate result, :new?
74
+
75
+ result.save
76
+
77
+ refute_predicate result, :new?
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
@@ -48,28 +48,6 @@ module ESP::Integration
48
48
  assert_equal ESP::ExternalAccount, external_accounts.resource_class
49
49
  end
50
50
  end
51
-
52
- context '#CRUD' do
53
- should 'be able to create, update and destroy' do
54
- 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."
55
-
56
- 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)
57
-
58
- assert_predicate external_account, :new?
59
- assert_contains external_account.errors, "The account for this ARN is already being checked by Dev"
60
-
61
- refute_predicate @external_account, :new?
62
- @external_account.name = @external_account.name
63
-
64
- assert_predicate @external_account, :save
65
-
66
- external_account = build(:external_account, id: 999)
67
-
68
- assert_raises ActiveResource::ResourceNotFound do
69
- external_account.destroy
70
- end
71
- end
72
- end
73
51
  end
74
52
  end
75
53
  end
@@ -7,7 +7,7 @@ module ESP::Integration
7
7
  context ESP::Report::Export::Integration do
8
8
  context 'live calls' do
9
9
  context '#create' do
10
- should 'return regions' do
10
+ should 'queue export' do
11
11
  report = ESP::Report.last
12
12
  fail "Live DB does not have any reports. Add a report with stats and run tests again." if report.blank?
13
13
 
@@ -0,0 +1,77 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../../test_helper')
2
+
3
+ module ESP
4
+ class CustomSignature
5
+ class DefinitionTest < ActiveSupport::TestCase
6
+ context ESP::CustomSignature::Definition do
7
+ context '#custom_signature' do
8
+ should 'call the api' do
9
+ definition = build(:definition, custom_signature_id: 4)
10
+ stubbed_custom_signature = stub_request(:get, %r{custom_signatures/#{definition.custom_signature_id}.json*}).to_return(body: json(:custom_signature))
11
+
12
+ definition.custom_signature
13
+
14
+ assert_requested(stubbed_custom_signature)
15
+ end
16
+ end
17
+
18
+ context '#results' do
19
+ should 'call the api' do
20
+ definition = build(:definition)
21
+ stub_request(:get, /custom_signature_results.json*/).to_return(body: json_list(:result, 2))
22
+
23
+ definition.results
24
+
25
+ assert_requested(:get, /custom_signature_results.json*/) do |req|
26
+ assert_equal "filter[definition_id_eq]=#{definition.id}", URI.unescape(req.uri.query)
27
+ end
28
+ end
29
+ end
30
+
31
+ context 'activate' do
32
+ should 'call the api' do
33
+ definition = build(:definition)
34
+ stubbed_defintion = stub_request(:patch, %r{custom_signature_definitions/#{definition.id}/activate.json}).to_return(body: json(:definition))
35
+
36
+ definition.activate
37
+
38
+ assert_requested stubbed_defintion
39
+ end
40
+
41
+ should 'parse errors' do
42
+ definition = build(:definition)
43
+ stub_request(:patch, %r{custom_signature_definitions/#{definition.id}/activate.json}).to_return(status: 422, body: json(:error, :active_record))
44
+
45
+ definition.activate
46
+
47
+ assert_contains definition.errors.full_messages, "Name can't be blank"
48
+ assert_contains definition.errors.full_messages, "Name is invalid"
49
+ assert_contains definition.errors.full_messages, "Description can't be blank"
50
+ end
51
+ end
52
+
53
+ context 'archive' do
54
+ should 'call the api' do
55
+ definition = build(:definition)
56
+ stubbed_defintion = stub_request(:patch, %r{custom_signature_definitions/#{definition.id}/archive.json}).to_return(body: json(:definition))
57
+
58
+ definition.archive
59
+
60
+ assert_requested stubbed_defintion
61
+ end
62
+
63
+ should 'parse errors' do
64
+ definition = build(:definition)
65
+ stub_request(:patch, %r{custom_signature_definitions/#{definition.id}/archive.json}).to_return(status: 422, body: json(:error, :active_record))
66
+
67
+ definition.archive
68
+
69
+ assert_contains definition.errors.full_messages, "Name can't be blank"
70
+ assert_contains definition.errors.full_messages, "Name is invalid"
71
+ assert_contains definition.errors.full_messages, "Description can't be blank"
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end