4285: prepend './' to file path being retrieved when it is in a subdir in a collection.
authorradhika <radhika@curoverse.com>
Sat, 25 Oct 2014 14:01:40 +0000 (10:01 -0400)
committerradhika <radhika@curoverse.com>
Sat, 25 Oct 2014 14:01:40 +0000 (10:01 -0400)
apps/workbench/app/controllers/collections_controller.rb
apps/workbench/test/functional/collections_controller_test.rb

index 4e0008d93cf63887926c7d3ef7907d4f1f377bd3..b484df36318eb609ef3ba94d84d55eaa29c749e7 100644 (file)
@@ -145,9 +145,12 @@ class CollectionsController < ApplicationController
     usable_token = find_usable_token(tokens) do
       coll = Collection.find(params[:uuid])
     end
+
+    file_name = params[:file]
+    file_name = ('./' + file_name) if (file_name and file_name.include?('/'))
     if usable_token.nil?
       return  # Response already rendered.
-    elsif params[:file].nil? or not coll.manifest.has_file?(params[:file])
+    elsif file_name.nil? or not coll.manifest.has_file?(file_name)
       return render_not_found
     end
 
index ff53777da42ea35ea243418eb2180f0d05be8617..e62101003008044f97c305774855190ec0864d04 100644 (file)
@@ -206,4 +206,12 @@ class CollectionsControllerTest < ActionController::TestCase
     # runs.
     @response.body.length
   end
+
+  test "show file in a subdirectory of a collection" do
+    params = collection_params(:collection_with_files_in_subdir, 'subdir2/subdir3/subdir4/file1_in_subdir4.txt')
+    expect_content = stub_file_content
+    get(:show_file, params, session_for(:user1_with_load))
+    assert_response :success
+    assert_equal(expect_content, @response.body, "failed to get a correct file from Keep")
+  end
 end