google_auth_bridge 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/README.md +2 -2
- data/google_auth_bridge.gemspec +3 -2
- data/lib/google_auth_bridge.rb +5 -6
- data/lib/google_auth_bridge/version.rb +1 -1
- data/spec/google_auth_bridge_spec.rb +94 -39
- metadata +19 -8
data/.gitignore
CHANGED
data/README.md
CHANGED
data/google_auth_bridge.gemspec
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
require File.expand_path('../lib/google_auth_bridge/version', __FILE__)
|
3
3
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
|
-
gem.authors =
|
6
|
-
gem.email = %w(
|
5
|
+
gem.authors = ["GOV.UK Dev"]
|
6
|
+
gem.email = %w(govuk-dev@digital.cabinet-office.gov.uk)
|
7
7
|
gem.description = "bridge for supporting multiple google authentication libraries"
|
8
8
|
gem.summary = "bridge for supporting multiple google authentication libraries"
|
9
9
|
gem.homepage = "https://github.com/alphagov/google-auth-bridge"
|
@@ -21,6 +21,7 @@ Gem::Specification.new do |gem|
|
|
21
21
|
gem.add_development_dependency("rake")
|
22
22
|
gem.add_development_dependency("rspec")
|
23
23
|
gem.add_development_dependency("ci_reporter")
|
24
|
+
gem.add_development_dependency("simplecov")
|
24
25
|
gem.add_development_dependency("gem_publisher", "~> 1.1.1")
|
25
26
|
|
26
27
|
end
|
data/lib/google_auth_bridge.rb
CHANGED
@@ -7,10 +7,12 @@ module GoogleAuthenticationBridge
|
|
7
7
|
|
8
8
|
def self.create_from_config_file(scope, file_name, token_file)
|
9
9
|
config = YAML.load_file(file_name)
|
10
|
+
client_id, client_secret = config[:google_client_id], config[:google_client_secret]
|
11
|
+
raise InvalidFileFormatError.new(@token_file) if client_id.nil? or client_secret.nil?
|
10
12
|
GoogleAuthentication.new(
|
11
13
|
scope,
|
12
|
-
|
13
|
-
|
14
|
+
client_id,
|
15
|
+
client_secret,
|
14
16
|
token_file)
|
15
17
|
end
|
16
18
|
|
@@ -40,10 +42,7 @@ module GoogleAuthenticationBridge
|
|
40
42
|
|
41
43
|
begin
|
42
44
|
token_data = YAML.load_file(@token_file)
|
43
|
-
|
44
|
-
|
45
|
-
raise InvalidFileFormatError.new(@token_file) unless token
|
46
|
-
token
|
45
|
+
token_data[:refresh_token] or raise
|
47
46
|
rescue
|
48
47
|
raise InvalidFileFormatError.new(@token_file)
|
49
48
|
end
|
@@ -1,54 +1,109 @@
|
|
1
|
+
require "simplecov"
|
2
|
+
SimpleCov.start
|
3
|
+
|
1
4
|
require_relative "../lib/google_auth_bridge"
|
2
5
|
require "tempfile"
|
3
6
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
@auth = GoogleAuthenticationBridge::GoogleAuthentication.new(nil, nil, nil, @filename)
|
8
|
-
@yaml_content = "---\n:refresh_token: foo bar\n"
|
9
|
-
@yaml_pattern = /---\s?\n:refresh_token: foo bar\n/
|
7
|
+
module GoogleAuthenticationBridge
|
8
|
+
class GoogleAuthentication
|
9
|
+
attr_reader :client_id, :client_secret
|
10
10
|
end
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
end
|
13
|
+
describe "Google Authentication Client" do
|
14
|
+
describe "Config file" do
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
File.exists?(@filename).should be_true
|
20
|
-
File.read(@filename).should match(@yaml_pattern)
|
21
|
-
end
|
16
|
+
before(:each) do
|
17
|
+
@filename = "/tmp/config-test.yaml"
|
18
|
+
end
|
22
19
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
}.should raise_error(GoogleAuthenticationBridge::InvalidTokenError)
|
27
|
-
end
|
20
|
+
after(:each) do
|
21
|
+
File.unlink(@filename) if File.exist?(@filename)
|
22
|
+
end
|
28
23
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
end
|
24
|
+
it "should read the client id and the client secret" do
|
25
|
+
File.open(@filename, "w") { |f| f.write("---\n:google_client_id: foo bar\n:google_client_secret: very secret\n") }
|
26
|
+
auth = GoogleAuthenticationBridge::GoogleAuthentication.create_from_config_file(nil, @filename, nil)
|
33
27
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
28
|
+
auth.client_id.should == "foo bar"
|
29
|
+
auth.client_secret.should == "very secret"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should raise an error when client id is missing" do
|
33
|
+
File.open(@filename, "w") { |f| f.write("---\n:google_client_secret: very secret\n") }
|
34
|
+
|
35
|
+
-> {
|
36
|
+
GoogleAuthenticationBridge::GoogleAuthentication.create_from_config_file(nil, @filename, nil)
|
37
|
+
}.should raise_error(GoogleAuthenticationBridge::InvalidFileFormatError)
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should raise an error when client secret is missing" do
|
42
|
+
File.open(@filename, "w") { |f| f.write("---\n:google_client_secret: very secret\n") }
|
43
|
+
|
44
|
+
-> {
|
45
|
+
GoogleAuthenticationBridge::GoogleAuthentication.create_from_config_file(nil, @filename, nil)
|
46
|
+
}.should raise_error(GoogleAuthenticationBridge::InvalidFileFormatError)
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should raise an error when config file is missing" do
|
51
|
+
-> {
|
52
|
+
GoogleAuthenticationBridge::GoogleAuthentication.create_from_config_file(nil, @filename, nil)
|
53
|
+
}.should raise_error
|
54
|
+
end
|
39
55
|
|
40
|
-
it "should raise an InvalidFileFormatError exception if the file is badly formatted" do
|
41
|
-
File.open(@filename, 'w') {|f| f.write("bad content") }
|
42
|
-
lambda {
|
43
|
-
@auth.load_token_from_file
|
44
|
-
}.should raise_error(GoogleAuthenticationBridge::InvalidFileFormatError)
|
45
56
|
end
|
46
57
|
|
58
|
+
describe "Token file" do
|
59
|
+
before(:each) do
|
60
|
+
@filename = "/tmp/test.token"
|
61
|
+
@auth = GoogleAuthenticationBridge::GoogleAuthentication.new(nil, nil, nil, @filename)
|
62
|
+
@yaml_content = "---\n:refresh_token: foo bar\n"
|
63
|
+
@yaml_pattern = /---\s?\n:refresh_token: foo bar\n/
|
64
|
+
end
|
65
|
+
|
66
|
+
after(:each) do
|
67
|
+
File.delete(@filename) if File.exists? @filename
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should save refresh token to file as yaml" do
|
71
|
+
File.exists?(@filename).should be_false
|
72
|
+
@auth.save_token_to_file("foo bar")
|
73
|
+
File.exists?(@filename).should be_true
|
74
|
+
File.read(@filename).should match(@yaml_pattern)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should raise an InvalidTokenError exception if the refresh token is nil" do
|
78
|
+
lambda {
|
79
|
+
@auth.save_token_to_file(nil)
|
80
|
+
}.should raise_error(GoogleAuthenticationBridge::InvalidTokenError)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should load refresh token from yaml file" do
|
84
|
+
File.open(@filename, 'w') { |f| f.write(@yaml_content) }
|
85
|
+
@auth.load_token_from_file.should == "foo bar"
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should raise a FileNotFoundError exception if the file is not there" do
|
89
|
+
lambda {
|
90
|
+
@auth.load_token_from_file
|
91
|
+
}.should raise_error(GoogleAuthenticationBridge::FileNotFoundError)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should raise an InvalidFileFormatError exception if the file is badly formatted" do
|
95
|
+
File.open(@filename, 'w') { |f| f.write("bad content") }
|
96
|
+
lambda {
|
97
|
+
@auth.load_token_from_file
|
98
|
+
}.should raise_error(GoogleAuthenticationBridge::InvalidFileFormatError)
|
99
|
+
end
|
100
|
+
|
47
101
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
102
|
+
it "should raise an InvalidFileFormatError exception if the file does not contain refresh token" do
|
103
|
+
File.open(@filename, 'w') { |f| f.write("---\n:refresh_token: \n") }
|
104
|
+
lambda {
|
105
|
+
@auth.load_token_from_file
|
106
|
+
}.should raise_error(GoogleAuthenticationBridge::InvalidFileFormatError)
|
107
|
+
end
|
53
108
|
end
|
54
109
|
end
|
metadata
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
name: google_auth_bridge
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
|
-
-
|
8
|
+
- GOV.UK Dev
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-08-
|
13
|
+
date: 2012-08-29 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: oauth2
|
@@ -68,8 +68,19 @@ dependencies:
|
|
68
68
|
prerelease: false
|
69
69
|
version_requirements: *id005
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
|
-
name:
|
71
|
+
name: simplecov
|
72
72
|
requirement: &id006 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: "0"
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: *id006
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: gem_publisher
|
83
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
73
84
|
none: false
|
74
85
|
requirements:
|
75
86
|
- - ~>
|
@@ -77,10 +88,10 @@ dependencies:
|
|
77
88
|
version: 1.1.1
|
78
89
|
type: :development
|
79
90
|
prerelease: false
|
80
|
-
version_requirements: *
|
91
|
+
version_requirements: *id007
|
81
92
|
description: bridge for supporting multiple google authentication libraries
|
82
93
|
email:
|
83
|
-
-
|
94
|
+
- govuk-dev@digital.cabinet-office.gov.uk
|
84
95
|
executables: []
|
85
96
|
|
86
97
|
extensions: []
|
@@ -111,7 +122,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
111
122
|
requirements:
|
112
123
|
- - ">="
|
113
124
|
- !ruby/object:Gem::Version
|
114
|
-
hash:
|
125
|
+
hash: 4326175119099848763
|
115
126
|
segments:
|
116
127
|
- 0
|
117
128
|
version: "0"
|
@@ -120,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
131
|
requirements:
|
121
132
|
- - ">="
|
122
133
|
- !ruby/object:Gem::Version
|
123
|
-
hash:
|
134
|
+
hash: 4326175119099848763
|
124
135
|
segments:
|
125
136
|
- 0
|
126
137
|
version: "0"
|