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,90 @@
1
+ FactoryGirl.define do
2
+ factory :suppression_region, class: 'ESP::Suppression::Region' do
3
+ skip_create
4
+
5
+ sequence(:id) { |n| n }
6
+ type "suppressions"
7
+ created_at { Time.current }
8
+ reason "because"
9
+ status "active"
10
+ updated_at { Time.current }
11
+ configuration do
12
+ { suppression_type: "regions",
13
+ resource: nil,
14
+ regions: [
15
+ {
16
+ id: "1",
17
+ type: "regions",
18
+ attributes: {
19
+ code: "ap_northeast_1"
20
+ }
21
+ }
22
+ ],
23
+ external_accounts: [
24
+ {
25
+ id: "1",
26
+ type: "external_accounts",
27
+ attributes: {
28
+ account: "762160981991",
29
+ arn: "arn:aws:iam::762160981991:role/Evident-Service-Role-Kevin",
30
+ created_at: "2015-09-23T14:43:47.000Z",
31
+ external_id: "913310e7-6a9c-49f7-bd69-120721ec1122",
32
+ name: "Dev",
33
+ updated_at: "2015-09-23T14:43:47.000Z"
34
+ },
35
+ relationships: {
36
+ organization: {
37
+ data: {
38
+ id: "1",
39
+ type: "organizations"
40
+ },
41
+ links: {
42
+ related: "http://localhost:3000/api/v2/organizations/1.json"
43
+ }
44
+ },
45
+ sub_organization: {
46
+ data: {
47
+ id: "1",
48
+ type: "sub_organizations"
49
+ },
50
+ links: {
51
+ related: "http://localhost:3000/api/v2/sub_organizations/1.json"
52
+ }
53
+ },
54
+ team: {
55
+ data: {
56
+ id: "1",
57
+ type: "teams"
58
+ },
59
+ links: {
60
+ related: "http://localhost:3000/api/v2/teams/1.json"
61
+ }
62
+ }
63
+ }
64
+ }
65
+ ]
66
+ }
67
+ end
68
+ relationships do
69
+ { organization: {
70
+ data: {
71
+ id: "1",
72
+ type: "organizations"
73
+ },
74
+ links: {
75
+ related: "http://localhost:3000/api/v2/organizations/1.json"
76
+ }
77
+ },
78
+ created_by: {
79
+ data: {
80
+ id: "1",
81
+ type: "users"
82
+ },
83
+ links: {
84
+ related: "http://localhost:3000/api/v2/users/1.json"
85
+ }
86
+ }
87
+ }
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,117 @@
1
+ FactoryGirl.define do
2
+ factory :suppression_signature, class: 'ESP::Suppression::Signature' do
3
+ skip_create
4
+
5
+ sequence(:id) { |n| n }
6
+ type "suppressions"
7
+ created_at { Time.current }
8
+ reason "because"
9
+ status "active"
10
+ updated_at { Time.current }
11
+ configuration do
12
+ { suppression_type: "signatures",
13
+ resource: nil,
14
+ signatures: [
15
+ {
16
+ id: "67",
17
+ type: "signatures",
18
+ attributes: {
19
+ created_at: "2015-09-23T14:37:49.000Z",
20
+ description: "\"This signature detects the presence of \\\"Global Edit\\\" ACL permissions on S3 Bucket(s) for the All Users group. These permissions permit anyone, malicious or not, to edit the bucket and/or contents of your S3 bucket if they can guess the namespace. Since the S3 service does not protect the namespace other than with ACLs, you risk exposing critical data by leaving this open.\"",
21
+ identifier: "AWS:SSS-004",
22
+ name: "S3 Bucket has Global Edit ACL Permissions Enabled",
23
+ resolution: "\"Log into your AWS console and select the S3 service. Locate the affected bucket and click on it. Select the \\\"Properties\\\" button in the upper right of the window, and expand the \\\"Permissions\\\" object. Remove the \\\"Edit\\\" checkbox next to \\\"Everyone\\\". More information about managing S3 access with ACLs can be found in the S3 ACL Documentation.\"",
24
+ risk_level: "High",
25
+ updated_at: "2015-09-23T14:37:49.000Z"
26
+ },
27
+ relationships: {
28
+ service: {
29
+ data: {
30
+ id: "2",
31
+ type: "services"
32
+ },
33
+ links: {
34
+ related: "http://localhost:3000/api/v2/services/2.json"
35
+ }
36
+ }
37
+ }
38
+ }
39
+ ],
40
+ custom_signatures: [],
41
+ regions: [
42
+ {
43
+ id: "1",
44
+ type: "regions",
45
+ attributes: {
46
+ code: "ap_northeast_1"
47
+ }
48
+ }
49
+ ],
50
+ external_accounts: [
51
+ {
52
+ id: "1",
53
+ type: "external_accounts",
54
+ attributes: {
55
+ account: "762160981991",
56
+ arn: "arn:aws:iam::762160981991:role/Evident-Service-Role-Kevin",
57
+ created_at: "2015-09-23T14:43:47.000Z",
58
+ external_id: "913310e7-6a9c-49f7-bd69-120721ec1122",
59
+ name: "Dev",
60
+ updated_at: "2015-09-23T14:43:47.000Z"
61
+ },
62
+ relationships: {
63
+ organization: {
64
+ data: {
65
+ id: "1",
66
+ type: "organizations"
67
+ },
68
+ links: {
69
+ related: "http://localhost:3000/api/v2/organizations/1.json"
70
+ }
71
+ },
72
+ sub_organization: {
73
+ data: {
74
+ id: "1",
75
+ type: "sub_organizations"
76
+ },
77
+ links: {
78
+ related: "http://localhost:3000/api/v2/sub_organizations/1.json"
79
+ }
80
+ },
81
+ team: {
82
+ data: {
83
+ id: "1",
84
+ type: "teams"
85
+ },
86
+ links: {
87
+ related: "http://localhost:3000/api/v2/teams/1.json"
88
+ }
89
+ }
90
+ }
91
+ }
92
+ ]
93
+ }
94
+ end
95
+ relationships do
96
+ { organization: {
97
+ data: {
98
+ id: "1",
99
+ type: "organizations"
100
+ },
101
+ links: {
102
+ related: "http://localhost:3000/api/v2/organizations/1.json"
103
+ }
104
+ },
105
+ created_by: {
106
+ data: {
107
+ id: "1",
108
+ type: "users"
109
+ },
110
+ links: {
111
+ related: "http://localhost:3000/api/v2/users/1.json"
112
+ }
113
+ }
114
+ }
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,111 @@
1
+ FactoryGirl.define do
2
+ factory :suppression_unique_identifier, class: 'ESP::Suppression::UniqueIdentifier' do
3
+ skip_create
4
+
5
+ sequence(:id) { |n| n }
6
+ type "suppressions"
7
+ created_at { Time.current }
8
+ reason "because"
9
+ status "active"
10
+ updated_at { Time.current }
11
+ configuration do
12
+ { suppression_type: "unique_identifiers",
13
+ resource: "test-cloudtrail-johnathan",
14
+ custom_signature: nil,
15
+ signature: {
16
+ id: "67",
17
+ type: "signatures",
18
+ attributes: {
19
+ created_at: "2015-09-23T14:37:49.000Z",
20
+ description: "\"This signature detects the presence of \\\"Global Edit\\\" ACL permissions on S3 Bucket(s) for the All Users group. These permissions permit anyone, malicious or not, to edit the bucket and/or contents of your S3 bucket if they can guess the namespace. Since the S3 service does not protect the namespace other than with ACLs, you risk exposing critical data by leaving this open.\"",
21
+ identifier: "AWS:SSS-004",
22
+ name: "S3 Bucket has Global Edit ACL Permissions Enabled",
23
+ resolution: "\"Log into your AWS console and select the S3 service. Locate the affected bucket and click on it. Select the \\\"Properties\\\" button in the upper right of the window, and expand the \\\"Permissions\\\" object. Remove the \\\"Edit\\\" checkbox next to \\\"Everyone\\\". More information about managing S3 access with ACLs can be found in the S3 ACL Documentation.\"",
24
+ risk_level: "High",
25
+ updated_at: "2015-09-23T14:37:49.000Z"
26
+ },
27
+ relationships: {
28
+ service: {
29
+ data: {
30
+ id: "2",
31
+ type: "services"
32
+ },
33
+ links: {
34
+ related: "http://localhost:3000/api/v2/services/2.json"
35
+ }
36
+ }
37
+ }
38
+ },
39
+ region: {
40
+ id: "1",
41
+ type: "regions",
42
+ attributes: {
43
+ code: "ap_northeast_1"
44
+ }
45
+ },
46
+ external_account: {
47
+ id: "1",
48
+ type: "external_accounts",
49
+ attributes: {
50
+ account: "762160981991",
51
+ arn: "arn:aws:iam::762160981991:role/Evident-Service-Role-Kevin",
52
+ created_at: "2015-09-23T14:43:47.000Z",
53
+ external_id: "913310e7-6a9c-49f7-bd69-120721ec1122",
54
+ name: "Dev",
55
+ updated_at: "2015-09-23T14:43:47.000Z"
56
+ },
57
+ relationships: {
58
+ organization: {
59
+ data: {
60
+ id: "1",
61
+ type: "organizations"
62
+ },
63
+ links: {
64
+ related: "http://localhost:3000/api/v2/organizations/1.json"
65
+ }
66
+ },
67
+ sub_organization: {
68
+ data: {
69
+ id: "1",
70
+ type: "sub_organizations"
71
+ },
72
+ links: {
73
+ related: "http://localhost:3000/api/v2/sub_organizations/1.json"
74
+ }
75
+ },
76
+ team: {
77
+ data: {
78
+ id: "1",
79
+ type: "teams"
80
+ },
81
+ links: {
82
+ related: "http://localhost:3000/api/v2/teams/1.json"
83
+ }
84
+ }
85
+ }
86
+ }
87
+ }
88
+ end
89
+ relationships do
90
+ { organization: {
91
+ data: {
92
+ id: "1",
93
+ type: "organizations"
94
+ },
95
+ links: {
96
+ related: "http://localhost:3000/api/v2/organizations/1.json"
97
+ }
98
+ },
99
+ created_by: {
100
+ data: {
101
+ id: "1",
102
+ type: "users"
103
+ },
104
+ links: {
105
+ related: "http://localhost:3000/api/v2/users/1.json"
106
+ }
107
+ }
108
+ }
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,71 @@
1
+ FactoryGirl.define do
2
+ factory :suppression, class: 'ESP::Suppression' do
3
+ skip_create
4
+
5
+ sequence(:id) { |n| n }
6
+ type "suppressions"
7
+ created_at { Time.current }
8
+ reason "I said"
9
+ resource ''
10
+ suppression_type "regions"
11
+ status "active"
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
+ created_by: {
24
+ data: {
25
+ type: "users",
26
+ id: "23"
27
+ },
28
+ links: {
29
+ related: "http://localhost:3000/api/v2/users/23.json"
30
+ }
31
+ },
32
+ regions: {
33
+ data: [
34
+ {
35
+ id: "1",
36
+ type: "regions"
37
+ }
38
+ ],
39
+ links: {
40
+ related: "http://test.host/api/v2/regions.json?filter%5Bsuppressions_id_eq%5D=4"
41
+ }
42
+ },
43
+ external_accounts: {
44
+ data: [
45
+ {
46
+ id: "1015",
47
+ type: "external_accounts"
48
+ }
49
+ ],
50
+ links: {
51
+ related: "http://test.host/api/v2/external_accounts.json?filter%5Bsuppressions_id_eq%5D=4"
52
+ }
53
+ },
54
+ signatures: {
55
+ data: [
56
+ {
57
+ id: "6",
58
+ type: "signatures"
59
+ }
60
+ ],
61
+ links: {
62
+ related: "http://test.host/api/v2/signatures.json?filter%5Bid_in%5D%5B%5D=6"
63
+ }
64
+ },
65
+ custom_signatures: {
66
+ data: []
67
+ }
68
+ }
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,12 @@
1
+ FactoryGirl.define do
2
+ factory :tag, class: 'ESP::Tag' do
3
+ skip_create
4
+
5
+ sequence(:id) { |n| n }
6
+ type "services"
7
+ key "Name"
8
+ value "abc123"
9
+ created_at { Time.current }
10
+ updated_at { Time.current }
11
+ end
12
+ end
@@ -0,0 +1,32 @@
1
+ FactoryGirl.define do
2
+ factory :team, class: 'ESP::Team' do
3
+ skip_create
4
+
5
+ sequence(:id) { |n| n }
6
+ type "teams"
7
+ name "Default Team"
8
+ created_at { Time.current }
9
+ updated_at { Time.current }
10
+ relationships do
11
+ { sub_organization: {
12
+ data: {
13
+ type: "sub_organizations",
14
+ id: "2"
15
+ },
16
+ links: {
17
+ related: "http://localhost:3000/api/v2/sub_organizations/2.json"
18
+ }
19
+ },
20
+ organization: {
21
+ data: {
22
+ type: "organizations",
23
+ id: "2"
24
+ },
25
+ links: {
26
+ related: "http://localhost:3000/api/v2/organizations/2.json"
27
+ }
28
+ }
29
+ }
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,54 @@
1
+ FactoryGirl.define do
2
+ factory :user, class: 'ESP::User' do
3
+ skip_create
4
+
5
+ sequence(:id) { |n| n }
6
+ created_at { Time.current }
7
+ email "customer@email.com"
8
+ time_zone "UTC"
9
+ updated_at { Time.current }
10
+ first_name "Custom"
11
+ last_name "McGaa"
12
+ phone "8135551234"
13
+ role "customer"
14
+ mfa_enabled false
15
+ disable_daily_emails false
16
+ locked false
17
+ locked_at nil
18
+
19
+ relationships do
20
+ { organization: {
21
+ data: {
22
+ type: "organizations",
23
+ id: "2"
24
+ },
25
+ links: {
26
+ related: "http://localhost:3000/api/v2/organizations/2.json"
27
+ }
28
+ },
29
+ sub_organizations: {
30
+ data: [
31
+ {
32
+ type: "sub_organizations",
33
+ id: "2"
34
+ }
35
+ ],
36
+ links: {
37
+ related: "http://localhost:3000/api/v2/sub_organizations.json?filter%5Bq%5D%5Bid_in%5D%5B%5D=1"
38
+ }
39
+ },
40
+ teams: {
41
+ data: [
42
+ {
43
+ type: "teams",
44
+ id: "2"
45
+ }
46
+ ],
47
+ links: {
48
+ related: "http://localhost:3000/api/v2/teams.json?filter%5Bq%5D%5Bid_in%5D%5B%5D=1"
49
+ }
50
+ }
51
+ }
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,25 @@
1
+ class JsonStrategy
2
+ def initialize
3
+ @strategy = FactoryGirl.strategy_by_name(:attributes_for).new
4
+ end
5
+
6
+ delegate :association, to: :@strategy
7
+
8
+ def result(evaluation)
9
+ convert_to_json_api_compliant_hash(@strategy.result(evaluation)).to_json
10
+ end
11
+
12
+ private
13
+
14
+ def convert_to_json_api_compliant_hash(attributes)
15
+ return attributes if attributes[:errors].present?
16
+ {}.tap do |h|
17
+ h['included'] = attributes.delete(:included)
18
+ h['data'] = {}
19
+ h['data']['id'] = attributes.delete(:id)
20
+ h['data']['type'] = attributes.delete(:type)
21
+ h['data']['relationships'] = attributes.delete(:relationships) if attributes[:relationships]
22
+ h['data']['attributes'] = attributes
23
+ end
24
+ end
25
+ end
data/test/test_helper.rb CHANGED
@@ -1,20 +1,59 @@
1
1
  ENV['ESP_ENV'] = 'test'
