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
|
@@ -4,6 +4,14 @@ module ESP
|
|
|
4
4
|
class Suppression
|
|
5
5
|
class SignatureTest < ActiveSupport::TestCase
|
|
6
6
|
context ESP::Suppression::Signature do
|
|
7
|
+
context '.where' do
|
|
8
|
+
should 'not be implemented' do
|
|
9
|
+
assert_raises ESP::NotImplementedError do
|
|
10
|
+
ESP::Suppression::Signature.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
|
|
@@ -93,7 +101,7 @@ module ESP
|
|
|
93
101
|
|
|
94
102
|
context 'for_alert' do
|
|
95
103
|
should 'return error when reason is not supplied' do
|
|
96
|
-
alert_id = ESP::Report.
|
|
104
|
+
alert_id = ESP::Report.all.detect { |r| r.status == 'complete' }.alerts.last.id
|
|
97
105
|
|
|
98
106
|
suppression = ESP::Suppression::Signature.create(alert_id: alert_id)
|
|
99
107
|
|
|
@@ -101,7 +109,7 @@ module ESP
|
|
|
101
109
|
end
|
|
102
110
|
|
|
103
111
|
should 'return suppression' do
|
|
104
|
-
alert_id = ESP::Report.
|
|
112
|
+
alert_id = ESP::Report.all.detect { |r| r.status == 'complete' }.alerts.last.id
|
|
105
113
|
|
|
106
114
|
suppression = ESP::Suppression::Signature.create(alert_id: alert_id, reason: 'test')
|
|
107
115
|
|
|
@@ -4,6 +4,14 @@ module ESP
|
|
|
4
4
|
class Suppression
|
|
5
5
|
class UniqueIdentifierTest < ActiveSupport::TestCase
|
|
6
6
|
context ESP::Suppression::UniqueIdentifier do
|
|
7
|
+
context '.where' do
|
|
8
|
+
should 'not be implemented' do
|
|
9
|
+
assert_raises ESP::NotImplementedError do
|
|
10
|
+
ESP::Suppression::UniqueIdentifier.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
|
|
@@ -56,7 +64,7 @@ module ESP
|
|
|
56
64
|
|
|
57
65
|
context '.create' do
|
|
58
66
|
should 'return error when reason is not supplied' do
|
|
59
|
-
alert_id = ESP::Report.
|
|
67
|
+
alert_id = ESP::Report.all.detect { |r| r.status == 'complete' }.alerts.last.id
|
|
60
68
|
|
|
61
69
|
suppression = ESP::Suppression::UniqueIdentifier.create(alert_id: alert_id)
|
|
62
70
|
|
|
@@ -64,7 +72,7 @@ module ESP
|
|
|
64
72
|
end
|
|
65
73
|
|
|
66
74
|
should 'return suppression' do
|
|
67
|
-
alert_id = ESP::Report.
|
|
75
|
+
alert_id = ESP::Report.all.detect { |r| r.status == 'complete' }.alerts.last.id
|
|
68
76
|
|
|
69
77
|
suppression = ESP::Suppression::UniqueIdentifier.create(alert_id: alert_id, reason: 'test')
|
|
70
78
|
|
|
@@ -53,54 +53,106 @@ module ESP
|
|
|
53
53
|
|
|
54
54
|
context '#regions' do
|
|
55
55
|
should 'call the api for the report and the passed in params' do
|
|
56
|
-
suppression = build(:suppression)
|
|
57
|
-
stub_request(:
|
|
56
|
+
suppression = build(:suppression, region_ids: [1, 2])
|
|
57
|
+
stub_request(:put, /regions.json*/).to_return(body: json_list(:region, 2))
|
|
58
58
|
|
|
59
59
|
suppression.regions
|
|
60
60
|
|
|
61
|
-
assert_requested(:
|
|
62
|
-
|
|
61
|
+
assert_requested(:put, /regions.json*/) do |req|
|
|
62
|
+
body = JSON.parse(req.body)
|
|
63
|
+
assert_equal [1, 2], body["filter"]["id_in"]
|
|
63
64
|
end
|
|
64
65
|
end
|
|
66
|
+
|
|
67
|
+
should 'not call the api if it was returned in an include' do
|
|
68
|
+
stub_request(:get, %r{suppressions/1.json*}).to_return(body: json(:suppression, :with_include))
|
|
69
|
+
suppression = ESP::Suppression.find(1)
|
|
70
|
+
stub_request(:put, /regions.json*/)
|
|
71
|
+
|
|
72
|
+
assert_not_nil suppression.attributes['regions']
|
|
73
|
+
|
|
74
|
+
suppression.regions
|
|
75
|
+
|
|
76
|
+
assert_not_requested(:put, /regions.json*/)
|
|
77
|
+
end
|
|
65
78
|
end
|
|
66
79
|
|
|
67
80
|
context '#external_accounts' do
|
|
68
81
|
should 'call the api for the report and the passed in params' do
|
|
69
|
-
suppression = build(:suppression)
|
|
70
|
-
stub_request(:
|
|
82
|
+
suppression = build(:suppression, external_account_ids: [1, 2])
|
|
83
|
+
stub_request(:put, /external_accounts.json*/).to_return(body: json_list(:external_account, 2))
|
|
71
84
|
|
|
72
85
|
suppression.external_accounts
|
|
73
86
|
|
|
74
|
-
assert_requested(:
|
|
75
|
-
|
|
87
|
+
assert_requested(:put, /external_accounts.json*/) do |req|
|
|
88
|
+
body = JSON.parse(req.body)
|
|
89
|
+
assert_equal [1, 2], body["filter"]["id_in"]
|
|
76
90
|
end
|
|
77
91
|
end
|
|
92
|
+
|
|
93
|
+
should 'not call the api if it was returned in an include' do
|
|
94
|
+
stub_request(:get, %r{suppressions/1.json*}).to_return(body: json(:suppression, :with_include))
|
|
95
|
+
suppression = ESP::Suppression.find(1)
|
|
96
|
+
stub_request(:put, /external_accounts.json*/)
|
|
97
|
+
|
|
98
|
+
assert_not_nil suppression.attributes['external_accounts']
|
|
99
|
+
|
|
100
|
+
suppression.external_accounts
|
|
101
|
+
|
|
102
|
+
assert_not_requested(:put, /external_accounts.json*/)
|
|
103
|
+
end
|
|
78
104
|
end
|
|
79
105
|
|
|
80
106
|
context '#signatures' do
|
|
81
107
|
should 'call the api for the report and the passed in params' do
|
|
82
108
|
suppression = build(:suppression, signature_ids: [1, 2])
|
|
83
|
-
stub_request(:
|
|
109
|
+
stub_request(:put, /signatures.json*/).to_return(body: json_list(:signature, 2))
|
|
84
110
|
|
|
85
111
|
suppression.signatures
|
|
86
112
|
|
|
87
|
-
assert_requested(:
|
|
88
|
-
|
|
113
|
+
assert_requested(:put, /signatures.json*/) do |req|
|
|
114
|
+
body = JSON.parse(req.body)
|
|
115
|
+
assert_equal [1, 2], body["filter"]["id_in"]
|
|
89
116
|
end
|
|
90
117
|
end
|
|
118
|
+
|
|
119
|
+
should 'not call the api if it was returned in an include' do
|
|
120
|
+
stub_request(:get, %r{suppressions/1.json*}).to_return(body: json(:suppression, :with_include))
|
|
121
|
+
suppression = ESP::Suppression.find(1)
|
|
122
|
+
stub_request(:put, /signatures.json*/)
|
|
123
|
+
|
|
124
|
+
assert_not_nil suppression.attributes['signatures']
|
|
125
|
+
|
|
126
|
+
suppression.signatures
|
|
127
|
+
|
|
128
|
+
assert_not_requested(:put, /signatures.json*/)
|
|
129
|
+
end
|
|
91
130
|
end
|
|
92
131
|
|
|
93
132
|
context '#custom_signatures' do
|
|
94
133
|
should 'call the api for the report and the passed in params' do
|
|
95
134
|
suppression = build(:suppression, custom_signature_ids: [1, 2])
|
|
96
|
-
stub_request(:
|
|
135
|
+
stub_request(:put, /custom_signatures.json*/).to_return(body: json_list(:custom_signature, 2))
|
|
97
136
|
|
|
98
137
|
suppression.custom_signatures
|
|
99
138
|
|
|
100
|
-
assert_requested(:
|
|
101
|
-
|
|
139
|
+
assert_requested(:put, /custom_signatures.json*/) do |req|
|
|
140
|
+
body = JSON.parse(req.body)
|
|
141
|
+
assert_equal [1, 2], body["filter"]["id_in"]
|
|
102
142
|
end
|
|
103
143
|
end
|
|
144
|
+
|
|
145
|
+
should 'not call the api if it was returned in an include' do
|
|
146
|
+
stub_request(:get, %r{suppressions/1.json*}).to_return(body: json(:suppression, :with_include))
|
|
147
|
+
suppression = ESP::Suppression.find(1)
|
|
148
|
+
stub_request(:put, /custom_signatures.json*/)
|
|
149
|
+
|
|
150
|
+
assert_not_nil suppression.attributes['custom_signatures']
|
|
151
|
+
|
|
152
|
+
suppression.custom_signatures
|
|
153
|
+
|
|
154
|
+
assert_not_requested(:put, /custom_signatures.json*/)
|
|
155
|
+
end
|
|
104
156
|
end
|
|
105
157
|
|
|
106
158
|
context '#deactivate' do
|
|
@@ -220,6 +272,14 @@ module ESP
|
|
|
220
272
|
end
|
|
221
273
|
end
|
|
222
274
|
end
|
|
275
|
+
|
|
276
|
+
context '.where' do
|
|
277
|
+
should 'return suppression objects' do
|
|
278
|
+
suppressions = ESP::Suppression.where(id_eq: @s.id)
|
|
279
|
+
|
|
280
|
+
assert_equal ESP::Suppression, suppressions.resource_class
|
|
281
|
+
end
|
|
282
|
+
end
|
|
223
283
|
end
|
|
224
284
|
end
|
|
225
285
|
end
|
|
@@ -29,6 +29,14 @@ module ESP
|
|
|
29
29
|
end
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
+
context '.where' do
|
|
33
|
+
should 'not be implemented' do
|
|
34
|
+
assert_raises ESP::NotImplementedError do
|
|
35
|
+
Tag.where(id_eq: 2)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
32
40
|
context '.for_alert' do
|
|
33
41
|
should 'throw an error if alert id is not supplied' do
|
|
34
42
|
error = assert_raises ArgumentError do
|
|
@@ -86,7 +94,7 @@ module ESP
|
|
|
86
94
|
|
|
87
95
|
context '.for_alert' do
|
|
88
96
|
should 'return tags for alert id' do
|
|
89
|
-
report = ESP::Report.
|
|
97
|
+
report = ESP::Report.all.detect { |r| r.status == 'complete' }
|
|
90
98
|
events = ESP::Tag.for_alert(report.alerts.last.id)
|
|
91
99
|
|
|
92
100
|
assert_equal ESP::Tag, events.resource_class
|
|
@@ -110,6 +110,14 @@ module ESP
|
|
|
110
110
|
end
|
|
111
111
|
end
|
|
112
112
|
|
|
113
|
+
context '.where' do
|
|
114
|
+
should 'return team objects' do
|
|
115
|
+
teams = ESP::Team.where(name_eq: @team.name)
|
|
116
|
+
|
|
117
|
+
assert_equal ESP::Team, teams.resource_class
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
113
121
|
context '#CRUD' do
|
|
114
122
|
should 'be able to create, update and destroy' do
|
|
115
123
|
team = ESP::Team.new(name: 'bob', organization_id: @team.organization_id, sub_organization_id: @team.sub_organization_id)
|
|
@@ -43,33 +43,61 @@ module ESP
|
|
|
43
43
|
context '#sub_organizations' do
|
|
44
44
|
should 'call the api' do
|
|
45
45
|
u = build(:user, sub_organization_ids: [1, 2])
|
|
46
|
-
stub_request(:
|
|
46
|
+
stub_request(:put, /sub_organizations.json*/).to_return(body: json_list(:sub_organization, 2))
|
|
47
47
|
|
|
48
48
|
u.sub_organizations
|
|
49
49
|
|
|
50
|
-
assert_requested(:
|
|
51
|
-
|
|
50
|
+
assert_requested(:put, /sub_organizations.json*/) do |req|
|
|
51
|
+
body = JSON.parse(req.body)
|
|
52
|
+
assert_equal [1, 2], body["filter"]["id_in"]
|
|
52
53
|
end
|
|
53
54
|
end
|
|
55
|
+
|
|
56
|
+
should 'not call the api if it was returned in an include' do
|
|
57
|
+
stub_request(:get, %r{users/1.json*}).to_return(body: json(:user, :with_include))
|
|
58
|
+
user = ESP::User.find(1)
|
|
59
|
+
stub_request(:put, /sub_organizations.json*/)
|
|
60
|
+
|
|
61
|
+
assert_not_nil user.attributes['sub_organizations']
|
|
62
|
+
|
|
63
|
+
user.sub_organizations
|
|
64
|
+
|
|
65
|
+
assert_not_requested(:put, /sub_organizations.json*/)
|
|
66
|
+
end
|
|
54
67
|
end
|
|
55
68
|
|
|
56
69
|
context '#teams' do
|
|
57
70
|
should 'call the api' do
|
|
58
71
|
u = build(:user, team_ids: [1, 2])
|
|
59
|
-
stub_request(:
|
|
72
|
+
stub_request(:put, /teams.json*/).to_return(body: json_list(:team, 2))
|
|
60
73
|
|
|
61
74
|
u.teams
|
|
62
75
|
|
|
63
|
-
assert_requested(:
|
|
64
|
-
|
|
76
|
+
assert_requested(:put, /teams.json*/) do |req|
|
|
77
|
+
body = JSON.parse(req.body)
|
|
78
|
+
assert_equal [1, 2], body["filter"]["id_in"]
|
|
65
79
|
end
|
|
66
80
|
end
|
|
81
|
+
|
|
82
|
+
should 'not call the api if it was returned in an include' do
|
|
83
|
+
stub_request(:get, %r{users/1.json*}).to_return(body: json(:user, :with_include))
|
|
84
|
+
user = ESP::User.find(1)
|
|
85
|
+
stub_request(:put, /teams.json*/)
|
|
86
|
+
|
|
87
|
+
assert_not_nil user.attributes['teams']
|
|
88
|
+
|
|
89
|
+
user.teams
|
|
90
|
+
|
|
91
|
+
assert_not_requested(:put, /teams.json*/)
|
|
92
|
+
end
|
|
67
93
|
end
|
|
68
94
|
|
|
69
95
|
context 'live calls' do
|
|
70
96
|
setup do
|
|
71
97
|
skip "Make sure you run the live calls locally to ensure proper integration" if ENV['CI_SERVER']
|
|
72
98
|
WebMock.allow_net_connect!
|
|
99
|
+
@user = ESP::User.last
|
|
100
|
+
skip "Live DB does not have any users. Add a user and run tests again." if @user.blank?
|
|
73
101
|
end
|
|
74
102
|
|
|
75
103
|
teardown do
|
|
@@ -78,33 +106,35 @@ module ESP
|
|
|
78
106
|
|
|
79
107
|
context '#organization' do
|
|
80
108
|
should 'return an organization' do
|
|
81
|
-
|
|
109
|
+
org = @user.organization
|
|
82
110
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
assert_equal u.organization_id, org.id
|
|
111
|
+
assert_equal @user.organization_id, org.id
|
|
86
112
|
end
|
|
87
113
|
end
|
|
88
114
|
|
|
89
115
|
context '#sub_organizations' do
|
|
90
116
|
should 'return an array of sub_organizations' do
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
sub_orgs = u.sub_organizations
|
|
117
|
+
sub_orgs = @user.sub_organizations
|
|
94
118
|
|
|
95
|
-
assert_equal
|
|
96
|
-
assert_equal
|
|
119
|
+
assert_equal @user.sub_organization_ids.count, sub_orgs.count
|
|
120
|
+
assert_equal @user.sub_organization_ids, sub_orgs.map(&:id)
|
|
97
121
|
end
|
|
98
122
|
end
|
|
99
123
|
|
|
100
124
|
context '#teams' do
|
|
101
125
|
should 'return an array of teams' do
|
|
102
|
-
|
|
126
|
+
teams = @user.teams
|
|
127
|
+
|
|
128
|
+
assert_equal @user.team_ids.count, teams.count
|
|
129
|
+
assert_equal @user.team_ids.sort, teams.map(&:id).sort
|
|
130
|
+
end
|
|
131
|
+
end
|
|
103
132
|
|
|
104
|
-
|
|
133
|
+
context '.where' do
|
|
134
|
+
should 'return user objects' do
|
|
135
|
+
users = ESP::User.where(id_eq: @user.id)
|
|
105
136
|
|
|
106
|
-
assert_equal
|
|
107
|
-
assert_equal u.team_ids.sort, teams.map(&:id).sort
|
|
137
|
+
assert_equal ESP::User, users.resource_class
|
|
108
138
|
end
|
|
109
139
|
end
|
|
110
140
|
end
|
data/test/esp_test.rb
CHANGED
|
@@ -44,6 +44,22 @@ class ESPTest < ActiveSupport::TestCase
|
|
|
44
44
|
end
|
|
45
45
|
end
|
|
46
46
|
|
|
47
|
+
context '.http_proxy' do
|
|
48
|
+
should 'be set manually' do
|
|
49
|
+
ESP.http_proxy = 'http://foo.com/blah_blah'
|
|
50
|
+
|
|
51
|
+
assert_equal 'http://foo.com/blah_blah', ESP.http_proxy
|
|
52
|
+
assert_equal URI.parse('http://foo.com/blah_blah'), ESP::Resource.proxy
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
should 'be set from an environment variable' do
|
|
56
|
+
ESP.http_proxy = nil
|
|
57
|
+
ENV['http_proxy'] = 'http://foo.com/blah_blah'
|
|
58
|
+
|
|
59
|
+
assert_equal 'http://foo.com/blah_blah', ESP.http_proxy
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
47
63
|
context '.host=' do
|
|
48
64
|
setup do
|
|
49
65
|
ESP.host = nil
|
|
@@ -97,11 +113,12 @@ class ESPTest < ActiveSupport::TestCase
|
|
|
97
113
|
ESP.host = nil
|
|
98
114
|
end
|
|
99
115
|
|
|
100
|
-
should 'set site, access_key_id, secret_access_key' do
|
|
116
|
+
should 'set site, access_key_id, secret_access_key, http_proxy' do
|
|
101
117
|
ESP.configure do |config|
|
|
102
118
|
config.host = 'https://sample.com'
|
|
103
119
|
config.access_key_id = '1234'
|
|
104
120
|
config.secret_access_key = '5678'
|
|
121
|
+
config.http_proxy = 'proxy.com'
|
|
105
122
|
end
|
|
106
123
|
|
|
107
124
|
assert_equal "https://sample.com#{ESP::PATH}", ESP.site
|
|
@@ -110,6 +127,7 @@ class ESPTest < ActiveSupport::TestCase
|
|
|
110
127
|
assert_equal '1234', ESP::Resource.hmac_access_id
|
|
111
128
|
assert_equal '5678', ESP.secret_access_key
|
|
112
129
|
assert_equal '5678', ESP::Resource.hmac_secret_key
|
|
130
|
+
assert_equal URI.parse("proxy.com"), ESP::Resource.proxy
|
|
113
131
|
end
|
|
114
132
|
end
|
|
115
133
|
|
data/test/factories/alerts.rb
CHANGED
|
@@ -125,6 +125,76 @@ FactoryGirl.define do
|
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
127
|
},
|
|
128
|
+
{
|
|
129
|
+
id: '5',
|
|
130
|
+
type: "teams",
|
|
131
|
+
name: "Default Team",
|
|
132
|
+
created_at: "2015-09-11T21:12:15.183Z",
|
|
133
|
+
updated_at: "2015-09-11T21:12:15.183Z",
|
|
134
|
+
relationships: {
|
|
135
|
+
sub_organization: {
|
|
136
|
+
data: {
|
|
137
|
+
type: "sub_organizations",
|
|
138
|
+
id: "5"
|
|
139
|
+
},
|
|
140
|
+
links: {
|
|
141
|
+
related: "http://localhost:3000/api/v2/sub_organizations/2.json"
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
organization: {
|
|
145
|
+
data: {
|
|
146
|
+
type: "organizations",
|
|
147
|
+
id: "5"
|
|
148
|
+
},
|
|
149
|
+
links: {
|
|
150
|
+
related: "http://localhost:3000/api/v2/organizations/2.json"
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
id: '5',
|
|
157
|
+
type: "organizations",
|
|
158
|
+
created_at: "2015-09-11T21:12:15.183Z",
|
|
159
|
+
name: "Test Org",
|
|
160
|
+
updated_at: "2015-09-11T21:12:15.183Z",
|
|
161
|
+
relationships: {
|
|
162
|
+
sub_organizations: {
|
|
163
|
+
data: [
|
|
164
|
+
{
|
|
165
|
+
type: "sub_organizations",
|
|
166
|
+
id: "24"
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
type: "sub_organizations",
|
|
170
|
+
id: "2"
|
|
171
|
+
}
|
|
172
|
+
],
|
|
173
|
+
links: {
|
|
174
|
+
related: "http://localhost:3000/api/v2/sub_organizations.json?filter%5Borganization_id_eq%5D=2"
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
teams: {
|
|
178
|
+
data: [
|
|
179
|
+
{
|
|
180
|
+
type: "teams",
|
|
181
|
+
id: "2"
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
type: "teams",
|
|
185
|
+
id: "20"
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
type: "teams",
|
|
189
|
+
id: "21"
|
|
190
|
+
}
|
|
191
|
+
],
|
|
192
|
+
links: {
|
|
193
|
+
related: "http://localhost:3000/api/v2/teams.json?filter%5Borganization_id_eq%5D=2"
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
},
|
|
128
198
|
{
|
|
129
199
|
id: "1014",
|
|
130
200
|
type: "regions",
|
|
@@ -20,7 +20,7 @@ FactoryGirl.define do
|
|
|
20
20
|
}
|
|
21
21
|
],
|
|
22
22
|
links: {
|
|
23
|
-
related: "http://localhost:3000/api/v2/sub_organizations.json?
|
|
23
|
+
related: "http://localhost:3000/api/v2/sub_organizations.json?filter%5Borganization_id_eq%5D=2"
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
26
|
teams: {
|
|
@@ -39,7 +39,7 @@ FactoryGirl.define do
|
|
|
39
39
|
}
|
|
40
40
|
],
|
|
41
41
|
links: {
|
|
42
|
-
related: "http://localhost:3000/api/v2/teams.json?
|
|
42
|
+
related: "http://localhost:3000/api/v2/teams.json?filter%5Borganization_id_eq%5D=2"
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
}
|
data/test/factories/regions.rb
CHANGED
|
@@ -4,12 +4,12 @@ FactoryGirl.define do
|
|
|
4
4
|
|
|
5
5
|
sequence(:id) { |n| n }
|
|
6
6
|
type "suppressions"
|
|
7
|
-
created_at
|
|
7
|
+
created_at "2015-09-11T21:12:15.183Z"
|
|
8
8
|
reason "I said"
|
|
9
9
|
resource ''
|
|
10
10
|
suppression_type "regions"
|
|
11
11
|
status "active"
|
|
12
|
-
updated_at
|
|
12
|
+
updated_at "2015-09-11T21:12:15.183Z"
|
|
13
13
|
relationships do
|
|
14
14
|
{ organization: {
|
|
15
15
|
data: {
|
|
@@ -63,9 +63,115 @@ FactoryGirl.define do
|
|
|
63
63
|
}
|
|
64
64
|
},
|
|
65
65
|
custom_signatures: {
|
|
66
|
-
data: [
|
|
66
|
+
data: [
|
|
67
|
+
{
|
|
68
|
+
id: "6",
|
|
69
|
+
type: "custom_signatures"
|
|
70
|
+
}
|
|
71
|
+
],
|
|
72
|
+
links: {
|
|
73
|
+
related: "http://test.host/api/v2/custom_signatures.json?filter%5Bid_in%5D%5B%5D=6"
|
|
74
|
+
}
|
|
67
75
|
}
|
|
68
76
|
}
|
|
69
77
|
end
|
|
78
|
+
|
|
79
|
+
trait :with_include do
|
|
80
|
+
included do
|
|
81
|
+
[
|
|
82
|
+
{
|
|
83
|
+
id: '1',
|
|
84
|
+
type: "regions",
|
|
85
|
+
code: "us_east_test_1"
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
id: '1015',
|
|
89
|
+
type: "external_accounts",
|
|
90
|
+
account: "762160981991",
|
|
91
|
+
arn: "arn:aws:iam::762160981991:role/Evident-Service-Role-Kevin",
|
|
92
|
+
created_at: "2015-09-11T21:12:15.183Z",
|
|
93
|
+
external_id: "913310e7-6a9c-49f7-bd69-120721ec1122",
|
|
94
|
+
name: "Dev",
|
|
95
|
+
updated_at: "2015-09-11T21:12:15.183Z",
|
|
96
|
+
relationships: {
|
|
97
|
+
organization: {
|
|
98
|
+
data: {
|
|
99
|
+
type: "organizations",
|
|
100
|
+
id: "1"
|
|
101
|
+
},
|
|
102
|
+
links: {
|
|
103
|
+
related: "http://localhost:3000/api/v2/organizations/1.json"
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
sub_organization: {
|
|
107
|
+
data: {
|
|
108
|
+
type: "sub_organizations",
|
|
109
|
+
id: "1"
|
|
110
|
+
},
|
|
111
|
+
links: {
|
|
112
|
+
related: "http://localhost:3000/api/v2/sub_organizations/1.json"
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
team: {
|
|
116
|
+
data: {
|
|
117
|
+
type: "teams",
|
|
118
|
+
id: "1"
|
|
119
|
+
},
|
|
120
|
+
links: {
|
|
121
|
+
related: "http://localhost:3000/api/v2/teams/1.json"
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
id: '6',
|
|
128
|
+
type: "signatures",
|
|
129
|
+
created_at: "2015-09-11T21:12:15.183Z",
|
|
130
|
+
description: "Some description for some test",
|
|
131
|
+
identifier: "1 Unique ID",
|
|
132
|
+
name: "1_test_signature",
|
|
133
|
+
resolution: "Turn on some setting",
|
|
134
|
+
risk_level: "High",
|
|
135
|
+
updated_at: nil,
|
|
136
|
+
relationships: {
|
|
137
|
+
service: {
|
|
138
|
+
data: {
|
|
139
|
+
type: "services",
|
|
140
|
+
id: "1"
|
|
141
|
+
},
|
|
142
|
+
links: {
|
|
143
|
+
related: "http://test.host/api/v2/services/1.json"
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
id: '6',
|
|
150
|
+
type: "custom_signatures",
|
|
151
|
+
created_at: "2015-09-11T21:12:15.183Z",
|
|
152
|
+
active: true,
|
|
153
|
+
description: "Test description",
|
|
154
|
+
identifier: "AWS::Test::001",
|
|
155
|
+
name: "Test",
|
|
156
|
+
resolution: "Test resolution",
|
|
157
|
+
risk_level: "Medium",
|
|
158
|
+
signature: "Some javascript",
|
|
159
|
+
language: "javascript",
|
|
160
|
+
updated_at: nil,
|
|
161
|
+
relationships: {
|
|
162
|
+
organization: {
|
|
163
|
+
data: {
|
|
164
|
+
type: "organizations",
|
|
165
|
+
id: "1003"
|
|
166
|
+
},
|
|
167
|
+
links: {
|
|
168
|
+
related: "http://test.host/api/v2/organizations/1003.json"
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
]
|
|
174
|
+
end
|
|
175
|
+
end
|
|
70
176
|
end
|
|
71
177
|
end
|