new_cfoundry 4.8.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (269) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/.gitmodules +3 -0
  4. data/.rspec +2 -0
  5. data/.ruby-gemset +1 -0
  6. data/.ruby-version +1 -0
  7. data/.travis.yml +11 -0
  8. data/Checkfile +2 -0
  9. data/Gemfile +3 -0
  10. data/LICENSE +987 -0
  11. data/NOTICE +10 -0
  12. data/README.md +9 -0
  13. data/Rakefile +14 -0
  14. data/VERSION +1 -0
  15. data/cfoundry.gemspec +40 -0
  16. data/config/locales/en.yml +168 -0
  17. data/lib/cc_api_stub/app_usage_events.rb +11 -0
  18. data/lib/cc_api_stub/applications.rb +57 -0
  19. data/lib/cc_api_stub/domains.rb +32 -0
  20. data/lib/cc_api_stub/events.rb +11 -0
  21. data/lib/cc_api_stub/frameworks.rb +22 -0
  22. data/lib/cc_api_stub/helper.rb +148 -0
  23. data/lib/cc_api_stub/login.rb +21 -0
  24. data/lib/cc_api_stub/organization_users.rb +27 -0
  25. data/lib/cc_api_stub/organizations.rb +82 -0
  26. data/lib/cc_api_stub/routes.rb +26 -0
  27. data/lib/cc_api_stub/runtimes.rb +22 -0
  28. data/lib/cc_api_stub/service_bindings.rb +22 -0
  29. data/lib/cc_api_stub/service_instances.rb +22 -0
  30. data/lib/cc_api_stub/services.rb +21 -0
  31. data/lib/cc_api_stub/space_users.rb +27 -0
  32. data/lib/cc_api_stub/spaces.rb +58 -0
  33. data/lib/cc_api_stub/users.rb +85 -0
  34. data/lib/cc_api_stub.rb +20 -0
  35. data/lib/cfoundry/auth_token.rb +63 -0
  36. data/lib/cfoundry/baseclient.rb +216 -0
  37. data/lib/cfoundry/chatty_hash.rb +46 -0
  38. data/lib/cfoundry/client.rb +42 -0
  39. data/lib/cfoundry/concerns/login_helpers.rb +14 -0
  40. data/lib/cfoundry/concerns/proxy_options.rb +17 -0
  41. data/lib/cfoundry/errors.rb +163 -0
  42. data/lib/cfoundry/rest_client.rb +317 -0
  43. data/lib/cfoundry/test_support.rb +3 -0
  44. data/lib/cfoundry/trace_helpers.rb +64 -0
  45. data/lib/cfoundry/uaaclient.rb +160 -0
  46. data/lib/cfoundry/upload_helpers.rb +222 -0
  47. data/lib/cfoundry/v2/app.rb +303 -0
  48. data/lib/cfoundry/v2/app_event.rb +13 -0
  49. data/lib/cfoundry/v2/app_instance.rb +74 -0
  50. data/lib/cfoundry/v2/app_usage_event.rb +14 -0
  51. data/lib/cfoundry/v2/base.rb +108 -0
  52. data/lib/cfoundry/v2/client.rb +104 -0
  53. data/lib/cfoundry/v2/domain.rb +20 -0
  54. data/lib/cfoundry/v2/event.rb +17 -0
  55. data/lib/cfoundry/v2/helper.rb +11 -0
  56. data/lib/cfoundry/v2/managed_service_instance.rb +12 -0
  57. data/lib/cfoundry/v2/model.rb +211 -0
  58. data/lib/cfoundry/v2/model_magic/attribute.rb +49 -0
  59. data/lib/cfoundry/v2/model_magic/client_extensions.rb +170 -0
  60. data/lib/cfoundry/v2/model_magic/has_summary.rb +49 -0
  61. data/lib/cfoundry/v2/model_magic/query_multi_value_helper.rb +21 -0
  62. data/lib/cfoundry/v2/model_magic/query_value_helper.rb +33 -0
  63. data/lib/cfoundry/v2/model_magic/queryable_by.rb +39 -0
  64. data/lib/cfoundry/v2/model_magic/to_many.rb +138 -0
  65. data/lib/cfoundry/v2/model_magic/to_one.rb +81 -0
  66. data/lib/cfoundry/v2/model_magic.rb +134 -0
  67. data/lib/cfoundry/v2/organization.rb +44 -0
  68. data/lib/cfoundry/v2/quota_definition.rb +12 -0
  69. data/lib/cfoundry/v2/route.rb +25 -0
  70. data/lib/cfoundry/v2/service.rb +22 -0
  71. data/lib/cfoundry/v2/service_auth_token.rb +9 -0
  72. data/lib/cfoundry/v2/service_binding.rb +10 -0
  73. data/lib/cfoundry/v2/service_broker.rb +12 -0
  74. data/lib/cfoundry/v2/service_instance.rb +14 -0
  75. data/lib/cfoundry/v2/service_plan.rb +16 -0
  76. data/lib/cfoundry/v2/space.rb +30 -0
  77. data/lib/cfoundry/v2/stack.rb +10 -0
  78. data/lib/cfoundry/v2/user.rb +93 -0
  79. data/lib/cfoundry/v2/user_provided_service_instance.rb +15 -0
  80. data/lib/cfoundry/validator.rb +41 -0
  81. data/lib/cfoundry/version.rb +4 -0
  82. data/lib/cfoundry/zip.rb +56 -0
  83. data/lib/cfoundry.rb +5 -0
  84. data/release_notes/release_1_5_3.md +177 -0
  85. data/release_notes/release_2.3.1.md +14 -0
  86. data/release_notes/release_2.3.3.md +38 -0
  87. data/release_notes/release_2.3.4.md +16 -0
  88. data/release_notes/release_2.3.5.md +14 -0
  89. data/release_notes/release_2.3.6.md +14 -0
  90. data/release_notes/release_2.3.6.rc1.md +29 -0
  91. data/release_notes/release_2.3.6.rc2.md +19 -0
  92. data/release_notes/release_2.3.7.rc1.md +14 -0
  93. data/release_notes/release_2.4.0.md +41 -0
  94. data/release_notes/release_2.4.1.rc1.md +58 -0
  95. data/release_notes/release_3.0.0.md +21 -0
  96. data/release_notes/release_3.0.1.md +16 -0
  97. data/release_notes/release_3.0.2.rc1.md +19 -0
  98. data/release_notes/release_4.0.0.md +19 -0
  99. data/release_notes/release_4.0.1.md +14 -0
  100. data/release_notes/release_4.0.2.rc1.md +14 -0
  101. data/release_notes/release_4.0.2.rc2.md +11 -0
  102. data/release_notes/release_4.0.2.rc3.md +11 -0
  103. data/release_notes/release_4.0.2.rc4.md +19 -0
  104. data/release_notes/release_4.0.2.rc5.md +14 -0
  105. data/release_notes/release_4.0.3.md +19 -0
  106. data/release_notes/release_4.0.4.rc1.md +14 -0
  107. data/release_notes/release_4.0.4.rc2.md +14 -0
  108. data/release_notes/release_4.1.0.md +19 -0
  109. data/release_notes/release_4.2.0.rc.md +24 -0
  110. data/release_notes/release_4.3.0.md +22 -0
  111. data/release_notes/release_4.3.1.md +14 -0
  112. data/release_notes/release_4.3.10.md +14 -0
  113. data/release_notes/release_4.3.11.md +14 -0
  114. data/release_notes/release_4.3.12.md +14 -0
  115. data/release_notes/release_4.3.2.rc1.md +21 -0
  116. data/release_notes/release_4.3.3.md +24 -0
  117. data/release_notes/release_4.3.4.md +11 -0
  118. data/release_notes/release_4.3.4.rc1.md +24 -0
  119. data/release_notes/release_4.3.5.md +36 -0
  120. data/release_notes/release_4.3.5.rc1.md +21 -0
  121. data/release_notes/release_4.3.6.md +14 -0
  122. data/release_notes/release_4.3.7.md +50 -0
  123. data/release_notes/release_4.3.8.md +19 -0
  124. data/release_notes/release_4.3.9.md +14 -0
  125. data/release_notes/release_4.4.0.md +16 -0
  126. data/release_notes/release_4.5.1.md +11 -0
  127. data/release_notes/release_4.5.2.md +14 -0
  128. data/release_notes/release_4.5.3.md +29 -0
  129. data/release_notes/release_4.6.0.md +24 -0
  130. data/release_notes/release_4.6.1.md +14 -0
  131. data/release_notes/release_4.6.2.md +16 -0
  132. data/release_notes/release_4.6.3.rc1.md +14 -0
  133. data/release_notes/release_4.6.3.rc2.md +14 -0
  134. data/release_notes/release_4.6.3.rc3.md +17 -0
  135. data/release_notes/release_4.7.0.md +11 -0
  136. data/release_notes/release_4.7.1.md +14 -0
  137. data/release_notes/release_4.7.1.rc.1.md +14 -0
  138. data/release_notes/release_4.7.1.rc1.md +19 -0
  139. data/script/gpp +3 -0
  140. data/spec/cc_api_stub/app_usage_events_spec.rb +12 -0
  141. data/spec/cc_api_stub/applications_spec.rb +69 -0
  142. data/spec/cc_api_stub/domains_spec.rb +40 -0
  143. data/spec/cc_api_stub/events_spec.rb +12 -0
  144. data/spec/cc_api_stub/frameworks_spec.rb +19 -0
  145. data/spec/cc_api_stub/login_spec.rb +20 -0
  146. data/spec/cc_api_stub/organization_users_spec.rb +35 -0
  147. data/spec/cc_api_stub/organizations_spec.rb +118 -0
  148. data/spec/cc_api_stub/routes_spec.rb +19 -0
  149. data/spec/cc_api_stub/runtimes_spec.rb +19 -0
  150. data/spec/cc_api_stub/service_bindings_spec.rb +13 -0
  151. data/spec/cc_api_stub/service_instances_spec.rb +19 -0
  152. data/spec/cc_api_stub/services_spec.rb +11 -0
  153. data/spec/cc_api_stub/space_users_spec.rb +35 -0
  154. data/spec/cc_api_stub/spaces_spec.rb +38 -0
  155. data/spec/cc_api_stub/users_spec.rb +107 -0
  156. data/spec/cfoundry/auth_token_spec.rb +154 -0
  157. data/spec/cfoundry/baseclient_spec.rb +298 -0
  158. data/spec/cfoundry/client_spec.rb +13 -0
  159. data/spec/cfoundry/errors_spec.rb +117 -0
  160. data/spec/cfoundry/rest_client_spec.rb +349 -0
  161. data/spec/cfoundry/trace_helpers_spec.rb +91 -0
  162. data/spec/cfoundry/uaaclient_spec.rb +435 -0
  163. data/spec/cfoundry/upload_helpers_spec.rb +182 -0
  164. data/spec/cfoundry/v2/app_event_spec.rb +97 -0
  165. data/spec/cfoundry/v2/app_instance_spec.rb +31 -0
  166. data/spec/cfoundry/v2/app_spec.rb +354 -0
  167. data/spec/cfoundry/v2/app_usage_event_spec.rb +15 -0
  168. data/spec/cfoundry/v2/base_spec.rb +375 -0
  169. data/spec/cfoundry/v2/client_spec.rb +121 -0
  170. data/spec/cfoundry/v2/domain_spec.rb +63 -0
  171. data/spec/cfoundry/v2/event_spec.rb +15 -0
  172. data/spec/cfoundry/v2/managed_service_instance_spec.rb +149 -0
  173. data/spec/cfoundry/v2/model_magic/attribute_spec.rb +123 -0
  174. data/spec/cfoundry/v2/model_magic/has_summary_spec.rb +17 -0
  175. data/spec/cfoundry/v2/model_magic/to_many_spec.rb +53 -0
  176. data/spec/cfoundry/v2/model_magic/to_one_spec.rb +106 -0
  177. data/spec/cfoundry/v2/model_magic_spec.rb +43 -0
  178. data/spec/cfoundry/v2/model_spec.rb +434 -0
  179. data/spec/cfoundry/v2/organization_spec.rb +135 -0
  180. data/spec/cfoundry/v2/quota_definition_spec.rb +50 -0
  181. data/spec/cfoundry/v2/route_spec.rb +42 -0
  182. data/spec/cfoundry/v2/service_plan_spec.rb +53 -0
  183. data/spec/cfoundry/v2/service_spec.rb +58 -0
  184. data/spec/cfoundry/v2/space_spec.rb +13 -0
  185. data/spec/cfoundry/v2/user_provided_service_instance_spec.rb +57 -0
  186. data/spec/cfoundry/v2/user_spec.rb +206 -0
  187. data/spec/cfoundry/validator_spec.rb +94 -0
  188. data/spec/factories/app_events_factory.rb +7 -0
  189. data/spec/factories/app_usage_events_factory.rb +32 -0
  190. data/spec/factories/apps_factory.rb +11 -0
  191. data/spec/factories/clients_factory.rb +7 -0
  192. data/spec/factories/domains_factory.rb +10 -0
  193. data/spec/factories/events_factory.rb +50 -0
  194. data/spec/factories/organizations_factory.rb +12 -0
  195. data/spec/factories/quota_definitions_factory.rb +8 -0
  196. data/spec/factories/routes_factory.rb +10 -0
  197. data/spec/factories/service_instances_factory.rb +10 -0
  198. data/spec/factories/service_plans_factory.rb +10 -0
  199. data/spec/factories/services_factory.rb +10 -0
  200. data/spec/factories/spaces_factory.rb +10 -0
  201. data/spec/factories/user_provided_service_instances_factory.rb +10 -0
  202. data/spec/factories/users_factory.rb +10 -0
  203. data/spec/fixtures/apps/with_cfignore/.cfignore +4 -0
  204. data/spec/fixtures/apps/with_cfignore/.hidden_file +1 -0
  205. data/spec/fixtures/apps/with_cfignore/ambiguous_ignored +0 -0
  206. data/spec/fixtures/apps/with_cfignore/ignored_dir/file_in_ignored_dir.txt +1 -0
  207. data/spec/fixtures/apps/with_cfignore/ignored_file.txt +1 -0
  208. data/spec/fixtures/apps/with_cfignore/non_ignored_dir/file_in_non_ignored_dir.txt +1 -0
  209. data/spec/fixtures/apps/with_cfignore/non_ignored_dir/ignored_file.txt +1 -0
  210. data/spec/fixtures/apps/with_cfignore/non_ignored_dir/toplevel_ignored.txt +0 -0
  211. data/spec/fixtures/apps/with_cfignore/non_ignored_file.txt +1 -0
  212. data/spec/fixtures/apps/with_cfignore/toplevel_ignored.txt +0 -0
  213. data/spec/fixtures/apps/with_dotfiles/.dotfile +1 -0
  214. data/spec/fixtures/apps/with_dotfiles/xyz +1 -0
  215. data/spec/fixtures/apps/with_external_symlink/foo +1 -0
  216. data/spec/fixtures/apps/with_ignored_external_symlink/.cfignore +1 -0
  217. data/spec/fixtures/apps/with_ignored_external_symlink/foo +1 -0
  218. data/spec/fixtures/apps/with_nested_directories/foo/bar/baz/fizz +0 -0
  219. data/spec/fixtures/apps/with_nested_directories/xyz +0 -0
  220. data/spec/fixtures/empty_file +0 -0
  221. data/spec/fixtures/fake_cc_app_usage_events.json +152 -0
  222. data/spec/fixtures/fake_cc_application.json +20 -0
  223. data/spec/fixtures/fake_cc_application_summary.json +56 -0
  224. data/spec/fixtures/fake_cc_created_application.json +11 -0
  225. data/spec/fixtures/fake_cc_created_domain.json +15 -0
  226. data/spec/fixtures/fake_cc_created_organization.json +11 -0
  227. data/spec/fixtures/fake_cc_created_route.json +13 -0
  228. data/spec/fixtures/fake_cc_created_service_instance.json +11 -0
  229. data/spec/fixtures/fake_cc_created_space.json +11 -0
  230. data/spec/fixtures/fake_cc_created_user.json +11 -0
  231. data/spec/fixtures/fake_cc_domain.json +55 -0
  232. data/spec/fixtures/fake_cc_domain_spaces.json +27 -0
  233. data/spec/fixtures/fake_cc_empty_search.json +7 -0
  234. data/spec/fixtures/fake_cc_events.json +419 -0
  235. data/spec/fixtures/fake_cc_frameworks.json +20 -0
  236. data/spec/fixtures/fake_cc_managed_service_instance.json +83 -0
  237. data/spec/fixtures/fake_cc_organization.json +161 -0
  238. data/spec/fixtures/fake_cc_organization_domains.json +59 -0
  239. data/spec/fixtures/fake_cc_organization_search.json +37 -0
  240. data/spec/fixtures/fake_cc_organization_spaces.json +99 -0
  241. data/spec/fixtures/fake_cc_organization_summary.json +20 -0
  242. data/spec/fixtures/fake_cc_organization_users.json +81 -0
  243. data/spec/fixtures/fake_cc_route.json +16 -0
  244. data/spec/fixtures/fake_cc_runtimes.json +20 -0
  245. data/spec/fixtures/fake_cc_service_binding.json +22 -0
  246. data/spec/fixtures/fake_cc_service_bindings.json +24 -0
  247. data/spec/fixtures/fake_cc_service_instance.json +83 -0
  248. data/spec/fixtures/fake_cc_service_instances.json +72 -0
  249. data/spec/fixtures/fake_cc_services.json +160 -0
  250. data/spec/fixtures/fake_cc_space.json +45 -0
  251. data/spec/fixtures/fake_cc_space_apps.json +49 -0
  252. data/spec/fixtures/fake_cc_space_summary.json +84 -0
  253. data/spec/fixtures/fake_cc_spaces.json +92 -0
  254. data/spec/fixtures/fake_cc_stats.json +29 -0
  255. data/spec/fixtures/fake_cc_user.json +139 -0
  256. data/spec/fixtures/fake_cc_user_organizations.json +92 -0
  257. data/spec/fixtures/fake_cc_user_provided_service_instance.json +51 -0
  258. data/spec/fixtures/fake_cc_user_with_managers.json +85 -0
  259. data/spec/integration/client_spec.rb +38 -0
  260. data/spec/spec_helper.rb +22 -0
  261. data/spec/support/factory_girl.rb +6 -0
  262. data/spec/support/shared_examples/cc_api_stub_request_examples.rb +79 -0
  263. data/spec/support/shared_examples/client_login_examples.rb +46 -0
  264. data/spec/support/shared_examples/model_summary_examples.rb +34 -0
  265. data/spec/support/test_model_builder.rb +10 -0
  266. data/vendor/errors/README.md +4 -0
  267. data/vendor/errors/v1.yml +189 -0
  268. data/vendor/errors/v2.yml +384 -0
  269. metadata +693 -0
