Improve "allow editing" tests
While making changes to the test suite, I ran into some issues with these tests failing on occasion. I added some setup and teardown to help with this. But one thing I did notice is that the word "Upload" appears in the response body whether uploading is enabled or not, so I made these assertions more specific to the HTML rather than other places the word "Upload" might appear (which is related to Critic Markup).
This commit is contained in:
+38
-25
@@ -7,15 +7,29 @@ context "Precious::Views::Editing" do
|
|||||||
setup do
|
setup do
|
||||||
@path = cloned_testpath('examples/revert.git')
|
@path = cloned_testpath('examples/revert.git')
|
||||||
Precious::App.set(:gollum_path, @path)
|
Precious::App.set(:gollum_path, @path)
|
||||||
|
Precious::App.set(:wiki_options, {allow_editing: true, allow_uploads: true})
|
||||||
@wiki = Gollum::Wiki.new(@path)
|
@wiki = Gollum::Wiki.new(@path)
|
||||||
end
|
end
|
||||||
|
|
||||||
teardown do
|
teardown do
|
||||||
|
Precious::App.set(:wiki_options, {allow_editing: true, allow_uploads: true})
|
||||||
FileUtils.rm_rf(@path)
|
FileUtils.rm_rf(@path)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test 'creating pages is not blocked' do
|
||||||
|
post '/gollum/create',
|
||||||
|
content: 'abc',
|
||||||
|
format: 'markdown',
|
||||||
|
message: 'def',
|
||||||
|
page: 'D'
|
||||||
|
|
||||||
|
assert_equal last_response.status, 302
|
||||||
|
|
||||||
|
refute_nil @wiki.page('D')
|
||||||
|
end
|
||||||
|
|
||||||
test 'creating pages is blocked' do
|
test 'creating pages is blocked' do
|
||||||
Precious::App.set(:wiki_options, {allow_editing: false})
|
Precious::App.set(:wiki_options, {allow_editing: false, allow_uploads: false})
|
||||||
|
|
||||||
post '/gollum/create',
|
post '/gollum/create',
|
||||||
content: 'abc',
|
content: 'abc',
|
||||||
@@ -31,63 +45,62 @@ context "Precious::Views::Editing" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
test ".redirects.gollum file should not be accessible" do
|
test ".redirects.gollum file should not be accessible" do
|
||||||
Precious::App.set(:wiki_options, { allow_editing: true, allow_uploads: true })
|
|
||||||
get '/.redirects.gollum'
|
get '/.redirects.gollum'
|
||||||
assert_match /Accessing this resource is not allowed/, last_response.body
|
assert_match /Accessing this resource is not allowed/, last_response.body
|
||||||
end
|
end
|
||||||
|
|
||||||
test ".redirects.gollum file should not be editable" do
|
test ".redirects.gollum file should not be editable" do
|
||||||
Precious::App.set(:wiki_options, { allow_editing: true, allow_uploads: true })
|
|
||||||
get '/gollum/edit/.redirects.gollum'
|
get '/gollum/edit/.redirects.gollum'
|
||||||
assert_match /Changing this resource is not allowed/, last_response.body
|
assert_match /Changing this resource is not allowed/, last_response.body
|
||||||
end
|
end
|
||||||
|
|
||||||
test "frontend links for editing are not blocked" do
|
test "frontend links for editing are not blocked" do
|
||||||
Precious::App.set(:wiki_options, { allow_editing: true, allow_uploads: true })
|
|
||||||
get '/A'
|
get '/A'
|
||||||
|
|
||||||
assert_match /Delete this Page/, last_response.body, "'Delete this Page' link is blocked in page template"
|
assert last_response.body.include? "Delete this Page"
|
||||||
assert_match /New/, last_response.body, "'New' button is blocked in page template"
|
assert last_response.body.include? "New"
|
||||||
assert_match /Upload\b/, last_response.body, "'Upload' link is blocked in page template"
|
assert last_response.body.include? "<span>Upload</span>"
|
||||||
assert_match /Rename/, last_response.body, "'Rename' link is blocked in page template"
|
assert last_response.body.include? "Rename"
|
||||||
assert_match /Edit/, last_response.body, "'Edit' link is blocked in page template"
|
assert last_response.body.include? "Edit"
|
||||||
|
|
||||||
get '/gollum/overview'
|
get '/gollum/overview'
|
||||||
|
|
||||||
assert_match /New/, last_response.body, "'New' link is blocked in pages template"
|
assert last_response.body.include? "New"
|
||||||
|
|
||||||
get '/gollum/history/A'
|
get '/gollum/history/A'
|
||||||
|
|
||||||
refute_match /Edit/, last_response.body, "'Edit' link is not blocked in history template"
|
refute last_response.body.include? "Edit"
|
||||||
|
|
||||||
get '/gollum/compare/A/fc66539528eb96f21b2bbdbf557788fe8a1196ac..b26b791cb7917c4f37dd9cb4d1e0efb24ac4d26f'
|
get '/gollum/compare/A/fc665395..b26b791c'
|
||||||
|
|
||||||
refute_match /Edit Page/, last_response.body, "'Edit Page' link is not blocked in compare template"
|
refute last_response.body.include? "Edit Page"
|
||||||
assert_match /Revert Changes/, last_response.body, "'Revert Changes' link is blocked in compare template"
|
|
||||||
|
assert last_response.body.include? "Revert Changes"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "frontend links for editing blocked" do
|
test "frontend links for editing blocked" do
|
||||||
Precious::App.set(:wiki_options, { allow_editing: false })
|
Precious::App.set(:wiki_options, {allow_editing: false, allow_uploads: false})
|
||||||
|
|
||||||
get '/A'
|
get '/A'
|
||||||
|
|
||||||
refute_match /Delete this Page/, last_response.body, "'Delete this Page' link not blocked in page template"
|
refute last_response.body.include? "Delete this Page"
|
||||||
refute_match /New/, last_response.body, "'New' button not blocked in page template"
|
refute last_response.body.include? "<span>Upload</span>"
|
||||||
refute_match /Upload\b/, last_response.body, "'Upload' link not blocked in page template"
|
refute last_response.body.include? "Rename"
|
||||||
refute_match /Rename/, last_response.body, "'Rename' link not blocked in page template"
|
refute last_response.body.include? "Edit"
|
||||||
refute_match /Edit/, last_response.body, "'Edit' link not blocked in page template"
|
refute last_response.body.include? "New"
|
||||||
|
|
||||||
get '/gollum/overview'
|
get '/gollum/overview'
|
||||||
|
|
||||||
refute_match /New/, last_response.body, "'New' link not blocked in pages template"
|
refute last_response.body.include? "New"
|
||||||
|
|
||||||
get '/gollum/history/A'
|
get '/gollum/history/A'
|
||||||
|
|
||||||
refute_match /Edit/, last_response.body, "'Edit' link not blocked in history template"
|
refute last_response.body.include? "Edit"
|
||||||
|
|
||||||
get '/gollum/compare/A/fc66539528eb96f21b2bbdbf557788fe8a1196ac..b26b791cb7917c4f37dd9cb4d1e0efb24ac4d26f'
|
get '/gollum/compare/A/fc665395..b26b791c'
|
||||||
|
|
||||||
refute_match /Edit Page/, last_response.body, "'Edit Page' link not blocked in compare template"
|
refute last_response.body.include? "Edit Page"
|
||||||
refute_match /Revert Changes/, last_response.body, "'Revert Changes' link not blocked in compare template"
|
refute last_response.body.include? "Revert Changes"
|
||||||
end
|
end
|
||||||
|
|
||||||
def app
|
def app
|
||||||
|
|||||||
Reference in New Issue
Block a user