aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/dispatch/routing/ipv6_redirect_test.rb
blob: 179aee9ba7b4b38d4399e9410123c991e589c5da (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
require "abstract_unit"

class IPv6IntegrationTest < ActionDispatch::IntegrationTest
  Routes = ActionDispatch::Routing::RouteSet.new
  include Routes.url_helpers

  class ::BadRouteRequestController < ActionController::Base
    include Routes.url_helpers
    def index
      render plain: foo_path
    end

    def foo
      redirect_to action: :index
    end
  end

  Routes.draw do
    get "/",    to: "bad_route_request#index", as: :index
    get "/foo", to: "bad_route_request#foo", as: :foo
  end

  def _routes
    Routes
  end

  APP = build_app Routes
  def app
    APP
  end

  test "bad IPv6 redirection" do
    #   def test_simple_redirect
    request_env = {
      "REMOTE_ADDR" => "fd07:2fa:6cff:2112:225:90ff:fec7:22aa",
      "HTTP_HOST"   => "[fd07:2fa:6cff:2112:225:90ff:fec7:22aa]:3000",
      "SERVER_NAME" => "[fd07:2fa:6cff:2112:225:90ff:fec7:22aa]",
      "SERVER_PORT" => 3000 }

    get "/foo", env: request_env
    assert_response :redirect
    assert_equal "http://[fd07:2fa:6cff:2112:225:90ff:fec7:22aa]:3000/", redirect_to_url
  end
end