Commit e9eeb111 authored by Terence Lee's avatar Terence Lee

actually test https with hitting https

parent ff012e3a
...@@ -118,11 +118,18 @@ RSpec.describe "Simple" do ...@@ -118,11 +118,18 @@ RSpec.describe "Simple" do
let(:name) { "https_only" } let(:name) { "https_only" }
it "should redirect http to https" do it "should redirect http to https" do
response = app.get("/foo") app.run do
response = app.get("/foo.html")
expect(response.code).to eq("301") expect(response.code).to eq("301")
uri = URI(response['Location']) uri = URI(response['Location'])
expect(uri.scheme).to eq("https") expect(uri.scheme).to eq("https")
expect(uri.path).to eq("/foo") expect(uri.path).to eq("/foo.html")
response = app.get(uri)
expect(response.code).to eq("200")
expect(response.body.chomp).to eq("foobar")
end
end
end end
end end
......
...@@ -116,10 +116,17 @@ class AppRunner ...@@ -116,10 +116,17 @@ class AppRunner
network_retry(max_retries) do network_retry(max_retries) do
uri = URI(path) uri = URI(path)
uri.host = RouterRunner::HOST_IP if uri.host.nil? uri.host = RouterRunner::HOST_IP if uri.host.nil?
uri.port = RouterRunner::HOST_PORT if (uri.host == RouterRunner::HOST_IP && uri.port != RouterRunner::HOST_PORT) || uri.port.nil?
uri.scheme = "http" if uri.scheme.nil? uri.scheme = "http" if uri.scheme.nil?
Net::HTTP.get_response(URI(uri.to_s)) Net::HTTP.start(
uri.host,
uri.port,
use_ssl: uri.scheme == "https",
verify_mode: OpenSSL::SSL::VERIFY_NONE
) do |http|
request = Net::HTTP::Get.new(uri.to_s)
http.request(request)
end
end end
end end
......
...@@ -7,8 +7,8 @@ class RouterRunner < ContainerRunner ...@@ -7,8 +7,8 @@ class RouterRunner < ContainerRunner
rescue Errno::ENOENT rescue Errno::ENOENT
end end
CONTAINER_PORT = "80" HTTP_PORT = "80"
HOST_PORT = "80" HTTPS_PORT = "443"
HOST_IP = boot2docker_ip || "127.0.0.1" HOST_IP = boot2docker_ip || "127.0.0.1"
def initialize def initialize
...@@ -18,9 +18,13 @@ class RouterRunner < ContainerRunner ...@@ -18,9 +18,13 @@ class RouterRunner < ContainerRunner
"HostConfig" => { "HostConfig" => {
"Links" => ["app:app"], "Links" => ["app:app"],
"PortBindings" => { "PortBindings" => {
"#{CONTAINER_PORT}/tcp" => [{ "#{HTTP_PORT}/tcp" => [{
"HostIp" => HOST_IP, "HostIp" => HOST_IP,
"HostPort" => HOST_PORT, "HostPort" => HTTP_PORT
}],
"#{HTTPS_PORT}/tcp" => [{
"HostIp" => HOST_IP,
"HostPort" => HTTPS_PORT
}] }]
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment