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.
@@ -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[:expires] ||= (Time.now.utc + valid_for).to_s unless valid_for.nil?
23
- unless user_hash[:email].to_s.match(EMAIL_FORMAT)
24
- raise Unauthorized.new("'#{user_hash[:email]}' is not a valid email address")
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
@@ -1,3 +1,3 @@
1
1
  module Uservoice
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -2,14 +2,21 @@ require 'spec_helper'
2
2
 
3
3
  describe UserVoice do
4
4
 
5
- it "should generate SSO token" do
6
- token = UserVoice.generate_sso_token(config['subdomain_name'], config['sso_key'], {
7
- :display_name => "User Name",
8
- :email => 'mailaddress@example.com'
9
- })
10
- encrypted_raw_data = Base64.decode64(CGI.unescape(token))
11
-
12
- key = EzCrypto::Key.with_password(config['subdomain_name'], config['sso_key'])
13
- key.decrypt(encrypted_raw_data).should match('mailaddress@example.com')
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.7
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-09 00:00:00.000000000 Z
12
+ date: 2012-10-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec