Skip to content

Commit 2622ebf

Browse files
committed
Add minimal tests for ClientSecrets
1 parent fda7288 commit 2622ebf

File tree

3 files changed

+62
-4
lines changed

3 files changed

+62
-4
lines changed

lib/google/api_client/client_secrets.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,12 @@ def initialize(options={})
8888
@client_id = fdata[:client_id] || fdata["client_id"]
8989
@client_secret = fdata[:client_secret] || fdata["client_secret"]
9090
@redirect_uris = fdata[:redirect_uris] || fdata["redirect_uris"]
91-
@redirect_uris ||= [fdata[:redirect_uri]]
91+
@redirect_uris ||= [fdata[:redirect_uri] || fdata["redirect_uri"]].compact
9292
@javascript_origins = (
9393
fdata[:javascript_origins] ||
9494
fdata["javascript_origins"]
9595
)
96-
@javascript_origins ||= [fdata[:javascript_origin]]
96+
@javascript_origins ||= [fdata[:javascript_origin] || fdata["javascript_origin"]].compact
9797
@authorization_uri = fdata[:auth_uri] || fdata["auth_uri"]
9898
@authorization_uri ||= fdata[:authorization_uri]
9999
@token_credential_uri = fdata[:token_uri] || fdata["token_uri"]
@@ -120,7 +120,11 @@ def initialize(options={})
120120
# @return [String]
121121
# JSON
122122
def to_json
123-
return MultiJson.dump({
123+
return MultiJson.dump(to_hash)
124+
end
125+
126+
def to_hash
127+
{
124128
self.flow => ({
125129
'client_id' => self.client_id,
126130
'client_secret' => self.client_secret,
@@ -141,7 +145,7 @@ def to_json
141145
end
142146
accu
143147
end
144-
})
148+
}
145149
end
146150

147151
def to_authorization
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"installed":{"auth_uri":"https://accounts.google.com/o/oauth2/auth","client_secret":"i8YaXdGgiQ4_KrTVNGsB7QP1","token_uri":"https://accounts.google.com/o/oauth2/token","client_email":"","client_x509_cert_url":"","client_id":"898243283568.apps.googleusercontent.com","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs"}}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# encoding:utf-8
2+
3+
# Copyright 2013 Google Inc.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
require 'spec_helper'
18+
19+
require 'google/api_client/client_secrets'
20+
21+
FIXTURES_PATH = File.expand_path('../../../fixtures', __FILE__)
22+
23+
RSpec.describe Google::APIClient::ClientSecrets do
24+
25+
context 'with JSON file' do
26+
let(:file) { File.join(FIXTURES_PATH, 'files', 'client_secrets.json') }
27+
subject(:secrets) { Google::APIClient::ClientSecrets.load(file)}
28+
29+
it 'should load the correct client ID' do
30+
expect(secrets.client_id).to be == '898243283568.apps.googleusercontent.com'
31+
end
32+
33+
it 'should load the correct client secret' do
34+
expect(secrets.client_secret).to be == 'i8YaXdGgiQ4_KrTVNGsB7QP1'
35+
end
36+
37+
context 'serialzed to hash' do
38+
subject(:hash) { secrets.to_hash }
39+
it 'should contain the flow as the first key' do
40+
expect(hash).to have_key "installed"
41+
end
42+
43+
it 'should contain the client ID' do
44+
expect(hash["installed"]["client_id"]).to be == '898243283568.apps.googleusercontent.com'
45+
end
46+
47+
it 'should contain the client secret' do
48+
expect(hash["installed"]["client_secret"]).to be == 'i8YaXdGgiQ4_KrTVNGsB7QP1'
49+
end
50+
51+
end
52+
end
53+
end

0 commit comments

Comments
 (0)