esp_sdk 1.1.0 → 2.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (199) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -2
  3. data/.rubocop.yml +53 -6
  4. data/.ruby-version +1 -1
  5. data/.travis.yml +8 -2
  6. data/Gemfile.lock +171 -0
  7. data/Guardfile +47 -0
  8. data/README.md +230 -5
  9. data/Rakefile +14 -1
  10. data/assets/logo.png +0 -0
  11. data/bin/esp_console +71 -0
  12. data/esp_sdk.gemspec +27 -18
  13. data/lib/esp/exceptions.rb +3 -0
  14. data/lib/esp/extensions/active_resource/formats/json_api_format.rb +105 -0
  15. data/lib/esp/extensions/active_resource/paginated_collection.rb +198 -0
  16. data/lib/esp/extensions/active_resource/validations.rb +45 -0
  17. data/lib/esp/resources/alert.rb +135 -0
  18. data/lib/esp/resources/cloud_trail_event.rb +45 -0
  19. data/lib/esp/resources/concerns/stat_totals.rb +79 -0
  20. data/lib/esp/resources/contact_request.rb +42 -0
  21. data/lib/esp/resources/custom_signature.rb +224 -0
  22. data/lib/esp/resources/dashboard.rb +31 -0
  23. data/lib/esp/resources/external_account.rb +89 -0
  24. data/lib/esp/resources/organization.rb +61 -0
  25. data/lib/esp/resources/region.rb +46 -0
  26. data/lib/esp/resources/report.rb +100 -0
  27. data/lib/esp/resources/resource.rb +66 -0
  28. data/lib/esp/resources/service.rb +31 -0
  29. data/lib/esp/resources/signature.rb +106 -0
  30. data/lib/esp/resources/stat.rb +124 -0
  31. data/lib/esp/resources/stat_custom_signature.rb +121 -0
  32. data/lib/esp/resources/stat_region.rb +121 -0
  33. data/lib/esp/resources/stat_service.rb +121 -0
  34. data/lib/esp/resources/stat_signature.rb +121 -0
  35. data/lib/esp/resources/sub_organization.rb +69 -0
  36. data/lib/esp/resources/suppression/region.rb +99 -0
  37. data/lib/esp/resources/suppression/signature.rb +107 -0
  38. data/lib/esp/resources/suppression/unique_identifier.rb +60 -0
  39. data/lib/esp/resources/suppression.rb +86 -0
  40. data/lib/esp/resources/tag.rb +45 -0
  41. data/lib/esp/resources/team.rb +79 -0
  42. data/lib/esp/resources/user.rb +46 -0
  43. data/lib/esp/version.rb +3 -0
  44. data/lib/esp.rb +95 -0
  45. data/lib/esp_sdk.rb +9 -45
  46. data/lib/tasks/rubocop.rake +2 -0
  47. data/lib/tasks/testing.rake +3 -0
  48. data/rdoc/ActiveResource/Formats.html +176 -0
  49. data/rdoc/ActiveResource/PaginatedCollection.html +910 -0
  50. data/rdoc/ActiveResource.html +180 -0
  51. data/rdoc/ESP/Alert.html +771 -0
  52. data/rdoc/ESP/CloudTrailEvent.html +375 -0
  53. data/rdoc/ESP/ContactRequest.html +366 -0
  54. data/rdoc/ESP/CustomSignature.html +746 -0
  55. data/rdoc/ESP/Dashboard.html +355 -0
  56. data/rdoc/ESP/ExternalAccount.html +565 -0
  57. data/rdoc/ESP/Organization.html +590 -0
  58. data/rdoc/ESP/Region.html +399 -0
  59. data/rdoc/ESP/Report.html +622 -0
  60. data/rdoc/ESP/Service.html +380 -0
  61. data/rdoc/ESP/Signature.html +555 -0
  62. data/rdoc/ESP/Stat.html +1778 -0
  63. data/rdoc/ESP/StatCustomSignature.html +1599 -0
  64. data/rdoc/ESP/StatRegion.html +1598 -0
  65. data/rdoc/ESP/StatService.html +1598 -0
  66. data/rdoc/ESP/StatSignature.html +1598 -0
  67. data/rdoc/ESP/SubOrganization.html +540 -0
  68. data/rdoc/ESP/Suppression/Region.html +454 -0
  69. data/rdoc/ESP/Suppression/Signature.html +470 -0
  70. data/rdoc/ESP/Suppression/UniqueIdentifier.html +417 -0
  71. data/rdoc/ESP/Suppression.html +649 -0
  72. data/rdoc/ESP/Tag.html +371 -0
  73. data/rdoc/ESP/Team.html +584 -0
  74. data/rdoc/ESP/User.html +483 -0
  75. data/rdoc/ESP.html +546 -0
  76. data/rdoc/README_md.html +501 -0
  77. data/rdoc/created.rid +30 -0
  78. data/rdoc/images/add.png +0 -0
  79. data/rdoc/images/arrow_up.png +0 -0
  80. data/rdoc/images/brick.png +0 -0
  81. data/rdoc/images/brick_link.png +0 -0
  82. data/rdoc/images/bug.png +0 -0
  83. data/rdoc/images/bullet_black.png +0 -0
  84. data/rdoc/images/bullet_toggle_minus.png +0 -0
  85. data/rdoc/images/bullet_toggle_plus.png +0 -0
  86. data/rdoc/images/date.png +0 -0
  87. data/rdoc/images/delete.png +0 -0
  88. data/rdoc/images/find.png +0 -0
  89. data/rdoc/images/loadingAnimation.gif +0 -0
  90. data/rdoc/images/macFFBgHack.png +0 -0
  91. data/rdoc/images/package.png +0 -0
  92. data/rdoc/images/page_green.png +0 -0
  93. data/rdoc/images/page_white_text.png +0 -0
  94. data/rdoc/images/page_white_width.png +0 -0
  95. data/rdoc/images/plugin.png +0 -0
  96. data/rdoc/images/ruby.png +0 -0
  97. data/rdoc/images/tag_blue.png +0 -0
  98. data/rdoc/images/tag_green.png +0 -0
  99. data/rdoc/images/transparent.png +0 -0
  100. data/rdoc/images/wrench.png +0 -0
  101. data/rdoc/images/wrench_orange.png +0 -0
  102. data/rdoc/images/zoom.png +0 -0
  103. data/rdoc/index.html +134 -0
  104. data/rdoc/js/darkfish.js +155 -0
  105. data/rdoc/js/jquery.js +4 -0
  106. data/rdoc/js/navigation.js +142 -0
  107. data/rdoc/js/search.js +94 -0
  108. data/rdoc/js/search_index.js +1 -0
  109. data/rdoc/js/searcher.js +228 -0
  110. data/rdoc/rdoc.css +595 -0
  111. data/rdoc/table_of_contents.html +927 -0
  112. data/test/esp/extensions/active_resource/formats/json_api_format_test.rb +109 -0
  113. data/test/esp/extensions/active_resource/paginated_collection_test.rb +435 -0
  114. data/test/esp/extensions/active_resource/validations_test.rb +59 -0
  115. data/test/esp/resources/alert_test.rb +263 -0
  116. data/test/esp/resources/cloud_trail_event_test.rb +98 -0
  117. data/test/esp/resources/contact_request_test.rb +73 -0
  118. data/test/esp/resources/custom_signature_test.rb +241 -0
  119. data/test/esp/resources/dashboard_test.rb +71 -0
  120. data/test/esp/resources/external_account_test.rb +125 -0
  121. data/test/esp/resources/organization_test.rb +175 -0
  122. data/test/esp/resources/region_test.rb +84 -0
  123. data/test/esp/resources/report_test.rb +180 -0
  124. data/test/esp/resources/resource_test.rb +183 -0
  125. data/test/esp/resources/service_test.rb +64 -0
  126. data/test/esp/resources/signature_test.rb +177 -0
  127. data/test/esp/resources/stat_custom_signature_test.rb +115 -0
  128. data/test/esp/resources/stat_region_test.rb +114 -0
  129. data/test/esp/resources/stat_service_test.rb +114 -0
  130. data/test/esp/resources/stat_signature_test.rb +115 -0
  131. data/test/esp/resources/stat_test.rb +159 -0
  132. data/test/esp/resources/sub_organization_test.rb +127 -0
  133. data/test/esp/resources/suppression/region_test.rb +115 -0
  134. data/test/esp/resources/suppression/signature_test.rb +117 -0
  135. data/test/esp/resources/suppression/unique_identifier_test.rb +79 -0
  136. data/test/esp/resources/suppression_test.rb +226 -0
  137. data/test/esp/resources/tag_test.rb +98 -0
  138. data/test/esp/resources/team_test.rb +140 -0
  139. data/test/esp/resources/user_test.rb +113 -0
  140. data/test/esp_test.rb +139 -0
  141. data/test/factories/alerts.rb +234 -0
  142. data/test/factories/cloud_trail_events.rb +16 -0
  143. data/test/factories/contact_requests.rb +14 -0
  144. data/test/factories/custom_signatures.rb +30 -0
  145. data/test/factories/dashboards.rb +91 -0
  146. data/test/factories/errors.rb +24 -0
  147. data/test/factories/external_accounts.rb +44 -0
  148. data/test/factories/organizations.rb +48 -0
  149. data/test/factories/regions.rb +9 -0
  150. data/test/factories/reports.rb +56 -0
  151. data/test/factories/services.rb +12 -0
  152. data/test/factories/signatures.rb +28 -0
  153. data/test/factories/stat_custom_signatures.rb +97 -0
  154. data/test/factories/stat_regions.rb +97 -0
  155. data/test/factories/stat_services.rb +97 -0
  156. data/test/factories/stat_signautures.rb +97 -0
  157. data/test/factories/stats.rb +129 -0
  158. data/test/factories/sub_organizations.rb +34 -0
  159. data/test/factories/suppression/regions.rb +90 -0
  160. data/test/factories/suppression/signatures.rb +117 -0
  161. data/test/factories/suppression/unique_identifiers.rb +111 -0
  162. data/test/factories/suppressions.rb +71 -0
  163. data/test/factories/tags.rb +12 -0
  164. data/test/factories/teams.rb +32 -0
  165. data/test/factories/users.rb +54 -0
  166. data/test/json_strategy.rb +25 -0
  167. data/test/test_helper.rb +44 -5
  168. metadata +387 -119
  169. data/bin/esp_repl +0 -60
  170. data/lib/esp_sdk/api.rb +0 -33
  171. data/lib/esp_sdk/client.rb +0 -62
  172. data/lib/esp_sdk/configure.rb +0 -40
  173. data/lib/esp_sdk/end_points/base.rb +0 -102
  174. data/lib/esp_sdk/end_points/contact_requests.rb +0 -6
  175. data/lib/esp_sdk/end_points/custom_signatures.rb +0 -41
  176. data/lib/esp_sdk/end_points/dashboard.rb +0 -35
  177. data/lib/esp_sdk/end_points/external_accounts.rb +0 -9
  178. data/lib/esp_sdk/end_points/organizations.rb +0 -6
  179. data/lib/esp_sdk/end_points/reports.rb +0 -6
  180. data/lib/esp_sdk/end_points/services.rb +0 -6
  181. data/lib/esp_sdk/end_points/signatures.rb +0 -39
  182. data/lib/esp_sdk/end_points/sub_organizations.rb +0 -6
  183. data/lib/esp_sdk/end_points/teams.rb +0 -6
  184. data/lib/esp_sdk/end_points/users.rb +0 -6
  185. data/lib/esp_sdk/exceptions.rb +0 -8
  186. data/lib/esp_sdk/extensions/rest_client/request.rb +0 -9
  187. data/lib/esp_sdk/repl.rb +0 -61
  188. data/lib/esp_sdk/version.rb +0 -3
  189. data/test/esp_sdk/api_test.rb +0 -36
  190. data/test/esp_sdk/client_test.rb +0 -129
  191. data/test/esp_sdk/configure_test.rb +0 -65
  192. data/test/esp_sdk/end_points/.keep +0 -0
  193. data/test/esp_sdk/end_points/base_test.rb +0 -230
  194. data/test/esp_sdk/end_points/custom_signatures_test.rb +0 -90
  195. data/test/esp_sdk/end_points/dashboard_test.rb +0 -55
  196. data/test/esp_sdk/end_points/external_accounts_test.rb +0 -20
  197. data/test/esp_sdk/end_points/signatures_test.rb +0 -83
  198. data/test/esp_sdk/exceptions_test.rb +0 -41
  199. data/test/esp_sdk_test.rb +0 -70
