Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base: 6895a01901
...
compare: d11e82fbc6
  • 2 commits
  • 8 files changed
  • 0 commit comments
  • 2 contributors
Commits on Dec 17, 2011
Eugene Park Add HTTPS support to the Sfn::Loader#get and #post methods. fc4425b
Commits on Dec 19, 2011
Pair Fix ssl calls
0.7.1

* Integration smoke tests to validate proper ssl
request.
* Test loader code on the SSL context also
* Suppress the 'warning: peer certificate won't be verified in this SSL session'
* Changed version file namespace so it does not colide with the one on the gem
d11e82f
View
4 Gemfile.lock
@@ -28,7 +28,7 @@ GEM
open_gem (1.4.2)
launchy (~> 0.3.5)
rake (0.8.7)
- rr (1.0.2)
+ rr (1.0.4)
rspec (2.2.0)
rspec-core (~> 2.2)
rspec-expectations (~> 2.2)
@@ -56,7 +56,7 @@ DEPENDENCIES
nokogiri (>= 1.4.2)
oauth (>= 0.3.5)
open_gem (>= 1.4)
- rr (= 1.0.2)
+ rr (= 1.0.4)
rspec (~> 2.2)
ruby-debug (>= 0.10.4)
ruby-satisfaction!
View
7 README.markdown
@@ -11,6 +11,13 @@ For questions, please visit the [Get Satisfaction API community][3]
Changelog
=========
+0.7.1
+
+* Integration smoke tests to validate proper ssl
+request.
+* Test loader code on the SSL context also
+* Suppress the 'warning: peer certificate won't be verified in this SSL session'
+
0.7.0
* Revised Sfn::Resource so that it supports calls to API endpoints for nested resources
View
9 lib/satisfaction.rb
@@ -1,4 +1,13 @@
require 'satisfaction/external_dependencies'
+# Suppress the 'warning: peer certificate won't be verified in this SSL session'
+class Net::HTTP
+ alias_method :old_initialize, :initialize
+ def initialize(*args)
+ old_initialize(*args)
+ @ssl_context = OpenSSL::SSL::SSLContext.new
+ @ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
+ end
+end
module Sfn
end
class Satisfaction
View
2  lib/satisfaction/loader.rb
@@ -34,6 +34,7 @@ def get(url, options = {})
end
http = Net::HTTP.new(uri.host, uri.port)
+ http.use_ssl = true if uri.scheme.try(:downcase) == 'https'
add_authentication(request, http, options)
response = execute(http, request)
@@ -86,6 +87,7 @@ def post(url, options)
request.set_form_data(form)
http = Net::HTTP.new(uri.host, uri.port)
+ http.use_ssl = true if uri.scheme.try(:downcase) == 'https'
add_authentication(request, http, options)
response = execute(http, request)
View
4 lib/satisfaction/version.rb
@@ -1,8 +1,8 @@
-module Satisfaction
+module GemSatisfaction
module VERSION
MAJOR = 0
MINOR = 7
- PATCH = 0
+ PATCH = 1
PRE = nil
STRING = [MAJOR, MINOR, PATCH, PRE].compact.join('.')
View
4 ruby-satisfaction.gemspec
@@ -3,7 +3,7 @@ require File.expand_path("../lib/satisfaction/version", __FILE__)
Gem::Specification.new do |s|
s.name = "ruby-satisfaction"
- s.version = Satisfaction::VERSION::STRING
+ s.version = GemSatisfaction::VERSION::STRING
s.platform = Gem::Platform::RUBY
s.author = 'Get Satisfaction'
s.email = ["nerds+rubygems@getsatisfaction.com"]
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
s.add_development_dependency "fakeweb", "~> 1.3"
s.add_development_dependency "open_gem", ">= 1.4"
s.add_development_dependency "ruby-debug", ">= 0.10.4"
- s.add_development_dependency "rr", '1.0.2'
+ s.add_development_dependency "rr", '1.0.4'
s.extra_rdoc_files = [ "README.markdown" ]
s.files = `git ls-files`.split("\n") - ['.rvmrc', '.gitignore']
View
45 spec/integration_spec.rb
@@ -0,0 +1,45 @@
+require 'spec_helper'
+
+describe 'Smoke test SSL conections' do
+ before do
+ @app_host = 'getsatisfaction.com'
+ @api_host = 'api.getsatisfaction.com'
+ FakeWeb.clean_registry
+ FakeWeb.allow_net_connect = true
+ end
+
+ shared_examples_for 'get' do
+ it 'should get the first page of getsat topics' do
+ results = @sfn.companies['getsatisfaction'].topics.page(1, :limit => 10)
+ results.items.size.should == 10
+ end
+ end
+
+ context 'over ssl' do
+ before do
+ @sfn = Satisfaction.new(
+ :root => "https://#{@api_host}",
+ :autoload => false,
+ :request_token_url => "https://#{@app_host}/api/request_token",
+ :access_token_url => "https://#{@app_host}/api/access_token",
+ :authorize_url => "https://#{@app_host}/api/authorize"
+ )
+ end
+
+ it_should_behave_like 'get'
+ end
+
+ context 'not over ssl' do
+ before do
+ @sfn = Satisfaction.new(
+ :root => "http://#{@api_host}",
+ :autoload => false,
+ :request_token_url => "http://#{@app_host}/api/request_token",
+ :access_token_url => "http://#{@app_host}/api/access_token",
+ :authorize_url => "http://#{@app_host}/api/authorize"
+ )
+ end
+
+ it_should_behave_like 'get'
+ end
+end
View
187 spec/satisfaction/loader_spec.rb
@@ -3,8 +3,7 @@
describe Sfn::Loader do
# ==== GET ==========================================================================================================
-
- describe "#get" do
+ shared_examples_for "#get" do
before(:each) do
@response = nil
@status_code = '200'
@@ -12,12 +11,12 @@
@get = lambda do
FakeWeb.register_uri(
:get,
- 'http://test',
+ "http://#{@api_host}:#{@api_port}",
:body => @response_body,
:status => [@status_code]
)
stub(@loader).add_authentication {}
- @response = @loader.get('http://test')
+ @response = @loader.get(@api_url)
end
end
@@ -48,44 +47,6 @@
end
end
- describe "when we are in a redirect loop" do
- attr_reader :loader
-
- before(:each) do
- @url = 'http://loop/'
- @loader = Sfn::Loader.new
- stub(loader).add_authentication {}
- end
-
- describe "and the status is 301" do
- before(:each) do
- @get = lambda {
- FakeWeb.register_uri(:get, @url, :status => 301, :location => @url)
- @response = loader.get(@url)
- }
- end
-
- it "should raise a TooManyRedirects exception with an appropriate message" do
- @get.should raise_error(Sfn::TooManyRedirects, "Too many redirects")
- end
- end
-
- describe "and the status is 302" do
- before(:each) do
- @get = lambda {
- FakeWeb.register_uri(:get, @url, :status => 302, :location => @url)
- @response = loader.get(@url)
- }
- end
-
- it "should raise a TooManyRedirects exception with an appropriate message" do
- @get.should raise_error(Sfn::TooManyRedirects, "Too many redirects")
- end
- end
-
-
- end
-
describe "when the status is 400 (Bad Request)" do
before(:each) do
@status_code = '400'
@@ -193,20 +154,20 @@
end
# ==== POST ==================================================================================================
- describe "#post" do
+ shared_examples_for "#post" do
before(:each) do
@response = nil
@status_code = '200'
@post = lambda do
FakeWeb.register_uri(
:post,
- 'http://test',
+ "http://#{@api_host}:#{@api_port}",
:body => @response_body,
:status => [@status_code]
)
loader = Sfn::Loader.new
stub(loader).add_authentication {}
- @response = loader.post('http://test', "a=b")
+ @response = loader.post(@api_url, "a=b")
end
end
@@ -265,13 +226,113 @@
end
end
+ # ---- GATEWAY -----------------------------------------------------------------------------------------------
+ describe "when the status is 502 (Bad Gateway, returned when a Unicorn worker is killed)" do
+ before(:each) do
+ @status_code = '502'
+ end
+
+ it "should raise an Sfn::BadGateway error" do
+ @post.should raise_error(Sfn::BadGateway, "Bad Gateway")
+ end
+ end
+
+ describe "when the status is 504 (GatewayTimeOut)" do
+ before(:each) do
+ @status_code = '504'
+ end
+
+ it "should raise an Sfn::GatewayTimeOut error" do
+ @post.should raise_error(Sfn::GatewayTimeOut, "Gateway TimeOut")
+ end
+ end
+ end
+
+ context 'over ssl' do
+ before do
+ @api_host = 'test'
+ @api_url = "https://#{@api_host}"
+ @api_port = "443"
+ any_instance_of(Net::HTTP) do |n|
+ mock(n).use_ssl=(true)
+ end
+ end
+
+ it_should_behave_like '#get'
+ it_should_behave_like '#post'
+ end
+
+ context 'not over ssl' do
+ before do
+ @api_host = 'test'
+ @api_url = "http://#{@api_host}"
+ @api_port = ""
+ end
+
+ it_should_behave_like '#get'
+ it_should_behave_like '#post'
+
+
+ describe "when we are in a redirect loop" do
+ attr_reader :loader
+
+ before(:each) do
+ @url = @api_url
+ @loader = Sfn::Loader.new
+ stub(loader).add_authentication {}
+ end
+
+ describe "and the status is 301" do
+ before(:each) do
+ @get = lambda {
+ FakeWeb.register_uri(:get, "http://#{@api_host}:#{@api_port}", :status => 301, :location => @url)
+ @response = loader.get(@url)
+ }
+ end
+
+ it "should raise a TooManyRedirects exception with an appropriate message" do
+ @get.should raise_error(Sfn::TooManyRedirects, "Too many redirects")
+ end
+ end
+
+ describe "and the status is 302" do
+ before(:each) do
+ @get = lambda {
+ FakeWeb.register_uri(:get, "http://#{@api_host}:#{@api_port}", :status => 302, :location => @url)
+ @response = loader.get(@url)
+ }
+ end
+
+ it "should raise a TooManyRedirects exception with an appropriate message" do
+ @get.should raise_error(Sfn::TooManyRedirects, "Too many redirects")
+ end
+ end
+ end
+ end
+
# ---- MAINTENANCE --------------------------------------------------------------------------------------------------
+ describe 'MAINTENANCE' do
+ before(:each) do
+ @api_url = "http://test"
+ @response = nil
+ @status_code = '200'
+ @post = lambda do
+ FakeWeb.register_uri(
+ :post,
+ @api_url,
+ :body => @response_body,
+ :status => [@status_code]
+ )
+ loader = Sfn::Loader.new
+ stub(loader).add_authentication {}
+ @response = loader.post(@api_url, "a=b")
+ end
+ end
shared_examples_for "the site is in maintenance mode" do
-
describe "and there is not an element with a class of error_message_summary in the HTML" do
before(:each) do
- FakeWeb.register_uri(:get, 'http://test', :body => "blah", :status => "503")
+ FakeWeb.register_uri(:get, @api_url, :body => "blah", :status => "503")
end
it "should raise an error and include the default maintenance message" do
@@ -282,15 +343,14 @@
describe "and there is an element with a class of error_message_summary in the HTML" do
before(:each) do
@custom_error = "Something crazy is going down!"
- @response_body = "<html><head></head><body><h2 class='error_message_summary'>#{@custom_error}</h2></body>"
- FakeWeb.register_uri(:get, 'http://test', :body => @response_body, :status => "503")
- end
+ @response_body = "<html><head></head><body><h2 class='error_message_summary'>#{@custom_error}</h2></body>"
+ FakeWeb.register_uri(:get, @api_url, :body => @response_body, :status => "503")
+ end
it "should raise an error and include the contents of the element" do
@post.should raise_error(Sfn::SiteMaintenance, @custom_error)
end
end
-
end
describe "when the status is 405 (Method Not Allowed)" do
@@ -303,7 +363,7 @@
describe "when the site is not in maintenance mode" do
before(:each) do
- FakeWeb.register_uri(:get, 'http://test', :body => "blah", :status => "200")
+ FakeWeb.register_uri(:get, @api_url, :body => "blah", :status => "200")
end
it "should raise an error and include the reponse body" do
@@ -337,28 +397,5 @@
end
end
end
-
- # ---- GATEWAY -----------------------------------------------------------------------------------------------
- describe "when the status is 502 (Bad Gateway, returned when a Unicorn worker is killed)" do
- before(:each) do
- @status_code = '502'
- end
-
- it "should raise an Sfn::BadGateway error" do
- @post.should raise_error(Sfn::BadGateway, "Bad Gateway")
- end
- end
-
- describe "when the status is 504 (GatewayTimeOut)" do
- before(:each) do
- @status_code = '504'
- end
-
- it "should raise an Sfn::GatewayTimeOut error" do
- @post.should raise_error(Sfn::GatewayTimeOut, "Gateway TimeOut")
- end
- end
-
end
-
end

No commit comments for this range

Something went wrong with that request. Please try again.