diff --git a/app/controllers/application.rb b/app/controllers/application.rb index 3f4fc67e..f6e15080 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -40,7 +40,13 @@ class ApplicationController < ActionController::Base @action_name = @params['action'] || 'index' @web_name = @params['web'] @wiki = wiki - @web = @wiki.webs[@web_name] unless @web_name.nil? + if @web_name + @web = @wiki.webs[@web_name] + if @web.nil? + render_text "Unknown web '#{@web_name}'", '404 Not Found' + return false + end + end @page_name = @file_name = @params['id'] @page = @wiki.read_page(@web_name, @page_name) unless @page_name.nil? @author = cookies['author'] || 'AnonymousCoward' diff --git a/test/functional/application_test.rb b/test/functional/application_test.rb index 5e74cd2e..3a33df74 100755 --- a/test/functional/application_test.rb +++ b/test/functional/application_test.rb @@ -22,5 +22,10 @@ class ApplicationTest < Test::Unit::TestCase r = process('show', 'web' => 'wiki1', 'id' => 'HomePage') assert_equal 'text/html; charset=UTF-8', r.headers['Content-Type'] end + + def test_connect_to_model_unknown_wiki + r = process('show', 'web' => 'unknown_wiki', 'id' => 'HomePage') + assert_equal 404, r.response_code + end end diff --git a/test/functional/wiki_controller_test.rb b/test/functional/wiki_controller_test.rb index 39cce055..93bdb6d4 100755 --- a/test/functional/wiki_controller_test.rb +++ b/test/functional/wiki_controller_test.rb @@ -166,6 +166,7 @@ class WikiControllerTest < Test::Unit::TestCase end def test_index_multiple_webs_web_explicit + @wiki.create_web('Test Wiki 2', 'wiki2') process('index', 'web' => 'wiki2') assert_redirected_to :web => 'wiki2', :action => 'show', :id => 'HomePage' end