2
- require 'codeclimate-test-reporter'
3
- CodeClimate::TestReporter.start
2
+ require 'coveralls'
3
+ Coveralls.wear!
4
4
 
5
- require 'esp_sdk'
6
5
  require 'minitest/autorun'
7
6
  require 'minitest/reporters'
7
+ require 'factory_girl'
8
8
  require 'mocha/mini_test'
9
+ require 'bourne'
9
10
  require 'shoulda'
10
- require 'fakeweb'
11
+ require 'webmock/minitest'
11
12
  require 'awesome_print'
13
+ require 'rubygems'
14
+ require 'active_resource'
15
+ require_relative 'json_strategy'
16
+ require_relative '../lib/esp_sdk'
12
17
 
18
+ FactoryGirl.definition_file_paths = [File.expand_path('factories', File.dirname(__FILE__))]
19
+ FactoryGirl.find_definitions
20
+ FactoryGirl.register_strategy(:json, JsonStrategy)
13
21
  Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
14
22
 
15
23
  class ActiveSupport::TestCase
24
+ include FactoryGirl::Syntax::Methods # so we can use json(:object) instead of FactoryGirl.json(:object)
25
+
26
+ self.test_order = :random
27
+
16
28
  setup do
17
29
  # Clear stubs
18
- FakeWeb.clean_registry
30
+ WebMock.reset!
31
+ end
32
+
33
+ # factory girl helper to form the correct object when getting a collection of objects
34
+ def json_list(*args)
35
+ page_args = args.last.delete(:page) if args.last.present? && args.last.is_a?(Hash)
36
+ page_args ||= { number: 1, size: 20 }
37
+ json_array = super
38
+ data = json_array.map { |j| JSON.parse(j)['data'] }
39
+ links = build_links(data, page_args)
40
+ { 'data' => data.slice(0, page_args[:size]),
41
+ 'included' => JSON.parse(json_array.first)['included'],
42
+ "links" => links
43
+ }.to_json
44
+ end
45
+
46
+ private
47
+
48
+ def build_links(data, page)
49
+ current_page = page[:number]
50
+ last_page = (data.count.to_f / page[:size]).ceil
51
+ { "self" => "http://localhost:3000/api/v2/not_the_real_url/but_useful_for_testing.json?page%5Bnumber%5D=#{current_page}&page%5Bsize%5D=#{page[:size]}" }.tap do |links|
52
+ links["prev"] = "http://localhost:3000/api/v2/not_the_real_url/but_useful_for_testing.json?page%5Bnumber%5D=#{current_page - 1}&page%5Bsize%5D=#{page[:size]}" unless current_page == 1
53
+ unless current_page == last_page
54
+ links["next"] = "http://localhost:3000/api/v2/not_the_real_url/but_useful_for_testing.json?page%5Bnumber%5D=#{current_page + 1}&page%5Bsize%5D=#{page[:size]}"
55
+ links["last"] = "http://localhost:3000/api/v2/not_the_real_url/but_useful_for_testing.json?page%5Bnumber%5D=#{last_page}&page%5Bsize%5D=#{page[:size]}"
56
+ end
57
+ end
19
58
  end
20
59
  end