yus 1.0.2 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/.gitignore +3 -0
- data/.ruby-version +1 -0
- data/.travis.yml +22 -0
- data/0001-Added-support-for-running-yus-via-docker.patch +172 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +84 -0
- data/History.txt +11 -0
- data/Manifest.txt +25 -0
- data/Rakefile +26 -0
- data/bin/yus_add_user +5 -41
- data/bin/yus_delete_user +3 -37
- data/bin/yus_dump +19 -0
- data/bin/yus_grant +8 -32
- data/bin/yus_passwd +5 -41
- data/bin/yus_show +8 -34
- data/bin/yusd +2 -2
- data/data/yus_dump.yml +42 -0
- data/lib/data/yus_dump.yml +42 -0
- data/lib/yus/helpers.rb +74 -0
- data/lib/yus/server.rb +1 -2
- data/lib/yus/session.rb +2 -1
- data/lib/yus/version.rb +3 -0
- data/readme.md +27 -0
- data/second.env +1 -0
- data/yus.gemspec +45 -0
- data/yus_migrate_to_utf_8 +214 -0
- metadata +239 -44
- data/.gemtest +0 -0
- data/README.txt +0 -35
- data/test/suite.rb +0 -15
- data/test/test_entity.rb +0 -238
- data/test/test_privilege.rb +0 -57
- data/test/test_server.rb +0 -127
- data/test/test_session.rb +0 -909
data/.gemtest
DELETED
File without changes
|
data/README.txt
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
= yus
|
2
|
-
|
3
|
-
* http://scm.ywesee.com/?p=yus/.git;a=summary
|
4
|
-
|
5
|
-
== DESCRIPTION:
|
6
|
-
|
7
|
-
ywesee user server. Works with the ywesee webframework and all the ywesee
|
8
|
-
software packages.
|
9
|
-
|
10
|
-
== FEATURES/PROBLEMS:
|
11
|
-
|
12
|
-
* Only runs on Ruby 1.8
|
13
|
-
|
14
|
-
== REQUIREMENTS:
|
15
|
-
|
16
|
-
* Install the following packages with gem:
|
17
|
-
|
18
|
-
* needle (1.3.0)
|
19
|
-
* pg (0.9.0)
|
20
|
-
* postgres (0.7.9.2008.01.28)
|
21
|
-
* flexmock (0.8.6) - to run the tests
|
22
|
-
|
23
|
-
== INSTALL:
|
24
|
-
|
25
|
-
* sudo gem install yus
|
26
|
-
|
27
|
-
== DEVELOPERS:
|
28
|
-
|
29
|
-
* Masaomi Hatakeyama
|
30
|
-
* Zeno Davatz
|
31
|
-
* Hannes Wyss (upto Version 1.0)
|
32
|
-
|
33
|
-
== LICENSE:
|
34
|
-
|
35
|
-
* GPLv2
|
data/test/suite.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# TestSuite -- yus -- 02.06.2006 -- rwaltert@ywesee.com
|
3
|
-
|
4
|
-
$: << File.dirname(File.expand_path(__FILE__))
|
5
|
-
|
6
|
-
if /^1\.8/.match(RUBY_VERSION)
|
7
|
-
gem 'minitest'
|
8
|
-
require 'minitest/autorun'
|
9
|
-
else
|
10
|
-
require 'test/unit'
|
11
|
-
end
|
12
|
-
|
13
|
-
Dir.foreach(File.dirname(__FILE__)) { |file|
|
14
|
-
require file if /^test_.*\.rb$/o.match(file)
|
15
|
-
}
|
data/test/test_entity.rb
DELETED
@@ -1,238 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# TestEntity -- yus -- 29.05.2006 -- hwyss@ywesee.com
|
3
|
-
|
4
|
-
|
5
|
-
$: << File.expand_path('../lib', File.dirname(__FILE__))
|
6
|
-
|
7
|
-
gem 'minitest'
|
8
|
-
require 'minitest/autorun'
|
9
|
-
require 'yus/entity'
|
10
|
-
|
11
|
-
module Yus
|
12
|
-
class TestEntity <Minitest::Test
|
13
|
-
def setup
|
14
|
-
@user = Entity.new('user')
|
15
|
-
end
|
16
|
-
def test_authenticate
|
17
|
-
assert_equal(false, @user.authenticate(nil))
|
18
|
-
@user.passhash = '12345abcde'
|
19
|
-
assert_equal(false, @user.authenticate('abcde12345'))
|
20
|
-
assert_equal(true, @user.authenticate('12345abcde'))
|
21
|
-
end
|
22
|
-
def test_authenticate_token
|
23
|
-
assert_equal(false, @user.authenticate_token(nil))
|
24
|
-
token = '123456'
|
25
|
-
@user.set_token token, Time.now + 60
|
26
|
-
other = '654321'
|
27
|
-
@user.set_token other, Time.now + 60
|
28
|
-
assert_equal(true, @user.authenticate_token(token))
|
29
|
-
assert_equal(true, @user.authenticate_token(other))
|
30
|
-
assert_equal(false, @user.authenticate_token(token))
|
31
|
-
@user.set_token token, Time.now - 60
|
32
|
-
assert_equal(false, @user.authenticate_token(token))
|
33
|
-
|
34
|
-
# Be paranoid
|
35
|
-
token = '123456'
|
36
|
-
@user.set_token token, Time.now + 60
|
37
|
-
other = '654321'
|
38
|
-
@user.set_token other, Time.now + 60
|
39
|
-
assert_equal(false, @user.authenticate_token('hacker'))
|
40
|
-
assert_equal(false, @user.authenticate_token(token))
|
41
|
-
assert_equal(false, @user.authenticate_token(other))
|
42
|
-
end
|
43
|
-
def test_join
|
44
|
-
group1 = Entity.new('A Group')
|
45
|
-
group2 = Entity.new('Another Group')
|
46
|
-
assert_equal([], @user.affiliations)
|
47
|
-
@user.join(group1)
|
48
|
-
assert_equal([group1], @user.affiliations)
|
49
|
-
@user.join(group1)
|
50
|
-
assert_equal([group1], @user.affiliations)
|
51
|
-
@user.join(group2)
|
52
|
-
assert_equal([group1, group2], @user.affiliations)
|
53
|
-
@user.join(group1)
|
54
|
-
assert_equal([group1, group2], @user.affiliations)
|
55
|
-
@user.join(group2)
|
56
|
-
assert_equal([group1, group2], @user.affiliations)
|
57
|
-
end
|
58
|
-
def test_join__circular
|
59
|
-
group1 = Entity.new('A Group')
|
60
|
-
group2 = Entity.new('Another Group')
|
61
|
-
assert_equal([], @user.affiliations)
|
62
|
-
@user.join(group1)
|
63
|
-
assert_raises(CircularAffiliationError) {
|
64
|
-
group1.join(@user)
|
65
|
-
}
|
66
|
-
group1.join(group2)
|
67
|
-
assert_raises(CircularAffiliationError) {
|
68
|
-
group2.join(@user)
|
69
|
-
}
|
70
|
-
end
|
71
|
-
def test_leave
|
72
|
-
group1 = Entity.new('A Group')
|
73
|
-
group2 = Entity.new('Another Group')
|
74
|
-
group3 = Entity.new('A third Group')
|
75
|
-
@user.affiliations.push(group1, group2, group3)
|
76
|
-
assert_equal([group1, group2, group3], @user.affiliations)
|
77
|
-
@user.leave(group2)
|
78
|
-
assert_equal([group1, group3], @user.affiliations)
|
79
|
-
@user.leave(group2)
|
80
|
-
assert_equal([group1, group3], @user.affiliations)
|
81
|
-
end
|
82
|
-
def test_grant__action
|
83
|
-
assert_equal(false, @user.allowed?('write'))
|
84
|
-
@user.grant('write')
|
85
|
-
assert_equal(true, @user.allowed?('write'))
|
86
|
-
assert_equal(true, @user.allowed?('write', 'Article'))
|
87
|
-
end
|
88
|
-
def test_grant__action_class
|
89
|
-
assert_equal(false, @user.allowed?('write'))
|
90
|
-
@user.grant('write', 'Article')
|
91
|
-
assert_equal(false, @user.allowed?('write'))
|
92
|
-
assert_equal(true, @user.allowed?('write', 'Article'))
|
93
|
-
end
|
94
|
-
def test_allowed
|
95
|
-
assert_equal(false, @user.allowed?('write', 'Article'))
|
96
|
-
assert_equal(false, @user.allowed?('read', 'Article'))
|
97
|
-
@user.grant('read', 'Article')
|
98
|
-
assert_equal(false, @user.allowed?('write', 'Article'))
|
99
|
-
assert_equal(true, @user.allowed?('read', 'Article'))
|
100
|
-
assert_equal(false, @user.allowed?('write'))
|
101
|
-
assert_equal(false, @user.allowed?('read'))
|
102
|
-
end
|
103
|
-
def test_allowed__delegated
|
104
|
-
group1 = Entity.new('group1')
|
105
|
-
assert_equal(false, @user.allowed?('write', 'Article'))
|
106
|
-
group1.grant('read', 'Article')
|
107
|
-
@user.join(group1)
|
108
|
-
assert_equal(false, @user.allowed?('write', 'Article'))
|
109
|
-
assert_equal(true, @user.allowed?('read', 'Article'))
|
110
|
-
assert_equal(false, @user.allowed?('write'))
|
111
|
-
assert_equal(false, @user.allowed?('read'))
|
112
|
-
end
|
113
|
-
def test_allowed__delegated__once_removed
|
114
|
-
group1 = Entity.new('group1')
|
115
|
-
group2 = Entity.new('group1')
|
116
|
-
assert_equal(false, @user.allowed?('write', 'Article'))
|
117
|
-
group1.grant('read', 'Article')
|
118
|
-
group2.join(group1)
|
119
|
-
@user.join(group2)
|
120
|
-
assert_equal(false, @user.allowed?('write', 'Article'))
|
121
|
-
assert_equal(true, @user.allowed?('read', 'Article'))
|
122
|
-
assert_equal(false, @user.allowed?('write'))
|
123
|
-
assert_equal(false, @user.allowed?('read'))
|
124
|
-
end
|
125
|
-
def test_privileged
|
126
|
-
assert_equal(false, @user.privileged?('write', 'Article'))
|
127
|
-
@user.grant('read', 'Article')
|
128
|
-
assert_equal(false, @user.privileged?('write', 'Article'))
|
129
|
-
assert_equal(true, @user.privileged?('read', 'Article'))
|
130
|
-
assert_equal(false, @user.privileged?('write'))
|
131
|
-
assert_equal(false, @user.privileged?('read'))
|
132
|
-
end
|
133
|
-
def test_privileged__delegated
|
134
|
-
group1 = Entity.new('group1')
|
135
|
-
assert_equal(false, @user.privileged?('write', 'Article'))
|
136
|
-
group1.grant('read', 'Article')
|
137
|
-
@user.join(group1)
|
138
|
-
assert_equal(false, @user.privileged?('write', 'Article'))
|
139
|
-
assert_equal(false, @user.privileged?('read', 'Article'))
|
140
|
-
assert_equal(false, @user.privileged?('write'))
|
141
|
-
assert_equal(false, @user.privileged?('read'))
|
142
|
-
end
|
143
|
-
def test_privileged_until
|
144
|
-
assert_raises(NotPrivilegedError) {
|
145
|
-
@user.privileged_until('read', 'Article')
|
146
|
-
}
|
147
|
-
assert_raises(NotPrivilegedError) {
|
148
|
-
@user.privileged_until('write', 'Article')
|
149
|
-
}
|
150
|
-
@user.grant('read', 'Article')
|
151
|
-
assert_nil(@user.privileged_until('read', 'Article'))
|
152
|
-
assert_raises(NotPrivilegedError) {
|
153
|
-
@user.privileged_until('read')
|
154
|
-
}
|
155
|
-
assert_raises(NotPrivilegedError) {
|
156
|
-
@user.privileged_until('write', 'Article')
|
157
|
-
}
|
158
|
-
@user.grant('read', 'Article', Time.local(3000))
|
159
|
-
assert_raises(NotPrivilegedError) {
|
160
|
-
@user.privileged_until('read')
|
161
|
-
}
|
162
|
-
assert_equal(Time.local(3000),
|
163
|
-
@user.privileged_until('read', 'Article'))
|
164
|
-
assert_raises(NotPrivilegedError) {
|
165
|
-
@user.privileged_until('write', 'Article')
|
166
|
-
}
|
167
|
-
@user.grant('read', :everything, Time.local(4000))
|
168
|
-
assert_equal(Time.local(4000),
|
169
|
-
@user.privileged_until('read', 'Article'))
|
170
|
-
@user.grant('read', 'Article', Time.local(5000))
|
171
|
-
assert_equal(Time.local(5000),
|
172
|
-
@user.privileged_until('read', 'Article'))
|
173
|
-
end
|
174
|
-
def test_valid
|
175
|
-
assert_equal(true, @user.valid?)
|
176
|
-
@user.valid_from = Time.now + 100
|
177
|
-
assert_equal(false, @user.valid?)
|
178
|
-
@user.valid_until = Time.now - 100
|
179
|
-
assert_equal(false, @user.valid?)
|
180
|
-
@user.valid_from = Time.now - 200
|
181
|
-
assert_equal(false, @user.valid?)
|
182
|
-
@user.valid_until = Time.now + 100
|
183
|
-
assert_equal(true, @user.valid?)
|
184
|
-
@user.valid_until = nil
|
185
|
-
assert_equal(true, @user.valid?)
|
186
|
-
end
|
187
|
-
def test_domain_based_preference
|
188
|
-
assert_nil(@user.get_preference('other'))
|
189
|
-
assert_nil(@user.get_preference('pref'))
|
190
|
-
assert_nil(@user.get_preference('pref', 'domain'))
|
191
|
-
assert_nil(@user.get_preference('pref', 'other'))
|
192
|
-
@user.set_preference('pref', 'value', 'domain')
|
193
|
-
assert_nil(@user.get_preference('other'))
|
194
|
-
assert_nil(@user.get_preference('pref'))
|
195
|
-
assert_equal('value', @user.get_preference('pref', 'domain'))
|
196
|
-
assert_nil(@user.get_preference('pref', 'other'))
|
197
|
-
@user.set_preference('pref', 'global')
|
198
|
-
assert_nil(@user.get_preference('other'))
|
199
|
-
assert_equal('global', @user.get_preference('pref'))
|
200
|
-
assert_equal('value', @user.get_preference('pref', 'domain'))
|
201
|
-
assert_equal('global', @user.get_preference('pref', 'other'))
|
202
|
-
end
|
203
|
-
def test_rename
|
204
|
-
assert_equal('user', @user.name)
|
205
|
-
@user.rename('renamed')
|
206
|
-
assert_equal('renamed', @user.name)
|
207
|
-
end
|
208
|
-
def test_revoke__action
|
209
|
-
assert_equal(false, @user.allowed?('write'))
|
210
|
-
@user.grant('write')
|
211
|
-
assert_equal(true, @user.allowed?('write'))
|
212
|
-
@user.revoke('write')
|
213
|
-
assert_equal(false, @user.allowed?('write'))
|
214
|
-
end
|
215
|
-
def test_to_s
|
216
|
-
assert_equal('user', @user.to_s)
|
217
|
-
end
|
218
|
-
def test_info
|
219
|
-
assert_equal ['user'], @user.info
|
220
|
-
@user.grant('write')
|
221
|
-
assert_equal ['user', ['write', [['everything']]]], @user.info
|
222
|
-
@user.grant('write', 'Article')
|
223
|
-
assert_equal ['user', ['write', [['Article'], ['everything']]]], @user.info
|
224
|
-
group1 = Entity.new('group1')
|
225
|
-
group1.grant('read', 'Article')
|
226
|
-
@user.join(group1)
|
227
|
-
assert_equal ['user', ['write', [['Article'], ['everything']]], ['group1']], @user.info
|
228
|
-
group2 = Entity.new('group2')
|
229
|
-
group2.grant('read', 'Journal')
|
230
|
-
@user.join(group2)
|
231
|
-
assert_equal ['user', ['write', [['Article'], ['everything']]], ['group1', 'group2']], @user.info
|
232
|
-
assert_equal ['user', ['write', [['Article'], ['everything']]],
|
233
|
-
['group1', ['read', [['Article']]]],
|
234
|
-
['group2', ['read', [['Journal']]]]],
|
235
|
-
@user.info(true)
|
236
|
-
end
|
237
|
-
end
|
238
|
-
end
|
data/test/test_privilege.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# TestPrivilege -- yus -- 31.05.2006 -- hwyss@ywesee.com
|
3
|
-
|
4
|
-
$: << File.expand_path('../lib', File.dirname(__FILE__))
|
5
|
-
|
6
|
-
gem 'minitest'
|
7
|
-
require 'minitest/autorun'
|
8
|
-
require 'yus/privilege'
|
9
|
-
|
10
|
-
module Yus
|
11
|
-
class TestPrivilege <Minitest::Test
|
12
|
-
def setup
|
13
|
-
@privilege = Privilege.new
|
14
|
-
end
|
15
|
-
def test_grant
|
16
|
-
assert_equal(false, @privilege.granted?('Article'))
|
17
|
-
@privilege.grant('Article')
|
18
|
-
assert_equal(false, @privilege.granted?('Book'))
|
19
|
-
assert_equal(true, @privilege.granted?('Article'))
|
20
|
-
end
|
21
|
-
def test_grant__timed
|
22
|
-
assert_equal(false, @privilege.granted?('Article'))
|
23
|
-
@privilege.grant('Article', Time.now)
|
24
|
-
assert_equal(false, @privilege.granted?('Article'))
|
25
|
-
@privilege.grant('Article', Time.now + 0.5)
|
26
|
-
assert_equal(true, @privilege.granted?('Article'))
|
27
|
-
sleep(1)
|
28
|
-
assert_equal(false, @privilege.granted?('Article'))
|
29
|
-
end
|
30
|
-
def test_grant__everything
|
31
|
-
assert_equal(false, @privilege.granted?('Article'))
|
32
|
-
@privilege.grant(:everything)
|
33
|
-
assert_equal(true, @privilege.granted?('Article'))
|
34
|
-
end
|
35
|
-
def test_grant__wildcard
|
36
|
-
assert_equal(false, @privilege.granted?('org.oddb.company'))
|
37
|
-
@privilege.grant('org.oddb.*')
|
38
|
-
assert_equal(true, @privilege.granted?('org.oddb.company'))
|
39
|
-
assert_equal(false, @privilege.granted?('org.oddb'))
|
40
|
-
assert_equal(false, @privilege.granted?('org.foo.company'))
|
41
|
-
end
|
42
|
-
def test_revoke
|
43
|
-
@privilege.grant('Article')
|
44
|
-
assert_equal(true, @privilege.granted?('Article'))
|
45
|
-
@privilege.revoke('Article')
|
46
|
-
assert_equal(false, @privilege.granted?('Article'))
|
47
|
-
end
|
48
|
-
def test_revoke__timed
|
49
|
-
@privilege.grant('Article')
|
50
|
-
assert_equal(true, @privilege.granted?('Article'))
|
51
|
-
@privilege.revoke('Article', Time.now + 0.5)
|
52
|
-
assert_equal(true, @privilege.granted?('Article'))
|
53
|
-
sleep(1)
|
54
|
-
assert_equal(false, @privilege.granted?('Article'))
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
data/test/test_server.rb
DELETED
@@ -1,127 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# TestServer -- yus -- 01.06.2006 -- hwyss@ywesee.com
|
3
|
-
|
4
|
-
$: << File.expand_path('../lib', File.dirname(__FILE__))
|
5
|
-
|
6
|
-
require 'yus/server'
|
7
|
-
require 'flexmock'
|
8
|
-
|
9
|
-
module Yus
|
10
|
-
class Server
|
11
|
-
public :authenticate, :clean
|
12
|
-
end
|
13
|
-
class TestServer < Minitest::Test
|
14
|
-
def setup
|
15
|
-
@config = FlexMock.new
|
16
|
-
@config.should_receive(:cleaner_interval).and_return { 100000000 }
|
17
|
-
digest = FlexMock.new
|
18
|
-
digest.should_receive(:hexdigest).and_return { |input| input }
|
19
|
-
@config.should_receive(:digest).and_return { digest }
|
20
|
-
@config.should_receive(:session_timeout).and_return { 0.5 }
|
21
|
-
@config.should_receive(:root_name).and_return { 'admin' }
|
22
|
-
@config.should_receive(:root_pass).and_return { 'admin' }
|
23
|
-
@logger = FlexMock.new
|
24
|
-
@logger.should_receive(:info)
|
25
|
-
@logger.should_receive(:debug)
|
26
|
-
@persistence = FlexMock.new
|
27
|
-
@server = Server.new(@persistence, @config, @logger)
|
28
|
-
end
|
29
|
-
def test_authenticate__no_user
|
30
|
-
@logger.should_receive(:warn).times(1)
|
31
|
-
@persistence.should_receive(:find_entity).times(1)
|
32
|
-
assert_raises(UnknownEntityError) {
|
33
|
-
@server.authenticate('name', 'password')
|
34
|
-
}
|
35
|
-
end
|
36
|
-
def test_authenticate__wrong_password
|
37
|
-
@logger.should_receive(:warn).times(1)
|
38
|
-
user = FlexMock.new
|
39
|
-
user.should_receive(:authenticate).and_return { false }
|
40
|
-
@persistence.should_receive(:find_entity).times(1).and_return { user }
|
41
|
-
assert_raises(AuthenticationError) {
|
42
|
-
@server.authenticate('name', 'password')
|
43
|
-
}
|
44
|
-
end
|
45
|
-
def test_authenticate__success
|
46
|
-
user = FlexMock.new
|
47
|
-
user.should_receive(:authenticate).and_return { |pass|
|
48
|
-
assert_equal('password', pass)
|
49
|
-
true
|
50
|
-
}
|
51
|
-
@persistence.should_receive(:find_entity).times(1).and_return { user }
|
52
|
-
result = @server.authenticate('name', 'password')
|
53
|
-
assert_equal(user, result)
|
54
|
-
end
|
55
|
-
def test_autosession
|
56
|
-
@server.autosession('domain') { |session|
|
57
|
-
assert_instance_of(AutoSession, session)
|
58
|
-
}
|
59
|
-
end
|
60
|
-
def test_login__success
|
61
|
-
user = FlexMock.new
|
62
|
-
user.should_receive(:authenticate).and_return { |pass|
|
63
|
-
assert_equal('password', pass)
|
64
|
-
true
|
65
|
-
}
|
66
|
-
user.should_receive(:login)
|
67
|
-
user.should_receive(:get_preference).and_return { |key, domain|
|
68
|
-
{
|
69
|
-
'session_timeout' => 0.5,
|
70
|
-
}[key]
|
71
|
-
}
|
72
|
-
@persistence.should_receive(:find_entity).times(1).and_return { user }
|
73
|
-
@persistence.should_receive(:save_entity).times(1)
|
74
|
-
session = @server.login('name', 'password', 'domain')
|
75
|
-
assert_instance_of(EntitySession, session)
|
76
|
-
assert_kind_of(DRb::DRbUndumped, session)
|
77
|
-
assert_equal([session], @server.instance_variable_get('@sessions'))
|
78
|
-
end
|
79
|
-
def test_logout
|
80
|
-
needle = FlexMock.new
|
81
|
-
needle.should_receive(:config).and_return { @config }
|
82
|
-
@config.should_receive(:session_timeout).and_return { 200 }
|
83
|
-
sessions = @server.instance_variable_get('@sessions')
|
84
|
-
session = RootSession.new(needle)
|
85
|
-
sessions.push(session)
|
86
|
-
@server.logout(session)
|
87
|
-
assert_equal([], sessions)
|
88
|
-
end
|
89
|
-
def test_login__root
|
90
|
-
session = @server.login('admin', 'admin', 'domain')
|
91
|
-
assert_instance_of(RootSession, session)
|
92
|
-
end
|
93
|
-
def test_ping
|
94
|
-
assert(@server.ping)
|
95
|
-
end
|
96
|
-
def test_clean
|
97
|
-
needle = FlexMock.new
|
98
|
-
needle.should_receive(:config).and_return { @config }
|
99
|
-
@config.should_receive(:session_timeout).and_return { 0.5 }
|
100
|
-
sessions = @server.instance_variable_get('@sessions')
|
101
|
-
session = RootSession.new(needle)
|
102
|
-
sessions.push(session)
|
103
|
-
sleep(1)
|
104
|
-
@server.clean
|
105
|
-
assert_equal([], sessions)
|
106
|
-
end
|
107
|
-
end
|
108
|
-
class TestServerCleaner < Minitest::Test
|
109
|
-
def test_autoclean
|
110
|
-
config = FlexMock.new
|
111
|
-
config.should_receive(:cleaner_interval).and_return { 0.5 }
|
112
|
-
config.should_receive(:session_timeout).and_return { 0.5 }
|
113
|
-
logger = FlexMock.new
|
114
|
-
logger.should_receive(:info)
|
115
|
-
logger.should_receive(:debug)
|
116
|
-
needle = FlexMock.new
|
117
|
-
needle.should_receive(:config).and_return { config }
|
118
|
-
persistence = FlexMock.new
|
119
|
-
server = Server.new(persistence, config, logger)
|
120
|
-
sessions = server.instance_variable_get('@sessions')
|
121
|
-
session = RootSession.new(needle)
|
122
|
-
sessions.push(session)
|
123
|
-
sleep(2)
|
124
|
-
assert_equal([], sessions)
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|