uservoice-ruby 0.0.7 → 0.0.8
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/lib/uservoice/user_voice.rb +12 -3
- data/lib/uservoice/version.rb +1 -1
- data/spec/lib/user_voice_spec.rb +16 -9
- metadata +2 -2
data/lib/uservoice/user_voice.rb
CHANGED
@@ -19,10 +19,14 @@ module UserVoice
|
|
19
19
|
ApplicationError = Class.new(APIError)
|
20
20
|
|
21
21
|
def self.generate_sso_token(subdomain_key, sso_key, user_hash, valid_for = 5 * 60)
|
22
|
-
user_hash[
|
23
|
-
|
24
|
-
|
22
|
+
expiration_key = user_hash['expires'].nil? ? :expires : 'expires'
|
23
|
+
user_hash[expiration_key] ||= (Time.now.utc + valid_for).to_s unless valid_for.nil?
|
24
|
+
email = (user_hash[:email] || user_hash['email'])
|
25
|
+
|
26
|
+
unless email.to_s.match(EMAIL_FORMAT)
|
27
|
+
raise Unauthorized.new("'#{email}' is not a valid email address")
|
25
28
|
end
|
29
|
+
|
26
30
|
unless sso_key.to_s.length > 1
|
27
31
|
raise Unauthorized.new("Please specify your SSO key")
|
28
32
|
end
|
@@ -33,4 +37,9 @@ module UserVoice
|
|
33
37
|
|
34
38
|
return CGI.escape(encoded)
|
35
39
|
end
|
40
|
+
|
41
|
+
def self.decrypt_sso_token(subdomain_key, sso_key, encoded)
|
42
|
+
encrypted = Base64.decode64(CGI.unescape(encoded))
|
43
|
+
return JSON.parse(EzCrypto::Key.with_password(subdomain_key, sso_key).decrypt(encrypted))
|
44
|
+
end
|
36
45
|
end
|
data/lib/uservoice/version.rb
CHANGED
data/spec/lib/user_voice_spec.rb
CHANGED
@@ -2,14 +2,21 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe UserVoice do
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
:display_name => "User Name",
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
5
|
+
context 'having an SSO token for User Name' do
|
6
|
+
let(:user_attributes) do
|
7
|
+
{ :display_name => "User Name", :email => 'mailaddress@example.com' }
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should generate SSO token" do
|
11
|
+
token = UserVoice.generate_sso_token(config['subdomain_name'], config['sso_key'], user_attributes)
|
12
|
+
encrypted_raw_data = Base64.decode64(CGI.unescape(token))
|
13
|
+
key = EzCrypto::Key.with_password(config['subdomain_name'], config['sso_key'])
|
14
|
+
key.decrypt(encrypted_raw_data).should match('mailaddress@example.com')
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should decrypt SSO token" do
|
18
|
+
token = UserVoice.generate_sso_token(config['subdomain_name'], config['sso_key'], user_attributes)
|
19
|
+
UserVoice.decrypt_sso_token(config['subdomain_name'], config['sso_key'], token)['display_name'].should match('User Name')
|
20
|
+
end
|
14
21
|
end
|
15
22
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uservoice-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|