hancock-client 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +14 -2
- data/lib/hancock-client.rb +4 -6
- data/lib/sinatra/hancock/sso.rb +4 -8
- data/spec/client.rb +11 -2
- data/spec/features/signing_up.feature +17 -0
- data/spec/features/step_definitions/signup_steps.rb +62 -0
- data/spec/features/support/env.rb +21 -0
- data/spec/hancock_sinatra_spec.rb +4 -3
- data/spec/spec_helper.rb +6 -3
- metadata +10 -4
data/Rakefile
CHANGED
@@ -3,13 +3,14 @@ require 'rake/gempackagetask'
|
|
3
3
|
require 'rubygems/specification'
|
4
4
|
require 'date'
|
5
5
|
require 'spec/rake/spectask'
|
6
|
+
require 'cucumber/rake/task'
|
6
7
|
|
7
8
|
GEM = "hancock-client"
|
8
|
-
GEM_VERSION = "0.0.
|
9
|
+
GEM_VERSION = "0.0.3"
|
9
10
|
AUTHOR = "Corey Donohoe"
|
10
11
|
EMAIL = ['atmos@atmos.org', 'tim@spork.in']
|
11
12
|
HOMEPAGE = "http://github.com/atmos/hancock-client"
|
12
|
-
SUMMARY = "
|
13
|
+
SUMMARY = "Hancock SSO rack middleware written in sinatra"
|
13
14
|
|
14
15
|
spec = Gem::Specification.new do |s|
|
15
16
|
s.name = GEM
|
@@ -56,3 +57,14 @@ task :make_spec do
|
|
56
57
|
file.puts spec.to_ruby
|
57
58
|
end
|
58
59
|
end
|
60
|
+
|
61
|
+
Cucumber::Rake::Task.new(:features) do |t|
|
62
|
+
t.libs << 'lib'
|
63
|
+
t.cucumber_opts = "--format pretty"
|
64
|
+
t.step_list = 'spec/features/**/*.rb'
|
65
|
+
t.feature_list = 'spec/features/**/*.feature'
|
66
|
+
t.rcov = true
|
67
|
+
t.rcov_opts << '--text-summary'
|
68
|
+
t.rcov_opts << '--sort' << 'coverage' << '--sort-reverse'
|
69
|
+
t.rcov_opts << '--exclude' << '.gem/,spec,examples'
|
70
|
+
end
|
data/lib/hancock-client.rb
CHANGED
@@ -7,20 +7,18 @@ require 'dm-core'
|
|
7
7
|
gem 'ruby-openid', '>=2.1.2'
|
8
8
|
require 'openid'
|
9
9
|
|
10
|
+
gem 'haml', '~>2.0.9'
|
11
|
+
require 'haml'
|
12
|
+
|
10
13
|
require File.dirname(__FILE__)+'/sinatra/hancock/sso'
|
11
14
|
|
12
15
|
module Hancock
|
13
16
|
module Client
|
14
17
|
class Default < ::Sinatra::Default
|
15
18
|
enable :sessions
|
16
|
-
|
19
|
+
set :sso_url, nil
|
17
20
|
|
18
21
|
register Sinatra::Hancock::SSO
|
19
|
-
|
20
|
-
def self.sso_configure(&block)
|
21
|
-
yield self
|
22
|
-
end
|
23
22
|
end
|
24
23
|
end
|
25
24
|
end
|
26
|
-
|
data/lib/sinatra/hancock/sso.rb
CHANGED
@@ -5,10 +5,6 @@ module Sinatra
|
|
5
5
|
module Hancock
|
6
6
|
module SSO
|
7
7
|
module Helpers
|
8
|
-
def sso_url
|
9
|
-
@app.class.sso_url
|
10
|
-
end
|
11
|
-
|
12
8
|
def absolute_url(suffix = nil)
|
13
9
|
port_part = case request.scheme
|
14
10
|
when "http"
|
@@ -25,12 +21,12 @@ module Sinatra
|
|
25
21
|
app.helpers Hancock::SSO::Helpers
|
26
22
|
app.enable :sessions
|
27
23
|
app.disable :raise_errors
|
28
|
-
app.before { ensure_sso_authenticated unless request.path_info =~ %r!^/sso/log(in|out)! }
|
24
|
+
# app.before { ensure_sso_authenticated unless request.path_info =~ %r!^/sso/log(in|out)! }
|
29
25
|
|
30
26
|
app.get '/sso/login' do
|
31
27
|
if contact_id = params['id']
|
32
28
|
response['WWW-Authenticate'] = Rack::OpenID.build_header(
|
33
|
-
:identifier => "#{sso_url}/users/#{contact_id}",
|
29
|
+
:identifier => "#{options.sso_url}/users/#{contact_id}",
|
34
30
|
:trust_root => absolute_url('/sso/login')
|
35
31
|
)
|
36
32
|
throw :halt, [401, 'got openid?']
|
@@ -52,13 +48,13 @@ module Sinatra
|
|
52
48
|
throw :halt, [503, "Error: #{openid.status}"]
|
53
49
|
end
|
54
50
|
else
|
55
|
-
redirect "#{sso_url}/login?return_to=#{absolute_url('/sso/login')}"
|
51
|
+
redirect "#{options.sso_url}/login?return_to=#{absolute_url('/sso/login')}"
|
56
52
|
end
|
57
53
|
end
|
58
54
|
|
59
55
|
app.get '/sso/logout' do
|
60
56
|
session.clear
|
61
|
-
redirect "#{sso_url}/logout"
|
57
|
+
redirect "#{options.sso_url}/logout"
|
62
58
|
end
|
63
59
|
end
|
64
60
|
end
|
data/spec/client.rb
CHANGED
@@ -3,11 +3,20 @@ require 'sinatra/base'
|
|
3
3
|
module Hancock
|
4
4
|
module Spec
|
5
5
|
class Client < ::Hancock::Client::Default
|
6
|
+
set :environment, :development
|
6
7
|
get '/' do
|
7
8
|
redirect '/sso/login' unless session[:user_id]
|
8
9
|
haml(<<-HAML
|
9
|
-
%
|
10
|
-
|
10
|
+
%table
|
11
|
+
%thead
|
12
|
+
%tr
|
13
|
+
%td Key
|
14
|
+
%td Value
|
15
|
+
%tbody
|
16
|
+
- session.keys.sort { |a,b| a.to_s <=> b.to_s }.each do |key|
|
17
|
+
%tr
|
18
|
+
%td= key
|
19
|
+
%td= session[key]
|
11
20
|
HAML
|
12
21
|
)
|
13
22
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
Feature: Signing Up for an SSO Account
|
2
|
+
In order to get users involved
|
3
|
+
As a new user
|
4
|
+
Scenario: Signing Up
|
5
|
+
When I request a page on the Site
|
6
|
+
And I am redirected to the SSO Server
|
7
|
+
Then I should click the signup button
|
8
|
+
When the page loads I should see a signup form
|
9
|
+
Then I fill out the required information
|
10
|
+
And click submit
|
11
|
+
Then I should receive a registration URL
|
12
|
+
When I click on the registration URL
|
13
|
+
Then I should be prompted to enter my new password
|
14
|
+
When I provide a new password
|
15
|
+
And click Am I Done Yet?
|
16
|
+
Then I should be redirected back to the consumer application
|
17
|
+
Then I should know a little bit about myself as a user
|
@@ -0,0 +1,62 @@
|
|
1
|
+
When /^I request a page on the Site$/ do
|
2
|
+
browser.goto('http://localhost:4567/sso/logout')
|
3
|
+
browser.goto('http://localhost:4567/')
|
4
|
+
end
|
5
|
+
|
6
|
+
And /^I am redirected to the SSO Server$/ do
|
7
|
+
true
|
8
|
+
end
|
9
|
+
|
10
|
+
Then /^I should click the signup button$/ do
|
11
|
+
browser.link(:url, "#{sso_server}/signup").click
|
12
|
+
end
|
13
|
+
|
14
|
+
When /^the page loads I should see a signup form$/ do
|
15
|
+
browser.html.should have_selector("input[type='text'][name='first_name']")
|
16
|
+
end
|
17
|
+
|
18
|
+
Then /^I fill out the required information$/ do
|
19
|
+
@email = /\w+@\w+\.\w{2,3}/.gen.downcase
|
20
|
+
@first_name, @last_name = /\w+/.gen.capitalize, /\w+/.gen.capitalize
|
21
|
+
browser.text_field(:name, :first_name).set(@first_name)
|
22
|
+
browser.text_field(:name, :last_name).set(@last_name)
|
23
|
+
browser.text_field(:name, :email).set(@email)
|
24
|
+
end
|
25
|
+
|
26
|
+
And /^click submit$/ do
|
27
|
+
browser.button(:value, 'Signup').click
|
28
|
+
end
|
29
|
+
|
30
|
+
Then /^I should receive a registration URL$/ do
|
31
|
+
@register_url = browser.html.match(%r!#{sso_server}/register/\w{40}!).to_s
|
32
|
+
@register_url.should_not eql('')
|
33
|
+
@password = /\w+{9,32}/.gen
|
34
|
+
end
|
35
|
+
|
36
|
+
When /^I click on the registration URL$/ do
|
37
|
+
browser.goto(@register_url)
|
38
|
+
end
|
39
|
+
|
40
|
+
Then /^I should be prompted to enter my new password$/ do
|
41
|
+
true
|
42
|
+
end
|
43
|
+
|
44
|
+
When /^I provide a new password$/ do
|
45
|
+
browser.text_field(:name, :password).set(@password)
|
46
|
+
browser.text_field(:name, :password_confirmation).set(@password)
|
47
|
+
end
|
48
|
+
|
49
|
+
And /^click Am I Done Yet\?$/ do
|
50
|
+
browser.button(:value, 'Am I Done Yet?').click
|
51
|
+
end
|
52
|
+
|
53
|
+
Then /^I should be redirected back to the consumer application$/ do
|
54
|
+
true
|
55
|
+
end
|
56
|
+
|
57
|
+
Then /^I should know a little bit about myself as a user$/ do
|
58
|
+
browser.html.should have_selector "h1:contains('Hancock Client: Sinatra')"
|
59
|
+
browser.have_selector "td:contains('#{@email}')"
|
60
|
+
browser.have_selector "td:contains('#{@first_name}')"
|
61
|
+
browser.have_selector "td:contains('#{@last_name}')"
|
62
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__)+'/../../spec_helper')
|
2
|
+
gem 'safariwatir', '~>0.3.3'
|
3
|
+
require 'safariwatir'
|
4
|
+
|
5
|
+
World do
|
6
|
+
def sso_server
|
7
|
+
@sso_server ||= 'http://hancock.atmos.org/sso'
|
8
|
+
end
|
9
|
+
def browser
|
10
|
+
@browser ||= Watir::Safari.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def app
|
14
|
+
@app = Rack::Builder.new do
|
15
|
+
run Hancock::Spec::Client
|
16
|
+
end
|
17
|
+
end
|
18
|
+
include Rack::Test::Methods
|
19
|
+
include Webrat::Methods
|
20
|
+
include Webrat::Matchers
|
21
|
+
end
|
@@ -3,10 +3,11 @@ require File.dirname(__FILE__) + '/spec_helper'
|
|
3
3
|
describe Sinatra::Hancock::SSO do
|
4
4
|
it "should protect the root url" do
|
5
5
|
get '/'
|
6
|
-
|
6
|
+
last_response.headers['Location'].should eql('/sso/login')
|
7
7
|
end
|
8
8
|
it "should greet the user when authenticated" do
|
9
|
-
|
10
|
-
|
9
|
+
pending
|
10
|
+
get '/'
|
11
|
+
last_response.body.should have_selector('p')
|
11
12
|
end
|
12
13
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -9,20 +9,23 @@ require 'dm-sweatshop'
|
|
9
9
|
|
10
10
|
gem 'sinatra', '~>0.9.1'
|
11
11
|
require 'sinatra/base'
|
12
|
-
require 'sinatra/test'
|
13
12
|
require 'sinatra/hancock/sso'
|
13
|
+
gem 'rack-test', '~>0.1.0'
|
14
|
+
require 'rack/test'
|
14
15
|
|
15
16
|
require 'hancock-client'
|
16
17
|
|
17
18
|
require File.dirname(__FILE__)+'/client'
|
18
19
|
|
19
20
|
Spec::Runner.configure do |config|
|
20
|
-
config.include(
|
21
|
+
config.include(Rack::Test::Methods)
|
21
22
|
config.include(Webrat::Methods)
|
22
23
|
config.include(Webrat::Matchers)
|
23
|
-
|
24
|
+
def app
|
24
25
|
@app = Rack::Builder.new do
|
25
26
|
run Hancock::Spec::Client
|
26
27
|
end
|
27
28
|
end
|
29
|
+
#config.before(:each) do
|
30
|
+
#end
|
28
31
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hancock-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Corey Donohoe
|
@@ -9,7 +9,7 @@ autorequire: hancock-client
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-03-
|
12
|
+
date: 2009-03-21 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 2.1.2
|
34
34
|
version:
|
35
|
-
description:
|
35
|
+
description: Hancock SSO rack middleware written in sinatra
|
36
36
|
email:
|
37
37
|
- atmos@atmos.org
|
38
38
|
- tim@spork.in
|
@@ -53,6 +53,12 @@ files:
|
|
53
53
|
- lib/sinatra/hancock
|
54
54
|
- lib/sinatra/hancock/sso.rb
|
55
55
|
- spec/client.rb
|
56
|
+
- spec/features
|
57
|
+
- spec/features/signing_up.feature
|
58
|
+
- spec/features/step_definitions
|
59
|
+
- spec/features/step_definitions/signup_steps.rb
|
60
|
+
- spec/features/support
|
61
|
+
- spec/features/support/env.rb
|
56
62
|
- spec/hancock_sinatra_spec.rb
|
57
63
|
- spec/spec_helper.rb
|
58
64
|
has_rdoc: true
|
@@ -80,6 +86,6 @@ rubyforge_project:
|
|
80
86
|
rubygems_version: 1.3.1
|
81
87
|
signing_key:
|
82
88
|
specification_version: 2
|
83
|
-
summary:
|
89
|
+
summary: Hancock SSO rack middleware written in sinatra
|
84
90
|
test_files: []
|
85
91
|
|