live_ensure 0.2.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 +5 -0
- data/.rspec +1 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +6 -0
- data/lib/live_ensure/accessible.rb +13 -0
- data/lib/live_ensure/configure.rb +24 -0
- data/lib/live_ensure/errors.rb +6 -0
- data/lib/live_ensure/response.rb +12 -0
- data/lib/live_ensure/session_status_response.rb +40 -0
- data/lib/live_ensure/setup_response.rb +41 -0
- data/lib/live_ensure/version.rb +3 -0
- data/lib/live_ensure.rb +47 -0
- data/live_ensure.gemspec +26 -0
- data/readme.md +108 -0
- data/spec/live_ensure_spec.rb +103 -0
- data/spec/session_status_response_spec.rb +69 -0
- data/spec/setup_response_spec.rb +80 -0
- metadata +111 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
-f progress -c
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Inspire Studios Inc.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject
|
9
|
+
to the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
16
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
3
|
+
module LiveEnsure
|
4
|
+
module Configure
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def configure
|
9
|
+
yield configuration
|
10
|
+
end
|
11
|
+
|
12
|
+
def configuration
|
13
|
+
@configuration ||= Configuration.new
|
14
|
+
end
|
15
|
+
|
16
|
+
class Configuration
|
17
|
+
attr_accessor :api_key
|
18
|
+
attr_accessor :api_password
|
19
|
+
attr_accessor :api_agent_id
|
20
|
+
attr_accessor :enabled
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'live_ensure/accessible'
|
2
|
+
require 'live_ensure/response'
|
3
|
+
require 'live_ensure'
|
4
|
+
require 'live_ensure/errors'
|
5
|
+
|
6
|
+
module LiveEnsure
|
7
|
+
class SessionStatusResponse < Response
|
8
|
+
accessible :token, :message, :client, :session, :deviceHash, :knownDevice, :agent
|
9
|
+
|
10
|
+
def parse_response
|
11
|
+
@response_lines = @response.split("\n")
|
12
|
+
parse_token
|
13
|
+
parse_other
|
14
|
+
end
|
15
|
+
|
16
|
+
def parse_token
|
17
|
+
split_line = @response_lines.shift.split(':')
|
18
|
+
@hash['token'] = split_line[1]
|
19
|
+
end
|
20
|
+
|
21
|
+
def parse_other
|
22
|
+
@response_lines.each do |line|
|
23
|
+
key, val = line.split(':').map(&:strip)
|
24
|
+
@hash[key] = val
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def valid?
|
29
|
+
@hash['message'] == 'SUCCESS'
|
30
|
+
end
|
31
|
+
|
32
|
+
def failed?
|
33
|
+
@hash['message'] == 'FAILED'
|
34
|
+
end
|
35
|
+
|
36
|
+
def undetermined?
|
37
|
+
@hash['message'] == 'SESSION_UNDETERMINED'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'live_ensure/accessible'
|
2
|
+
require 'live_ensure/response'
|
3
|
+
require 'live_ensure'
|
4
|
+
require 'live_ensure/errors'
|
5
|
+
|
6
|
+
module LiveEnsure
|
7
|
+
class SetupResponse < Response
|
8
|
+
accessible :launch_url, :token, :code, :base_url
|
9
|
+
|
10
|
+
def parse_response
|
11
|
+
raise InvalidResponse unless vars.size > 0
|
12
|
+
|
13
|
+
parse_response_code
|
14
|
+
end
|
15
|
+
|
16
|
+
def parse_response_code
|
17
|
+
response_code = vars[0].split(':')
|
18
|
+
|
19
|
+
@hash['code'] = response_code[0].to_i
|
20
|
+
|
21
|
+
case @hash['code']
|
22
|
+
when 0
|
23
|
+
raise AuthSessionError
|
24
|
+
when 1
|
25
|
+
@hash['base_url'] = LiveEnsure::HOST
|
26
|
+
@hash['launch_url'] = "#{HOST}/launcher?sessionToken=#{response_code[1]}"
|
27
|
+
@hash['token'] = response_code[1]
|
28
|
+
when 2
|
29
|
+
raise ServiceDown
|
30
|
+
when 4
|
31
|
+
@hash['base_url'] = @vars[1]
|
32
|
+
@hash['launch_url'] = "#{@vars[1]}/launcher?sessionToken=#{response_code[1]}"
|
33
|
+
@hash['token'] = response_code[1]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def vars
|
38
|
+
@vars ||= @response.split("\n")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/live_ensure.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'patron'
|
2
|
+
|
3
|
+
require 'live_ensure/accessible'
|
4
|
+
require 'live_ensure/configure'
|
5
|
+
require 'live_ensure/errors'
|
6
|
+
require 'live_ensure/session_status_response'
|
7
|
+
require 'live_ensure/setup_response'
|
8
|
+
require "live_ensure/version"
|
9
|
+
|
10
|
+
module LiveEnsure
|
11
|
+
HOST = "https://app.liveensure.com/live-identity"
|
12
|
+
|
13
|
+
include Configure
|
14
|
+
|
15
|
+
class << self
|
16
|
+
|
17
|
+
def request_launch(email)
|
18
|
+
SetupResponse.new(get(start_url(email)))
|
19
|
+
end
|
20
|
+
|
21
|
+
def session_status(token, base_url)
|
22
|
+
SessionStatusResponse.new(get(session_status_url(token), base_url))
|
23
|
+
end
|
24
|
+
|
25
|
+
def get(url, base_url = '')
|
26
|
+
connection = Patron::Session.new
|
27
|
+
connection.connect_timeout = 5
|
28
|
+
connection.timeout = 10
|
29
|
+
connection.base_url = base_url unless base_url.empty?
|
30
|
+
response = connection.get(url)
|
31
|
+
|
32
|
+
if response.status < 400
|
33
|
+
response.body
|
34
|
+
else
|
35
|
+
raise ConnectionError, response.status
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def start_url(email)
|
40
|
+
"#{HOST}/idr/sessionStart/4/#{email}/#{configuration.api_agent_id}/#{configuration.api_key}/#{configuration.api_password}"
|
41
|
+
end
|
42
|
+
|
43
|
+
def session_status_url(token)
|
44
|
+
"/idr/sessionStatus/4/#{token}/#{configuration.api_key}/#{configuration.api_password}"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/live_ensure.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "live_ensure/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "live_ensure"
|
7
|
+
s.version = LiveEnsure::VERSION
|
8
|
+
s.authors = ["Steve Thompson"]
|
9
|
+
s.email = ["me@stevedev.com"]
|
10
|
+
s.homepage = "http://www.inspirestudios.ca"
|
11
|
+
s.summary = %q{Live Ensure API for Ruby}
|
12
|
+
s.description = %q{Library for interfacing with Live Ensure's Two Factor Auth}
|
13
|
+
|
14
|
+
s.rubyforge_project = "live_ensure"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
s.add_development_dependency "rake", "~> 0.9.2.2"
|
23
|
+
s.add_development_dependency "rspec", "~> 2.10"
|
24
|
+
s.add_runtime_dependency "patron", "~> 0.4"
|
25
|
+
s.add_runtime_dependency "activesupport", "~> 3.2.3"
|
26
|
+
end
|
data/readme.md
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
# LiveEnsure
|
2
|
+
|
3
|
+
[](http://travis-ci.org/InspireStudios/live_ensure)
|
4
|
+
|
5
|
+
Library for implementing two-factor auth via liveensure.com.
|
6
|
+
|
7
|
+
## Getting Started
|
8
|
+
|
9
|
+
First, head over to http://www.liveensure.com/ to setup your account and get your API credentials.
|
10
|
+
|
11
|
+
Add a line to your gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'live_ensure', :git => 'git@github.com:InspireStudios/live_ensure.git'
|
15
|
+
```
|
16
|
+
|
17
|
+
Create an initializer for your rails app:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
# /config/initializers/live_ensure.rb
|
21
|
+
|
22
|
+
LiveEnsure.configure do |config|
|
23
|
+
config.api_key = 'KEY'
|
24
|
+
config.api_password = 'PASSWORD'
|
25
|
+
config.api_agent_id = 'AGENT_ID'
|
26
|
+
config.enabled = true # Leave this out if you want to set it per environment
|
27
|
+
end
|
28
|
+
```
|
29
|
+
|
30
|
+
Optionally, enable or disable per environment by adding to your development.rb/staging.rb/etc...
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
LiveEnsure.configure { |config| config.enabled = true }
|
34
|
+
```
|
35
|
+
|
36
|
+
## Implementing LiveEnsure
|
37
|
+
|
38
|
+
*Refer to the guides at http://support.liveensure.com/forums/20038873-guides for more details.*
|
39
|
+
|
40
|
+
Request a token:
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
@live_ensure = LiveEnsure.request_launch(email)
|
44
|
+
session[:live_ensure_token] = @live_ensure.token
|
45
|
+
session[:live_ensure_base_url] = @live_ensure.base_url
|
46
|
+
```
|
47
|
+
|
48
|
+
Add to your view:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
<%= content_tag(:iframe, '', { src: @live_ensure.launch_url, width: 190, height: 190, frameborder: 0}) %>
|
52
|
+
```
|
53
|
+
|
54
|
+
You will need to setup an action to handle a session check using the LiveEnsure.session_status method to detect when the user has successfully authenticated. I use something like this on my sessions controller:
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
def check_auth
|
58
|
+
if session[:live_ensure_token]
|
59
|
+
response = LiveEnsure.session_status(session[:live_ensure_token], session[:live_ensure_base_url])
|
60
|
+
result = { status: response.message }
|
61
|
+
else
|
62
|
+
result = { status: 'no-token' }
|
63
|
+
end
|
64
|
+
|
65
|
+
render json: result
|
66
|
+
end
|
67
|
+
```
|
68
|
+
|
69
|
+
Then I check it from the view using this javascript:
|
70
|
+
|
71
|
+
```javascript
|
72
|
+
var check_auth_interval;
|
73
|
+
|
74
|
+
function checkAuth() {
|
75
|
+
$.getJSON('/check_auth', function(data) {
|
76
|
+
|
77
|
+
if (data.status == 'SUCCESS') {
|
78
|
+
location.href = '/complete_auth';
|
79
|
+
} else if (data.status == null || data.status == 'FAILED') {
|
80
|
+
location.href = '/login';
|
81
|
+
} else {
|
82
|
+
setTimeout(checkAuth, 1000);
|
83
|
+
}
|
84
|
+
});
|
85
|
+
}
|
86
|
+
|
87
|
+
$(function() {
|
88
|
+
check_auth_interval = setTimeout(checkAuth, 1000);
|
89
|
+
});
|
90
|
+
```
|
91
|
+
|
92
|
+
When you get a success message and redirect to the final step, do another check on the session status:
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
response = LiveEnsure.session_status(session[:live_ensure_token], session[:live_ensure_base_url])
|
96
|
+
|
97
|
+
if response.valid?
|
98
|
+
# sign in the user!
|
99
|
+
else
|
100
|
+
# fail!
|
101
|
+
end
|
102
|
+
```
|
103
|
+
|
104
|
+
Want to contribute? Write specs, and send me a detailed pull request.
|
105
|
+
|
106
|
+
## License
|
107
|
+
|
108
|
+
Licensed under the MIT license: http://www.opensource.org/licenses/MIT
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'live_ensure'
|
2
|
+
|
3
|
+
describe LiveEnsure do
|
4
|
+
|
5
|
+
def stub_patron(body = 'success')
|
6
|
+
@stub_response = stub('patron_response', :status => 200, :body => body)
|
7
|
+
Patron::Session.any_instance.stub(:get).and_return(@stub_response)
|
8
|
+
end
|
9
|
+
|
10
|
+
def configure_live_ensure
|
11
|
+
LiveEnsure.configure do |config|
|
12
|
+
config.api_key = 'API_KEY'
|
13
|
+
config.api_password = 'API_PASSWORD'
|
14
|
+
config.api_agent_id = 'AGENT_ID'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe ".configure" do
|
19
|
+
it "should let you set the api_key" do
|
20
|
+
LiveEnsure.configure do |config|
|
21
|
+
config.api_key = '1234'
|
22
|
+
end
|
23
|
+
|
24
|
+
LiveEnsure.configuration.api_key.should == '1234'
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should let you set the api_password" do
|
28
|
+
LiveEnsure.configure do |config|
|
29
|
+
config.api_password = '1234'
|
30
|
+
end
|
31
|
+
|
32
|
+
LiveEnsure.configuration.api_password.should == '1234'
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should let you set the agent_id" do
|
36
|
+
LiveEnsure.configure do |config|
|
37
|
+
config.api_agent_id = '1234'
|
38
|
+
end
|
39
|
+
|
40
|
+
LiveEnsure.configuration.api_agent_id.should == '1234'
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should let you set the enabled config" do
|
44
|
+
LiveEnsure.configure do |config|
|
45
|
+
config.enabled = true
|
46
|
+
end
|
47
|
+
|
48
|
+
LiveEnsure.configuration.enabled = true
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe ".request_launch" do
|
53
|
+
before do
|
54
|
+
configure_live_ensure
|
55
|
+
stub_patron("4:5yqUulMdWhmXStCWVlJCKDjl:1\nhttps://app01.liveensure.com/live-identity\n")
|
56
|
+
end
|
57
|
+
|
58
|
+
subject { LiveEnsure.request_launch('test@stevedev.com') }
|
59
|
+
|
60
|
+
it { should be_a LiveEnsure::SetupResponse }
|
61
|
+
its(:launch_url) { should == "https://app01.liveensure.com/live-identity/launcher?sessionToken=5yqUulMdWhmXStCWVlJCKDjl" }
|
62
|
+
its(:token) { should == '5yqUulMdWhmXStCWVlJCKDjl' }
|
63
|
+
end
|
64
|
+
|
65
|
+
describe ".session_status" do
|
66
|
+
let(:session_status_response) { "3:a3SDQmP8PUf6jdGqqTN9O7D5:6\nmessage: SESSION_UNDETERMINED\nclient: light plus\nsession: unknown\ndeviceHash: f234eb56bcde603d85176e6c1c3db473\nknownDevice: true\nagent: quick\n" }
|
67
|
+
let(:token) { '5yqUulMdWhmXStCWVlJCKDjl' }
|
68
|
+
let(:base_url) { 'https://app01.liveensure.com/live-identity/' }
|
69
|
+
|
70
|
+
before do
|
71
|
+
configure_live_ensure
|
72
|
+
stub_patron(session_status_response)
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should raise an ArgumentError if the base_url is blank" do
|
76
|
+
expect {
|
77
|
+
LiveEnsure.session_status(token)
|
78
|
+
}.to raise_error ArgumentError
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should return a SessionStatusResponse object" do
|
82
|
+
LiveEnsure.session_status(token, base_url).should be_a LiveEnsure::SessionStatusResponse
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe ".get" do
|
87
|
+
it "should create a new Patron session" do
|
88
|
+
session = Patron::Session.new
|
89
|
+
Patron::Session.should_receive(:new).and_return(session)
|
90
|
+
|
91
|
+
stub_patron
|
92
|
+
LiveEnsure.get('http://www.example.com')
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should raise a ConnectionError if response status is >= 400" do
|
96
|
+
stub_patron
|
97
|
+
@stub_response.stub(:status => 404)
|
98
|
+
expect {
|
99
|
+
LiveEnsure.get('http://www.example.com')
|
100
|
+
}.to raise_error LiveEnsure::ConnectionError
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'live_ensure/session_status_response'
|
2
|
+
|
3
|
+
describe LiveEnsure::SessionStatusResponse do
|
4
|
+
let(:response) { "3:a3SDQmP8PUf6jdGqqTN9O7D5:6\nmessage: SESSION_UNDETERMINED\nclient: light plus\nsession: unknown\ndeviceHash: f234eb56bcde603d85176e6c1c3db473\nknownDevice: true\nagent: quick\n" }
|
5
|
+
|
6
|
+
describe "attrs" do
|
7
|
+
before do
|
8
|
+
@response = LiveEnsure::SessionStatusResponse.new(response)
|
9
|
+
end
|
10
|
+
|
11
|
+
subject { @response }
|
12
|
+
|
13
|
+
its(:message) { should == 'SESSION_UNDETERMINED' }
|
14
|
+
its(:token) { should == 'a3SDQmP8PUf6jdGqqTN9O7D5' }
|
15
|
+
its(:client) { should == 'light plus' }
|
16
|
+
its(:session) { should == 'unknown' }
|
17
|
+
its(:deviceHash) { should == 'f234eb56bcde603d85176e6c1c3db473' }
|
18
|
+
its(:knownDevice) { should == 'true' }
|
19
|
+
its(:agent) { should == 'quick' }
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#valid?" do
|
23
|
+
it "should be valid if message == SUCCESS" do
|
24
|
+
response_str = "3:a3SDQmP8PUf6jdGqqTN9O7D5:6\nmessage: SUCCESS\nclient: light plus\nsession: unknown\ndeviceHash: f234eb56bcde603d85176e6c1c3db473\nknownDevice: true\nagent: quick\n"
|
25
|
+
response = LiveEnsure::SessionStatusResponse.new(response_str)
|
26
|
+
response.should be_valid
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should not be valid if message == FAILED" do
|
30
|
+
response_str = "3:a3SDQmP8PUf6jdGqqTN9O7D5:6\nmessage: FAILED\nclient: light plus\nsession: unknown\ndeviceHash: f234eb56bcde603d85176e6c1c3db473\nknownDevice: true\nagent: quick\n"
|
31
|
+
response = LiveEnsure::SessionStatusResponse.new(response_str)
|
32
|
+
response.should_not be_valid
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should not be valid if message == SESSION_UNDETERMINED" do
|
36
|
+
response_str = "3:a3SDQmP8PUf6jdGqqTN9O7D5:6\nmessage: SESSION_UNDETERMINED\nclient: light plus\nsession: unknown\ndeviceHash: f234eb56bcde603d85176e6c1c3db473\nknownDevice: true\nagent: quick\n"
|
37
|
+
response = LiveEnsure::SessionStatusResponse.new(response_str)
|
38
|
+
response.should_not be_valid
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#failed?" do
|
43
|
+
it "should be failed if message == FAILED" do
|
44
|
+
response_str = "3:a3SDQmP8PUf6jdGqqTN9O7D5:6\nmessage: FAILED\nclient: light plus\nsession: unknown\ndeviceHash: f234eb56bcde603d85176e6c1c3db473\nknownDevice: true\nagent: quick\n"
|
45
|
+
response = LiveEnsure::SessionStatusResponse.new(response_str)
|
46
|
+
response.should be_failed
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should not be valid if message != FAILED" do
|
50
|
+
response_str = "3:a3SDQmP8PUf6jdGqqTN9O7D5:6\nmessage: SUCCESS\nclient: light plus\nsession: unknown\ndeviceHash: f234eb56bcde603d85176e6c1c3db473\nknownDevice: true\nagent: quick\n"
|
51
|
+
response = LiveEnsure::SessionStatusResponse.new(response_str)
|
52
|
+
response.should_not be_failed
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "#undetermined?" do
|
57
|
+
it "should be undetermined if message == SESSION_UNDETERMINED" do
|
58
|
+
response_str = "3:a3SDQmP8PUf6jdGqqTN9O7D5:6\nmessage: SESSION_UNDETERMINED\nclient: light plus\nsession: unknown\ndeviceHash: f234eb56bcde603d85176e6c1c3db473\nknownDevice: true\nagent: quick\n"
|
59
|
+
response = LiveEnsure::SessionStatusResponse.new(response_str)
|
60
|
+
response.should be_undetermined
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should not be undetermined if message != SESSION_UNDETERMINED" do
|
64
|
+
response_str = "3:a3SDQmP8PUf6jdGqqTN9O7D5:6\nmessage: SUCCESS\nclient: light plus\nsession: unknown\ndeviceHash: f234eb56bcde603d85176e6c1c3db473\nknownDevice: true\nagent: quick\n"
|
65
|
+
response = LiveEnsure::SessionStatusResponse.new(response_str)
|
66
|
+
response.should_not be_undetermined
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
2
|
+
|
3
|
+
require 'live_ensure/setup_response'
|
4
|
+
|
5
|
+
describe LiveEnsure::SetupResponse do
|
6
|
+
let(:input) { "4:5yqUulMdWhmXStCWVlJCKDjl:1\nhttps://app01.liveensure.com/live-identity\n" }
|
7
|
+
|
8
|
+
it "should accept the provided string" do
|
9
|
+
response = LiveEnsure::SetupResponse.new(input)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "attrs" do
|
13
|
+
before do
|
14
|
+
@response = LiveEnsure::SetupResponse.new("4:Foo:1\nhttps://app01.liveensure.com/live-identity\n")
|
15
|
+
end
|
16
|
+
|
17
|
+
subject { @response }
|
18
|
+
|
19
|
+
its(:launch_url) { should == "https://app01.liveensure.com/live-identity/launcher?sessionToken=Foo" }
|
20
|
+
its(:token) { should == "Foo" }
|
21
|
+
its(:code) { should == 4 }
|
22
|
+
its(:base_url) { should == 'https://app01.liveensure.com/live-identity' }
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "invalid input" do
|
26
|
+
it "should throw an exeption if content of input is invalid" do
|
27
|
+
expect {
|
28
|
+
LiveEnsure::SetupResponse.new("")
|
29
|
+
}.to raise_error LiveEnsure::InvalidResponse
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "response codes" do
|
34
|
+
describe "0" do
|
35
|
+
it "should raise an AuthSessionError" do
|
36
|
+
expect {
|
37
|
+
LiveEnsure::SetupResponse.new("0:null:error_code_or_message")
|
38
|
+
}.to raise_error LiveEnsure::AuthSessionError
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "1" do
|
43
|
+
before do
|
44
|
+
response_string = "1:5yqUulMdWhmXStCWVlJCKDjl:successMessage\n"
|
45
|
+
@response = LiveEnsure::SetupResponse.new(response_string)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should return the default URL" do
|
49
|
+
@response.launch_url.should == "#{LiveEnsure::HOST}/launcher?sessionToken=5yqUulMdWhmXStCWVlJCKDjl"
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should set the code to 1" do
|
53
|
+
@response.code.should == 1
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "2" do
|
58
|
+
it "should raise a ServiceDown exception" do
|
59
|
+
expect {
|
60
|
+
LiveEnsure::SetupResponse.new('2:errorToken:service_down_message')
|
61
|
+
}.to raise_error LiveEnsure::ServiceDown
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "4" do
|
66
|
+
before do
|
67
|
+
@response = LiveEnsure::SetupResponse.new(input)
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should return the supplied URL instead of the default" do
|
71
|
+
@response.launch_url.should == 'https://app01.liveensure.com/live-identity/launcher?sessionToken=5yqUulMdWhmXStCWVlJCKDjl'
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should set the code to 4" do
|
75
|
+
@response.code.should == 4
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: live_ensure
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Steve Thompson
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-23 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: &70109444336520 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.9.2.2
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70109444336520
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &70109444197080 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2.10'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70109444197080
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: patron
|
38
|
+
requirement: &70109444194640 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0.4'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70109444194640
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: activesupport
|
49
|
+
requirement: &70109444191580 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.2.3
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70109444191580
|
58
|
+
description: Library for interfacing with Live Ensure's Two Factor Auth
|
59
|
+
email:
|
60
|
+
- me@stevedev.com
|
61
|
+
executables: []
|
62
|
+
extensions: []
|
63
|
+
extra_rdoc_files: []
|
64
|
+
files:
|
65
|
+
- .gitignore
|
66
|
+
- .rspec
|
67
|
+
- .travis.yml
|
68
|
+
- Gemfile
|
69
|
+
- MIT-LICENSE
|
70
|
+
- Rakefile
|
71
|
+
- lib/live_ensure.rb
|
72
|
+
- lib/live_ensure/accessible.rb
|
73
|
+
- lib/live_ensure/configure.rb
|
74
|
+
- lib/live_ensure/errors.rb
|
75
|
+
- lib/live_ensure/response.rb
|
76
|
+
- lib/live_ensure/session_status_response.rb
|
77
|
+
- lib/live_ensure/setup_response.rb
|
78
|
+
- lib/live_ensure/version.rb
|
79
|
+
- live_ensure.gemspec
|
80
|
+
- readme.md
|
81
|
+
- spec/live_ensure_spec.rb
|
82
|
+
- spec/session_status_response_spec.rb
|
83
|
+
- spec/setup_response_spec.rb
|
84
|
+
homepage: http://www.inspirestudios.ca
|
85
|
+
licenses: []
|
86
|
+
post_install_message:
|
87
|
+
rdoc_options: []
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
92
|
+
requirements:
|
93
|
+
- - ! '>='
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project: live_ensure
|
104
|
+
rubygems_version: 1.8.10
|
105
|
+
signing_key:
|
106
|
+
specification_version: 3
|
107
|
+
summary: Live Ensure API for Ruby
|
108
|
+
test_files:
|
109
|
+
- spec/live_ensure_spec.rb
|
110
|
+
- spec/session_status_response_spec.rb
|
111
|
+
- spec/setup_response_spec.rb
|