@@ -0,0 +1,113 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ module ESP
4
+ class UserTest < ActiveSupport::TestCase
5
+ context ESP::User do
6
+ context '#create' do
7
+ should 'not be implemented' do
8
+ assert_raises ESP::NotImplementedError do
9
+ ESP::User.create(name: 'test')
10
+ end
11
+ end
12
+ end
13
+
14
+ context '#update' do
15
+ should 'not be implemented' do
16
+ u = build(:user)
17
+ assert_raises ESP::NotImplementedError do
18
+ u.save
19
+ end
20
+ end
21
+ end
22
+
23
+ context '#destroy' do
24
+ should 'not be implemented' do
25
+ u = build(:user)
26
+ assert_raises ESP::NotImplementedError do
27
+ u.destroy
28
+ end
29
+ end
30
+ end
31
+
32
+ context '#organization' do
33
+ should 'call the api' do
34
+ u = build(:user, organization_id: 1)
35
+ stub_org = stub_request(:get, %r{organizations/#{u.organization_id}.json*}).to_return(body: json(:organization))
36
+
37
+ u.organization
38
+
39
+ assert_requested(stub_org)
40
+ end
41
+ end
42
+
43
+ context '#sub_organizations' do
44
+ should 'call the api' do
45
+ u = build(:user, sub_organization_ids: [1, 2])
46
+ stub_request(:get, /sub_organizations.json*/).to_return(body: json_list(:sub_organization, 2))
47
+
48
+ u.sub_organizations
49
+
50
+ assert_requested(:get, /sub_organizations.json*/) do |req|
51
+ assert_equal "filter[id_in][0]=#{u.sub_organization_ids.first}&filter[id_in][1]=#{u.sub_organization_ids.second}", URI.unescape(req.uri.query)
52
+ end
53
+ end
54
+ end
55
+
56
+ context '#teams' do
57
+ should 'call the api' do
58
+ u = build(:user, team_ids: [1, 2])
59
+ stub_request(:get, /teams.json*/).to_return(body: json_list(:team, 2))
60
+
61
+ u.teams
62
+
63
+ assert_requested(:get, /teams.json*/) do |req|
64
+ assert_equal "filter[id_in][0]=#{u.team_ids.first}&filter[id_in][1]=#{u.team_ids.second}", URI.unescape(req.uri.query)
65
+ end
66
+ end
67
+ end
68
+
69
+ context 'live calls' do
70
+ setup do
71
+ skip "Make sure you run the live calls locally to ensure proper integration" if ENV['CI_SERVER']
72
+ WebMock.allow_net_connect!
73
+ end
74
+
75
+ teardown do
76
+ WebMock.disable_net_connect!
77
+ end
78
+
79
+ context '#organization' do
80
+ should 'return an organization' do
81
+ u = ESP::User.last
82
+
83
+ org = u.organization
84
+
85
+ assert_equal u.organization_id, org.id
86
+ end
87
+ end
88
+
89
+ context '#sub_organizations' do
90
+ should 'return an array of sub_organizations' do
91
+ u = ESP::User.last
92
+
93
+ sub_orgs = u.sub_organizations
94
+
95
+ assert_equal u.sub_organization_ids.count, sub_orgs.count
96
+ assert_equal u.sub_organization_ids, sub_orgs.map(&:id)
97
+ end
98
+ end
99
+
100
+ context '#teams' do
101
+ should 'return an array of teams' do
102
+ u = ESP::User.last
103
+
104
+ teams = u.teams
105
+
106
+ assert_equal u.team_ids.count, teams.count
107
+ assert_equal u.team_ids.sort, teams.map(&:id).sort
108
+ end
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
data/test/esp_test.rb ADDED
@@ -0,0 +1,139 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/test_helper')
2
+
3
+ class ESPTest < ActiveSupport::TestCase
4
+ context ESP do
5
+ setup do
6
+ @original_access_key_id = ESP.access_key_id
7
+ @original_secret_access_key = ESP.secret_access_key
8
+ end
9
+
10
+ teardown do
11
+ ESP.access_key_id = @original_access_key_id
12
+ ESP.secret_access_key = @original_secret_access_key
13
+ end
14
+
15
+ context '.access_key_id' do
16
+ should 'be set manually' do
17
+ ESP.access_key_id = '1234'
18
+
19
+ assert_equal '1234', ESP.access_key_id
20
+ assert_equal '1234', ESP::Resource.hmac_access_id
21
+ end
22
+
23
+ should 'be set from an environment variable' do
24
+ ESP.access_key_id = nil
25
+ ENV['ESP_ACCESS_KEY_ID'] = '4321'
26
+
27
+ assert_equal '4321', ESP.access_key_id
28
+ end
29
+ end
30
+
31
+ context '.secret_access_key' do
32
+ should 'be set manually' do
33
+ ESP.secret_access_key = '1234'
34
+
35
+ assert_equal '1234', ESP.secret_access_key
36
+ assert_equal '1234', ESP::Resource.hmac_secret_key
37
+ end
38
+
39
+ should 'be set from an environment variable' do
40
+ ESP.secret_access_key = nil
41
+ ENV['ESP_SECRET_ACCESS_KEY'] = '4321'
42
+
43
+ assert_equal '4321', ESP.secret_access_key
44
+ end
45
+ end
46
+
47
+ context '.host=' do
48
+ setup do
49
+ ESP.host = nil
50
+ end
51
+
52
+ teardown do
53
+ ESP.host = nil
54
+ ENV['ESP_HOST'] = nil
55
+ end
56
+
57
+ should 'set ESP::Resource.site' do
58
+ ESP.host = 'http://sample.com'
59
+
60
+ assert_equal URI.parse("http://sample.com#{ESP::PATH}"), ESP::Resource.site
61
+ end
62
+ end
63
+
64
+ context '.site' do
65
+ setup do
66
+ ESP.host = nil
67
+ end
68
+
69
+ teardown do
70
+ ESP.host = nil
71
+ ENV['ESP_HOST'] = nil
72
+ end
73
+
74
+ should "return manually set host with path when set" do
75
+ ESP.host = 'http://sample.com'
76
+
77
+ assert_equal URI.parse("http://sample.com#{ESP::PATH}"), ESP::Resource.site
78
+ end
79
+
80
+ should 'should return the test host with path' do
81
+ assert_equal "#{ESP::HOST[ESP.env.to_sym]}#{ESP::PATH}", ESP.site
82
+ end
83
+
84
+ should "return ENV['ESP_HOST'] with path when in appliance env" do
85
+ ENV['ESP_HOST'] = 'https://sample.com'
86
+ ESP.stubs(:env).returns('appliance')
87
+ assert_equal "https://sample.com#{ESP::PATH}", ESP.site
88
+ end
89
+ end
90
+
91
+ context '.configure' do
92
+ setup do
93
+ ESP.host = nil
94
+ end
95
+
96
+ teardown do
97
+ ESP.host = nil
98
+ end
99
+
100
+ should 'set site, access_key_id, secret_access_key' do
101
+ ESP.configure do |config|
102
+ config.host = 'https://sample.com'
103
+ config.access_key_id = '1234'
104
+ config.secret_access_key = '5678'
105
+ end
106
+
107
+ assert_equal "https://sample.com#{ESP::PATH}", ESP.site
108
+ assert_equal URI.parse("https://sample.com#{ESP::PATH}"), ESP::Resource.site
109
+ assert_equal '1234', ESP.access_key_id
110
+ assert_equal '1234', ESP::Resource.hmac_access_id
111
+ assert_equal '5678', ESP.secret_access_key
112
+ assert_equal '5678', ESP::Resource.hmac_secret_key
113
+ end
114
+ end
115
+
116
+ context '.env' do
117
+ setup do
118
+ ESP.instance_variable_set(:@env, nil)
119
+ end
120
+
121
+ teardown do
122
+ ESP.instance_variable_set(:@env, nil)
123
+ ENV['ESP_ENV'] = 'test'
124
+ ENV['RAILS_ENV'] = 'test'
125
+ end
126
+
127
+ should 'return production when ENV is not set' do
128
+ ENV['ESP_ENV'] = nil
129
+ ENV['RAILS_ENV'] = nil
130
+ assert_predicate ESP.env, :production?
131
+ end
132
+
133
+ should 'return test when ENV[ESP_ENV] is set to test' do
134
+ ENV['ESP_ENV'] = 'test'
135
+ assert_predicate ESP.env, :test?
136
+ end
137
+ end
138
+ end
139
+ end
@@ -0,0 +1,234 @@
1
+ FactoryGirl.define do
2
+ factory :alert, class: 'ESP::Alert' do
3
+ skip_create
4
+
5
+ sequence(:id) { |n| n }
6
+ type "alerts"
7
+ created_at { Time.current }
8
+ status "fail"
9
+ resource "resource-3"
10
+ updated_at nil
11
+ metadata { { abc: 123 } }
12
+ started_at { Time.current }
13
+ ended_at nil
14
+ relationships do
15
+ {
16
+ external_account: {
17
+ data: {
18
+ type: "external_accounts",
19
+ id: "1015"
20
+ },
21
+ links: {
22
+ related: "http://test.host/api/v2/external_accounts/1015.json"
23
+ }
24
+ },
25
+ region: {
26
+ data: {
27
+ type: "regions",
28
+ id: "1014"
29
+ }
30
+ },
31
+ signature: {
32
+ data: {
33
+ type: "signatures",
34
+ id: "1013"
35
+ },
36
+ links: {
37
+ related: "http://test.host/api/v2/signatures/1013.json"
38
+ }
39
+ },
40
+ custom_signature: {
41
+ data: nil
42
+ },
43
+ suppression: {
44
+ data: {
45
+ id: "1",
46
+ type: "suppressions"
47
+ },
48
+ links: {
49
+ related: "http://test.host/api/v2/suppressions/1.json"
50
+ }
51
+ },
52
+ cloud_trail_events: {
53
+ data: [
54
+ {
55
+ type: "cloud_trail_events",
56
+ id: "1"
57
+ }
58
+ ],
59
+ links: {
60
+ related: "http://test.host/api/v2/alerts/1017/cloud_trail_events.json"
61
+ }
62
+ },
63
+ tags: {
64
+ data: [
65
+ {
66
+ id: "1",
67
+ type: "tags"
68
+ },
69
+ {
70
+ id: "2",
71
+ type: "tags"
72
+ }
73
+ ]
74
+ }
75
+ }
76
+ end
77
+ included do
78
+ [
79
+ {
80
+ id: "1015",
81
+ type: "external_accounts",
82
+ attributes: {
83
+ account: "5",
84
+ arn: "arn:aws:iam::5:role/test_sts_role",
85
+ created_at: "2015-09-11T21:12:15.183Z",
86
+ external_id: "test_sts_external_id_1",
87
+ name: nil,
88
+ updated_at: nil,
89
+ user_attribution_role: nil
90
+ },
91
+ relationships: {
92
+ organization: {
93
+ data: {
94
+ type: "organizations",
95
+ id: "5"
96
+ },
97
+ links: {
98
+ related: "http://test.host/api/v2/organizations/5.json"
99
+ }
100
+ },
101
+ sub_organization: {
102
+ data: {
103
+ type: "sub_organizations",
104
+ id: "5"
105
+ },
106
+ links: {
107
+ related: "http://test.host/api/v2/sub_organizations/5.json"
108
+ }
109
+ },
110
+ team: {
111
+ data: {
112
+ type: "teams",
113
+ id: "5"
114
+ },
115
+ links: {
116
+ related: "http://test.host/api/v2/teams/5.json"
117
+ }
118
+ },
119
+ user_attribution_role: {
120
+ data: nil
121
+ }
122
+ }
123
+ },
124
+ {
125
+ id: "1014",
126
+ type: "regions",
127
+ attributes: {
128
+ code: "us_east_test_3"
129
+ }
130
+ },
131
+ {
132
+ id: "1013",
133
+ type: "signatures",
134
+ attributes: {
135
+ created_at: "2015-09-11T21:12:15.192Z",
136
+ description: "\"Some description for some test\"",
137
+ identifier: "3 Unique ID",
138
+ name: "3_test_signature",
139
+ resolution: "\"Turn on some setting\"",
140
+ risk_level: "High",
141
+ updated_at: nil
142
+ },
143
+ relationships: {
144
+ service: {
145
+ data: {
146
+ type: "services",
147
+ id: "3"
148
+ },
149
+ links: {
150
+ related: "http://test.host/api/v2/services/3.json"
151
+ }
152
+ }
153
+ }
154
+ },
155
+ {
156
+ id: "1",
157
+ type: "cloud_trail_events",
158
+ attributes: {
159
+ event_id: "1",
160
+ event_name: "1",
161
+ event_time: "2015-09-11T21:12:14.661Z",
162
+ username: "johndoe",
163
+ ip_address: "123.0.0.123",
164
+ user_agent: "Chrome"
165
+ }
166
+ },
167
+ {
168
+ id: "1",
169
+ type: "suppressions",
170
+ attributes: {
171
+ created_at: "2015-10-16T18:34:19.464Z",
172
+ reason: "I dont like this",
173
+ status: "setup",
174
+ updated_at: "2015-10-16T18:34:19.464Z",
175
+ configuration: {
176
+ suppression_type: "regions",
177
+ resource: nil,
178
+ regions: [
179
+ {
180
+ id: "4",
181
+ type: "regions",
182
+ attributes: {
183
+ code: "us_east_test_4"
184
+ }
185
+ }
186
+ ],
187
+ external_accounts: []
188
+ }
189
+ },
190
+ relationships: {
191
+ organization: {
192
+ data: {
193
+ id: "4",
194
+ type: "organizations"
195
+ },
196
+ links: {
197
+ related: "http://test.host/api/v2/organizations/4.json"
198
+ }
199
+ },
200
+ created_by: {
201
+ data: {
202
+ id: "1",
203
+ type: "users"
204
+ },
205
+ links: {
206
+ related: "http://test.host/api/v2/users/1.json"
207
+ }
208
+ }
209
+ }
210
+ },
211
+ {
212
+ id: "1",
213
+ type: "tags",
214
+ attributes: {
215
+ key: "Name",
216
+ value: "abc123",
217
+ created_at: "2015-10-16T18:34:19.569Z",
218
+ updated_at: "2015-10-16T18:34:19.569Z"
219
+ }
220
+ },
221
+ {
222
+ id: "2",
223
+ type: "tags",
224
+ attributes: {
225
+ key: "Name",
226
+ value: "abc123",
227
+ created_at: "2015-10-16T18:34:19.571Z",
228
+ updated_at: "2015-10-16T18:34:19.571Z"
229
+ }
230
+ }
231
+ ]
232
+ end
233
+ end
234
+ end
@@ -0,0 +1,16 @@
1
+ FactoryGirl.define do
2
+ factory :contact_request, class: 'ESP::ContactRequest' do
3
+ skip_create
4
+
5
+ sequence(:id) { |n| n }
6
+ type "cloud_trail_events"
7
+ title "test2"
8
+ event_id "1"
9
+ event_name "1"
10
+ event_time "2015-10-16T19:07:24.434Z"
11
+ raw_event { { test: "event data" } }
12
+ username "johndoe"
13
+ ip_address "123.0.0.123"
14
+ user_agent "Chrome"
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ FactoryGirl.define do
2
+ factory :cloud_trail_event, class: 'ESP::CloudTrailEvent' do
3
+ skip_create
4
+
5
+ sequence(:id) { |n| n }
6
+ type "cloud_trail_events"
7
+ event_id "1"
8
+ event_name "1"
9
+ event_time { Time.current }
10
+ username "johndoe"
11
+ ip_address "123.0.0.123"
12
+ user_agent "Chrome"
13
+ end
14
+ end
@@ -0,0 +1,30 @@
1
+ FactoryGirl.define do
2
+ factory :custom_signature, class: 'ESP::CustomSignature' do
3
+ skip_create
4
+
5
+ sequence(:id) { |n| n }
6
+ type "custom_signatures"
7
+ created_at { Time.current }
8
+ active true
9
+ description "Test description"
10
+ identifier "AWS::Test::001"
11
+ name "Test"
12
+ resolution "Test resolution"
13
+ risk_level "Medium"
14
+ signature "Some javascript"
15
+ language "javascript"
16
+ updated_at nil
17
+ relationships do
18
+ { organization: {
19
+ data: {
20
+ type: "organizations",
21
+ id: "1003"
22
+ },
23
+ links: {
24
+ related: "http://test.host/api/v2/organizations/1003.json"
25
+ }
26
+ }
27
+ }
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,91 @@
1
+ FactoryGirl.define do
2
+ factory :dashboard, class: 'ESP::Dashboard' do
3
+ skip_create
4
+
5
+ type "reports"
6
+ team_name "Operations 1"
7
+ sub_organization_name "IT Department 1"
8
+ organization_name "Test Organization 1"
9
+ created_at { Time.current }
10
+ updated_at { Time.current }
11
+ relationships do
12
+ { stat: {
13
+ data: {
14
+ type: "stats",
15
+ id: "1"
16
+ },
17
+ links: {
18
+ related: "http://test.host/api/v2/reports/1/stats.json"
19
+ }
20
+ }
21
+ }
22
+ end
23
+ included do
24
+ [
25
+ {
26
+ id: "1",
27
+ type: "stats",
28
+ attributes: {
29
+ total: 59,
30
+ stat_signatures: [
31
+ {
32
+ signature: {
33
+ id: 1,
34
+ name: "1_test_signature",
35
+ risk_level: "High",
36
+ service: {
37
+ code: "S1",
38
+ id: 1,
39
+ name: "SSS"
40
+ }
41
+ },
42
+ total_pass: 2,
43
+ total_fail: 6,
44
+ total_warn: 8,
45
+ total_error: 1,
46
+ total_new_1h: 7,
47
+ total_new_1d: 14
48
+ }
49
+ ],
50
+ stat_custom_signatures: [
51
+ {
52
+ custom_signature: {
53
+ id: 1,
54
+ name: "Test",
55
+ risk_level: "Medium"
56
+ },
57
+ total_pass: 8,
58
+ total_fail: 2,
59
+ total_warn: 4,
60
+ total_error: 6,
61
+ total_new_1h: 8,
62
+ total_new_1d: 12
63
+ }
64
+ ],
65
+ stat_regions: [
66
+ {
67
+ region: {
68
+ id: 1,
69
+ code: "us_east_test_1"
70
+ },
71
+ total_pass: 16,
72
+ total_fail: 18,
73
+ total_warn: 12,
74
+ total_error: 11,
75
+ total_high: 16,
76
+ total_medium: 18,
77
+ total_low: 20,
78
+ total_new_1h_high: 4,
79
+ total_new_1h_medium: 5,
80
+ total_new_1h_low: 9,
81
+ total_new_1d_high: 8,
82
+ total_new_1d_medium: 8,
83
+ total_new_1d_low: 13
84
+ }
85
+ ]
86
+ }
87
+ }
88
+ ]
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,24 @@
1
+ FactoryGirl.define do
2
+ factory :error, class: 'ActiveResource::Base' do
3
+ skip_create
4
+
5
+ errors do
6
+ [{ status: '401',
7
+ title: 'Access Denied' }]
8
+ end
9
+
10
+ trait :active_record do
11
+ errors do
12
+ [{ status: '401',
13
+ title: "Name can't be blank",
14
+ meta: { name: "can't be blank" } },
15
+ { status: '401',
16
+ title: "Name is invalid",
17
+ meta: { name: "is invalid" } },
18
+ { status: '401',
19
+ title: "Description can't be blank",
20
+ meta: { description: "can't be blank" } }]
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,44 @@
1
+ FactoryGirl.define do
2
+ factory :external_account, class: 'ESP::ExternalAccount' do
3
+ skip_create
4
+
5
+ sequence(:id) { |n| n }
6
+ type "external_accounts"
7
+ account "762160981991"
8
+ arn "arn:aws:iam::762160981991:role/Evident-Service-Role-Kevin"
9
+ created_at { Time.current }
10
+ external_id "913310e7-6a9c-49f7-bd69-120721ec1122"
11
+ name "Dev"
12
+ updated_at { Time.current }
13
+ relationships do
14
+ { organization: {
15
+ data: {
16
+ type: "organizations",
17
+ id: "1"
18
+ },
19
+ links: {
20
+ related: "http://localhost:3000/api/v2/organizations/1.json"
21
+ }
22
+ },
23
+ sub_organization: {
24
+ data: {
25
+ type: "sub_organizations",
26
+ id: "1"
27
+ },
28
+ links: {
29
+ related: "http://localhost:3000/api/v2/sub_organizations/1.json"
30
+ }
31
+ },
32
+ team: {
33
+ data: {
34
+ type: "teams",
35
+ id: "1"
36
+ },
37
+ links: {
38
+ related: "http://localhost:3000/api/v2/teams/1.json"
39
+ }
40
+ }
41
+ }
42
+ end
43
+ end
44
+ end