Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

allow v1 files api to work accross spaces

Change-Id: Ie49a43b6551228488659ef303f3aa9482eac95d2
  • Loading branch information...
commit 4a6a4a555299526576aa06645f5106dc49825189 1 parent f616666
Patrick Bozeman pbozeman authored
13 lib/cloud_controller/legacy_api/legacy_apps.rb
View
@@ -151,9 +151,16 @@ def legacy_app_encoding(app)
end
def app_from_name(name)
- app = Models::App.user_visible[:name => name, :space => default_space]
- raise AppNotFound.new(name) unless app
- app
+ ds = Models::App.user_visible.filter(:name => name)
+
+ case ds.count
+ when 0
+ raise AppNotFound.new(name)
+ when 1
+ ds.first
+ else
+ ds[:space => default_space]
+ end
end
def request_from_legacy_create_json(legacy_json)
54 spec/api/legacy_apps_spec.rb
View
@@ -150,7 +150,28 @@ module VCAP::CloudController
describe "GET /apps/:name/instances/:instance_id/files/(:path)" do
before do
+ @common_name = Sham.name
+
@app = Models::App.make(:space => user.default_space)
+
+ # make sure to create the app with the common name in a new space
+ # first. This is the non-optimal order for wanting to pick the
+ # one from the default space with higher priority, and we want to
+ # make sure the implementation finds the right even if the wrong
+ # one was created first.
+ @same_name_new_space = Models::App.make(
+ :name => @common_name,
+ :space => make_space_for_user(user)
+ )
+
+ @same_name_default_space = Models::App.make(
+ :name => @common_name,
+ :space => user.default_space
+ )
+
+ @diff_name_new_space = Models::App.make(
+ :space => make_space_for_user(user)
+ )
end
it "should delegate to v2 files api with path" do
@@ -182,6 +203,39 @@ module VCAP::CloudController
last_response.status.should == 200
last_response.body.should == "files"
end
+
+ it "should use the app from the default space" do
+ files_obj = mock("files")
+
+ Files.should_receive(:new).once.and_return(files_obj)
+ files_obj.should_receive(:dispatch).once.
+ with(:files, @same_name_default_space.guid, "1", nil, :allow_redirect => false).
+ and_return([HTTP::OK, "files"])
+
+ get "/apps/#{@common_name}/instances/1/files", {}, headers_for(user)
+
+ last_response.status.should == 200
+ last_response.body.should == "files"
+ end
+
+ it "should find an app from a non-default space" do
+ files_obj = mock("files")
+
+ Files.should_receive(:new).once.and_return(files_obj)
+ files_obj.should_receive(:dispatch).once.
+ with(:files, @diff_name_new_space.guid, "1", nil, :allow_redirect => false).
+ and_return([HTTP::OK, "files"])
+
+ get "/apps/#{@diff_name_new_space.name}/instances/1/files", {}, headers_for(user)
+
+ last_response.status.should == 200
+ last_response.body.should == "files"
+ end
+
+ it "should return 404 for a non-existent app" do
+ get "/apps/#{Sham.name}/instances/1/files", {}, headers_for(user)
+ last_response.status.should == 404
+ end
end
describe "GET /apps/:name/stats" do
Please sign in to comment.
Something went wrong with that request. Please try again.