roman-rots 0.0.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +2 -2
- data/bin/rots +19 -6
- data/lib/rots.rb +11 -0
- data/lib/{ruby_openid_test_server/mock_identity_page.rb → rots/identity_page_app.rb} +7 -5
- data/lib/{ruby_openid_test_server → rots}/server_app.rb +26 -9
- data/lib/rots/test_helper.rb +22 -0
- data/rots.gemspec +3 -4
- data/spec/server_app_spec.rb +8 -5
- data/spec/spec_helper.rb +3 -3
- metadata +8 -8
- data/.gitignore +0 -1
- data/lib/ruby_openid_test_server.rb +0 -10
data/Rakefile
CHANGED
@@ -25,8 +25,8 @@ def git_tree_version
|
|
25
25
|
# @tree_version << ".0" unless @tree_version.count('.') == 2
|
26
26
|
#else
|
27
27
|
$: << "lib"
|
28
|
-
require '
|
29
|
-
@tree_version =
|
28
|
+
require 'rots'
|
29
|
+
@tree_version = Rots.release
|
30
30
|
#end
|
31
31
|
@tree_version
|
32
32
|
end
|
data/bin/rots
CHANGED
@@ -5,11 +5,13 @@ $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
5
5
|
require "rubygems"
|
6
6
|
require "optparse"
|
7
7
|
require "rack"
|
8
|
-
require "
|
8
|
+
require "rots"
|
9
9
|
|
10
10
|
server_options = {
|
11
|
+
:debugger => false,
|
11
12
|
:port => 1123,
|
12
13
|
:verbose => true,
|
14
|
+
:storage => File.join('.', 'tmp', 'rots'),
|
13
15
|
:config => <<-DEFAULT_CONFIG
|
14
16
|
# Default configuration file
|
15
17
|
identity: john.doe
|
@@ -34,6 +36,11 @@ opts = OptionParser.new do |opts|
|
|
34
36
|
server_options[:port] = port
|
35
37
|
end
|
36
38
|
|
39
|
+
opts.on("-s", "--storage PATH",
|
40
|
+
"use PATH as the OpenID Server storage path (default: ./tmp/rots)") do |storage_path|
|
41
|
+
server_options[:storage] = storage_path
|
42
|
+
end
|
43
|
+
|
37
44
|
opts.on("-c", "--config FILE.yaml",
|
38
45
|
"server configuration YAML file") do |config_path|
|
39
46
|
abort "\x1B[31mConfiguration file #{config_path} not found\x1B[0m" unless File.exists?(config_path)
|
@@ -45,6 +52,10 @@ opts = OptionParser.new do |opts|
|
|
45
52
|
server_options[:verbose] = false
|
46
53
|
end
|
47
54
|
|
55
|
+
opts.on("-d", "--debugger") do
|
56
|
+
server_options[:debugger] = true
|
57
|
+
end
|
58
|
+
|
48
59
|
opts.separator ""
|
49
60
|
opts.separator "Common options:"
|
50
61
|
|
@@ -59,17 +70,19 @@ opts.parse!(ARGV)
|
|
59
70
|
|
60
71
|
config = YAML.load(server_options[:config])
|
61
72
|
|
73
|
+
require "ruby-debug" if server_options[:debugger]
|
74
|
+
|
62
75
|
server = Rack::Builder.new do
|
63
76
|
use Rack::Lint
|
64
77
|
if server_options[:verbose]
|
65
|
-
use Rack::CommonLogger,
|
78
|
+
use Rack::CommonLogger, STDOUT
|
66
79
|
use Rack::ShowExceptions
|
67
80
|
end
|
68
|
-
map "
|
69
|
-
run
|
81
|
+
map ("/%s" % config['identity']) do
|
82
|
+
run Rots::IdentityPageApp.new(config, server_options)
|
70
83
|
end
|
71
|
-
map "
|
72
|
-
run
|
84
|
+
map "/server" do
|
85
|
+
run Rots::ServerApp.new(config, server_options)
|
73
86
|
end
|
74
87
|
end
|
75
88
|
|
data/lib/rots.rb
ADDED
@@ -1,10 +1,12 @@
|
|
1
|
-
|
1
|
+
require 'rack/request'
|
2
2
|
require 'rack/response'
|
3
3
|
require 'rack/utils'
|
4
|
+
require 'openid'
|
4
5
|
|
5
|
-
class
|
6
|
+
class Rots::IdentityPageApp
|
6
7
|
|
7
|
-
def initialize(config)
|
8
|
+
def initialize(config, server_options)
|
9
|
+
@server_options = server_options
|
8
10
|
@config = config
|
9
11
|
end
|
10
12
|
|
@@ -15,8 +17,8 @@ class RubyOpenIdTestServer::MockIdentityPage
|
|
15
17
|
response.write <<-HERE
|
16
18
|
<html>
|
17
19
|
<head>
|
18
|
-
<link rel="
|
19
|
-
<link rel="
|
20
|
+
<link rel="openid2.provider" href="http://localhost:#{@server_options[:port]}/server/#{flag}" />
|
21
|
+
<link rel="openid.server" href="http://localhost:#{@server_options[:port]}/server/#{flag}" />
|
20
22
|
</head>
|
21
23
|
<body>
|
22
24
|
<h1>This is #{@config['identity']} identity page</h1>
|
@@ -1,14 +1,14 @@
|
|
1
|
-
gem 'ruby-openid', '~> 2' if defined? Gem
|
2
|
-
require 'rack/request'
|
3
|
-
require 'rack/utils'
|
4
1
|
require 'openid'
|
5
2
|
require 'openid/extension'
|
6
3
|
require 'openid/extensions/sreg'
|
7
|
-
require 'openid/store/
|
4
|
+
require 'openid/store/filesystem'
|
8
5
|
require 'openid/util'
|
6
|
+
require 'rack/request'
|
7
|
+
require 'rack/utils'
|
8
|
+
require 'fileutils'
|
9
9
|
|
10
10
|
|
11
|
-
module
|
11
|
+
module Rots
|
12
12
|
|
13
13
|
class ServerApp
|
14
14
|
|
@@ -16,7 +16,8 @@ module RubyOpenIdTestServer
|
|
16
16
|
:response, :openid_response,
|
17
17
|
:server
|
18
18
|
|
19
|
-
def initialize(config)
|
19
|
+
def initialize(config, server_options)
|
20
|
+
@server_options = server_options
|
20
21
|
@sreg_fields = config['sreg']
|
21
22
|
end
|
22
23
|
|
@@ -38,8 +39,8 @@ module RubyOpenIdTestServer
|
|
38
39
|
def on_openid_request(env)
|
39
40
|
create_wrappers(env)
|
40
41
|
if @openid_request.nil?
|
41
|
-
[200, {'Content-Type' => 'text/
|
42
|
-
["This is an OpenID endpoint"] ]
|
42
|
+
[200, {'Content-Type' => 'text/html'},
|
43
|
+
["<html><body><h1>ROTS => This is an OpenID endpoint</h1></body></html>"] ]
|
43
44
|
else
|
44
45
|
yield
|
45
46
|
end
|
@@ -47,7 +48,7 @@ module RubyOpenIdTestServer
|
|
47
48
|
|
48
49
|
def create_wrappers(env)
|
49
50
|
@request = Rack::Request.new(env)
|
50
|
-
@server = OpenID::Server::Server.new(
|
51
|
+
@server = OpenID::Server::Server.new(storage, op_endpoint)
|
51
52
|
@openid_request = @server.decode_request(@request.params)
|
52
53
|
@openid_sreg_request = OpenID::SReg::Request.from_openid_request(@openid_request) unless @openid_request.nil?
|
53
54
|
end
|
@@ -121,9 +122,25 @@ module RubyOpenIdTestServer
|
|
121
122
|
[] ]
|
122
123
|
end
|
123
124
|
|
125
|
+
def storage
|
126
|
+
# create the folder if it doesn't exist
|
127
|
+
FileUtils.mkdir_p(@server_options[:storage]) unless File.exist?(@server_options[:storage])
|
128
|
+
OpenID::Store::Filesystem.new(@server_options[:storage])
|
129
|
+
end
|
130
|
+
|
124
131
|
def success(text="")
|
125
132
|
Rack::Response.new(text).finish
|
126
133
|
end
|
134
|
+
|
135
|
+
def op_endpoint
|
136
|
+
if @request.url =~ /(.*\?openid.success=true)/
|
137
|
+
$1
|
138
|
+
elsif @request.url =~ /([^?]*)/
|
139
|
+
$1
|
140
|
+
else
|
141
|
+
nil
|
142
|
+
end
|
143
|
+
end
|
127
144
|
|
128
145
|
end
|
129
146
|
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "openid/consumer"
|
2
|
+
require "openid/consumer/checkid_request.rb"
|
3
|
+
require "net/http"
|
4
|
+
|
5
|
+
module Rots::TestHelper
|
6
|
+
|
7
|
+
def openid_request(openid_request_uri)
|
8
|
+
openid_response = Net::HTTP.get_response(URI.parse(openid_request_uri))
|
9
|
+
openid_response_uri = URI(openid_response['Location'])
|
10
|
+
openid_response_qs = Rack::Utils.parse_query(openid_response_uri.query)
|
11
|
+
|
12
|
+
# invoking the OpenID consumer with the options of the response of the ServerApp
|
13
|
+
if defined?(Webrat)
|
14
|
+
visit(openid_response_uri.to_s)
|
15
|
+
else
|
16
|
+
# NOTE: Works on Rails and Merb frameworks via duck typing
|
17
|
+
# later we will check on Sinatra
|
18
|
+
get(openid_response_uri.path, openid_response_qs)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
data/rots.gemspec
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
|
-
|
5
4
|
s.name = "rots"
|
6
|
-
s.version = '0.0
|
5
|
+
s.version = '0.2.0'
|
7
6
|
s.platform = Gem::Platform::RUBY
|
8
7
|
s.summary = "an OpenID server for making tests of OpenID clients implementations"
|
9
8
|
|
@@ -13,7 +12,7 @@ With this small server, you can make dummy OpenID request for testing purposes,
|
|
13
12
|
the success of the response will depend on a parameter given on the url of the authentication request.
|
14
13
|
EOF
|
15
14
|
|
16
|
-
s.files = ["
|
15
|
+
s.files = ["AUTHORS", "README", "Rakefile", "bin/rots", "lib/rots.rb", "lib/rots/identity_page_app.rb", "lib/rots/server_app.rb", "lib/rots/test_helper.rb","rots.gemspec", "spec/server_app_spec.rb", "spec/spec_helper.rb"]
|
17
16
|
s.bindir = 'bin'
|
18
17
|
s.executables << 'rots'
|
19
18
|
s.require_path = 'lib'
|
@@ -28,5 +27,5 @@ the success of the response will depend on a parameter given on the url of the a
|
|
28
27
|
|
29
28
|
s.add_development_dependency 'rspec'
|
30
29
|
s.add_development_dependency 'rack'
|
31
|
-
s.add_development_dependency 'ruby-openid'
|
30
|
+
s.add_development_dependency 'ruby-openid'
|
32
31
|
end
|
data/spec/server_app_spec.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe Rots::ServerApp do
|
4
4
|
|
5
5
|
describe "when the request is not an OpenID request" do
|
6
6
|
|
7
7
|
it "should return a helpful message saying that is an OpenID endpoint" do
|
8
|
-
request = Rack::MockRequest.new(
|
8
|
+
request = Rack::MockRequest.new(Rots::ServerApp.new({'sreg' => {}},
|
9
|
+
{:storage => File.join(*%w(. tmp rots)) }))
|
9
10
|
response = request.get("/")
|
10
11
|
response.should be_ok
|
11
|
-
response.body.should == "This is an OpenID endpoint"
|
12
|
+
response.body.should == "<html><body><h1>ROTS => This is an OpenID endpoint</h1></body></html>"
|
12
13
|
end
|
13
14
|
|
14
15
|
end
|
@@ -16,7 +17,7 @@ describe RubyOpenIdTestServer::ServerApp do
|
|
16
17
|
describe "when the request is an OpenID request" do
|
17
18
|
|
18
19
|
before(:each) do
|
19
|
-
@request = Rack::MockRequest.new(
|
20
|
+
@request = Rack::MockRequest.new(Rots::ServerApp.new({
|
20
21
|
'identity' => 'john.doe',
|
21
22
|
'sreg' => {
|
22
23
|
'email' => "john@doe.com",
|
@@ -24,7 +25,8 @@ describe RubyOpenIdTestServer::ServerApp do
|
|
24
25
|
'fullname' => "John Doe",
|
25
26
|
'dob' => "1985-09-21",
|
26
27
|
'gender' => "M"
|
27
|
-
}
|
28
|
+
}},
|
29
|
+
{:storage => File.join(*%w(. tmp rots))}
|
28
30
|
))
|
29
31
|
end
|
30
32
|
|
@@ -91,4 +93,5 @@ describe RubyOpenIdTestServer::ServerApp do
|
|
91
93
|
end
|
92
94
|
end
|
93
95
|
end
|
96
|
+
|
94
97
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -2,9 +2,9 @@ $:.unshift(File.dirname(__FILE__), '..', 'lib')
|
|
2
2
|
require "rubygems"
|
3
3
|
require "spec"
|
4
4
|
require "rack"
|
5
|
-
require "
|
5
|
+
require "rots"
|
6
6
|
|
7
|
-
module
|
7
|
+
module Rots::RequestHelper
|
8
8
|
|
9
9
|
def checkid_setup(request, params={}, with_associate=true)
|
10
10
|
assoc_handle = make_association(request) if with_associate
|
@@ -69,5 +69,5 @@ module RubyOpenIdTestServer::RequestHelper
|
|
69
69
|
end
|
70
70
|
|
71
71
|
Spec::Runner.configure do |config|
|
72
|
-
config.include
|
72
|
+
config.include Rots::RequestHelper
|
73
73
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: roman-rots
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roman Gonzalez
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-03-21 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -38,9 +38,9 @@ dependencies:
|
|
38
38
|
version_requirement:
|
39
39
|
version_requirements: !ruby/object:Gem::Requirement
|
40
40
|
requirements:
|
41
|
-
- -
|
41
|
+
- - ">="
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
version:
|
43
|
+
version: "0"
|
44
44
|
version:
|
45
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
46
|
email: romanandreg@gmail.com
|
@@ -51,14 +51,14 @@ extensions: []
|
|
51
51
|
extra_rdoc_files:
|
52
52
|
- README
|
53
53
|
files:
|
54
|
-
- .gitignore
|
55
54
|
- AUTHORS
|
56
55
|
- README
|
57
56
|
- Rakefile
|
58
57
|
- bin/rots
|
59
|
-
- lib/
|
60
|
-
- lib/
|
61
|
-
- lib/
|
58
|
+
- lib/rots.rb
|
59
|
+
- lib/rots/identity_page_app.rb
|
60
|
+
- lib/rots/server_app.rb
|
61
|
+
- lib/rots/test_helper.rb
|
62
62
|
- rots.gemspec
|
63
63
|
- spec/server_app_spec.rb
|
64
64
|
- spec/spec_helper.rb
|
data/.gitignore
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
pkg/*
|