mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
6a8519ca89
Host authentication introduced by #33145 allows only "0.0.0.0/0", "::/0" and "localhost" in the development environment.4298df00ae/railties/lib/rails/application/configuration.rb (L33)
But `rack-test` use `example.org` for default host.6c07bf53ad/lib/rack/test.rb (L13)
Therefore, if `hosts` is not specified, host authentication rejects the request. In Travis CI, this problem does not occur because `test` is specified by default in `RAILS_ENV` and `RACK_ENV`. https://docs.travis-ci.com/user/environment-variables/#default-environment-variables If user actually use it, env may not always be specified. Explicitly specify hosts in the file so that it works in any environment.
51 lines
903 B
Ruby
51 lines
903 B
Ruby
# frozen_string_literal: true
|
|
|
|
require "bundler/inline"
|
|
|
|
gemfile(true) do
|
|
source "https://rubygems.org"
|
|
|
|
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
|
|
|
gem "rails", github: "rails/rails"
|
|
end
|
|
|
|
require "action_controller/railtie"
|
|
|
|
class TestApp < Rails::Application
|
|
config.root = __dir__
|
|
config.hosts << "example.org"
|
|
secrets.secret_key_base = "secret_key_base"
|
|
|
|
config.logger = Logger.new($stdout)
|
|
Rails.logger = config.logger
|
|
|
|
routes.draw do
|
|
get "/" => "test#index"
|
|
end
|
|
end
|
|
|
|
class TestController < ActionController::Base
|
|
include Rails.application.routes.url_helpers
|
|
|
|
def index
|
|
render plain: "Home"
|
|
end
|
|
end
|
|
|
|
require "minitest/autorun"
|
|
require "rack/test"
|
|
|
|
class BugTest < Minitest::Test
|
|
include Rack::Test::Methods
|
|
|
|
def test_returns_success
|
|
get "/"
|
|
assert last_response.ok?
|
|
end
|
|
|
|
private
|
|
def app
|
|
Rails.application
|
|
end
|
|
end
|