@@ -0,0 +1,53 @@
1
+ require "spec_helper"
2
+
3
+ module CFoundry
4
+ module V2
5
+ describe ServicePlan do
6
+ let(:client) { build(:client) }
7
+
8
+ subject do
9
+ build(:service_plan)
10
+ end
11
+
12
+ before :each do
13
+ stub_request(:get, /\/service_plans\/service-plan-guid-\d{1,2}/).to_return :status => 200,
14
+ :headers => {'Content-Type' => 'application/json'},
15
+ :body => <<EOF
16
+ {
17
+ "metadata": {
18
+ "guid": "d1251ac1-fe42-4b4a-84d4-e31e95b547d8",
19
+ "url": "/v2/service_plans/d1251ac1-fe42-4b4a-84d4-e31e95b547d8",
20
+ "created_at": "2013-08-28T12:28:35+04:00",
21
+ "updated_at": "2013-08-28T12:33:27+04:00"
22
+ },
23
+ "entity": {
24
+ "name": "free",
25
+ "free": true,
26
+ "description": "free as in beer",
27
+ "unique_id": "0aa2f82c-6918-41df-b676-c275b5954ed7",
28
+ "extra": "",
29
+ "public": true
30
+ }
31
+ }
32
+ EOF
33
+ end
34
+
35
+ let(:uuid) { "4692e0ca-25ed-495e-9ae1-fcb0bcf26a96" }
36
+
37
+ it "has unique_id that can be mutated" do
38
+ expect(subject.unique_id).to eq("0aa2f82c-6918-41df-b676-c275b5954ed7")
39
+
40
+ subject.unique_id = uuid
41
+ expect(subject.unique_id).to eq(uuid)
42
+ end
43
+
44
+ it "has free/paid indicator attribute" do
45
+ expect(subject.free).to be_true
46
+ end
47
+
48
+ it "has a boolean 'public' attribute" do
49
+ expect(subject.public).to be_true
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,58 @@
1
+ require "spec_helper"
2
+
3
+ module CFoundry
4
+ module V2
5
+ describe Service do
6
+ let(:client) { build(:client) }
7
+
8
+ subject do
9
+ build(:service)
10
+ end
11
+
12
+ before :each do
13
+ stub_request(:get, /\/services\/service-guid-\d{1,2}/).to_return :status => 200,
14
+ :headers => {'Content-Type' => 'application/json'},
15
+ :body => <<EOF
16
+ {
17
+ "metadata": {
18
+ "guid": "d1251ac1-fe42-4b4a-84d4-e31e95b547d8",
19
+ "url": "/v2/services/d1251ac1-fe42-4b4a-84d4-e31e95b547d8",
20
+ "created_at": "2013-08-28T12:28:35+04:00",
21
+ "updated_at": "2013-08-28T12:33:27+04:00"
22
+ },
23
+ "entity": {
24
+ "label": "rabbitmq",
25
+ "provider": "rabbitherd",
26
+ "url": "http://rabbitmq.com",
27
+ "description": "RabbitMQ service",
28
+ "version": "1.0",
29
+ "info_url": null,
30
+ "active": true,
31
+ "bindable": true,
32
+ "unique_id": "0aa2f82c-6918-41df-b676-c275b5954ed7",
33
+ "extra": "",
34
+ "tags": [
35
+
36
+ ],
37
+ "documentation_url": null,
38
+ "service_plans_url": "/v2/services/d1251ac1-fe42-4b4a-84d4-e31e95b547d8/service_plans"
39
+ }
40
+ }
41
+ EOF
42
+ end
43
+
44
+ let(:uuid) { "4692e0ca-25ed-495e-9ae1-fcb0bcf26a96" }
45
+
46
+ it "has unique_id that can be mutated" do
47
+ expect(subject.unique_id).to eq("0aa2f82c-6918-41df-b676-c275b5954ed7")
48
+
49
+ subject.unique_id = uuid
50
+ expect(subject.unique_id).to eq(uuid)
51
+ end
52
+
53
+ it "has tags" do
54
+ expect(subject.tags).to eq([])
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,13 @@
1
+ require "spec_helper"
2
+
3
+ module CFoundry
4
+ module V2
5
+ describe Space do
6
+ it_behaves_like "a summarizeable model" do
7
+ let(:summary_attributes) { {:name => "fizzbuzz"} }
8
+ let(:client) { build(:client) }
9
+ subject { build(:space, :client => client) }
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+
3
+ module CFoundry
4
+ module V2
5
+ describe UserProvidedServiceInstance do
6
+ let(:client) { build(:client) }
7
+ subject { build(:user_provided_service_instance, :client => client) }
8
+
9
+ describe 'space' do
10
+ let(:space) { build(:space) }
11
+
12
+ it 'has a space' do
13
+ subject.space = space
14
+ expect(subject.space).to eq(space)
15
+ end
16
+
17
+ context 'when an invalid value is assigned' do
18
+ it 'raises a Mismatch exception' do
19
+ expect {
20
+ subject.space = [build(:organization)]
21
+ }.to raise_error(CFoundry::Mismatch)
22
+ end
23
+ end
24
+ end
25
+
26
+ describe 'creating' do
27
+ let(:body) {
28
+ {
29
+ 'metadata' => {
30
+ 'guid' => 'someguid'
31
+ }
32
+ }.to_json
33
+ }
34
+
35
+ it 'calls the correct endpoint' do
36
+ stub_request(:any, %r[.*]).
37
+ to_return(:body => body, :status => 200)
38
+
39
+ subject.create!
40
+
41
+ expect(a_request(:post, 'http://api.example.com/v2/user_provided_service_instances')).to have_been_made
42
+ end
43
+ end
44
+
45
+ describe 'deleting' do
46
+ it 'calls the correct endpoint' do
47
+ stub_request(:any, %r[.*])
48
+
49
+ subject.delete!
50
+
51
+ expect(a_request(:delete, "http://api.example.com/v2/service_instances/#{subject.guid}")).to have_been_made
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+
@@ -0,0 +1,206 @@
1
+ require "spec_helper"
2
+
3
+ module CFoundry
4
+ module V2
5
+ describe User do
6
+ let(:client) { build(:client) }
7
+ subject { build(:user, client: client) }
8
+
9
+ describe '#delete!' do
10
+ describe 'when cloud controller was able to delete the user' do
11
+ before do
12
+ stub_request(:delete, /v2\/users\/.*/).to_return(:status => 200, :body => "", :headers => {})
13
+ allow(client.base).to receive(:info).and_return({:authorization_endpoint => 'some_endpoint'})
14
+ end
15
+
16
+ it "also removes the user from uaa" do
17
+ expect_any_instance_of(CFoundry::UAAClient).to receive(:delete_user)
18
+
19
+ expect(subject.delete!).to be_true
20
+ end
21
+ end
22
+
23
+ describe "when cloud controller was unable to delete the user" do
24
+ before do
25
+ allow(client.base).to receive(:delete).and_raise(CFoundry::APIError)
26
+ end
27
+
28
+ it "allows the exception to bubble up" do
29
+ expect{ subject.delete! }.to raise_error(CFoundry::APIError)
30
+ end
31
+ end
32
+ end
33
+
34
+ describe '#get_meta_from_uaa' do
35
+
36
+ let(:api_target) { 'http://api.example.com' }
37
+ let(:login_target) { 'https://login.example.com' }
38
+ let(:uaa_target) { 'https://uaa.example.com' }
39
+ let(:user_email) { 'test-user@example.com' }
40
+ let(:given_name) { 'John' }
41
+ let(:family_name) { 'Doe' }
42
+
43
+ before do
44
+
45
+ stub_request(:get, "#{api_target}/info").to_return :status => 200,
46
+ :headers => {'Content-Type' => 'application/json'},
47
+ :body => <<EOF
48
+ {
49
+ "name": "vcap",
50
+ "build": "2222",
51
+ "support": "http://support.example.com",
52
+ "version": 2,
53
+ "description": "Cloud Foundry sponsored by Pivotal",
54
+ "authorization_endpoint": "https://login.example.com",
55
+ "token_endpoint": "https://uaa.example.com",
56
+ "allow_debug": true,
57
+ "user": "00000000-0000-0000-0000-000000000000",
58
+ "limits": {
59
+ "memory": 2048,
60
+ "app_uris": 4,
61
+ "services": 16,
62
+ "apps": 20
63
+ },
64
+ "usage": {
65
+ "memory": 896,
66
+ "apps": 4,
67
+ "services": 6
68
+ }
69
+ }
70
+ EOF
71
+
72
+ stub_request(:get, "#{login_target}/login").to_return :status => 200,
73
+ :headers => {'Content-Type' => 'application/json'},
74
+ :body => <<EOF
75
+ {
76
+ "timestamp": "2013-06-12T22:32:57-0700",
77
+ "app": {
78
+ "artifact": "cloudfoundry-login-server",
79
+ "description": "Cloud Foundry Login App",
80
+ "name": "Cloud Foundry Login",
81
+ "version": "1.2.3"
82
+ },
83
+ "links": {
84
+ "register": "https://console.example.com/register",
85
+ "passwd": "https://console.example.com/password_resets/new",
86
+ "home": "https://console.example.com",
87
+ "login": "https://login.example.com",
88
+ "uaa": "https://uaa.example.com"
89
+ },
90
+ "analytics": {
91
+ "code": "UA-00000000-00",
92
+ "domain": "example.com"
93
+ },
94
+ "commit_id": "0000000",
95
+ "prompts": {
96
+ "username": [
97
+ "text",
98
+ "Email"
99
+ ],
100
+ "password": [
101
+ "password",
102
+ "Password"
103
+ ]
104
+ }
105
+ }
106
+ EOF
107
+
108
+ stub_request(:get, /#{uaa_target}\/Users\/user-guid-\d{1,2}/).to_return :status => 200,
109
+ :headers => {'Content-Type' => 'application/json'},
110
+ :body => <<EOF
111
+ {
112
+ "id": "00000000-0000-0000-0000-000000000000",
113
+ "meta": {
114
+ "version": 0,
115
+ "created": "2013-06-24T13:44:38.000Z",
116
+ "lastModified": "2013-06-24T13:44:38.000Z"
117
+ },
118
+ "userName": "#{user_email}",
119
+ "name": {
120
+ "familyName": "#{family_name}",
121
+ "givenName": "#{given_name}"
122
+ },
123
+ "emails": [
124
+ {
125
+ "value": "#{user_email}"
126
+ }
127
+ ],
128
+ "groups": [
129
+ {
130
+ "value": "00000000-0000-0000-0000-000000000000",
131
+ "display": "password.write",
132
+ "type": "DIRECT"
133
+ },
134
+ {
135
+ "value": "00000000-0000-0000-0000-000000000000",
136
+ "display": "openid",
137
+ "type": "DIRECT"
138
+ },
139
+ {
140
+ "value": "00000000-0000-0000-0000-000000000000",
141
+ "display": "uaa.user",
142
+ "type": "DIRECT"
143
+ },
144
+ {
145
+ "value": "00000000-0000-0000-0000-000000000000",
146
+ "display": "scim.userids",
147
+ "type": "DIRECT"
148
+ },
149
+ {
150
+ "value": "00000000-0000-0000-0000-000000000000",
151
+ "display": "approvals.me",
152
+ "type": "DIRECT"
153
+ },
154
+ {
155
+ "value": "00000000-0000-0000-0000-000000000000",
156
+ "display": "cloud_controller.write",
157
+ "type": "DIRECT"
158
+ },
159
+ {
160
+ "value": "00000000-0000-0000-0000-000000000000",
161
+ "display": "scim.me",
162
+ "type": "DIRECT"
163
+ },
164
+ {
165
+ "value": "00000000-0000-0000-0000-000000000000",
166
+ "display": "cloud_controller.read",
167
+ "type": "DIRECT"
168
+ }
169
+ ],
170
+ "approvals": [
171
+
172
+ ],
173
+ "active": true,
174
+ "schemas": [
175
+ "urn:scim:schemas:core:1.0"
176
+ ]
177
+ }
178
+ EOF
179
+ end
180
+
181
+ it "retrieves metadata from the UAA" do
182
+ expect(subject.email).to eq(user_email)
183
+ expect(subject.given_name).to eq(given_name)
184
+ expect(subject.family_name).to eq(family_name)
185
+ expect(subject.full_name).to eq("#{given_name} #{family_name}")
186
+ end
187
+
188
+ it "should be nil if user doesn't have permission to query uaa" do
189
+
190
+ stub_request(:get, /#{uaa_target}\/Users\/user-guid-\d{1,2}/).to_return :status => 200,
191
+ :headers => {'Content-Type' => 'application/json'},
192
+ :body => <<EOF
193
+ {
194
+ "error": "access_denied",
195
+ "error_description": "Access is denied"
196
+ }
197
+ EOF
198
+ expect(subject.email).to eq(nil)
199
+ expect(subject.given_name).to eq(nil)
200
+ expect(subject.family_name).to eq(nil)
201
+ end
202
+
203
+ end
204
+ end
205
+ end
206
+ end
@@ -0,0 +1,94 @@
1
+ require "spec_helper"
2
+
3
+ module CFoundry
4
+ describe Validator do
5
+ let(:validator) { described_class }
6
+
7
+ describe "value_matches?" do
8
+ it "returns true on nil values" do
9
+ expect(validator.value_matches?(nil, :something)).to be_true
10
+ end
11
+
12
+ context "with a type of Class" do
13
+ it "returns true when value is of type class" do
14
+ expect(validator.value_matches?(1, Integer)).to be_true
15
+ end
16
+ end
17
+
18
+ context "with a Regex" do
19
+ it "returns true when the regex matches" do
20
+ expect(validator.value_matches?("value", /lue/)).to eq(true)
21
+ end
22
+ end
23
+
24
+ context "with type of url" do
25
+ it "requires http or https urls" do
26
+ expect(validator.value_matches?("http:whatever", :url)).to be_true
27
+ expect(validator.value_matches?("https:whatever", :url)).to be_true
28
+ expect(validator.value_matches?("htt_no:whatever", :url)).to be_false
29
+ end
30
+ end
31
+
32
+ context "with type of https_url" do
33
+ it "requires http or https urls" do
34
+ expect(validator.value_matches?("https:whatever", :https_url)).to be_true
35
+ expect(validator.value_matches?("http:whatever", :https_url)).to be_false
36
+ end
37
+ end
38
+
39
+ context "with type boolean" do
40
+ it "returns true on presence of true or false" do
41
+ expect(validator.value_matches?(true, :boolean)).to be_true
42
+ expect(validator.value_matches?(false, :boolean)).to be_true
43
+ expect(validator.value_matches?("no boolean", :boolean)).to be_false
44
+ end
45
+ end
46
+
47
+ context "with an Array" do
48
+ it "returns true when all elements are of same type" do
49
+ expect(validator.value_matches?(["https:whatever"], [String])).to be_true
50
+ expect(validator.value_matches?(["https:whatever"], [Integer])).to be_false
51
+ end
52
+ end
53
+
54
+ context "with a hash" do
55
+ it "returns true when specified types match" do
56
+ expect(validator.value_matches?({:name => "thing"}, {:name => String})).to be_true
57
+ expect(validator.value_matches?({:name => "thing", :unspecified => 1}, {:name => String})).to be_true
58
+ expect(validator.value_matches?({:name => 1}, {:name => String})).to be_false
59
+ end
60
+ end
61
+
62
+ it "returns true when type is nil" do
63
+ expect(validator.value_matches?("some value", nil)).to be_true
64
+ end
65
+
66
+ context "with a symbol" do
67
+ it "returns true when the value is of specified type" do
68
+ expect(validator.value_matches?("some value", :string)).to be_true
69
+ expect(validator.value_matches?("some value", :integer)).to be_false
70
+ end
71
+ end
72
+ end
73
+
74
+ describe "validate_type" do
75
+ it "passes validation with a nil value" do
76
+ expect {
77
+ validator.validate_type(nil, :whatever)
78
+ }.to_not raise_error
79
+ end
80
+
81
+ it "passes validation when the value matches" do
82
+ expect {
83
+ validator.validate_type("string", :string)
84
+ }.to_not raise_error
85
+ end
86
+
87
+ it "raises a validation error when value does not match" do
88
+ expect {
89
+ validator.validate_type("string", :integer)
90
+ }.to raise_error(CFoundry::Mismatch)
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,7 @@
1
+ FactoryGirl.define do
2
+ factory :app_event, :class => CFoundry::V2::AppEvent do
3
+ sequence(:guid) { |n| "app-event-guid-#{n}" }
4
+
5
+ initialize_with { new(guid, build(:client)) }
6
+ end
7
+ end
@@ -0,0 +1,32 @@
1
+ FactoryGirl.define do
2
+ factory :app_usage_event, :class => CFoundry::V2::AppUsageEvent do
3
+ sequence(:guid) { |n| "app-usage-event-guid-#{n}" }
4
+ created_at '2013-01-01T12:00:00+00:00'
5
+ state 'STARTED'
6
+ memory_in_mb_per_instance 512
7
+ instance_count 1
8
+ app_guid 'app-guid-1'
9
+ app_name 'app-name-1'
10
+ space_guid 'space-guid-1'
11
+ space_name 'space-name-1'
12
+ org_guid 'org-guid-1'
13
+
14
+ initialize_with do
15
+ new(guid, build(:client), {
16
+ metadata: {
17
+ created_at: created_at
18
+ },
19
+ entity: {
20
+ state: state,
21
+ memory_in_mb_per_instance: memory_in_mb_per_instance,
22
+ instance_count: instance_count,
23
+ app_guid: app_guid,
24
+ app_name: app_name,
25
+ space_guid: space_guid,
26
+ space_name: space_name,
27
+ org_guid: org_guid
28
+ }
29
+ })
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,11 @@
1
+ FactoryGirl.define do
2
+ factory :app, :class => CFoundry::V2::App do
3
+ sequence(:guid) { |n| "app-guid-#{n}" }
4
+ transient do
5
+ manifest { {} }
6
+ client { FactoryGirl.build(:client) }
7
+ end
8
+
9
+ initialize_with { new(guid, client, manifest) }
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ FactoryGirl.define do
2
+ factory :client, :class => CFoundry::V2::Client do
3
+ initialize_with do
4
+ new("http://api.example.com")
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ FactoryGirl.define do
2
+ factory :domain, :class => CFoundry::V2::Domain do
3
+ sequence(:guid) { |n| "domain-guid-#{n}" }
4
+ transient do
5
+ client build(:client)
6
+ end
7
+
8
+ initialize_with { new(guid, client) }
9
+ end
10
+ end
@@ -0,0 +1,50 @@
1
+ FactoryGirl.define do
2
+ factory :event, :class => CFoundry::V2::Event do
3
+ sequence(:guid) { |n| "event-guid-#{n}" }
4
+ timestamp '2013-01-01T12:00:00+00:00'
5
+ actee 'app-guid-1'
6
+ actee_type 'app'
7
+ actor 'actor-guid-1'
8
+ actor_type 'user'
9
+ organization_guid 'organization-guid-1'
10
+ space_guid 'space-guid-1'
11
+ type ''
12
+ metadata {}
13
+
14
+ initialize_with do
15
+ new(guid, build(:client), {
16
+ entity: {
17
+ type: type,
18
+ actee: actee,
19
+ actee_type: actee_type,
20
+ actor: actor,
21
+ actor_type: actor_type,
22
+ organization_guid: organization_guid,
23
+ space_guid: space_guid,
24
+ timestamp: timestamp,
25
+ metadata: metadata
26
+ }
27
+ })
28
+ end
29
+
30
+ trait :app_update do
31
+ type 'audit.app.update'
32
+
33
+ changes do
34
+ {state: 'STARTED'}
35
+ end
36
+
37
+ metadata do
38
+ {
39
+ request: changes,
40
+ desired_memory: 128,
41
+ desired_instances: 1
42
+ }
43
+ end
44
+ end
45
+
46
+ trait :app_delete do
47
+ type 'audit.app.delete'
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,12 @@
1
+ FactoryGirl.define do
2
+ factory :organization, :class => CFoundry::V2::Organization do
3
+ sequence(:guid) { |n| "organization-guid-#{n}" }
4
+ status "active"
5
+
6
+ transient do
7
+ client { FactoryGirl.build(:client) }
8
+ end
9
+
10
+ initialize_with { new(guid, client) }
11
+ end
12
+ end
@@ -0,0 +1,8 @@
1
+ FactoryGirl.define do
2
+ factory :quota_definition, :class => CFoundry::V2::QuotaDefinition do
3
+ sequence(:name) { |n| "quota-definition-name-#{n}" }
4
+ sequence(:guid) { |n| "quota-definition-guid-#{n}" }
5
+
6
+ initialize_with { new(guid, build(:client)) }
7
+ end
8
+ end
@@ -0,0 +1,10 @@
1
+ FactoryGirl.define do
2
+ factory :route, :class => CFoundry::V2::Route do
3
+ sequence(:guid) { |n| "route-guid-#{n}" }
4
+ transient do
5
+ client { FactoryGirl.build(:client) }
6
+ end
7
+
8
+ initialize_with { new(guid, client) }
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ FactoryGirl.define do
2
+ factory :service_instance, :class => CFoundry::V2::ManagedServiceInstance do
3
+ sequence(:guid) { |n| "service-instance-guid-#{n}" }
4
+ transient do
5
+ client { FactoryGirl.build(:client) }
6
+ end
7
+
8
+ initialize_with { new(guid, client) }
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ FactoryGirl.define do
2
+ factory :service_plan, :class => CFoundry::V2::ServicePlan do
3
+ sequence(:guid) { |n| "service-plan-guid-#{n}" }
4
+ transient do
5
+ client { FactoryGirl.build(:client) }
6
+ end
7
+
8
+ initialize_with { new(guid, client) }
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ FactoryGirl.define do
2
+ factory :service, :class => CFoundry::V2::Service do
3
+ sequence(:guid) { |n| "service-guid-#{n}" }
4
+ transient do
5
+ client { FactoryGirl.build(:client) }
6
+ end
7
+
8
+ initialize_with { new(guid, client) }
9
+ end
10
+ end