You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2023 Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. require_relative '../test_helper'
  19. class WelcomeTest < Redmine::IntegrationTest
  20. fixtures :users, :email_addresses,
  21. :projects, :enabled_modules, :members, :member_roles, :roles
  22. def test_robots
  23. Project.find(3).update_attribute :status, Project::STATUS_CLOSED
  24. get '/robots.txt'
  25. assert_response :success
  26. assert_equal 'text/plain', @response.media_type
  27. # Redmine::Utils.relative_url_root does not effect on Rails 5.1.4.
  28. assert @response.body.match(%r{^Disallow: /projects/ecookbook/issues\r?$})
  29. assert @response.body.match(%r{^Disallow: /issues\?\*sort=\r?$})
  30. assert @response.body.match(%r{^Disallow: /issues\?\*set_filter=\r?$})
  31. assert @response.body.match(%r{^Disallow: /issues/\*\.pdf\$\r?$})
  32. assert @response.body.match(%r{^Disallow: /projects/\*\.pdf\$\r?$})
  33. assert @response.body.match(%r{^Disallow: /login\r?$})
  34. assert @response.body.match(%r{^Disallow: /account/register\r?$})
  35. assert @response.body.match(%r{^Disallow: /account/lost_password\r?$})
  36. # closed projects are included in the list
  37. assert @response.body.match(%r{^Disallow: /projects/subproject1/issues\r?$})
  38. end
  39. def test_robots_when_login_is_required
  40. with_settings :login_required => '1' do
  41. get '/robots.txt'
  42. assert_response :success
  43. assert_equal 'text/plain', @response.media_type
  44. # Disallow everything if logins are required
  45. assert_not @response.body.match(%r{^Disallow: /projects/ecookbook/issues\r?$})
  46. assert @response.body.match(%r{^Disallow: /\r?$})
  47. end
  48. end
  49. def test_robots_should_not_respond_to_formats_other_than_txt
  50. %w(robots.json robots).each do |file|
  51. get "/#{file}"
  52. assert_response :not_found
  53. end
  54. end
  55. end