sinatra 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of sinatra might be problematic. Click here for more details.

Files changed (109) hide show
  1. data/ChangeLog +64 -0
  2. data/LICENSE +1 -1
  3. data/README.rdoc +244 -141
  4. data/Rakefile +111 -0
  5. data/lib/sinatra.rb +942 -627
  6. data/{vendor/rack/lib → lib/sinatra}/rack/handler/mongrel.rb +10 -3
  7. data/lib/sinatra/test/methods.rb +56 -36
  8. data/lib/sinatra/test/rspec.rb +10 -0
  9. data/lib/sinatra/test/spec.rb +2 -2
  10. data/lib/sinatra/test/unit.rb +1 -1
  11. data/sinatra.gemspec +71 -43
  12. data/test/app_test.rb +181 -32
  13. data/test/application_test.rb +179 -36
  14. data/test/custom_error_test.rb +17 -22
  15. data/test/erb_test.rb +42 -22
  16. data/test/event_context_test.rb +3 -3
  17. data/test/events_test.rb +8 -11
  18. data/test/filter_test.rb +30 -0
  19. data/test/haml_test.rb +83 -31
  20. data/test/helper.rb +6 -3
  21. data/test/mapped_error_test.rb +32 -21
  22. data/test/pipeline_test.rb +66 -0
  23. data/test/sass_test.rb +7 -7
  24. data/test/sessions_test.rb +8 -9
  25. data/test/streaming_test.rb +10 -4
  26. data/test/sym_params_test.rb +1 -1
  27. data/test/template_test.rb +11 -11
  28. data/test/use_in_file_templates_test.rb +9 -10
  29. metadata +22 -101
  30. data/CHANGELOG +0 -3
  31. data/Manifest +0 -122
  32. data/index.html +0 -9
  33. data/test/diddy_test.rb +0 -41
  34. data/test/rest_test.rb +0 -16
  35. data/vendor/rack/AUTHORS +0 -7
  36. data/vendor/rack/COPYING +0 -18
  37. data/vendor/rack/KNOWN-ISSUES +0 -18
  38. data/vendor/rack/README +0 -242
  39. data/vendor/rack/Rakefile +0 -174
  40. data/vendor/rack/bin/rackup +0 -153
  41. data/vendor/rack/contrib/rack_logo.svg +0 -111
  42. data/vendor/rack/example/lobster.ru +0 -4
  43. data/vendor/rack/example/protectedlobster.rb +0 -14
  44. data/vendor/rack/example/protectedlobster.ru +0 -8
  45. data/vendor/rack/lib/rack.rb +0 -92
  46. data/vendor/rack/lib/rack/adapter/camping.rb +0 -22
  47. data/vendor/rack/lib/rack/auth/abstract/handler.rb +0 -28
  48. data/vendor/rack/lib/rack/auth/abstract/request.rb +0 -37
  49. data/vendor/rack/lib/rack/auth/basic.rb +0 -58
  50. data/vendor/rack/lib/rack/auth/digest/md5.rb +0 -124
  51. data/vendor/rack/lib/rack/auth/digest/nonce.rb +0 -51
  52. data/vendor/rack/lib/rack/auth/digest/params.rb +0 -55
  53. data/vendor/rack/lib/rack/auth/digest/request.rb +0 -40
  54. data/vendor/rack/lib/rack/auth/openid.rb +0 -116
  55. data/vendor/rack/lib/rack/builder.rb +0 -56
  56. data/vendor/rack/lib/rack/cascade.rb +0 -36
  57. data/vendor/rack/lib/rack/commonlogger.rb +0 -56
  58. data/vendor/rack/lib/rack/file.rb +0 -112
  59. data/vendor/rack/lib/rack/handler/cgi.rb +0 -57
  60. data/vendor/rack/lib/rack/handler/fastcgi.rb +0 -83
  61. data/vendor/rack/lib/rack/handler/lsws.rb +0 -52
  62. data/vendor/rack/lib/rack/handler/scgi.rb +0 -57
  63. data/vendor/rack/lib/rack/handler/webrick.rb +0 -57
  64. data/vendor/rack/lib/rack/lint.rb +0 -394
  65. data/vendor/rack/lib/rack/lobster.rb +0 -65
  66. data/vendor/rack/lib/rack/mock.rb +0 -160
  67. data/vendor/rack/lib/rack/recursive.rb +0 -57
  68. data/vendor/rack/lib/rack/reloader.rb +0 -64
  69. data/vendor/rack/lib/rack/request.rb +0 -197
  70. data/vendor/rack/lib/rack/response.rb +0 -166
  71. data/vendor/rack/lib/rack/session/abstract/id.rb +0 -126
  72. data/vendor/rack/lib/rack/session/cookie.rb +0 -71
  73. data/vendor/rack/lib/rack/session/memcache.rb +0 -83
  74. data/vendor/rack/lib/rack/session/pool.rb +0 -67
  75. data/vendor/rack/lib/rack/showexceptions.rb +0 -344
  76. data/vendor/rack/lib/rack/showstatus.rb +0 -103
  77. data/vendor/rack/lib/rack/static.rb +0 -38
  78. data/vendor/rack/lib/rack/urlmap.rb +0 -48
  79. data/vendor/rack/lib/rack/utils.rb +0 -240
  80. data/vendor/rack/test/cgi/lighttpd.conf +0 -20
  81. data/vendor/rack/test/cgi/test +0 -9
  82. data/vendor/rack/test/cgi/test.fcgi +0 -7
  83. data/vendor/rack/test/cgi/test.ru +0 -7
  84. data/vendor/rack/test/spec_rack_auth_basic.rb +0 -69
  85. data/vendor/rack/test/spec_rack_auth_digest.rb +0 -169
  86. data/vendor/rack/test/spec_rack_builder.rb +0 -50
  87. data/vendor/rack/test/spec_rack_camping.rb +0 -47
  88. data/vendor/rack/test/spec_rack_cascade.rb +0 -50
  89. data/vendor/rack/test/spec_rack_cgi.rb +0 -91
  90. data/vendor/rack/test/spec_rack_commonlogger.rb +0 -32
  91. data/vendor/rack/test/spec_rack_fastcgi.rb +0 -91
  92. data/vendor/rack/test/spec_rack_file.rb +0 -40
  93. data/vendor/rack/test/spec_rack_lint.rb +0 -317
  94. data/vendor/rack/test/spec_rack_lobster.rb +0 -45
  95. data/vendor/rack/test/spec_rack_mock.rb +0 -152
  96. data/vendor/rack/test/spec_rack_mongrel.rb +0 -165
  97. data/vendor/rack/test/spec_rack_recursive.rb +0 -77
  98. data/vendor/rack/test/spec_rack_request.rb +0 -384
  99. data/vendor/rack/test/spec_rack_response.rb +0 -167
  100. data/vendor/rack/test/spec_rack_session_cookie.rb +0 -49
  101. data/vendor/rack/test/spec_rack_session_memcache.rb +0 -100
  102. data/vendor/rack/test/spec_rack_session_pool.rb +0 -84
  103. data/vendor/rack/test/spec_rack_showexceptions.rb +0 -21
  104. data/vendor/rack/test/spec_rack_showstatus.rb +0 -71
  105. data/vendor/rack/test/spec_rack_static.rb +0 -37
  106. data/vendor/rack/test/spec_rack_urlmap.rb +0 -175
  107. data/vendor/rack/test/spec_rack_utils.rb +0 -57
  108. data/vendor/rack/test/spec_rack_webrick.rb +0 -106
  109. data/vendor/rack/test/testrequest.rb +0 -43
