add more comprehensive unit tests for transport parser config
[arvados.git] / spec / google / api_client / auth / oauth_1_spec.rb
1 # Copyright 2010 Google Inc.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #      http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 require 'spec_helper'
16
17 require 'oauth'
18 require 'google/api_client/auth/oauth_1'
19
20 describe Google::APIClient::OAuth1, 'in the default configuration' do
21   before do
22     @oauth = Google::APIClient::OAuth1.new
23   end
24
25   it 'should have the correct request_token_uri' do
26     @oauth.request_token_uri.should ==
27       'https://www.google.com/accounts/OAuthGetRequestToken'
28   end
29
30   it 'should have the correct authorization_uri' do
31     @oauth.authorization_endpoint_uri.should ==
32       'https://www.google.com/accounts/OAuthAuthorizeToken'
33   end
34
35   it 'should have the correct access_token_uri' do
36     @oauth.access_token_uri.should ==
37       'https://www.google.com/accounts/OAuthGetAccessToken'
38   end
39
40   it 'should have the correct consumer_key' do
41     @oauth.consumer_key.should == 'anonymous'
42   end
43
44   it 'should have the correct consumer_secret' do
45     @oauth.consumer_secret.should == 'anonymous'
46   end
47
48   it 'should allow the request_token to be set manually' do
49     @oauth.request_token = OAuth::RequestToken.new(@oauth, 'key', 'secret')
50     @oauth.request_token.token.should == 'key'
51     @oauth.request_token.secret.should == 'secret'
52   end
53
54   it 'should not allow the request_token to be set to bogus value' do
55     (lambda do
56       @oauth.request_token = 42
57     end).should raise_error(TypeError)
58   end
59 end
60
61 describe Google::APIClient::OAuth1, 'configured for use with bogus service' do
62   before do
63     @oauth = Google::APIClient::OAuth1.new(:service => :bogus)
64   end
65
66   it 'should have the default configuration' do
67     @oauth.request_token_uri.should ==
68       Google::APIClient::OAuth1::DEFAULTS[:request_token_uri]
69     @oauth.authorization_endpoint_uri.should ==
70       Google::APIClient::OAuth1::DEFAULTS[:authorization_uri]
71     @oauth.access_token_uri.should ==
72       Google::APIClient::OAuth1::DEFAULTS[:access_token_uri]
73     @oauth.scopes.should ==
74       Google::APIClient::OAuth1::DEFAULTS[:scopes]
75     @oauth.callback.should ==
76       Google::APIClient::OAuth1::DEFAULTS[:callback]
77     @oauth.display_name.should ==
78       Google::APIClient::OAuth1::DEFAULTS[:display_name]
79     @oauth.consumer_key.should ==
80       Google::APIClient::OAuth1::DEFAULTS[:consumer_key]
81     @oauth.consumer_secret.should ==
82       Google::APIClient::OAuth1::DEFAULTS[:consumer_secret]
83   end
84 end