Created
June 6, 2012 14:52
-
-
Save paneq/2882353 to your computer and use it in GitHub Desktop.
Capybara, SSL and non-SSL pages tested via Selenium with javascript.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
instruction = <<-COMMENT | |
# Yo dawg, I heard you like tests that are easy to setup... | |
# | |
# Define domains "trainer.project.test login.project.test" in /etc/hosts | |
# to point to one of your local interface (probably 127.0.0.1) | |
# | |
# /etc/hosts: | |
# 192.168.50.1 trainer.project.test | |
# 192.168.50.1 login.project.test | |
# | |
# Define a mechanism that will proxy ssl requests from port 443 to port 80 | |
# Define a mechanism that will proxy non-ssl request from port 80 to 8080 | |
# | |
# It is simple with nginx | |
# | |
# server { | |
# listen 192.168.50.1:443 ssl; | |
# server_name login.project.test; | |
# | |
# ssl on; | |
# ssl_certificate /home/rupert/develop/trainer/config/environments/development/host.pem; | |
# ssl_certificate_key /home/rupert/develop/trainer/config/environments/development/host.key; | |
# | |
# location / { | |
# proxy_pass http://192.168.50.1:80; | |
# proxy_set_header Host $host; | |
# proxy_set_header X-Real-IP $remote_addr; | |
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
# proxy_set_header X-Forwarded-Proto https; | |
# } | |
# } | |
# | |
# server { | |
# listen 192.168.50.1:80; | |
# server_name login.project.test; | |
# | |
# location / { | |
# proxy_pass http://192.168.50.1:8000; | |
# proxy_set_header Host $host; | |
# proxy_set_header X-Real-IP $remote_addr; | |
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
# } | |
# } | |
COMMENT | |
Capybara.server_port = 8000 | |
Capybara.app_host = "https://login.project.test/" | |
require 'net/http' | |
require 'net/https' | |
require "uri" | |
begin | |
# Test 80 => 8000 | |
# should fail with 502 because Capybara | |
# has not started server yet but should be | |
# connectable and host name should be properly | |
# resolved | |
uri = URI.parse(Capybara.app_host) | |
http = Net::HTTP.new(uri.host, 80) | |
request = Net::HTTP::Get.new(uri.request_uri) | |
response1 = http.request(request) | |
raise instruction unless response1.code.to_s.start_with?("5") | |
# Test 443 => 80 | |
# should fail in identical way but perform ssl unboxing | |
http = Net::HTTP.new(uri.host, 443) | |
http.use_ssl = true | |
http.verify_mode = OpenSSL::SSL::VERIFY_NONE | |
response2 = http.request(request) | |
raise instruction unless response2.code.to_s.start_with?("5") | |
raise instruction unless response1.body == response2.body | |
rescue Exception => exc | |
puts exc | |
raise instruction | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment