Updated the configuration handling code.
[arvados.git] / spec / google / api_client / auth / services / buzz_slow_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 require "addressable/uri"
20
21 describe Google::APIClient::OAuth1, "configured for use with Buzz" do
22   before do
23     @oauth = Google::APIClient::OAuth1.new(:service => :buzz)
24   end
25
26   it "should not have the default configuration" do
27     @oauth.authorization_endpoint_uri.should_not ==
28       Google::APIClient::OAuth1::DEFAULTS[:authorization_uri]
29     @oauth.scopes.should_not ==
30       Google::APIClient::OAuth1::DEFAULTS[:scopes]
31   end
32
33   it "should have the correct authorization_uri" do
34     @oauth.authorization_endpoint_uri.should ==
35       "https://www.google.com/buzz/api/auth/OAuthAuthorizeToken"
36   end
37
38   it "should have the correct scope" do
39     @oauth.scopes.should include("https://www.googleapis.com/auth/buzz")
40   end
41   
42   it "should be able to get a request token" do
43     @oauth.request_token.token.should =~ /^[a-zA-Z0-9\/\-\_\+]+$/
44     @oauth.request_token.secret.should =~ /^[a-zA-Z0-9\/\-\_\+]+$/
45   end
46   
47   it "should issue only a single request token" do
48     @oauth.request_token.token.should == @oauth.request_token.token
49     @oauth.request_token.secret.should == @oauth.request_token.secret
50   end
51   
52   it "should build the correct authorization URI" do
53     icon_uri = "http://www.google.com/images/icons/feature/padlock-g128.png"
54     uri = @oauth.authorization_uri(
55       :domain => @oauth.consumer_key,
56       :iconUrl => icon_uri,
57       :scope => @oauth.scopes.join(" ")
58     )
59     uri.should =~
60       /^https:\/\/www.google.com\/buzz\/api\/auth\/OAuthAuthorizeToken/
61     Addressable::URI.unencode(uri).should =~
62       Regexp.new(Regexp.escape(@oauth.request_token.token))
63     Addressable::URI.unencode(uri).should =~
64       Regexp.new(Regexp.escape(icon_uri))
65     for scope in @oauth.scopes
66       Addressable::URI.unencode(uri).should =~
67         Regexp.new(Regexp.escape(scope))
68     end
69   end
70   
71   # Not much we can do to test any further into the OAuth flow
72 end