roman-rots 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/AUTHORS +2 -0
- data/README +64 -0
- data/Rakefile +125 -0
- data/bin/rots +81 -0
- data/lib/ruby_openid_test_server/mock_identity_page.rb +29 -0
- data/lib/ruby_openid_test_server/server_app.rb +130 -0
- data/lib/ruby_openid_test_server.rb +10 -0
- data/rots.gemspec +32 -0
- data/spec/server_app_spec.rb +94 -0
- data/spec/spec_helper.rb +73 -0
- metadata +93 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
pkg/*
|
data/AUTHORS
ADDED
data/README
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
= Ruby OpenID Test Server (ROTS), a dummy OpenID server that makes consumer tests dead easy.
|
2
|
+
|
3
|
+
ROTS is a minimal implementation of an OpenID server, developed on top of the Rack middleware, this
|
4
|
+
server provides an easy to use interface to make testing OpenID consumers really easy.
|
5
|
+
|
6
|
+
== No more mocks
|
7
|
+
|
8
|
+
Have you always wanted to test the authentication of an OpenID consumer implementation, but find your self
|
9
|
+
in a point where is to hard to mock? A lot of people have been there.
|
10
|
+
|
11
|
+
With ROTS, you only need to specify an identity url provided by the dummy server, passing with it a flag
|
12
|
+
saying that you want the authentication to be successful. It handles SREG extensions as well.
|
13
|
+
|
14
|
+
== How does it works
|
15
|
+
|
16
|
+
When you install the ROTS gem, a binary called rots is provided for starting the server (for more
|
17
|
+
info about what options you have when executing this file, check the -h option).
|
18
|
+
|
19
|
+
By default, rots will have a test user called "John Doe", with an OpenID identity "john.doe".
|
20
|
+
If you want to use your own test user name, you can specify a config file to rots. The
|
21
|
+
default configuration file looks like this:
|
22
|
+
|
23
|
+
# Default configuration file
|
24
|
+
identity: john.doe
|
25
|
+
sreg:
|
26
|
+
nickname: jdoe
|
27
|
+
fullname: John Doe
|
28
|
+
email: jhon@doe.com
|
29
|
+
dob: 1985-09-21
|
30
|
+
gender: M
|
31
|
+
|
32
|
+
You can specify a new config file using the option --config.
|
33
|
+
|
34
|
+
== Getting Started
|
35
|
+
|
36
|
+
The best way to get started, is running the rots server, and then starting to execute your OpenID consumer tests/specs. You just have to specify the identity url of your test user, if you want the OpenID response be successful just add the openid.success=true flag to the user identity url. If you don't specify the flag it
|
37
|
+
will return a cancel response instead.
|
38
|
+
|
39
|
+
Example:
|
40
|
+
|
41
|
+
it "should authenticate with OpenID" do
|
42
|
+
post("/consumer_openid_login", 'identity_url' => 'http://localhost:1132/john.doe?openid.success=true')
|
43
|
+
end
|
44
|
+
|
45
|
+
== Copyright
|
46
|
+
|
47
|
+
Copyright (C) 2009 Roman Gonzalez <romanandreg@gmail.com>
|
48
|
+
|
49
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
50
|
+
of this software and associated documentation files (the "Software"), to
|
51
|
+
deal in the Software without restriction, including without limitation the
|
52
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
53
|
+
sell copies of the Software, and to permit persons to whom the Software is
|
54
|
+
furnished to do so, subject to the following conditions:
|
55
|
+
|
56
|
+
The above copyright notice and this permission notice shall be included in
|
57
|
+
all copies or substantial portions of the Software.
|
58
|
+
|
59
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
60
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
61
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
62
|
+
THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
63
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
64
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
# Rakefile for Rack. -*-ruby-*-
|
2
|
+
require 'rake/rdoctask'
|
3
|
+
require 'rake/testtask'
|
4
|
+
require 'spec/rake/spectask'
|
5
|
+
|
6
|
+
|
7
|
+
desc "Run all the tests"
|
8
|
+
task :default => [:spec]
|
9
|
+
|
10
|
+
desc "Do predistribution stuff"
|
11
|
+
task :predist => [:changelog, :rdoc]
|
12
|
+
|
13
|
+
|
14
|
+
desc "Make an archive as .tar.gz"
|
15
|
+
task :dist => [:fulltest, :predist] do
|
16
|
+
sh "git archive --format=tar --prefix=#{release}/ HEAD^{tree} >#{release}.tar"
|
17
|
+
sh "pax -waf #{release}.tar -s ':^:#{release}/:' RDOX SPEC ChangeLog doc"
|
18
|
+
sh "gzip -f -9 #{release}.tar"
|
19
|
+
end
|
20
|
+
|
21
|
+
# Helper to retrieve the "revision number" of the git tree.
|
22
|
+
def git_tree_version
|
23
|
+
#if File.directory?(".git")
|
24
|
+
# @tree_version ||= `git describe`.strip.sub('-', '.')
|
25
|
+
# @tree_version << ".0" unless @tree_version.count('.') == 2
|
26
|
+
#else
|
27
|
+
$: << "lib"
|
28
|
+
require 'ruby_openid_test_server'
|
29
|
+
@tree_version = RubyOpenIdTestServer.release
|
30
|
+
#end
|
31
|
+
@tree_version
|
32
|
+
end
|
33
|
+
|
34
|
+
def gem_version
|
35
|
+
git_tree_version.gsub(/-.*/, '')
|
36
|
+
end
|
37
|
+
|
38
|
+
def release
|
39
|
+
"ruby-openid-tester-#{git_tree_version}"
|
40
|
+
end
|
41
|
+
|
42
|
+
def manifest
|
43
|
+
`git ls-files`.split("\n")
|
44
|
+
end
|
45
|
+
|
46
|
+
desc "Generate a ChangeLog"
|
47
|
+
task :changelog do
|
48
|
+
File.open("ChangeLog", "w") do |out|
|
49
|
+
`git log -z`.split("\0").map do |chunk|
|
50
|
+
author = chunk[/Author: (.*)/, 1].strip
|
51
|
+
date = chunk[/Date: (.*)/, 1].strip
|
52
|
+
desc, detail = $'.strip.split("\n", 2)
|
53
|
+
detail ||= ""
|
54
|
+
detail.rstrip!
|
55
|
+
out.puts "#{date} #{author}"
|
56
|
+
out.puts " * #{desc.strip}"
|
57
|
+
out.puts detail unless detail.empty?
|
58
|
+
out.puts
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
begin
|
65
|
+
require 'rubygems'
|
66
|
+
|
67
|
+
require 'rake'
|
68
|
+
require 'rake/clean'
|
69
|
+
require 'rake/packagetask'
|
70
|
+
require 'rake/gempackagetask'
|
71
|
+
require 'fileutils'
|
72
|
+
rescue LoadError
|
73
|
+
# Too bad.
|
74
|
+
else
|
75
|
+
spec = Gem::Specification.new do |s|
|
76
|
+
s.name = "rots"
|
77
|
+
s.version = gem_version
|
78
|
+
s.platform = Gem::Platform::RUBY
|
79
|
+
s.summary = "an OpenID server for making tests of OpenID clients implementations"
|
80
|
+
|
81
|
+
s.description = <<-EOF
|
82
|
+
Ruby OpenID Test Server (ROST) provides a basic OpenID server made in top of the Rack gem.
|
83
|
+
With this small server, you can make dummy OpenID request for testing purposes,
|
84
|
+
the success of the response will depend on a parameter given on the url of the authentication request.
|
85
|
+
EOF
|
86
|
+
|
87
|
+
s.files = manifest
|
88
|
+
s.bindir = 'bin'
|
89
|
+
s.executables << 'rots'
|
90
|
+
s.require_path = 'lib'
|
91
|
+
s.has_rdoc = true
|
92
|
+
s.extra_rdoc_files = ['README']
|
93
|
+
s.test_files = Dir['spec/*_spec.rb']
|
94
|
+
|
95
|
+
s.author = 'Roman Gonzalez'
|
96
|
+
s.email = 'romanandreg@gmail.com'
|
97
|
+
s.homepage = 'http://github.com/roman'
|
98
|
+
s.rubyforge_project = 'rots'
|
99
|
+
|
100
|
+
s.add_development_dependency 'rspec'
|
101
|
+
s.add_development_dependency 'rack'
|
102
|
+
s.add_development_dependency 'ruby-openid', '~> 2.0.0'
|
103
|
+
end
|
104
|
+
|
105
|
+
Rake::GemPackageTask.new(spec) do |p|
|
106
|
+
p.gem_spec = spec
|
107
|
+
p.need_tar = false
|
108
|
+
p.need_zip = false
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
Spec::Rake::SpecTask.new do |t|
|
113
|
+
end
|
114
|
+
|
115
|
+
desc "Generate RDoc documentation"
|
116
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
117
|
+
rdoc.options << '--line-numbers' << '--inline-source' <<
|
118
|
+
'--main' << 'README' <<
|
119
|
+
'--title' << 'ROTS Documentation' <<
|
120
|
+
'--charset' << 'utf-8'
|
121
|
+
rdoc.rdoc_dir = "doc"
|
122
|
+
rdoc.rdoc_files.include 'README'
|
123
|
+
rdoc.rdoc_files.include('lib/ruby_openid_test_server.rb')
|
124
|
+
rdoc.rdoc_files.include('lib/ruby_openid_test_server/*.rb')
|
125
|
+
end
|
data/bin/rots
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- ruby -*-
|
3
|
+
|
4
|
+
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
5
|
+
require "rubygems"
|
6
|
+
require "optparse"
|
7
|
+
require "rack"
|
8
|
+
require "ruby_openid_test_server"
|
9
|
+
|
10
|
+
server_options = {
|
11
|
+
:port => 1123,
|
12
|
+
:verbose => true,
|
13
|
+
:config => <<-DEFAULT_CONFIG
|
14
|
+
# Default configuration file
|
15
|
+
identity: john.doe
|
16
|
+
sreg:
|
17
|
+
nickname: jdoe
|
18
|
+
fullname: John Doe
|
19
|
+
email: jhon@doe.com
|
20
|
+
dob: 1985-09-21
|
21
|
+
gender: M
|
22
|
+
|
23
|
+
DEFAULT_CONFIG
|
24
|
+
}
|
25
|
+
|
26
|
+
opts = OptionParser.new do |opts|
|
27
|
+
opts.banner = "Usage: rots [options]"
|
28
|
+
|
29
|
+
opts.separator ""
|
30
|
+
opts.separator "Options:"
|
31
|
+
|
32
|
+
opts.on("-p", "--port PORT",
|
33
|
+
"use PORT (default: 1123)") do |port|
|
34
|
+
server_options[:port] = port
|
35
|
+
end
|
36
|
+
|
37
|
+
opts.on("-c", "--config FILE.yaml",
|
38
|
+
"server configuration YAML file") do |config_path|
|
39
|
+
abort "\x1B[31mConfiguration file #{config_path} not found\x1B[0m" unless File.exists?(config_path)
|
40
|
+
server_options[:config] = File.new(config_path)
|
41
|
+
end
|
42
|
+
|
43
|
+
opts.on("-s", "--silent",
|
44
|
+
"If specified, the server will be in silent mode") do
|
45
|
+
server_options[:verbose] = false
|
46
|
+
end
|
47
|
+
|
48
|
+
opts.separator ""
|
49
|
+
opts.separator "Common options:"
|
50
|
+
|
51
|
+
opts.on_tail("-h", "--help", "Show this help message") do
|
52
|
+
puts opts
|
53
|
+
exit
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
opts.parse!(ARGV)
|
59
|
+
|
60
|
+
config = YAML.load(server_options[:config])
|
61
|
+
|
62
|
+
server = Rack::Builder.new do
|
63
|
+
use Rack::Lint
|
64
|
+
if server_options[:verbose]
|
65
|
+
use Rack::CommonLogger, $STDOUT
|
66
|
+
use Rack::ShowExceptions
|
67
|
+
end
|
68
|
+
map "/" do
|
69
|
+
run RubyOpenIdTestServer::ServerApp.new(config)
|
70
|
+
end
|
71
|
+
map "/#{config['identity']}" do
|
72
|
+
run RubyOpenIdTestServer::MockIdentityPage.new(config)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
puts "\x1B[32mRunning OpenID Test server on port 1123\x1B[0m" if server_options[:verbose]
|
77
|
+
begin
|
78
|
+
Rack::Handler::Mongrel.run server, :Port => server_options[:port]
|
79
|
+
rescue LoadError
|
80
|
+
Rack::Handler::WEBrick.run server, :Port => server_options[:port]
|
81
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
gem 'ruby-openid', '~> 2' if defined? Gem
|
2
|
+
require 'rack/response'
|
3
|
+
require 'rack/utils'
|
4
|
+
|
5
|
+
class RubyOpenIdTestServer::MockIdentityPage
|
6
|
+
|
7
|
+
def initialize(config)
|
8
|
+
@config = config
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(env)
|
12
|
+
request = Rack::Request.new(env)
|
13
|
+
flag = request.params['openid.success'] == 'true' ? '?openid.success=true' : ''
|
14
|
+
Rack::Response.new do |response|
|
15
|
+
response.write <<-HERE
|
16
|
+
<html>
|
17
|
+
<head>
|
18
|
+
<link rel="openid.server" href="http://localhost:1123/#{flag}" />
|
19
|
+
<link rel="openid2.provider" href="http://localhost:1123/#{flag}" />
|
20
|
+
</head>
|
21
|
+
<body>
|
22
|
+
<h1>This is #{@config['identity']} identity page</h1>
|
23
|
+
</body>
|
24
|
+
</html>
|
25
|
+
HERE
|
26
|
+
end.finish
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
gem 'ruby-openid', '~> 2' if defined? Gem
|
2
|
+
require 'rack/request'
|
3
|
+
require 'rack/utils'
|
4
|
+
require 'openid'
|
5
|
+
require 'openid/extension'
|
6
|
+
require 'openid/extensions/sreg'
|
7
|
+
require 'openid/store/memory'
|
8
|
+
require 'openid/util'
|
9
|
+
|
10
|
+
|
11
|
+
module RubyOpenIdTestServer
|
12
|
+
|
13
|
+
class ServerApp
|
14
|
+
|
15
|
+
attr_accessor :request,:openid_request,
|
16
|
+
:response, :openid_response,
|
17
|
+
:server
|
18
|
+
|
19
|
+
def initialize(config)
|
20
|
+
@sreg_fields = config['sreg']
|
21
|
+
end
|
22
|
+
|
23
|
+
def call(env)
|
24
|
+
on_openid_request(env) do
|
25
|
+
if !is_checkid_request?
|
26
|
+
@openid_response = @server.handle_request(@openid_request)
|
27
|
+
reply_consumer
|
28
|
+
elsif is_checkid_immediate?
|
29
|
+
process_immediate_checkid_request
|
30
|
+
else
|
31
|
+
process_checkid_request
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
protected
|
37
|
+
|
38
|
+
def on_openid_request(env)
|
39
|
+
create_wrappers(env)
|
40
|
+
if @openid_request.nil?
|
41
|
+
[200, {'Content-Type' => 'text/plain'},
|
42
|
+
["This is an OpenID endpoint"] ]
|
43
|
+
else
|
44
|
+
yield
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def create_wrappers(env)
|
49
|
+
@request = Rack::Request.new(env)
|
50
|
+
@server = OpenID::Server::Server.new(OpenID::Store::Memory.new, @request.host)
|
51
|
+
@openid_request = @server.decode_request(@request.params)
|
52
|
+
@openid_sreg_request = OpenID::SReg::Request.from_openid_request(@openid_request) unless @openid_request.nil?
|
53
|
+
end
|
54
|
+
|
55
|
+
def is_checkid_request?
|
56
|
+
@openid_request.is_a?(OpenID::Server::CheckIDRequest)
|
57
|
+
end
|
58
|
+
|
59
|
+
def is_checkid_immediate?
|
60
|
+
@openid_request && @openid_request.immediate
|
61
|
+
end
|
62
|
+
|
63
|
+
def process_immediate_checkid_request
|
64
|
+
# TODO: We should enable the user to configure
|
65
|
+
# if she wants immediate request support or not
|
66
|
+
url = OpenID::Util.append_args(@openid_request.return_to,
|
67
|
+
@request.params.merge('openid.mode' => 'setup_needed'))
|
68
|
+
redirect(url)
|
69
|
+
end
|
70
|
+
|
71
|
+
def process_checkid_request
|
72
|
+
if checkid_request_is_valid?
|
73
|
+
return_successful_openid_response
|
74
|
+
else
|
75
|
+
return_cancel_openid_response
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def checkid_request_is_valid?
|
80
|
+
@request.params['openid.success'] == 'true'
|
81
|
+
end
|
82
|
+
|
83
|
+
def return_successful_openid_response
|
84
|
+
@openid_response = @openid_request.answer(true)
|
85
|
+
process_sreg_extension
|
86
|
+
# TODO: Add support for SREG extension
|
87
|
+
@server.signatory.sign(@openid_response) if @openid_response.needs_signing
|
88
|
+
reply_consumer
|
89
|
+
end
|
90
|
+
|
91
|
+
def process_sreg_extension
|
92
|
+
return if @openid_sreg_request.nil?
|
93
|
+
response = OpenID::SReg::Response.extract_response(@openid_sreg_request, @sreg_fields)
|
94
|
+
@openid_response.add_extension(response)
|
95
|
+
end
|
96
|
+
|
97
|
+
def return_cancel_openid_response
|
98
|
+
redirect(@openid_request.cancel_url)
|
99
|
+
end
|
100
|
+
|
101
|
+
def reply_consumer
|
102
|
+
web_response = @server.encode_response(@openid_response)
|
103
|
+
case web_response.code
|
104
|
+
when OpenID::Server::HTTP_OK
|
105
|
+
success(web_response.body)
|
106
|
+
when OpenID::Server::HTTP_REDIRECT
|
107
|
+
redirect(web_response.headers['location'])
|
108
|
+
else
|
109
|
+
bad_request
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def redirect(uri)
|
114
|
+
[ 303, {'Content-Length'=>'0', 'Content-Type'=>'text/plain',
|
115
|
+
'Location' => uri},
|
116
|
+
[] ]
|
117
|
+
end
|
118
|
+
|
119
|
+
def bad_request()
|
120
|
+
[ 400, {'Content-Type'=>'text/plain', 'Content-Length'=>'0'},
|
121
|
+
[] ]
|
122
|
+
end
|
123
|
+
|
124
|
+
def success(text="")
|
125
|
+
Rack::Response.new(text).finish
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
data/rots.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
|
5
|
+
s.name = "rots"
|
6
|
+
s.version = '0.0.1'
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.summary = "an OpenID server for making tests of OpenID clients implementations"
|
9
|
+
|
10
|
+
s.description = <<-EOF
|
11
|
+
Ruby OpenID Test Server (ROST) provides a basic OpenID server made in top of the Rack gem.
|
12
|
+
With this small server, you can make dummy OpenID request for testing purposes,
|
13
|
+
the success of the response will depend on a parameter given on the url of the authentication request.
|
14
|
+
EOF
|
15
|
+
|
16
|
+
s.files = [".gitignore", "AUTHORS", "README", "Rakefile", "bin/rots", "lib/ruby_openid_test_server.rb", "lib/ruby_openid_test_server/mock_identity_page.rb", "lib/ruby_openid_test_server/server_app.rb", "rots.gemspec", "spec/server_app_spec.rb", "spec/spec_helper.rb"]
|
17
|
+
s.bindir = 'bin'
|
18
|
+
s.executables << 'rots'
|
19
|
+
s.require_path = 'lib'
|
20
|
+
s.has_rdoc = true
|
21
|
+
s.extra_rdoc_files = ['README']
|
22
|
+
s.test_files = ['spec/server_app_spec.rb', 'spec/spec_helper.rb']
|
23
|
+
|
24
|
+
s.author = 'Roman Gonzalez'
|
25
|
+
s.email = 'romanandreg@gmail.com'
|
26
|
+
s.homepage = 'http://github.com/roman'
|
27
|
+
s.rubyforge_project = 'rots'
|
28
|
+
|
29
|
+
s.add_development_dependency 'rspec'
|
30
|
+
s.add_development_dependency 'rack'
|
31
|
+
s.add_development_dependency 'ruby-openid', '~> 2.0.0'
|
32
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
describe RubyOpenIdTestServer::ServerApp do
|
4
|
+
|
5
|
+
describe "when the request is not an OpenID request" do
|
6
|
+
|
7
|
+
it "should return a helpful message saying that is an OpenID endpoint" do
|
8
|
+
request = Rack::MockRequest.new(RubyOpenIdTestServer::ServerApp.new('sreg' => {}))
|
9
|
+
response = request.get("/")
|
10
|
+
response.should be_ok
|
11
|
+
response.body.should == "This is an OpenID endpoint"
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "when the request is an OpenID request" do
|
17
|
+
|
18
|
+
before(:each) do
|
19
|
+
@request = Rack::MockRequest.new(RubyOpenIdTestServer::ServerApp.new(
|
20
|
+
'identity' => 'john.doe',
|
21
|
+
'sreg' => {
|
22
|
+
'email' => "john@doe.com",
|
23
|
+
'nickname' => 'johndoe',
|
24
|
+
'fullname' => "John Doe",
|
25
|
+
'dob' => "1985-09-21",
|
26
|
+
'gender' => "M"
|
27
|
+
}
|
28
|
+
))
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
describe "and it is a check_id request" do
|
33
|
+
|
34
|
+
describe "and is immediate" do
|
35
|
+
|
36
|
+
it "should return an openid.mode equal to setup_needed" do
|
37
|
+
response = checkid_immediate(@request)
|
38
|
+
params = openid_params(response)
|
39
|
+
params['openid.mode'].should == 'setup_needed'
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "and is not immediate" do
|
45
|
+
|
46
|
+
describe "with a success flag" do
|
47
|
+
|
48
|
+
it "should return an openid.mode equal to id_res" do
|
49
|
+
response = checkid_setup(@request, 'openid.success' => 'true')
|
50
|
+
params = openid_params(response)
|
51
|
+
params['openid.mode'].should == 'id_res'
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "without a success flag" do
|
57
|
+
|
58
|
+
it "should return an openid.mode equal to cancel" do
|
59
|
+
response = checkid_setup(@request)
|
60
|
+
params = openid_params(response)
|
61
|
+
params['openid.mode'].should == 'cancel'
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "using SREG extension with a success flag" do
|
67
|
+
|
68
|
+
it "should return an openid.mode equal to id_res" do
|
69
|
+
response = checkid_setup(@request, 'openid.success' => 'true')
|
70
|
+
params = openid_params(response)
|
71
|
+
params['openid.mode'].should == 'id_res'
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should return all the sreg fields" do
|
75
|
+
response = checkid_setup(@request, {
|
76
|
+
'openid.success' => true,
|
77
|
+
'openid.ns.sreg' => OpenID::SReg::NS_URI,
|
78
|
+
'openid.sreg.required' => 'email,nickname,fullname',
|
79
|
+
'openid.sreg.optional' => 'dob,gender'
|
80
|
+
})
|
81
|
+
params = openid_params(response)
|
82
|
+
params['openid.sreg.email'].should == "john@doe.com"
|
83
|
+
params['openid.sreg.nickname'].should == 'johndoe'
|
84
|
+
params['openid.sreg.fullname'].should == "John Doe"
|
85
|
+
params['openid.sreg.dob'].should == "1985-09-21"
|
86
|
+
params['openid.sreg.gender'].should == "M"
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__), '..', 'lib')
|
2
|
+
require "rubygems"
|
3
|
+
require "spec"
|
4
|
+
require "rack"
|
5
|
+
require "ruby_openid_test_server"
|
6
|
+
|
7
|
+
module RubyOpenIdTestServer::RequestHelper
|
8
|
+
|
9
|
+
def checkid_setup(request, params={}, with_associate=true)
|
10
|
+
assoc_handle = make_association(request) if with_associate
|
11
|
+
send_checkid(request, :setup, params, assoc_handle)
|
12
|
+
end
|
13
|
+
|
14
|
+
def checkid_immediate(request, params={}, with_associate=true)
|
15
|
+
assoc_handle = make_association(request) if with_associate
|
16
|
+
send_checkid(request, :immediate, params, assoc_handle)
|
17
|
+
end
|
18
|
+
|
19
|
+
def openid_params(response)
|
20
|
+
uri = URI(response.headers['Location'])
|
21
|
+
Rack::Utils.parse_query(uri.query)
|
22
|
+
end
|
23
|
+
|
24
|
+
protected
|
25
|
+
|
26
|
+
def send_checkid(request, mode, params={}, assoc_handle = nil)
|
27
|
+
params = self.send(:"checkid_#{mode}_params", params)
|
28
|
+
params.merge('openid.assoc_handle' => assoc_handle) if assoc_handle
|
29
|
+
qs = "/?" + Rack::Utils.build_query(params)
|
30
|
+
request.get(qs)
|
31
|
+
end
|
32
|
+
|
33
|
+
def make_association(request)
|
34
|
+
associate_qs = Rack::Utils.build_query(associate_params)
|
35
|
+
response = request.post('/', :input => associate_qs)
|
36
|
+
parse_assoc_handle_from(response)
|
37
|
+
end
|
38
|
+
|
39
|
+
def parse_assoc_handle_from(response)
|
40
|
+
response.body.split("\n")[0].match(/^assoc_handle:(.*)$/).captures[0]
|
41
|
+
end
|
42
|
+
|
43
|
+
def checkid_setup_params(params = {})
|
44
|
+
{
|
45
|
+
"openid.ns" => "http://specs.openid.net/auth/2.0",
|
46
|
+
"openid.mode" => "checkid_setup",
|
47
|
+
"openid.claimed_id" => 'john.doe',
|
48
|
+
"openid.identity" => 'john.doe',
|
49
|
+
"openid.return_to" => "http://www.google.com"
|
50
|
+
# need to specify the openid_handle by hand
|
51
|
+
}.merge!(params)
|
52
|
+
end
|
53
|
+
|
54
|
+
def checkid_immediate_params(params = {})
|
55
|
+
checkid_setup_params({'openid.mode' => 'checkid_immediate'}.merge!(params))
|
56
|
+
end
|
57
|
+
|
58
|
+
def associate_params
|
59
|
+
{
|
60
|
+
"openid.ns" => "http://specs.openid.net/auth/2.0",
|
61
|
+
"openid.mode" => "associate",
|
62
|
+
"openid.session_type" => "DH-SHA1",
|
63
|
+
"openid.assoc_type" => "HMAC-SHA1",
|
64
|
+
"openid.dh_consumer_public" =>
|
65
|
+
"U672/RsDUNxAFFAXA+ShVh5LMD2CRdsoqdqhDCPUzfCNy2f44uTWuid/MZuGfJmiVA7QmxqM3GSb8EVq3SGK8eGEwwyzUtatqHidx72rfwAav5AUrZTnwSPQJyiCFrKNGmNhXdRJzcfzSkgaC3hVz2kpADzEevIExG6agns1sYY="
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
Spec::Runner.configure do |config|
|
72
|
+
config.include RubyOpenIdTestServer::RequestHelper
|
73
|
+
end
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: roman-rots
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Roman Gonzalez
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-02-25 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rack
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: ruby-openid
|
37
|
+
type: :development
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 2.0.0
|
44
|
+
version:
|
45
|
+
description: Ruby OpenID Test Server (ROST) provides a basic OpenID server made in top of the Rack gem. With this small server, you can make dummy OpenID request for testing purposes, the success of the response will depend on a parameter given on the url of the authentication request.
|
46
|
+
email: romanandreg@gmail.com
|
47
|
+
executables:
|
48
|
+
- rots
|
49
|
+
extensions: []
|
50
|
+
|
51
|
+
extra_rdoc_files:
|
52
|
+
- README
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- AUTHORS
|
56
|
+
- README
|
57
|
+
- Rakefile
|
58
|
+
- bin/rots
|
59
|
+
- lib/ruby_openid_test_server.rb
|
60
|
+
- lib/ruby_openid_test_server/mock_identity_page.rb
|
61
|
+
- lib/ruby_openid_test_server/server_app.rb
|
62
|
+
- rots.gemspec
|
63
|
+
- spec/server_app_spec.rb
|
64
|
+
- spec/spec_helper.rb
|
65
|
+
has_rdoc: true
|
66
|
+
homepage: http://github.com/roman
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: "0"
|
77
|
+
version:
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: "0"
|
83
|
+
version:
|
84
|
+
requirements: []
|
85
|
+
|
86
|
+
rubyforge_project: rots
|
87
|
+
rubygems_version: 1.2.0
|
88
|
+
signing_key:
|
89
|
+
specification_version: 2
|
90
|
+
summary: an OpenID server for making tests of OpenID clients implementations
|
91
|
+
test_files:
|
92
|
+
- spec/server_app_spec.rb
|
93
|
+
- spec/spec_helper.rb
|