exvo_helpers 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +6 -0
- data/README.md +9 -0
- data/exvo_helpers.gemspec +2 -0
- data/lib/exvo_helpers/helpers.rb +69 -10
- data/lib/exvo_helpers/version.rb +1 -1
- data/spec/exvo_helpers/helpers_spec.rb +89 -64
- metadata +34 -2
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
|
3
3
|
Note, that only significant changes are listed.
|
4
4
|
|
5
|
+
## 0.5.0 (2012-06-15)
|
6
|
+
|
7
|
+
* all staging apps now use 'exvo.co' domain
|
8
|
+
* new `sso_cookie_domain` and `sso_cookie_secret` settings
|
9
|
+
|
10
|
+
|
5
11
|
## 0.4.0 (2012-05-15)
|
6
12
|
|
7
13
|
* support for Sinatra apps (use `ENV["RACK_ENV"]` to set environment)
|
data/README.md
CHANGED
@@ -16,6 +16,9 @@ Exvo::Helpers.auth_require_ssl => false
|
|
16
16
|
Exvo::Helpers.auth_client_id => nil
|
17
17
|
Exvo::Helpers.auth_client_secret => nil
|
18
18
|
|
19
|
+
Exvo::Helpers.sso_cookie_domain => 'exvo.local'
|
20
|
+
Exvo::Helpers.sso_cookie_secret => 'some secret cookie signing key'
|
21
|
+
|
19
22
|
Exvo::Helpers.auth_host => 'auth.exvo.local'
|
20
23
|
Exvo::Helpers.cdn_host => 'www.exvo.local'
|
21
24
|
Exvo::Helpers.cfs_host => 'cfs.exvo.local'
|
@@ -53,6 +56,9 @@ ENV['AUTH_REQUIRE_SSL'] = 'true'
|
|
53
56
|
ENV['AUTH_CLIENT_ID'] = '123'
|
54
57
|
ENV['AUTH_CLIENT_SECRET'] = 'abc'
|
55
58
|
|
59
|
+
ENV['SSO_COOKIE_DOMAIN'] = 'exvo.dev'
|
60
|
+
ENV['SSO_COOKIE_SECRET'] = 'exvo.dev'
|
61
|
+
|
56
62
|
ENV['AUTH_HOST'] = 'test.auth.exvo.com'
|
57
63
|
ENV['CDN_HOST'] = 'test.cdn.exvo.com'
|
58
64
|
ENV['CFS_HOST'] = 'test.cfs.exvo.com'
|
@@ -75,6 +81,9 @@ Exvo::Helpers.auth_require_ssl = true
|
|
75
81
|
Exvo::Helpers.auth_client_id = '123'
|
76
82
|
Exvo::Helpers.auth_client_secret = 'abc'
|
77
83
|
|
84
|
+
Exvo::Helpers.sso_cookie_domain = 'exvo.dev'
|
85
|
+
Exvo::Helpers.sso_cookie_key = 'some secret key'
|
86
|
+
|
78
87
|
Exvo::Helpers.auth_host = 'test.auth.exvo.com'
|
79
88
|
Exvo::Helpers.cdn_host = 'test.cdn.exvo.com'
|
80
89
|
Exvo::Helpers.cfs_host = 'test.cfs.exvo.com'
|
data/exvo_helpers.gemspec
CHANGED
@@ -16,8 +16,10 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
17
|
gem.require_paths = ["lib"]
|
18
18
|
|
19
|
+
gem.add_development_dependency "rake"
|
19
20
|
gem.add_development_dependency 'rspec', ['>= 2.8']
|
20
21
|
gem.add_development_dependency 'guard', ['>= 0.10.0']
|
22
|
+
gem.add_development_dependency 'guard-bundler'
|
21
23
|
gem.add_development_dependency 'guard-rspec', ['>= 0.6.0']
|
22
24
|
gem.add_development_dependency "rb-fsevent"
|
23
25
|
gem.add_development_dependency "rb-inotify"
|
data/lib/exvo_helpers/helpers.rb
CHANGED
@@ -105,6 +105,61 @@ module Exvo
|
|
105
105
|
define_method "auth_#{option}=" do |value|
|
106
106
|
class_variable_set("@@auth_#{option}", value)
|
107
107
|
end
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
# SSO Cookie Domain
|
115
|
+
|
116
|
+
# Dynamically define class methods
|
117
|
+
class << self
|
118
|
+
|
119
|
+
%w(sso_cookie_domain).each do |option|
|
120
|
+
|
121
|
+
# def self.sso_cookie_domain
|
122
|
+
# @@sso_cookie_domain ||= ENV['SSO_COOKIE_DOMAIN'] || default_opts[env.to_sym][:sso_cookie_domain]
|
123
|
+
# end
|
124
|
+
define_method "#{option}" do
|
125
|
+
if class_variable_defined?("@@#{option}") and class_variable_get("@@#{option}")
|
126
|
+
class_variable_get("@@#{option}")
|
127
|
+
else
|
128
|
+
domain = ENV["#{option.upcase}"] || default_opts[env.to_sym]["#{option}".to_sym]
|
129
|
+
class_variable_set("@@#{option}", domain)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
# def self.sso_cookie_domain=(domain)
|
134
|
+
# @@sso_cookie_domain = domain
|
135
|
+
# end
|
136
|
+
define_method "#{option}=" do |value|
|
137
|
+
class_variable_set("@@#{option}", value)
|
138
|
+
end
|
139
|
+
|
140
|
+
end
|
141
|
+
|
142
|
+
%w(sso_cookie_secret).each do |option|
|
143
|
+
|
144
|
+
# def self.sso_cookie_secret
|
145
|
+
# @@sso_cookie_secret ||= ENV['SSO_COOKIE_secret']
|
146
|
+
# end
|
147
|
+
define_method "#{option}" do
|
148
|
+
if class_variable_defined?("@@#{option}") and class_variable_get("@@#{option}")
|
149
|
+
class_variable_get("@@#{option}")
|
150
|
+
else
|
151
|
+
secret = ENV["#{option.upcase}"]
|
152
|
+
class_variable_set("@@#{option}", secret)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
# def self.sso_cookie_secret=(secret)
|
157
|
+
# @@sso_cookie_secret = secret
|
158
|
+
# end
|
159
|
+
define_method "#{option}=" do |value|
|
160
|
+
class_variable_set("@@#{option}", value)
|
161
|
+
end
|
162
|
+
|
108
163
|
end
|
109
164
|
|
110
165
|
end
|
@@ -113,7 +168,7 @@ module Exvo
|
|
113
168
|
# ENV
|
114
169
|
|
115
170
|
# by default fall back to production; this way the omniauth-exvo's gem specs can pass
|
116
|
-
# (they depend on this gem and on env, but nor Rails nor Merb is
|
171
|
+
# (they depend on this gem and on env, but nor Rails nor Merb is defined there)
|
117
172
|
def self.env
|
118
173
|
@@env ||= Rails.env if defined?(Rails)
|
119
174
|
@@env ||= Merb.env if defined?(Merb)
|
@@ -134,6 +189,7 @@ module Exvo
|
|
134
189
|
:auth_debug => false,
|
135
190
|
:auth_host => 'auth.exvo.com',
|
136
191
|
:auth_require_ssl => true,
|
192
|
+
:sso_cookie_domain => 'exvo.com',
|
137
193
|
:cdn_host => 'd33gjlr95u9pgf.cloudfront.net', # cloudfront.net so we can use https (cdn.exvo.com via https does not work properly)
|
138
194
|
:cfs_host => 'cfs.exvo.com',
|
139
195
|
:desktop_host => 'www.exvo.com',
|
@@ -147,23 +203,25 @@ module Exvo
|
|
147
203
|
},
|
148
204
|
:staging => {
|
149
205
|
:auth_debug => false,
|
150
|
-
:auth_host => '
|
206
|
+
:auth_host => 'auth.exvo.co',
|
151
207
|
:auth_require_ssl => false,
|
208
|
+
:sso_cookie_domain => 'exvo.co',
|
152
209
|
:cdn_host => 'd1by559a994699.cloudfront.net',
|
153
|
-
:cfs_host => '
|
210
|
+
:cfs_host => 'cfs.exvo.co',
|
154
211
|
:desktop_host => 'www.exvo.co',
|
155
|
-
:themes_host => '
|
156
|
-
:blog_host => '
|
157
|
-
:contacts_host => '
|
158
|
-
:inbox_host => '
|
159
|
-
:music_host => '
|
160
|
-
:pics_host => '
|
161
|
-
:preview_host => '
|
212
|
+
:themes_host => 'themes.exvo.co',
|
213
|
+
:blog_host => 'blog.exvo.co',
|
214
|
+
:contacts_host => 'contacts.exvo.co',
|
215
|
+
:inbox_host => 'inbox.exvo.co',
|
216
|
+
:music_host => 'music.exvo.co',
|
217
|
+
:pics_host => 'pics.exvo.co',
|
218
|
+
:preview_host => 'preview.exvo.co'
|
162
219
|
},
|
163
220
|
:development => {
|
164
221
|
:auth_debug => false,
|
165
222
|
:auth_host => 'auth.exvo.local',
|
166
223
|
:auth_require_ssl => false,
|
224
|
+
:sso_cookie_domain => 'exvo.local',
|
167
225
|
:cdn_host => 'www.exvo.local',
|
168
226
|
:cfs_host => 'cfs.exvo.local',
|
169
227
|
:desktop_host => 'www.exvo.local',
|
@@ -179,6 +237,7 @@ module Exvo
|
|
179
237
|
:auth_debug => false,
|
180
238
|
:auth_host => 'auth.exvo.local',
|
181
239
|
:auth_require_ssl => false,
|
240
|
+
:sso_cookie_domain => 'exvo.local',
|
182
241
|
:cdn_host => 'www.exvo.local',
|
183
242
|
:cfs_host => 'cfs.exvo.local',
|
184
243
|
:desktop_host => 'www.exvo.local',
|
data/lib/exvo_helpers/version.rb
CHANGED
@@ -2,6 +2,11 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Exvo::Helpers do
|
4
4
|
|
5
|
+
# clear all memoizations after each spec run
|
6
|
+
after do
|
7
|
+
clear_memoizations
|
8
|
+
end
|
9
|
+
|
5
10
|
describe ".env class method" do
|
6
11
|
it "should fall back to 'production' if Rails & Merb are undefined" do
|
7
12
|
Exvo::Helpers.env.should eql('production')
|
@@ -17,17 +22,12 @@ describe Exvo::Helpers do
|
|
17
22
|
it "returns 'staging' when RACK_ENV is set to 'staging'" do
|
18
23
|
ENV["RACK_ENV"] = 'staging'
|
19
24
|
Exvo::Helpers.env.should eql('staging')
|
20
|
-
ENV.delete("RACK_ENV")
|
21
25
|
end
|
22
26
|
|
23
27
|
it "allows setting env" do
|
24
28
|
Exvo::Helpers.env = 'test'
|
25
29
|
Exvo::Helpers.env.should eql('test')
|
26
30
|
end
|
27
|
-
|
28
|
-
after do
|
29
|
-
Exvo::Helpers.env = nil
|
30
|
-
end
|
31
31
|
end
|
32
32
|
|
33
33
|
describe "uri methods in production environment" do
|
@@ -58,95 +58,120 @@ describe Exvo::Helpers do
|
|
58
58
|
specify { Exvo::Helpers.preview_host.should eql('preview.exvo.com') }
|
59
59
|
end
|
60
60
|
|
61
|
+
describe "host methods in staging environment" do
|
62
|
+
before do
|
63
|
+
Exvo::Helpers.env = 'staging'
|
64
|
+
end
|
65
|
+
|
66
|
+
specify { Exvo::Helpers.auth_host.should match('auth.exvo.co') }
|
67
|
+
specify { Exvo::Helpers.cdn_host.should eql('d1by559a994699.cloudfront.net') }
|
68
|
+
specify { Exvo::Helpers.cfs_host.should eql('cfs.exvo.co') }
|
69
|
+
specify { Exvo::Helpers.desktop_host.should eql('www.exvo.co') }
|
70
|
+
specify { Exvo::Helpers.themes_host.should eql('themes.exvo.co') }
|
71
|
+
specify { Exvo::Helpers.blog_host.should eql('blog.exvo.co') }
|
72
|
+
specify { Exvo::Helpers.contacts_host.should eql('contacts.exvo.co') }
|
73
|
+
specify { Exvo::Helpers.inbox_host.should eql('inbox.exvo.co') }
|
74
|
+
specify { Exvo::Helpers.music_host.should eql('music.exvo.co') }
|
75
|
+
specify { Exvo::Helpers.pics_host.should eql('pics.exvo.co') }
|
76
|
+
specify { Exvo::Helpers.preview_host.should eql('preview.exvo.co') }
|
77
|
+
end
|
78
|
+
|
61
79
|
describe "#auth_debug by default for production env" do
|
62
80
|
specify { Exvo::Helpers.auth_debug.should be_false }
|
63
|
-
|
64
|
-
after do
|
65
|
-
# reset cached class instance variable
|
66
|
-
Exvo::Helpers.auth_debug = nil
|
67
|
-
end
|
68
81
|
end
|
69
82
|
|
70
83
|
describe "#auth_require_ssl by default for production env" do
|
71
84
|
specify { Exvo::Helpers.auth_require_ssl.should be_true }
|
72
|
-
|
73
|
-
after do
|
74
|
-
# reset cached class instance variable
|
75
|
-
Exvo::Helpers.auth_require_ssl = nil
|
76
|
-
end
|
77
85
|
end
|
78
86
|
|
79
|
-
describe "
|
80
|
-
|
81
|
-
ENV["AUTH_CLIENT_ID"] = '123'
|
82
|
-
ENV["AUTH_CLIENT_SECRET"] = 'abc'
|
83
|
-
end
|
84
|
-
|
85
|
-
specify { Exvo::Helpers.auth_client_id.should eq('123') }
|
86
|
-
specify { Exvo::Helpers.auth_client_secret.should eq('abc') }
|
87
|
-
|
88
|
-
after do
|
89
|
-
ENV["AUTH_CLIENT_ID"] = nil
|
90
|
-
ENV["AUTH_CLIENT_SECRET"] = nil
|
91
|
-
end
|
87
|
+
describe "#sso_cookie_domain by default for production env" do
|
88
|
+
specify { Exvo::Helpers.sso_cookie_domain.should eq("exvo.com") }
|
92
89
|
end
|
93
90
|
|
94
|
-
describe "ENV
|
95
|
-
#
|
91
|
+
describe "ENV settings override the defaults" do
|
92
|
+
# all *host* methods are defined the same using metaprogramming, only testing for 1 is enough
|
96
93
|
let(:cdn_host) { "test.cdn.exvo.com" }
|
94
|
+
let(:auth_client_id) { '123' }
|
95
|
+
let(:auth_client_secret) { 'abc' }
|
96
|
+
let(:auth_require_ssl) { 'false' }
|
97
|
+
let(:sso_cookie_domain) { "exvo.dev" }
|
98
|
+
let(:sso_cookie_secret) { "secret" }
|
97
99
|
|
98
100
|
before do
|
99
|
-
# clear any previous memoization
|
100
|
-
Exvo::Helpers.cdn_host = nil
|
101
|
-
|
102
101
|
# set ENV
|
103
102
|
ENV["CDN_HOST"] = cdn_host
|
103
|
+
ENV["AUTH_CLIENT_ID"] = auth_client_id
|
104
|
+
ENV["AUTH_CLIENT_SECRET"] = auth_client_secret
|
105
|
+
ENV["AUTH_REQUIRE_SSL"] = auth_require_ssl
|
106
|
+
ENV["SSO_COOKIE_DOMAIN"] = sso_cookie_domain
|
107
|
+
ENV["SSO_COOKIE_SECRET"] = sso_cookie_secret
|
104
108
|
end
|
105
109
|
|
106
110
|
specify { Exvo::Helpers.cdn_host.should eql(cdn_host) }
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
+
specify { Exvo::Helpers.auth_client_id.should eq(auth_client_id) }
|
112
|
+
specify { Exvo::Helpers.auth_client_secret.should eq(auth_client_secret) }
|
113
|
+
specify { Exvo::Helpers.auth_uri.should match(/http:\/\//) }
|
114
|
+
specify { Exvo::Helpers.sso_cookie_domain.should eql(sso_cookie_domain) }
|
115
|
+
specify { Exvo::Helpers.sso_cookie_secret.should eql(sso_cookie_secret) }
|
111
116
|
end
|
112
117
|
|
113
|
-
describe "
|
114
|
-
#
|
118
|
+
describe "direct settings override the defaults" do
|
119
|
+
# all *host* methods are defined the same using metaprogramming, only testing for 1 is enough
|
115
120
|
let(:cdn_host) { "new.cdn.exvo.com" }
|
121
|
+
let(:auth_client_id) { '123' }
|
122
|
+
let(:auth_client_secret) { 'abc' }
|
123
|
+
let(:auth_require_ssl) { false }
|
124
|
+
let(:sso_cookie_domain) { "exvo.new" }
|
125
|
+
let(:sso_cookie_secret) { "abc" }
|
116
126
|
|
117
127
|
before do
|
118
128
|
Exvo::Helpers.cdn_host = cdn_host
|
129
|
+
Exvo::Helpers.auth_client_id = auth_client_id
|
130
|
+
Exvo::Helpers.auth_client_secret = auth_client_secret
|
131
|
+
Exvo::Helpers.auth_require_ssl = auth_require_ssl
|
132
|
+
Exvo::Helpers.sso_cookie_domain = sso_cookie_domain
|
133
|
+
Exvo::Helpers.sso_cookie_secret = sso_cookie_secret
|
119
134
|
end
|
120
135
|
|
121
136
|
specify { Exvo::Helpers.cdn_host.should eql(cdn_host) }
|
122
|
-
|
123
|
-
|
124
|
-
Exvo::Helpers.cdn_host = nil
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
describe "setting the auth_require_ssl to false via ENV variable overrides the default" do
|
129
|
-
before do
|
130
|
-
ENV["AUTH_REQUIRE_SSL"] = 'false'
|
131
|
-
end
|
132
|
-
|
137
|
+
specify { Exvo::Helpers.auth_client_id.should eq(auth_client_id) }
|
138
|
+
specify { Exvo::Helpers.auth_client_secret.should eq(auth_client_secret) }
|
133
139
|
specify { Exvo::Helpers.auth_uri.should match(/http:\/\//) }
|
134
|
-
|
135
|
-
|
136
|
-
ENV["AUTH_REQUIRE_SSL"] = nil
|
137
|
-
end
|
140
|
+
specify { Exvo::Helpers.sso_cookie_domain.should eql(sso_cookie_domain) }
|
141
|
+
specify { Exvo::Helpers.sso_cookie_secret.should eql(sso_cookie_secret) }
|
138
142
|
end
|
139
143
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
144
|
+
# Clear all memoizations and ENV variables
|
145
|
+
def clear_memoizations
|
146
|
+
Exvo::Helpers.env = nil
|
147
|
+
|
148
|
+
Exvo::Helpers.auth_debug = nil
|
149
|
+
Exvo::Helpers.auth_require_ssl = nil
|
150
|
+
Exvo::Helpers.auth_client_id = nil
|
151
|
+
Exvo::Helpers.auth_client_secret = nil
|
152
|
+
Exvo::Helpers.sso_cookie_domain = nil
|
153
|
+
Exvo::Helpers.sso_cookie_secret = nil
|
154
|
+
|
155
|
+
Exvo::Helpers.auth_host = nil
|
156
|
+
Exvo::Helpers.cdn_host = nil
|
157
|
+
Exvo::Helpers.cfs_host = nil
|
158
|
+
Exvo::Helpers.desktop_host = nil
|
159
|
+
Exvo::Helpers.themes_host = nil
|
160
|
+
Exvo::Helpers.blog_host = nil
|
161
|
+
Exvo::Helpers.contacts_host = nil
|
162
|
+
Exvo::Helpers.inbox_host = nil
|
163
|
+
Exvo::Helpers.music_host = nil
|
164
|
+
Exvo::Helpers.pics_host = nil
|
165
|
+
Exvo::Helpers.preview_host = nil
|
166
|
+
|
167
|
+
ENV.delete("RACK_ENV")
|
168
|
+
ENV.delete("CDN_HOST")
|
169
|
+
ENV.delete("AUTH_DEBUG")
|
170
|
+
ENV.delete("AUTH_CLIENT_ID")
|
171
|
+
ENV.delete("AUTH_CLIENT_SECRET")
|
172
|
+
ENV.delete("AUTH_REQUIRE_SSL")
|
173
|
+
ENV.delete("SSO_COOKIE_DOMAIN")
|
174
|
+
ENV.delete("SSO_COOKIE_SECRET")
|
150
175
|
end
|
151
176
|
|
152
177
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: exvo_helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,24 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-06-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
14
30
|
- !ruby/object:Gem::Dependency
|
15
31
|
name: rspec
|
16
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -43,6 +59,22 @@ dependencies:
|
|
43
59
|
- - ! '>='
|
44
60
|
- !ruby/object:Gem::Version
|
45
61
|
version: 0.10.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: guard-bundler
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
46
78
|
- !ruby/object:Gem::Dependency
|
47
79
|
name: guard-rspec
|
48
80
|
requirement: !ruby/object:Gem::Requirement
|