@@ -1,58 +0,0 @@
1
- require 'rack/auth/abstract/handler'
2
- require 'rack/auth/abstract/request'
3
-
4
- module Rack
5
- module Auth
6
- # Rack::Auth::Basic implements HTTP Basic Authentication, as per RFC 2617.
7
- #
8
- # Initialize with the Rack application that you want protecting,
9
- # and a block that checks if a username and password pair are valid.
10
- #
11
- # See also: <tt>example/protectedlobster.rb</tt>
12
-
13
- class Basic < AbstractHandler
14
-
15
- def call(env)
16
- auth = Basic::Request.new(env)
17
-
18
- return unauthorized unless auth.provided?
19
-
20
- return bad_request unless auth.basic?
21
-
22
- if valid?(auth)
23
- env['REMOTE_USER'] = auth.username
24
-
25
- return @app.call(env)
26
- end
27
-
28
- unauthorized
29
- end
30
-
31
-
32
- private
33
-
34
- def challenge
35
- 'Basic realm="%s"' % realm
36
- end
37
-
38
- def valid?(auth)
39
- @authenticator.call(*auth.credentials)
40
- end
41
-
42
- class Request < Auth::AbstractRequest
43
- def basic?
44
- :basic == scheme
45
- end
46
-
47
- def credentials
48
- @credentials ||= params.unpack("m*").first.split(/:/, 2)
49
- end
50
-
51
- def username
52
- credentials.first
53
- end
54
- end
55
-
56
- end
57
- end
58
- end
@@ -1,124 +0,0 @@
1
- require 'rack/auth/abstract/handler'
2
- require 'rack/auth/digest/request'
3
- require 'rack/auth/digest/params'
4
- require 'rack/auth/digest/nonce'
5
- require 'digest/md5'
6
-
7
- module Rack
8
- module Auth
9
- module Digest
10
- # Rack::Auth::Digest::MD5 implements the MD5 algorithm version of
11
- # HTTP Digest Authentication, as per RFC 2617.
12
- #
13
- # Initialize with the [Rack] application that you want protecting,
14
- # and a block that looks up a plaintext password for a given username.
15
- #
16
- # +opaque+ needs to be set to a constant base64/hexadecimal string.
17
- #
18
- class MD5 < AbstractHandler
19
-
20
- attr_accessor :opaque
21
-
22
- attr_writer :passwords_hashed
23
-
24
- def initialize(app)
25
- super
26
- @passwords_hashed = nil
27
- end
28
-
29
- def passwords_hashed?
30
- !!@passwords_hashed
31
- end
32
-
33
- def call(env)
34
- auth = Request.new(env)
35
-
36
- unless auth.provided?
37
- return unauthorized
38
- end
39
-
40
- if !auth.digest? || !auth.correct_uri? || !valid_qop?(auth)
41
- return bad_request
42
- end
43
-
44
- if valid?(auth)
45
- if auth.nonce.stale?
46
- return unauthorized(challenge(:stale => true))
47
- else
48
- env['REMOTE_USER'] = auth.username
49
-
50
- return @app.call(env)
51
- end
52
- end
53
-
54
- unauthorized
55
- end
56
-
57
-
58
- private
59
-
60
- QOP = 'auth'.freeze
61
-
62
- def params(hash = {})
63
- Params.new do |params|
64
- params['realm'] = realm
65
- params['nonce'] = Nonce.new.to_s
66
- params['opaque'] = H(opaque)
67
- params['qop'] = QOP
68
-
69
- hash.each { |k, v| params[k] = v }
70
- end
71
- end
72
-
73
- def challenge(hash = {})
74
- "Digest #{params(hash)}"
75
- end
76
-
77
- def valid?(auth)
78
- valid_opaque?(auth) && valid_nonce?(auth) && valid_digest?(auth)
79
- end
80
-
81
- def valid_qop?(auth)
82
- QOP == auth.qop
83
- end
84
-
85
- def valid_opaque?(auth)
86
- H(opaque) == auth.opaque
87
- end
88
-
89
- def valid_nonce?(auth)
90
- auth.nonce.valid?
91
- end
92
-
93
- def valid_digest?(auth)
94
- digest(auth, @authenticator.call(auth.username)) == auth.response
95
- end
96
-
97
- def md5(data)
98
- ::Digest::MD5.hexdigest(data)
99
- end
100
-
101
- alias :H :md5
102
-
103
- def KD(secret, data)
104
- H([secret, data] * ':')
105
- end
106
-
107
- def A1(auth, password)
108
- [ auth.username, auth.realm, password ] * ':'
109
- end
110
-
111
- def A2(auth)
112
- [ auth.method, auth.uri ] * ':'
113
- end
114
-
115
- def digest(auth, password)
116
- password_hash = passwords_hashed? ? password : H(A1(auth, password))
117
-
118
- KD(password_hash, [ auth.nonce, auth.nc, auth.cnonce, QOP, H(A2(auth)) ] * ':')
119
- end
120
-
121
- end
122
- end
123
- end
124
- end
@@ -1,51 +0,0 @@
1
- require 'digest/md5'
2
-
3
- module Rack
4
- module Auth
5
- module Digest
6
- # Rack::Auth::Digest::Nonce is the default nonce generator for the
7
- # Rack::Auth::Digest::MD5 authentication handler.
8
- #
9
- # +private_key+ needs to set to a constant string.
10
- #
11
- # +time_limit+ can be optionally set to an integer (number of seconds),
12
- # to limit the validity of the generated nonces.
13
-
14
- class Nonce
15
-
16
- class << self
17
- attr_accessor :private_key, :time_limit
18
- end
19
-
20
- def self.parse(string)
21
- new(*string.unpack("m*").first.split(' ', 2))
22
- end
23
-
24
- def initialize(timestamp = Time.now, given_digest = nil)
25
- @timestamp, @given_digest = timestamp.to_i, given_digest
26
- end
27
-
28
- def to_s
29
- [([ @timestamp, digest ] * ' ')].pack("m*").strip
30
- end
31
-
32
- def digest
33
- ::Digest::MD5.hexdigest([ @timestamp, self.class.private_key ] * ':')
34
- end
35
-
36
- def valid?
37
- digest == @given_digest
38
- end
39
-
40
- def stale?
41
- !self.class.time_limit.nil? && (@timestamp - Time.now.to_i) < self.class.time_limit
42
- end
43
-
44
- def fresh?
45
- !stale?
46
- end
47
-
48
- end
49
- end
50
- end
51
- end
@@ -1,55 +0,0 @@
1
- module Rack
2
- module Auth
3
- module Digest
4
- class Params < Hash
5
-
6
- def self.parse(str)
7
- split_header_value(str).inject(new) do |header, param|
8
- k, v = param.split('=', 2)
9
- header[k] = dequote(v)
10
- header
11
- end
12
- end
13
-
14
- def self.dequote(str) # From WEBrick::HTTPUtils
15
- ret = (/\A"(.*)"\Z/ =~ str) ? $1 : str.dup
16
- ret.gsub!(/\\(.)/, "\\1")
17
- ret
18
- end
19
-
20
- def self.split_header_value(str) # From WEBrick::HTTPUtils
21
- str.scan(/((?:"(?:\\.|[^"])+?"|[^",]+)+)(?:,\s*|\Z)/n).collect{ |v| v[0] }
22
- end
23
-
24
- def initialize
25
- super
26
-
27
- yield self if block_given?
28
- end
29
-
30
- def [](k)
31
- super k.to_s
32
- end
33
-
34
- def []=(k, v)
35
- super k.to_s, v.to_s
36
- end
37
-
38
- UNQUOTED = ['qop', 'nc', 'stale']
39
-
40
- def to_s
41
- inject([]) do |parts, (k, v)|
42
- parts << "#{k}=" + (UNQUOTED.include?(k) ? v.to_s : quote(v))
43
- parts
44
- end.join(', ')
45
- end
46
-
47
- def quote(str) # From WEBrick::HTTPUtils
48
- '"' << str.gsub(/[\\\"]/o, "\\\1") << '"'
49
- end
50
-
51
- end
52
- end
53
- end
54
- end
55
-
@@ -1,40 +0,0 @@
1
- require 'rack/auth/abstract/request'
2
- require 'rack/auth/digest/params'
3
- require 'rack/auth/digest/nonce'
4
-
5
- module Rack
6
- module Auth
7
- module Digest
8
- class Request < Auth::AbstractRequest
9
-
10
- def method
11
- @env['REQUEST_METHOD']
12
- end
13
-
14
- def digest?
15
- :digest == scheme
16
- end
17
-
18
- def correct_uri?
19
- @env['PATH_INFO'] == uri
20
- end
21
-
22
- def nonce
23
- @nonce ||= Nonce.parse(params['nonce'])
24
- end
25
-
26
- def params
27
- @params ||= Params.parse(parts.last)
28
- end
29
-
30
- def method_missing(sym)
31
- if params.has_key? key = sym.to_s
32
- return params[key]
33
- end
34
- super
35
- end
36
-
37
- end
38
- end
39
- end
40
- end
@@ -1,116 +0,0 @@
1
- # AUTHOR: blink <blinketje@gmail.com>; blink#ruby-lang@irc.freenode.net
2
-
3
- gem_require 'ruby-openid', '~> 1.0.0' if defined? Gem
4
- require 'rack/auth/abstract/handler'
5
- require 'openid'
6
-
7
- module Rack
8
- module Auth
9
- # Rack::Auth::OpenID provides a simple method for permitting openid
10
- # based logins. It requires the ruby-openid lib from janrain to operate,
11
- # as well as some method of session management of a Hash type.
12
- #
13
- # After a transaction, the response status object is stored in the
14
- # environment at rack.auth.openid.status, which can be used in the
15
- # followup block or in a wrapping application to accomplish
16
- # additional data maniipulation.
17
- #
18
- # NOTE: Due to the amount of data that ruby-openid stores in the session,
19
- # Rack::Session::Cookie may fault.
20
- #
21
- # A hash of data is stored in the session hash at the key of :openid.
22
- # The fully canonicalized identity url is stored within at 'identity'.
23
- # Extension data from 'openid.sreg.nickname' would be stored as
24
- # { 'nickname' => value }.
25
- #
26
- # NOTE: To my knowledge there is no collision at this point from storage
27
- # of this manner, if there is please let me know so I may adjust this app
28
- # to cope.
29
- # NOTE: This rack application is only compatible with the 1.x.x versions
30
- # of the ruby-openid library. If rubygems is loaded at require time of
31
- # this app, the specification will be made. If it is not then the 'openid'
32
- # library will be required, and will fail if it is not compatible.
33
- class OpenID < AbstractHandler
34
- # Required for ruby-openid
35
- OIDStore = ::OpenID::MemoryStore.new
36
-
37
- # A Hash of options is taken as it's single initializing
38
- # argument. String keys are taken to be openid protocol
39
- # extension namespaces.
40
- #
41
- # For example: 'sreg' => { 'required' => # 'nickname' }
42
- #
43
- # Other keys are taken as options for Rack::Auth::OpenID, normally Symbols.
44
- # Only :return is required. :trust is highly recommended to be set.
45
- #
46
- # * :return defines the url to return to after the client authenticates
47
- # with the openid service provider. Should point to where this app is
48
- # mounted. (ex: 'http://mysite.com/openid')
49
- # * :trust defines the url identifying the site they are actually logging
50
- # into. (ex: 'http://mysite.com/')
51
- # * :session_key defines the key to the session hash in the env.
52
- # (by default it uses 'rack.session')
53
- def initialize(options={})
54
- raise ArgumentError, 'No return url provided.' unless options[:return]
55
- warn 'No trust url provided.' unless options[:trust]
56
- options[:trust] ||= options[:return]
57
-
58
- @options = {
59
- :session_key => 'rack.session'
60
- }.merge(options)
61
- end
62
-
63
- def call(env)
64
- request = Rack::Request.new env
65
- return no_session unless session = request.env[@options[:session_key]]
66
- resp = if request.GET['openid.mode']
67
- finish session, request.GET, env
68
- elsif request.GET['openid_url']
69
- check session, request.GET['openid_url'], env
70
- else
71
- bad_request
72
- end
73
- end
74
-
75
- def check(session, oid_url, env)
76
- consumer = ::OpenID::Consumer.new session, OIDStore
77
- oid = consumer.begin oid_url
78
- return auth_fail unless oid.status == ::OpenID::SUCCESS
79
- @options.each do |ns,s|
80
- next unless ns.is_a? String
81
- s.each {|k,v| oid.add_extension_arg(ns, k, v) }
82
- end
83
- r_url = @options.fetch :return do |k| request.url end
84
- t_url = @options.fetch :trust
85
- env['rack.auth.openid.status'] = oid
86
- return 303, {'Location'=>oid.redirect_url( t_url, r_url )}, []
87
- end
88
-
89
- def finish(session, params, env)
90
- consumer = ::OpenID::Consumer.new session, OIDStore
91
- oid = consumer.complete params
92
- return bad_login unless oid.status == ::OpenID::SUCCESS
93
- session[:openid] = {'identity' => oid.identity_url}
94
- @options.each do |ns,s|
95
- next unless ns.is_a? String
96
- oid.extension_response(ns).each{|k,v| session[k]=v }
97
- end
98
- env['rack.auth.openid.status'] = oid
99
- return 303, {'Location'=>@options[:trust]}, []
100
- end
101
-
102
- def no_session
103
- @options.
104
- fetch :no_session, [500,{'Content-Type'=>'text/plain'},'No session available.']
105
- end
106
- def auth_fail
107
- @options.
108
- fetch :auth_fail, [500, {'Content-Type'=>'text/plain'},'Foreign server failure.']
109
- end
110
- def bad_login
111
- @options.
112
- fetch :bad_login, [401, {'Content-Type'=>'text/plain'},'Identification has failed.']
113
- end
114
- end
115
- end
116
- end