roda 3.9.0 → 3.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +18 -0
- data/README.rdoc +43 -23
- data/doc/release_notes/3.10.0.txt +132 -0
- data/lib/roda.rb +3 -3
- data/lib/roda/plugins/assets.rb +2 -2
- data/lib/roda/plugins/flash.rb +8 -2
- data/lib/roda/plugins/json.rb +1 -3
- data/lib/roda/plugins/json_parser.rb +1 -2
- data/lib/roda/plugins/middleware.rb +12 -3
- data/lib/roda/plugins/route_csrf.rb +34 -32
- data/lib/roda/plugins/sessions.rb +451 -0
- data/lib/roda/plugins/typecast_params.rb +15 -2
- data/lib/roda/session_middleware.rb +175 -0
- data/lib/roda/version.rb +1 -1
- data/spec/plugin/csrf_spec.rb +2 -2
- data/spec/plugin/flash_spec.rb +17 -23
- data/spec/plugin/heartbeat_spec.rb +1 -1
- data/spec/plugin/middleware_spec.rb +15 -0
- data/spec/plugin/route_csrf_spec.rb +3 -2
- data/spec/plugin/sessions_spec.rb +371 -0
- data/spec/plugin/typecast_params_spec.rb +11 -0
- data/spec/session_middleware_spec.rb +129 -0
- data/spec/session_spec.rb +2 -2
- data/spec/spec_helper.rb +10 -1
- metadata +9 -3
@@ -274,6 +274,17 @@ describe "typecast_params plugin" do
|
|
274
274
|
tp.array!(:Integer, 'b').must_equal [2, 3]
|
275
275
|
lambda{tp.array!(:Integer, 'd')}.must_raise @tp_error
|
276
276
|
lambda{tp.array!(:Integer, 'g')}.must_raise @tp_error
|
277
|
+
|
278
|
+
a = 1
|
279
|
+
@app.plugin :hooks
|
280
|
+
@app.before do
|
281
|
+
request.define_singleton_method(:params){{'a'=>a}}
|
282
|
+
end
|
283
|
+
tp.Integer('a').must_equal 1
|
284
|
+
a = 1.0
|
285
|
+
tp.Integer('a').must_equal 1
|
286
|
+
a = 1.1
|
287
|
+
lambda{tp.Integer('a')}.must_raise @tp_error
|
277
288
|
end
|
278
289
|
|
279
290
|
it "#float should convert to float" do
|
@@ -0,0 +1,129 @@
|
|
1
|
+
require_relative "spec_helper"
|
2
|
+
|
3
|
+
if RUBY_VERSION >= '2'
|
4
|
+
require 'roda/session_middleware'
|
5
|
+
|
6
|
+
describe "RodaSessionMiddleware" do
|
7
|
+
include CookieJar
|
8
|
+
|
9
|
+
it "operates like a session middleware" do
|
10
|
+
sess = nil
|
11
|
+
env = nil
|
12
|
+
|
13
|
+
app(:bare) do
|
14
|
+
use RodaSessionMiddleware, :secret=>'1'*64
|
15
|
+
|
16
|
+
route do |r|
|
17
|
+
r.get('s', String, String){|k, v| session[k.to_sym] = v}
|
18
|
+
r.get('g', String){|k| session[k.to_sym].to_s}
|
19
|
+
r.get('c'){|k| session.clear; ''}
|
20
|
+
r.get('sh'){|k| env = r.env; sess = session; ''}
|
21
|
+
''
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
_, h, b = req('/')
|
26
|
+
h['Set-Cookie'].must_be_nil
|
27
|
+
b.must_equal ['']
|
28
|
+
|
29
|
+
_, h, b = req('/s/foo/bar')
|
30
|
+
h['Set-Cookie'].must_match(/\Aroda\.session=(.*); path=\/; HttpOnly(; SameSite=Lax)?\z/m)
|
31
|
+
b.must_equal ['bar']
|
32
|
+
body('/s/foo/bar').must_equal 'bar'
|
33
|
+
body('/g/foo').must_equal 'bar'
|
34
|
+
|
35
|
+
body('/s/foo/baz').must_equal 'baz'
|
36
|
+
body('/g/foo').must_equal 'baz'
|
37
|
+
|
38
|
+
body("/s/foo/\u1234").must_equal "\u1234"
|
39
|
+
body("/g/foo").must_equal "\u1234"
|
40
|
+
|
41
|
+
body("/c").must_equal ""
|
42
|
+
body("/g/foo").must_equal ""
|
43
|
+
|
44
|
+
body('/s/foo/bar')
|
45
|
+
body("/sh").must_equal ""
|
46
|
+
|
47
|
+
sess.must_be_kind_of RodaSessionMiddleware::SessionHash
|
48
|
+
sess.req.must_be_kind_of Roda::RodaRequest
|
49
|
+
sess.data.must_be_nil
|
50
|
+
sess.options[:secret].must_equal('1'*64)
|
51
|
+
sess.inspect.must_include "not yet loaded"
|
52
|
+
sess.loaded?.must_equal false
|
53
|
+
|
54
|
+
a = []
|
55
|
+
sess.each{|k, v| a << k << v}
|
56
|
+
a.must_equal %w'foo bar'
|
57
|
+
sess.data.must_equal("foo"=>"bar")
|
58
|
+
sess.inspect.must_equal '{"foo"=>"bar"}'
|
59
|
+
sess.loaded?.must_equal true
|
60
|
+
|
61
|
+
sess[:foo].must_equal "bar"
|
62
|
+
sess['foo'].must_equal "bar"
|
63
|
+
|
64
|
+
sess.fetch(:foo).must_equal "bar"
|
65
|
+
sess.fetch('foo').must_equal "bar"
|
66
|
+
proc{sess.fetch('foo2')}.must_raise KeyError
|
67
|
+
sess.fetch(:foo, "baz").must_equal "bar"
|
68
|
+
sess.fetch('foo', "baz").must_equal "bar"
|
69
|
+
sess.fetch('foo2', "baz").must_equal "baz"
|
70
|
+
|
71
|
+
sess.has_key?(:foo).must_equal true
|
72
|
+
sess.has_key?("foo").must_equal true
|
73
|
+
sess.has_key?("bar").must_equal false
|
74
|
+
sess.key?("foo").must_equal true
|
75
|
+
sess.key?("bar").must_equal false
|
76
|
+
sess.include?("foo").must_equal true
|
77
|
+
sess.include?("bar").must_equal false
|
78
|
+
|
79
|
+
sess[:foo2] = "bar2"
|
80
|
+
sess['foo2'].must_equal "bar2"
|
81
|
+
sess.store('foo3', "bar3").must_equal "bar3"
|
82
|
+
sess['foo3'].must_equal "bar3"
|
83
|
+
|
84
|
+
env['roda.session.created_at'] = true
|
85
|
+
env['roda.session.updated_at'] = true
|
86
|
+
sess.clear.must_equal({})
|
87
|
+
sess.data.must_equal({})
|
88
|
+
env['roda.session.created_at'].must_be_nil
|
89
|
+
env['roda.session.updated_at'].must_be_nil
|
90
|
+
|
91
|
+
sess['a'] = 'b'
|
92
|
+
env['roda.session.created_at'] = true
|
93
|
+
env['roda.session.updated_at'] = true
|
94
|
+
sess.destroy.must_equal({})
|
95
|
+
sess.data.must_equal({})
|
96
|
+
env['roda.session.created_at'].must_be_nil
|
97
|
+
env['roda.session.updated_at'].must_be_nil
|
98
|
+
|
99
|
+
sess[:foo] = "bar"
|
100
|
+
sess.to_hash.must_equal("foo"=>"bar")
|
101
|
+
sess.to_hash.wont_be_same_as(sess.data)
|
102
|
+
|
103
|
+
sess.update("foo2"=>"bar2", :foo=>"bar3").must_equal("foo"=>"bar3", "foo2"=>"bar2")
|
104
|
+
sess.data.must_equal("foo"=>"bar3", "foo2"=>"bar2")
|
105
|
+
sess.merge!("foo2"=>"bar4").must_equal("foo"=>"bar3", "foo2"=>"bar4")
|
106
|
+
|
107
|
+
sess.replace("foo2"=>"bar5", :foo3=>"bar").must_equal("foo3"=>"bar", "foo2"=>"bar5")
|
108
|
+
sess.data.must_equal("foo3"=>"bar", "foo2"=>"bar5")
|
109
|
+
|
110
|
+
sess.delete(:foo3).must_equal("bar")
|
111
|
+
sess.data.must_equal("foo2"=>"bar5")
|
112
|
+
sess.delete("foo2").must_equal("bar5")
|
113
|
+
sess.data.must_equal({})
|
114
|
+
|
115
|
+
sess.exists?.must_equal true
|
116
|
+
env.delete('roda.session.serialized')
|
117
|
+
sess.exists?.must_equal false
|
118
|
+
|
119
|
+
sess.empty?.must_equal true
|
120
|
+
sess[:foo] = "bar"
|
121
|
+
sess.empty?.must_equal false
|
122
|
+
sess.keys.must_equal ["foo"]
|
123
|
+
sess.values.must_equal ["bar"]
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
data/spec/session_spec.rb
CHANGED
@@ -12,10 +12,10 @@ describe "session handling" do
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
body.must_match(
|
15
|
+
body.must_match("You're missing a session handler, try using the sessions plugin.")
|
16
16
|
end
|
17
17
|
|
18
|
-
it "should return session if
|
18
|
+
it "should return session if rack session middleware is used" do
|
19
19
|
app(:bare) do
|
20
20
|
use Rack::Session::Cookie, :secret=>'1'
|
21
21
|
|
data/spec/spec_helper.rb
CHANGED
@@ -36,6 +36,15 @@ def (Roda::RodaPlugins).warn(s)
|
|
36
36
|
puts caller.grep(/_spec\.rb:\d+:/)
|
37
37
|
end
|
38
38
|
|
39
|
+
if ENV['RODA_RACK_SESSION_COOKIE'] != '1'
|
40
|
+
require_relative '../lib/roda/session_middleware'
|
41
|
+
DEFAULT_SESSION_MIDDLEWARE_ARGS = [RodaSessionMiddleware, :secret=>'1'*64]
|
42
|
+
DEFAULT_SESSION_ARGS = [:plugin, :sessions, :secret=>'1'*64]
|
43
|
+
else
|
44
|
+
DEFAULT_SESSION_MIDDLEWARE_ARGS = [Rack::Session::Cookie, :secret=>'1']
|
45
|
+
DEFAULT_SESSION_ARGS = [:use, Rack::Session::Cookie, :secret=>'1']
|
46
|
+
end
|
47
|
+
|
39
48
|
module CookieJar
|
40
49
|
def req(path='/', env={})
|
41
50
|
if path.is_a?(Hash)
|
@@ -47,7 +56,7 @@ module CookieJar
|
|
47
56
|
|
48
57
|
a = super(env)
|
49
58
|
if set = a[1]['Set-Cookie']
|
50
|
-
@cookie = set.sub(
|
59
|
+
@cookie = set.sub(/(; path=\/)?(; secure)?; HttpOnly/, '')
|
51
60
|
end
|
52
61
|
a
|
53
62
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: roda
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Evans
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -205,6 +205,7 @@ extra_rdoc_files:
|
|
205
205
|
- doc/release_notes/3.6.0.txt
|
206
206
|
- doc/release_notes/3.8.0.txt
|
207
207
|
- doc/release_notes/3.9.0.txt
|
208
|
+
- doc/release_notes/3.10.0.txt
|
208
209
|
files:
|
209
210
|
- CHANGELOG
|
210
211
|
- MIT-LICENSE
|
@@ -248,6 +249,7 @@ files:
|
|
248
249
|
- doc/release_notes/2.9.0.txt
|
249
250
|
- doc/release_notes/3.0.0.txt
|
250
251
|
- doc/release_notes/3.1.0.txt
|
252
|
+
- doc/release_notes/3.10.0.txt
|
251
253
|
- doc/release_notes/3.2.0.txt
|
252
254
|
- doc/release_notes/3.3.0.txt
|
253
255
|
- doc/release_notes/3.4.0.txt
|
@@ -327,6 +329,7 @@ files:
|
|
327
329
|
- lib/roda/plugins/route_csrf.rb
|
328
330
|
- lib/roda/plugins/run_append_slash.rb
|
329
331
|
- lib/roda/plugins/run_handler.rb
|
332
|
+
- lib/roda/plugins/sessions.rb
|
330
333
|
- lib/roda/plugins/shared_vars.rb
|
331
334
|
- lib/roda/plugins/sinatra_helpers.rb
|
332
335
|
- lib/roda/plugins/slash_path_empty.rb
|
@@ -344,6 +347,7 @@ files:
|
|
344
347
|
- lib/roda/plugins/typecast_params.rb
|
345
348
|
- lib/roda/plugins/unescape_path.rb
|
346
349
|
- lib/roda/plugins/view_options.rb
|
350
|
+
- lib/roda/session_middleware.rb
|
347
351
|
- lib/roda/version.rb
|
348
352
|
- spec/all.rb
|
349
353
|
- spec/assets/css/app.scss
|
@@ -425,6 +429,7 @@ files:
|
|
425
429
|
- spec/plugin/route_csrf_spec.rb
|
426
430
|
- spec/plugin/run_append_slash_spec.rb
|
427
431
|
- spec/plugin/run_handler_spec.rb
|
432
|
+
- spec/plugin/sessions_spec.rb
|
428
433
|
- spec/plugin/shared_vars_spec.rb
|
429
434
|
- spec/plugin/sinatra_helpers_spec.rb
|
430
435
|
- spec/plugin/slash_path_empty_spec.rb
|
@@ -446,6 +451,7 @@ files:
|
|
446
451
|
- spec/redirect_spec.rb
|
447
452
|
- spec/request_spec.rb
|
448
453
|
- spec/response_spec.rb
|
454
|
+
- spec/session_middleware_spec.rb
|
449
455
|
- spec/session_spec.rb
|
450
456
|
- spec/spec_helper.rb
|
451
457
|
- spec/version_spec.rb
|
@@ -488,7 +494,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
488
494
|
version: '0'
|
489
495
|
requirements: []
|
490
496
|
rubyforge_project:
|
491
|
-
rubygems_version:
|
497
|
+
rubygems_version: 2.7.6
|
492
498
|
signing_key:
|
493
499
|
specification_version: 4
|
494
500
|
summary: Routing tree web toolkit
|