EOD commit, working on issue #7

This commit is contained in:
Daniel Munn 2012-06-18 23:16:25 +01:00
parent d6ee91342a
commit 4d17cd4646
6 changed files with 188 additions and 5 deletions

View File

@ -3,7 +3,26 @@ dmsf_file_revisions_001:
dmsf_file_id: 1
source_dmsf_file_revision_id: NULL
name: "test.txt"
dmsf_folder_id: 1
dmsf_folder_id: NULL
disk_filename: "test.txt"
size: 4
mime_type: text/plain
title: "Test File"
description: NULL
workflow: NULL
minor_version: 0
major_version: 1
comment: NULL
deleted: 0
deleted_by_user_id: NULL
user_id: 1
#revision for file on non-enabled project
dmsf_file_revisions_002:
dmsf_file_id: 2
source_dmsf_file_revision_id: NULL
name: "test.txt"
dmsf_folder_id: NULL
disk_filename: "test.txt"
size: 4
mime_type: text/plain

View File

@ -7,3 +7,13 @@ dmsf_files_001:
notification: 0
deleted: 0
deleted_by_user_id: NULL
#file on non-dmsf enabled project
dmsf_files_002:
id: 2
project_id: 2
dmsf_folder_id: NULL
name: "test.txt"
notification: 0
deleted: 0
deleted_by_user_id: NULL

1
test/fixtures/files/test.txt vendored Normal file
View File

@ -0,0 +1 @@
1234

View File

@ -2,7 +2,7 @@ require File.expand_path('../../test_helper', __FILE__)
class DmsfWebdavIntegrationTest < RedmineDmsf::Test::IntegrationTest
fixtures :projects, :users, :members, :enabled_modules, :dmsf_folders, :dmsf_files, :dmsf_file_revisions
fixtures :projects, :users, :members, :member_roles, :roles, :enabled_modules, :dmsf_folders, :dmsf_files, :dmsf_file_revisions
def setup
@headers = credentials('admin')
@ -41,17 +41,34 @@ class DmsfWebdavIntegrationTest < RedmineDmsf::Test::IntegrationTest
get 'dmsf/webdav', nil, @headers
assert_response :success
assert response.body.match(Project.find(3).name).nil?, "Unexpected find of project #{Project.find(3).name} in return data"
assert response.body.match(Project.find(2).name).nil?, "Unexpected find of project #{Project.find(2).name} in return data"
end
test "should return status 404 when accessing non-existant or non dmsf-enabled project" do
## Test project resource object
get 'dmsf/webdav/project_does_not_exist', nil, @headers
assert_response 404
get "dmsf/webdav/#{Project.find(2).identifier}", nil, @headers
assert_response 404
## Test dmsf resource object
get 'dmsf/webdav/project_does_not_exist/test1', nil, @headers
assert_response 404
get "dmsf/webdav/#{Project.find(3).identifier}", nil, @headers
STDOUT.puts response.body
get "dmsf/webdav/#{Project.find(2).identifier}/test.txt", nil, @headers
assert_response 404
end
test "download file from DMSF enabled project" do
DmsfFile.storage_path = File.expand_path('../../fixtures/files', __FILE__)
get "dmsf/webdav/#{Project.find(1).identifier}/test.txt", nil, @headers
assert_response 200
assert (response.body != "1234"), "File downloaded with expected contents"
end
test "should list dmsf contents within \"#{Project.find(1).identifier}\"" do
@ -61,4 +78,41 @@ STDOUT.puts response.body
assert !response.body.match(DmsfFile.find(1).name).nil?, "Expected to find #{DmsfFile.find(1).name} in return data"
end
test "user assigned to project" do
#We'll be using project 2 and user jsmith for this test (Manager)
project = Project.find(2)
role = Role.find(2) #Developer role
jsmith = credentials('jsmith')
user = User.find(2)
get "dmsf/webdav/#{project.identifier}", nil, jsmith
assert_response 404
project.enable_module! :dmsf #Flag module enabled
get "dmsf/webdav/#{project.identifier}", nil, jsmith
assert_response 404
role.add_permission! :view_dmsf_folders #assign rights
get "dmsf/webdav/#{project.identifier}", nil, jsmith
assert_response :success
get "dmsf/webdav/#{project.identifier}/test.txt", nil, jsmith
assert_response 403 #Access is not granted as does not hold view_dmsf_files role (yet)
role.add_permission! :view_dmsf_files #assign rights
get "dmsf/webdav/#{project.identifier}/test.txt", nil, jsmith
assert_response :success
assert (response.body != "1234"), "File downloaded with expected contents"
#tear down
project.disable_module! :dmsf
role.remove_permission! :view_dmsf_folders
role.remove_permission! :view_dmsf_files
end
end

View File

@ -0,0 +1,72 @@
require File.expand_path('../../test_helper', __FILE__)
class DmsfWebdavMkcolTest < RedmineDmsf::Test::IntegrationTest
fixtures :projects, :users, :members, :member_roles, :roles, :enabled_modules, :dmsf_folders
def setup
@headers = credentials('admin')
super
end
def teardown
@headers = nil
end
test "MKCOL requires authentication" do
xml_http_request :mkcol, "dmsf/webdav/test1"
assert_response 401
end
test "MKCOL fails to create folder at root level" do
xml_http_request :mkcol, "dmsf/webdav/test1", nil, @headers
assert_response 501 #Not Implemented at this level
end
test "should not succeed on a non-existant project" do
xml_http_request :mkcol, "dmsf/webdav/project_doesnt_exist/test1", nil, @headers
assert_response 404 #Not found
end
test "should not succed on a non-dmsf enabled project" do
xml_http_request :mkcol, "dmsf/webdav/#{Project.find(2).identifier}/test1", nil, @headers
assert_response 404
end
test "should create folder on dmsf enabled project" do
xml_http_request :mkcol, "dmsf/webdav/#{Project.find(1).identifier}/test1", nil, @headers
assert_response :success
end
test "should fail to create folder that already exists" do
xml_http_request :mkcol, "dmsf/webdav/#{Project.find(1).identifier}/test1", nil, @headers
assert_response :success
xml_http_request :mkcol, "dmsf/webdav/#{Project.find(1).identifier}/test1", nil, @headers
assert_response 405 #Method not Allowed
end
test "should fail to create folder for user without rights" do
xml_http_request :mkcol, "dmsf/webdav/#{Project.find(1).identifier}/test1", nil, credentials('jsmith')
assert_response 403 #Forbidden
end
test "should create folder for non-admin user with rights" do
role = Role.find(2) #Developer role
jsmith = credentials('jsmith')
user = User.find(2)
project = Project.find(2)
role.add_permission! :folder_manipulation
project.enable_module! :dmsf
xml_http_request :mkcol, "dmsf/webdav/#{project.identifier}/test1", nil, credentials('jsmith')
assert_response :success
role.remove_permission! :folder_manipulation
project.disable_module! :dmsf
end
end

View File

@ -0,0 +1,27 @@
require File.expand_path('../../test_helper', __FILE__)
class DmsfWebdavPostTest < RedmineDmsf::Test::IntegrationTest
fixtures :users, :enabled_modules
def setup
@headers = credentials('admin')
super
end
def teardown
@headers = nil
end
#Test that any post request is authenticated
def test_post_request_authenticated
post "/dmsf/webdav/"
assert_response 401 #401 Unauthorized
end
#Test post is not implimented
def test_post_not_implemented
post "/dmsf/webdav/", nil, @headers
assert_response 501 #501 Not Implemented
end
end