From 311eeb86d60bd6cbffa6db7e75ebd12cb31cc011 Mon Sep 17 00:00:00 2001 From: "COLA@Redminetest" Date: Tue, 8 Nov 2016 22:11:37 +0100 Subject: [PATCH] Added tests for OPTIONS and HEAD requests for updated MsOffice support. --- test/integration/dmsf_webdav_head_test.rb | 50 +++++++++++++++++++- test/integration/dmsf_webdav_options_test.rb | 22 ++++++++- 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/test/integration/dmsf_webdav_head_test.rb b/test/integration/dmsf_webdav_head_test.rb index 676867ea..7e331d53 100644 --- a/test/integration/dmsf_webdav_head_test.rb +++ b/test/integration/dmsf_webdav_head_test.rb @@ -54,6 +54,18 @@ class DmsfWebdavHeadTest < RedmineDmsf::Test::IntegrationTest check_headers_exist end + def test_head_responds_anonymous_msoffice_user_agent + head "/dmsf/webdav/#{@project1.identifier}", nil, {:HTTP_USER_AGENT => "Microsoft Office Word 2014"} + assert_response :success + check_headers_exist + end + + def test_head_responds_anonymous_other_user_agent + head "/dmsf/webdav/#{@project1.identifier}", nil, {:HTTP_USER_AGENT => "Other"} + assert_response 401 + check_headers_dont_exist + end + # Note: # At present we use Rack to serve the file, this makes life easy however it removes the Etag # header and invalidates the test - where as a folder listing will always not include a last-modified @@ -65,18 +77,54 @@ class DmsfWebdavHeadTest < RedmineDmsf::Test::IntegrationTest check_headers_exist # Note it'll allow 1 out of the 3 expected to fail end + def test_head_responds_to_file_anonymous_msoffice_user_agent + head "/dmsf/webdav/#{@project1.identifier}/test.txt", nil, {:HTTP_USER_AGENT => "Microsoft Office Word 2014"} + assert_response :success + check_headers_exist # Note it'll allow 1 out of the 3 expected to fail + end + + def test_head_responds_to_file_anonymous_other_user_agent + head "/dmsf/webdav/#{@project1.identifier}/test.txt", nil, {:HTTP_USER_AGENT => "Other"} + assert_response 401 + check_headers_dont_exist + end + def test_head_fails_when_file_not_found head "/dmsf/webdav/#{@project1.identifier}/not_here.txt", nil, @admin assert_response :missing check_headers_dont_exist end + def test_head_fails_when_file_not_found_anonymous_msoffice_user_agent + head "/dmsf/webdav/#{@project1.identifier}/not_here.txt", nil, {:HTTP_USER_AGENT => "Microsoft Office Word 2014"} + assert_response :missing + check_headers_dont_exist + end + + def test_head_fails_when_file_not_found_anonymous_other_user_agent + head "/dmsf/webdav/#{@project1.identifier}/not_here.txt", nil, {:HTTP_USER_AGENT => "Other"} + assert_response 401 + check_headers_dont_exist + end + def test_head_fails_when_folder_not_found head '/dmsf/webdav/folder_not_here', nil, @admin assert_response :missing check_headers_dont_exist end + def test_head_fails_when_folder_not_found_anonymous_msoffice_user_agent + head '/dmsf/webdav/folder_not_here', nil, {:HTTP_USER_AGENT => "Microsoft Office Word 2014"} + assert_response :missing + check_headers_dont_exist + end + + def test_head_fails_when_folder_not_found_anonymous_other_user_agent + head '/dmsf/webdav/folder_not_here', nil, {:HTTP_USER_AGENT => "Other"} + assert_response 401 + check_headers_dont_exist + end + def test_head_fails_when_project_is_not_enabled_for_dmsf head "/dmsf/webdav/#{@project2.identifier}/test.txt", nil, @jsmith assert_response :missing @@ -116,4 +164,4 @@ class DmsfWebdavHeadTest < RedmineDmsf::Test::IntegrationTest end end -end \ No newline at end of file +end diff --git a/test/integration/dmsf_webdav_options_test.rb b/test/integration/dmsf_webdav_options_test.rb index 8e532280..0d0a140b 100644 --- a/test/integration/dmsf_webdav_options_test.rb +++ b/test/integration/dmsf_webdav_options_test.rb @@ -117,6 +117,26 @@ class DmsfWebdavOptionsTest < RedmineDmsf::Test::IntegrationTest assert response.headers['Ms-Author-Via'] == 'DAV', 'Ms-Author-Via header - expected: DAV' end + def test_un_authenticated_options_for_msoffice_user_agent + xml_http_request :options, "/dmsf/webdav/#{@project1.identifier}", nil, {:HTTP_USER_AGENT => "Microsoft Office Word 2014"} + assert_response 405 + end + + def test_authenticated_options_for_msoffice_user_agent + xml_http_request :options, "/dmsf/webdav/#{@project1.identifier}", nil, @admin.merge!({:HTTP_USER_AGENT => "Microsoft Office Word 2014"}) + assert_response :success + end + + def test_un_authenticated_options_for_other_user_agent + xml_http_request :options, "/dmsf/webdav/#{@project1.identifier}", nil, {:HTTP_USER_AGENT => "Other"} + assert_response 401 + end + + def test_authenticated_options_for_other_user_agent + xml_http_request :options, "/dmsf/webdav/#{@project1.identifier}", nil, @admin.merge!({:HTTP_USER_AGENT => "Other"}) + assert_response :success + end + # TODO: It doesn't work # def test_authenticated_options_returns_401_for_non_dmsf_enabled_items # @project2.disable_module! :dmsf @@ -129,4 +149,4 @@ class DmsfWebdavOptionsTest < RedmineDmsf::Test::IntegrationTest # assert_response 401 # refused # end -end \ No newline at end of file +end