new_cfoundry 4.8.2

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.
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,298 @@
1
+ require 'spec_helper'
2
+
3
+ describe CFoundry::BaseClient do
4
+ let(:authorization_endpoint) { "http://uaa.example.com" }
5
+ subject(:client) { CFoundry::BaseClient.new("http://api.example.com") }
6
+ describe "#request" do
7
+ before do
8
+ allow(subject).to receive(:handle_response).with(anything, anything, anything)
9
+ end
10
+
11
+ context "when given multiple segments" do
12
+ it "encodes the segments and joins them with '/'" do
13
+ expect(subject).to receive(:request_raw).with("GET", "foo/bar%2Fbaz", {})
14
+ subject.request("GET", "foo", "bar/baz")
15
+ end
16
+ end
17
+
18
+ context "when the first segment starts with a '/'" do
19
+ context "and there's only one segment" do
20
+ it "requests with the segment unaltered" do
21
+ expect(subject).to receive(:request_raw).with("GET", "/v2/apps", {})
22
+ subject.request("GET", "/v2/apps")
23
+ end
24
+ end
25
+
26
+ context "and there's more than one segment" do
27
+ it "encodes the segments and joins them with '/'" do
28
+ expect(subject).to receive(:request_raw).with("GET", "%2Ffoo/bar%2Fbaz", {})
29
+ subject.request("GET", "/foo", "bar/baz")
30
+ end
31
+ end
32
+ end
33
+
34
+ context "when there is a token with an auth_header" do
35
+ let(:refresh_token) { nil }
36
+ let(:token) { CFoundry::AuthToken.new("bearer something", refresh_token) }
37
+
38
+ before do
39
+ allow(subject).to receive(:request_raw)
40
+ subject.token = token
41
+ allow(token).to receive(:expires_soon?) { expires_soon? }
42
+ end
43
+
44
+ context "and the token is about to expire" do
45
+ let(:uaa) { Object.new }
46
+ let(:expires_soon?) { true }
47
+
48
+ context "and there is a refresh token" do
49
+ let(:refresh_token) { "some-refresh-token" }
50
+
51
+ it "sets the token's auth header to nil to prevent recursion" do
52
+ allow(subject).to receive(:refresh_token!)
53
+ subject.request("GET", "foo")
54
+ end
55
+
56
+ it "refreshes the access token" do
57
+ expect(subject).to receive(:refresh_token!)
58
+ subject.request("GET", "foo")
59
+ end
60
+ end
61
+
62
+ context "and there is NOT a refresh token" do
63
+ let(:refresh_token) { nil }
64
+
65
+ it "moves along" do
66
+ expect(subject).to receive(:request_raw).with(anything, anything, anything)
67
+ expect(subject).not_to receive(:refresh_token!)
68
+ subject.request("GET", "foo")
69
+ end
70
+ end
71
+ end
72
+
73
+ context "and the token is NOT about to expire" do
74
+ let(:expires_soon?) { nil }
75
+
76
+ it "moves along" do
77
+ expect(subject).to receive(:request_raw).with(anything, anything, anything)
78
+ expect(subject).not_to receive(:refresh_token!)
79
+ subject.request("GET", "foo")
80
+ end
81
+ end
82
+ end
83
+
84
+ describe "#refresh_token!" do
85
+ let(:uaa) { double }
86
+ let(:access_token) { Base64.encode64(%Q|{"algo": "h1234"}{"a":"b"}random-bytes|) }
87
+ let(:refresh_token) { "xyz" }
88
+ let(:new_access_token) { Base64.encode64(%Q|{"algo": "h1234"}{"a":"x"}random-bytes|) }
89
+ let(:auth_token) { CFoundry::AuthToken.new("bearer #{access_token}", refresh_token) }
90
+
91
+ before { allow(subject).to receive(:uaa) { uaa } }
92
+
93
+ it "refreshes the token with UAA client and assigns it" do
94
+ expect(uaa).to receive(:try_to_refresh_token!) {
95
+ CFoundry::AuthToken.new("bearer #{new_access_token}", auth_token.refresh_token)
96
+ }
97
+
98
+ subject.refresh_token!
99
+
100
+ expect(subject.token.auth_header).to eq "bearer #{new_access_token}"
101
+ end
102
+ end
103
+
104
+ end
105
+
106
+ describe "UAAClient" do
107
+ context "with a valid uaa endpoint" do
108
+ let(:info) { { :authorization_endpoint => authorization_endpoint } }
109
+
110
+ before do
111
+ allow(subject).to receive(:info) { info }
112
+ end
113
+
114
+ describe "#uaa" do
115
+ it "creates a UAAClient on the first call" do
116
+ expect(subject.uaa).to be_a CFoundry::UAAClient
117
+ end
118
+
119
+ it "returns the same object on later calls" do
120
+ uaa = subject.uaa
121
+ expect(subject.uaa).to eq uaa
122
+ end
123
+
124
+ it "has the same AuthToken as BaseClient" do
125
+ token = CFoundry::AuthToken.new(nil)
126
+ allow(subject).to receive(:token) { token }
127
+ expect(subject.uaa.token).to eq token
128
+ end
129
+
130
+ context "with the endpoint as 'authorization_endpoint'" do
131
+ let(:info) { { :authorization_endpoint => "foo" } }
132
+
133
+ it "uses it to create the UAAClient" do
134
+ expect(subject.uaa).to be_a CFoundry::UAAClient
135
+ expect(subject.uaa.target).to eq "foo"
136
+ end
137
+ end
138
+
139
+ context "when proxy is set" do
140
+ before do
141
+ subject.http_proxy = 'http-proxy.example.com'
142
+ subject.https_proxy = 'https-proxy.example.com'
143
+ end
144
+
145
+ it "passes the proxy to the uaa client" do
146
+ allow(CFoundry::UAAClient).to receive(:new).and_call_original
147
+ subject.uaa
148
+ expect(CFoundry::UAAClient).to have_received(:new).with(anything, anything, hash_including(
149
+ http_proxy: 'http-proxy.example.com',
150
+ https_proxy: 'https-proxy.example.com'
151
+ ))
152
+ end
153
+ end
154
+ end
155
+
156
+ describe "#token=" do
157
+ it "propagates the change to #uaa" do
158
+ subject.uaa
159
+ expect(subject.uaa.token).to eq subject.token
160
+ subject.token = CFoundry::AuthToken.new(nil)
161
+ expect(subject.uaa.token).to eq subject.token
162
+ end
163
+ end
164
+
165
+ describe "#trace=" do
166
+ it "propagates the change to #uaa" do
167
+ subject.uaa
168
+ subject.trace = true
169
+ expect(subject.uaa.trace).to eq true
170
+ subject.trace = false
171
+ expect(subject.uaa.trace).to eq false
172
+ end
173
+ end
174
+ end
175
+
176
+ context "with no uaa endpoint" do
177
+ before do
178
+ allow(subject).to receive(:info) { { :something => "else" } }
179
+ end
180
+
181
+ describe "#uaa" do
182
+ it "does not return a UAAClient" do
183
+ expect(subject.uaa).to be_nil
184
+ end
185
+ end
186
+
187
+ end
188
+ end
189
+
190
+ describe "#password_score" do
191
+ context "with a uaa" do
192
+ before do
193
+ allow(subject).to receive(:info) { { :authorization_endpoint => "http://uaa.example.com" } }
194
+ end
195
+
196
+ it "delegates to the uaa's password strength method" do
197
+ expect(subject.uaa).to receive(:password_score).with('password')
198
+ subject.password_score('password')
199
+ end
200
+ end
201
+
202
+ context "without a uaa" do
203
+ before do
204
+ allow(subject).to receive(:info) { { :something => "else" } }
205
+ end
206
+
207
+ it "returns :unknown" do
208
+ expect(subject.password_score('password')).to eq(:unknown)
209
+ end
210
+ end
211
+ end
212
+
213
+ describe "#stream_url" do
214
+ it "handles a chunked response by yielding chunks as they come in" do
215
+ stub_request(:get, "http://example.com/something").to_return(
216
+ :headers => { "Transfer-Encoding" => "chunked" },
217
+ :body => "result")
218
+
219
+ chunks = []
220
+ subject.stream_url("http://example.com/something") do |chunk|
221
+ chunks << chunk
222
+ end
223
+
224
+ expect(chunks).to eq(["result"])
225
+ end
226
+
227
+ it "handles https" do
228
+ stub_request(:get, "https://example.com/something").to_return(
229
+ :body => "https result")
230
+
231
+ chunks = []
232
+ subject.stream_url("https://example.com/something") do |chunk|
233
+ chunks << chunk
234
+ end
235
+
236
+ expect(chunks).to eq(["https result"])
237
+ end
238
+
239
+ it "sets proxy options if available" do
240
+ stub_request(:get, "https://example.com/something")
241
+ subject.https_proxy = "user:password@https-proxy.example.com:1234"
242
+ allow(Net::HTTP).to receive(:start).and_call_original
243
+
244
+ subject.stream_url("https://example.com/something")
245
+
246
+ expect(Net::HTTP).to have_received(:start).with(anything, anything, 'https-proxy.example.com', 1234, 'user', 'password', anything)
247
+ end
248
+
249
+ it "raises NotFound if response is 404" do
250
+ stub_request(:get, "http://example.com/something").to_return(
251
+ :status => 404, :body => "result")
252
+
253
+ expect {
254
+ subject.stream_url("http://example.com/something")
255
+ }.to raise_error(CFoundry::NotFound, /result/)
256
+ end
257
+
258
+ it "raises Denied if response is 403" do
259
+ stub_request(:get, "http://example.com/something").to_return(
260
+ :status => 403, :body => "result")
261
+
262
+ expect {
263
+ subject.stream_url("http://example.com/something")
264
+ }.to raise_error(CFoundry::Denied, /result/)
265
+ end
266
+
267
+ it "raises Unauthorized if response is 401" do
268
+ stub_request(:get, "http://example.com/something").to_return(
269
+ :status => 401, :body => "result")
270
+
271
+ expect {
272
+ subject.stream_url("http://example.com/something")
273
+ }.to raise_error(CFoundry::Unauthorized, /result/)
274
+ end
275
+
276
+ it "raises BadRespones if response is unexpected" do
277
+ stub_request(:get, "http://example.com/something").to_return(
278
+ :status => 344, :body => "result")
279
+
280
+ expect {
281
+ subject.stream_url("http://example.com/something")
282
+ }.to raise_error(CFoundry::BadResponse, /result/)
283
+ end
284
+ end
285
+
286
+ describe "#target=" do
287
+ let(:base_client) { CFoundry::BaseClient.new("https://api.example.com") }
288
+ let(:new_target) { "some-target-url.com"}
289
+
290
+ it "sets a new target" do
291
+ expect{base_client.target = new_target}.to change {base_client.target}.from("https://api.example.com").to(new_target)
292
+ end
293
+
294
+ it "sets a new target on the rest client" do
295
+ expect{base_client.target = new_target}.to change{base_client.rest_client.target}.from("https://api.example.com").to(new_target)
296
+ end
297
+ end
298
+ end
@@ -0,0 +1,13 @@
1
+ require "spec_helper"
2
+
3
+ describe CFoundry::Client do
4
+ before do
5
+ allow_any_instance_of(CFoundry::V2::Client).to receive(:info)
6
+ end
7
+
8
+ subject { CFoundry::Client.get('http://example.com') }
9
+
10
+ it "returns a v2 client" do
11
+ expect(subject).to be_a(CFoundry::V2::Client)
12
+ end
13
+ end
@@ -0,0 +1,117 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Errors' do
4
+ describe CFoundry::Timeout do
5
+ let(:parent) { Timeout::Error.new }
6
+
7
+ subject { CFoundry::Timeout.new("POST", '/blah', parent) }
8
+
9
+ describe '#to_s' do
10
+ subject { super().to_s }
11
+ it { should eq "POST /blah timed out" }
12
+ end
13
+
14
+ describe '#method' do
15
+ subject { super().method }
16
+ it { should eq "POST" }
17
+ end
18
+
19
+ describe '#uri' do
20
+ subject { super().uri }
21
+ it { should eq '/blah' }
22
+ end
23
+
24
+ describe '#parent' do
25
+ subject { super().parent }
26
+ it { should eq parent }
27
+ end
28
+ end
29
+
30
+ describe CFoundry::InvalidTarget do
31
+ let(:target) { "http://--foo-bar" }
32
+ subject { CFoundry::InvalidTarget.new(target) }
33
+
34
+ describe '#to_s' do
35
+ subject { super().to_s }
36
+ it { should eq "Invalid target URI: #{target}"}
37
+ end
38
+
39
+ describe '#target' do
40
+ subject { super().target }
41
+ it { should eq target }
42
+ end
43
+ end
44
+
45
+ describe CFoundry::APIError do
46
+ let(:request) { { :method => "GET", :url => "http://api.example.com/foo", :headers => {} } }
47
+ let(:response_body) { "NOT FOUND" }
48
+ let(:response) { { :status => 404, :headers => {}, :body => response_body } }
49
+
50
+ subject { CFoundry::APIError.new(nil, nil, request, response) }
51
+
52
+ describe '#to_s' do
53
+ subject { super().to_s }
54
+ it { should eq "404: NOT FOUND" }
55
+ end
56
+
57
+ describe '#request' do
58
+ subject { super().request }
59
+ it { should eq request }
60
+ end
61
+
62
+ describe '#response' do
63
+ subject { super().response }
64
+ it { should eq response }
65
+ end
66
+
67
+ describe "#initialize" do
68
+
69
+ context "Response body is JSON" do
70
+
71
+ let(:response_body) { "{\"description\":\"Something went wrong\"}"}
72
+
73
+ it "sets description to description field in parsed JSON" do
74
+ expect(CFoundry::APIError.new(nil, nil, request, response).description).to eq("Something went wrong")
75
+ end
76
+ end
77
+
78
+
79
+ context "Response body is not JSON" do
80
+
81
+ let(:response_body) { "Some plain text"}
82
+
83
+ it "sets description to body text" do
84
+ expect(CFoundry::APIError.new(nil, nil, request, response).description).to eq("Some plain text")
85
+ end
86
+ end
87
+
88
+ it "allows override of description" do
89
+ expect(CFoundry::APIError.new("My description", nil, request, response).description).to eq("My description")
90
+ end
91
+
92
+ end
93
+
94
+ describe "#request_trace" do
95
+ describe '#request_trace' do
96
+ subject { super().request_trace }
97
+ it { should include "REQUEST: " }
98
+ end
99
+ end
100
+
101
+ describe "#response_trace" do
102
+ describe '#response_trace' do
103
+ subject { super().response_trace }
104
+ it { should include "RESPONSE: " }
105
+ end
106
+ end
107
+
108
+ it "sets error code to response error code by default" do
109
+ expect(CFoundry::APIError.new(nil, nil, request, response).error_code).to eq(404)
110
+ end
111
+
112
+ it "allows override of error code" do
113
+ expect(CFoundry::APIError.new(nil, 303, request, response).error_code).to eq(303)
114
+ end
115
+
116
+ end
117
+ end