sbsm 1.5.2 → 1.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.txt +6 -0
- data/lib/sbsm/app.rb +2 -0
- data/lib/sbsm/session.rb +33 -34
- data/lib/sbsm/session_store.rb +20 -15
- data/lib/sbsm/version.rb +1 -1
- data/test/test_session_store.rb +88 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc9f5d89b19d63cc1e535df21aeb118e6b701b94
|
4
|
+
data.tar.gz: f938b3e39401c6edce02fac8fbbc50aa92fcf91c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3053e25db4359a6e37239361a402dc39b137742adc082002c0834633be846e064b0e6724f1e9e549cac0c23fb298bbb7e3aa473d658263cf8a9976d8434993b
|
7
|
+
data.tar.gz: 79952026cd9423c00d419e9bd6731fd6550f99c97dd288345e1c357f224577aaa2a85cea9370ae08fcfb850a10c07f137b1577ce1847b86d6a3d5a33a2a9b1a6
|
data/History.txt
CHANGED
data/lib/sbsm/app.rb
CHANGED
@@ -152,6 +152,8 @@ module SBSM
|
|
152
152
|
:path => "/",
|
153
153
|
:expires => (Time.now + (60 * 60 * 24 * 365 * 10))})
|
154
154
|
response.set_cookie(SESSION_ID, { :value => session_id, :path => '/' , :expires => (Time.now + (60 * 60 * 24 * 365 * 10)) })
|
155
|
+
request = nil
|
156
|
+
session.rack_request = nil
|
155
157
|
@@last_session = session
|
156
158
|
if response.headers['Set-Cookie'].to_s.index(session_id)
|
157
159
|
SBSM.debug "finish session_id.1 #{session_id}: matches response.headers['Set-Cookie'] #{response.headers['Set-Cookie']}"
|
data/lib/sbsm/session.rb
CHANGED
@@ -38,9 +38,9 @@ module SBSM
|
|
38
38
|
class Session
|
39
39
|
|
40
40
|
attr_reader :user, :active_thread, :key, :cookie_input, :persistent_cookie_name, :post_content,
|
41
|
-
:server_name, :server_port, :request_params, :request_method, :request_origin,
|
41
|
+
:server_name, :server_port, :user_agent, :request_params, :request_method, :request_origin,
|
42
42
|
:unsafe_input, :valid_input, :request_path, :request_post, :cgi, :attended_states
|
43
|
-
attr_accessor :validator, :trans_handler, :app
|
43
|
+
attr_accessor :validator, :trans_handler, :app, :rack_request
|
44
44
|
PERSISTENT_COOKIE_NAME = "sbsm-persistent-cookie"
|
45
45
|
DEFAULT_FLAVOR = 'sbsm'
|
46
46
|
DEFAULT_LANGUAGE = 'en'
|
@@ -161,6 +161,9 @@ module SBSM
|
|
161
161
|
@attended_states.size
|
162
162
|
end
|
163
163
|
end
|
164
|
+
def key=(key)
|
165
|
+
@key = key
|
166
|
+
end
|
164
167
|
def __checkout
|
165
168
|
@attended_states.each_value { |state| state.__checkout }
|
166
169
|
@attended_states.clear
|
@@ -203,36 +206,36 @@ module SBSM
|
|
203
206
|
end
|
204
207
|
def process_rack(rack_request:)
|
205
208
|
start = Time.now
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
209
|
+
html = @mutex.synchronize do
|
210
|
+
begin
|
211
|
+
@passthru = false
|
212
|
+
@disposition = false
|
213
|
+
@request_path ||= rack_request.path
|
214
|
+
@rack_request = rack_request
|
215
|
+
@post_content = nil
|
211
216
|
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
217
|
+
if rack_request.request_method.eql?('POST')
|
218
|
+
rack_request.params.each do |k, v|
|
219
|
+
# needed to test POST requests generated by curl (first parameter) or ARC (second parameter)
|
220
|
+
if /xml/i.match(k)
|
221
|
+
@post_content = "#{k} #{v}"
|
222
|
+
break
|
223
|
+
end
|
224
|
+
end
|
225
|
+
begin
|
226
|
+
# needed for request generated by https://github.com/wiztools/rest-client
|
227
|
+
rack_request.body.rewind # just to be sure
|
228
|
+
@post_content = rack_request.body.read
|
229
|
+
end unless @post_content
|
230
|
+
if @post_content
|
231
|
+
SBSM.debug "@post_content is #{@post_content}"
|
232
|
+
else
|
233
|
+
SBSM.debug "rack_request is #{rack_request}"
|
234
|
+
end
|
218
235
|
end
|
219
|
-
end
|
220
|
-
begin
|
221
|
-
# needed for request generated by https://github.com/wiztools/rest-client
|
222
|
-
rack_request.body.rewind # just to be sure
|
223
|
-
@post_content = rack_request.body.read
|
224
|
-
end unless @post_content
|
225
|
-
if @post_content
|
226
|
-
SBSM.debug "@post_content is #{@post_content}"
|
227
|
-
else
|
228
|
-
SBSM.debug "rack_request is #{rack_request}"
|
229
|
-
end
|
230
|
-
end
|
231
236
|
|
232
|
-
|
233
|
-
|
234
|
-
html = @mutex.synchronize do
|
235
|
-
begin
|
237
|
+
rack_request.params.each { |key, val| @cgi.params.store(key, val) }
|
238
|
+
@trans_handler.translate_uri(rack_request)
|
236
239
|
@request_method =rack_request.request_method
|
237
240
|
@request_path = rack_request.path
|
238
241
|
if rack_request.env
|
@@ -270,6 +273,7 @@ module SBSM
|
|
270
273
|
@zone = @active_state.zone
|
271
274
|
@active_state.touch
|
272
275
|
cap_max_states
|
276
|
+
self.process_late() if self.respond_to?(:process_late) # needed for ODDB.org limit_request
|
273
277
|
ensure
|
274
278
|
@user_input_imported = false
|
275
279
|
end
|
@@ -277,9 +281,6 @@ module SBSM
|
|
277
281
|
end
|
278
282
|
(@@stats[@request_path] ||= []).push(Time.now - start)
|
279
283
|
html
|
280
|
-
rescue => err
|
281
|
-
SBSM.info "Error in process_rack #{err.backtrace[0..5].join("\n")}"
|
282
|
-
raise err
|
283
284
|
end
|
284
285
|
def error(key)
|
285
286
|
@state.error(key) if @state.respond_to?(:error)
|
@@ -454,8 +455,6 @@ module SBSM
|
|
454
455
|
"#{key}="
|
455
456
|
end
|
456
457
|
end.join(';')
|
457
|
-
rescue => error
|
458
|
-
binding.pry
|
459
458
|
end
|
460
459
|
def http_headers
|
461
460
|
@state.http_headers
|
data/lib/sbsm/session_store.rb
CHANGED
@@ -61,6 +61,7 @@ module SBSM
|
|
61
61
|
unknown_user: UNKNOWN_USER.new,
|
62
62
|
multi_threaded: nil)
|
63
63
|
fail "You must specify an app!" unless app
|
64
|
+
@@sessions = {}
|
64
65
|
@cleaner = run_cleaner if(self.class.const_get(:RUN_CLEANER))
|
65
66
|
@app = app
|
66
67
|
@system = persistence_layer
|
@@ -75,23 +76,25 @@ module SBSM
|
|
75
76
|
@validator = validator
|
76
77
|
end
|
77
78
|
def cap_max_sessions(now = Time.now)
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
79
|
+
if(@@sessions.size > self::class::CAP_MAX_THRESHOLD)
|
80
|
+
SBSM.info "too many sessions! Keeping only #{self::class::MAX_SESSIONS}"
|
81
|
+
sess = nil
|
82
|
+
@@sessions.values.sort[0...(-self::class::MAX_SESSIONS)].each { |sess|
|
83
|
+
sess.__checkout
|
84
|
+
@@sessions.delete(sess.key)
|
85
|
+
}
|
86
|
+
if(sess)
|
87
|
+
age = sess.age(now)
|
88
|
+
SBSM.info sprintf("deleted all sessions that had not been accessed for more than %im %is", age / 60, age % 60)
|
89
|
+
end
|
89
90
|
end
|
90
|
-
|
91
|
+
seconds = (Time.now.to_i - now.to_i)
|
92
|
+
SBSM.warn sprintf("cap_max_sessions to #{self::class::CAP_MAX_THRESHOLD}. took %d seconds", seconds)
|
91
93
|
end
|
92
94
|
def clean
|
93
95
|
now = Time.now
|
94
|
-
@@sessions.
|
96
|
+
old_size = @@sessions.size
|
97
|
+
@@sessions.delete_if do |key, s|
|
95
98
|
begin
|
96
99
|
if s.respond_to?(:expired?)
|
97
100
|
if s.expired?(now)
|
@@ -107,8 +110,9 @@ module SBSM
|
|
107
110
|
rescue
|
108
111
|
true
|
109
112
|
end
|
110
|
-
|
111
|
-
|
113
|
+
end
|
114
|
+
seconds = (Time.now.to_i - now.to_i)
|
115
|
+
SBSM.warn sprintf("Cleaned #{old_size - @@sessions.size} sessions. Took %d seconds", seconds)
|
112
116
|
end
|
113
117
|
def SessionStore.sessions
|
114
118
|
@@sessions
|
@@ -148,6 +152,7 @@ module SBSM
|
|
148
152
|
unless((s = @@sessions[key]) && !s.expired?)
|
149
153
|
s = @@sessions[key] = @session_class.new(app: @app, cookie_name: @cookie_name, trans_handler: @trans_handler, validator: @validator, unknown_user: @unknown_user)
|
150
154
|
end
|
155
|
+
s.key=key
|
151
156
|
s.reset()
|
152
157
|
s.touch()
|
153
158
|
s
|
data/lib/sbsm/version.rb
CHANGED
@@ -0,0 +1,88 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
#--
|
4
|
+
#
|
5
|
+
# State Based Session Management
|
6
|
+
# Copyright (C) 2004 Hannes Wyss
|
7
|
+
#
|
8
|
+
# This library is free software; you can redistribute it and/or
|
9
|
+
# modify it under the terms of the GNU Lesser General Public
|
10
|
+
# License as published by the Free Software Foundation; either
|
11
|
+
# version 2.1 of the License, or (at your option) any later version.
|
12
|
+
#
|
13
|
+
# This library is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
16
|
+
# Lesser General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU Lesser General Public
|
19
|
+
# License along with this library; if not, write to the Free Software
|
20
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
21
|
+
#
|
22
|
+
# ywesee - intellectual capital connected, Winterthurerstrasse 52, CH-8006 Zürich, Switzerland
|
23
|
+
# hwyss@ywesee.com
|
24
|
+
#
|
25
|
+
# TestSession -- sbsm -- 22.10.2002 -- hwyss@ywesee.com
|
26
|
+
#++
|
27
|
+
|
28
|
+
require 'minitest/autorun'
|
29
|
+
require 'sbsm/session_store'
|
30
|
+
require 'sbsm/validator'
|
31
|
+
require 'sbsm/trans_handler'
|
32
|
+
require 'sbsm/app'
|
33
|
+
require 'rack'
|
34
|
+
require 'rack/test'
|
35
|
+
|
36
|
+
begin
|
37
|
+
require 'pry'
|
38
|
+
rescue LoadError
|
39
|
+
end
|
40
|
+
|
41
|
+
class SBSM::Session
|
42
|
+
attr_accessor :mtime
|
43
|
+
end
|
44
|
+
class SBSM::SessionStore
|
45
|
+
CAP_MAX_THRESHOLD = 2
|
46
|
+
MAX_SESSIONS = 3
|
47
|
+
end
|
48
|
+
class TestSessionStore < Minitest::Test
|
49
|
+
include Rack::Test::Methods
|
50
|
+
def setup
|
51
|
+
@app = SBSM::App.new()
|
52
|
+
@session = SBSM::Session.new(app: @app)
|
53
|
+
@session_store = SBSM::SessionStore.new(app: @app)
|
54
|
+
end
|
55
|
+
|
56
|
+
def app
|
57
|
+
@app
|
58
|
+
end
|
59
|
+
|
60
|
+
IDS = ['1', '2', '3', '4', '5', '6', '7']
|
61
|
+
NR_SESSIONS = IDS.size
|
62
|
+
def test_clean
|
63
|
+
assert_equal(0, SBSM::SessionStore.sessions.size)
|
64
|
+
IDS.each do |session_id|
|
65
|
+
@session_store[session_id].mtime = Time.now - (SBSM::Session::EXPIRES+2)
|
66
|
+
end
|
67
|
+
assert_equal(NR_SESSIONS, SBSM::SessionStore.sessions.size)
|
68
|
+
@session_store.clean
|
69
|
+
assert_equal(0, SBSM::SessionStore.sessions.size)
|
70
|
+
end
|
71
|
+
def test_session_store_clear
|
72
|
+
IDS.each do |session_id|
|
73
|
+
@session_store[session_id]
|
74
|
+
end
|
75
|
+
assert_equal(NR_SESSIONS, SBSM::SessionStore.sessions.size)
|
76
|
+
SBSM::SessionStore.clear
|
77
|
+
assert_equal(0, SBSM::SessionStore.sessions.size)
|
78
|
+
end
|
79
|
+
def test_session_cap_max_session
|
80
|
+
IDS.each do |session_id|
|
81
|
+
@session_store[session_id]
|
82
|
+
end
|
83
|
+
assert_equal(NR_SESSIONS, SBSM::SessionStore.sessions.size)
|
84
|
+
@session_store.cap_max_sessions
|
85
|
+
assert_equal(2, NR_SESSIONS - SBSM::SessionStore::CAP_MAX_THRESHOLD - SBSM::SessionStore::MAX_SESSIONS)
|
86
|
+
assert_equal(2+1, SBSM::SessionStore.sessions.size)
|
87
|
+
end
|
88
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sbsm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masaomi Hatakeyama, Zeno R.R. Davatz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-07-
|
11
|
+
date: 2017-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -305,6 +305,7 @@ files:
|
|
305
305
|
- test/test_rack_app.rb
|
306
306
|
- test/test_redirect.rb
|
307
307
|
- test/test_session.rb
|
308
|
+
- test/test_session_store.rb
|
308
309
|
- test/test_state.rb
|
309
310
|
- test/test_trans_handler.rb
|
310
311
|
- test/test_user.rb
|
@@ -350,6 +351,7 @@ test_files:
|
|
350
351
|
- test/test_rack_app.rb
|
351
352
|
- test/test_redirect.rb
|
352
353
|
- test/test_session.rb
|
354
|
+
- test/test_session_store.rb
|
353
355
|
- test/test_state.rb
|
354
356
|
- test/test_trans_handler.rb
|
355
357
|
- test/test_user.rb
|