Removing transport and OAuth code that is no longer needed.

git-svn-id: https://google-api-ruby-client.googlecode.com/svn/trunk@28 c1d61fac-ed7f-fcc1-18f7-ff78120a04ef
This commit is contained in:
bobaman@google.com committed 2010-09-13 21:54:18 +00:00
1 parent 541054e88d
commit 9d68bf115c
6 files changed
-822

No files matched your search

@@ -1,84 +0,0 @@
# Copyright 2010 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
require 'spec_helper'
require 'oauth'
require 'google/api_client/auth/oauth_1'
describe Google::APIClient::OAuth1, 'in the default configuration' do
before do
@oauth = Google::APIClient::OAuth1.new
end
it 'should have the correct request_token_uri' do
@oauth.request_token_uri.should ==
'https://www.google.com/accounts/OAuthGetRequestToken'
end
it 'should have the correct authorization_uri' do
@oauth.authorization_endpoint_uri.should ==
'https://www.google.com/accounts/OAuthAuthorizeToken'
end
it 'should have the correct access_token_uri' do
@oauth.access_token_uri.should ==
'https://www.google.com/accounts/OAuthGetAccessToken'
end
it 'should have the correct consumer_key' do
@oauth.consumer_key.should == 'anonymous'
end
it 'should have the correct consumer_secret' do
@oauth.consumer_secret.should == 'anonymous'
end
it 'should allow the request_token to be set manually' do
@oauth.request_token = OAuth::RequestToken.new(@oauth, 'key', 'secret')
@oauth.request_token.token.should == 'key'
@oauth.request_token.secret.should == 'secret'
end
it 'should not allow the request_token to be set to bogus value' do
(lambda do
@oauth.request_token = 42
end).should raise_error(TypeError)
end
end
describe Google::APIClient::OAuth1, 'configured for use with bogus service' do
before do
@oauth = Google::APIClient::OAuth1.new(:service => :bogus)
end
it 'should have the default configuration' do
@oauth.request_token_uri.should ==
Google::APIClient::OAuth1::DEFAULTS[:request_token_uri]
@oauth.authorization_endpoint_uri.should ==
Google::APIClient::OAuth1::DEFAULTS[:authorization_uri]
@oauth.access_token_uri.should ==
Google::APIClient::OAuth1::DEFAULTS[:access_token_uri]
@oauth.scopes.should ==
Google::APIClient::OAuth1::DEFAULTS[:scopes]
@oauth.callback.should ==
Google::APIClient::OAuth1::DEFAULTS[:callback]
@oauth.display_name.should ==
Google::APIClient::OAuth1::DEFAULTS[:display_name]
@oauth.consumer_key.should ==
Google::APIClient::OAuth1::DEFAULTS[:consumer_key]
@oauth.consumer_secret.should ==
Google::APIClient::OAuth1::DEFAULTS[:consumer_secret]
end
end
@@ -1,72 +0,0 @@
# Copyright 2010 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
require 'spec_helper'
require 'oauth'
require 'google/api_client/auth/oauth_1'
require 'addressable/uri'
describe Google::APIClient::OAuth1, 'configured for use with Buzz' do
before do
@oauth = Google::APIClient::OAuth1.new(:service => :buzz)
end
it 'should not have the default configuration' do
@oauth.authorization_endpoint_uri.should_not ==
Google::APIClient::OAuth1::DEFAULTS[:authorization_uri]
@oauth.scopes.should_not ==
Google::APIClient::OAuth1::DEFAULTS[:scopes]
end
it 'should have the correct authorization_uri' do
@oauth.authorization_endpoint_uri.should ==
'https://www.google.com/buzz/api/auth/OAuthAuthorizeToken'
end
it 'should have the correct scope' do
@oauth.scopes.should include('https://www.googleapis.com/auth/buzz')
end
it 'should be able to get a request token' do
@oauth.request_token.token.should =~ /^[a-zA-Z0-9\/\-\_\+]+$/
@oauth.request_token.secret.should =~ /^[a-zA-Z0-9\/\-\_\+]+$/
end
it 'should issue only a single request token' do
@oauth.request_token.token.should == @oauth.request_token.token
@oauth.request_token.secret.should == @oauth.request_token.secret
end
it 'should build the correct authorization URI' do
icon_uri = 'http://www.google.com/images/icons/feature/padlock-g128.png'
uri = @oauth.authorization_uri(
:domain => @oauth.consumer_key,
:iconUrl => icon_uri,
:scope => @oauth.scopes.join(' ')
)
uri.should =~
/^https:\/\/www.google.com\/buzz\/api\/auth\/OAuthAuthorizeToken/
Addressable::URI.unencode(uri).should =~
Regexp.new(Regexp.escape(@oauth.request_token.token))
Addressable::URI.unencode(uri).should =~
Regexp.new(Regexp.escape(icon_uri))
for scope in @oauth.scopes
Addressable::URI.unencode(uri).should =~
Regexp.new(Regexp.escape(scope))
end
end
# Not much we can do to test any further into the OAuth flow
end
@@ -1,104 +0,0 @@
# Copyright 2010 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
require 'spec_helper'
require 'net/http'
require 'net/https'
require 'google/api_client/transport/http_transport'
class AlwaysFail
def initialize(*args)
raise IOError, "This would never work."
end
end
Google::APIClient::HTTPTransport::METHOD_MAPPING[:fail] = AlwaysFail
describe Google::APIClient::HTTPTransport, 'in the default configuration' do
before do
@http = Google::APIClient::HTTPTransport.new
end
it 'should send a GET request' do
request = @http.build_request(:get, "http://www.google.com/")
response = @http.send_request(request)
status, headers, body = response
status.should >= 100
body.size.should > 0
headers.size.should > 0
end
it 'should send a GET request using SSL' do
request = @http.build_request(:get, "https://www.google.com/")
response = @http.send_request(request)
status, headers, body = response
status.should >= 100
body.size.should > 0
headers.size.should > 0
end
it 'should send a POST request' do
request = @http.build_request(
:post, "http://www.google.com/", :body => "A Body."
)
response = @http.send_request(request)
status, headers, body = response
status.should >= 100
body.size.should > 0
headers.size.should > 0
end
it 'should send a PUT request' do
request = @http.build_request(
:put, "http://www.google.com/", :body => "A Body."
)
response = @http.send_request(request)
status, headers, body = response
status.should >= 100
body.size.should > 0
headers.size.should > 0
end
it 'should send a DELETE request' do
request = @http.build_request(:delete, "http://www.google.com/")
response = @http.send_request(request)
status, headers, body = response
status.should >= 100
body.size.should > 0
headers.size.should > 0
end
it 'should fail to send a FAIL request' do
(lambda do
request = @http.build_request(:fail, "http://www.google.com/")
response = @http.send_request(request)
end).should raise_error(IOError)
end
it 'should fail to send a BOGUS request' do
(lambda do
response = @http.send_request(
["BOGUS", "http://www.google.com/", {}, [""]]
)
end).should raise_error(ArgumentError)
end
it 'should fail to connect to a non-addressable URI' do
(lambda do
request = @http.build_request(:get, "bogus://www.google.com/")
response = @http.send_request(request)
end).should raise_error(ArgumentError)
end
end
@@ -1,102 +0,0 @@
# Copyright 2010 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
require 'spec_helper'
require 'net/http'
require 'net/https'
require 'google/api_client/transport/http_transport'
def assemble_body_string(body)
body_string = ""
body.each do |chunk|
body_string += chunk
end
return body_string
end
describe Google::APIClient::HTTPTransport, 'in the default configuration' do
before do
@http = Google::APIClient::HTTPTransport.new
end
it 'should build a valid GET request' do
method, uri, headers, body =
@http.build_request(:get, "http://www.example.com/")
body_string = assemble_body_string(body)
method.should == "GET"
uri.should === "http://www.example.com/"
headers.keys.should_not include("Content-Length")
body_string.should == ""
end
it 'should build a valid POST request' do
method, uri, headers, body = @http.build_request(
:post, "http://www.example.com/", :body => "A body."
)
body_string = assemble_body_string(body)
method.should == "POST"
uri.should === "http://www.example.com/"
headers["Content-Length"].should == "7"
body_string.should == "A body."
end
it 'should build a valid PUT request' do
method, uri, headers, body = @http.build_request(
:put, "http://www.example.com/", :body => "A body."
)
body_string = assemble_body_string(body)
method.should == "PUT"
uri.should === "http://www.example.com/"
headers["Content-Length"].should == "7"
body_string.should == "A body."
end
it 'should build a valid DELETE request' do
method, uri, headers, body =
@http.build_request(:delete, "http://www.example.com/")
body_string = assemble_body_string(body)
method.should == "DELETE"
uri.should === "http://www.example.com/"
headers.keys.should_not include("Content-Length")
body_string.should == ""
end
it 'should not build a BOGUS request' do
(lambda do
@http.build_request(:bogus, "http://www.example.com/")
end).should raise_error(ArgumentError)
end
end
describe Google::APIClient::HTTPTransport,
'with a certificate store and connection pool' do
before do
@http = Google::APIClient::HTTPTransport.new(
:cert_store => OpenSSL::X509::Store.new,
:connection_pool => {
"http://www.example.com" => Net::HTTP.new("www.example.com", 80)
}
)
end
it 'should have the correct certificate store' do
# TODO(bobaman) Write a real test
@http.cert_store.should_not == nil
end
it 'should have the correct connection pool' do
@http.connection_pool.keys.should include("http://www.example.com")
end
end