yus 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/Guide.txt +62 -75
- data/History.txt +7 -0
- data/bin/yus_add_user +1 -0
- data/bin/yus_delete_user +1 -0
- data/bin/yus_grant +1 -0
- data/bin/yus_passwd +1 -0
- data/bin/yus_show +1 -0
- data/bin/yusd +1 -0
- data/lib/yus/server.rb +1 -1
- data/lib/yus/session.rb +27 -5
- data/test/suite.rb +7 -0
- data/test/test_entity.rb +5 -8
- data/test/test_privilege.rb +3 -2
- data/test/test_server.rb +8 -13
- data/test/test_session.rb +114 -41
- metadata +10 -16
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NzBiN2NhYjE5MzU5YzAxZDZmZDk1MzI4OTE0YmIwYmUxOWQ5ZmNlOQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YjNiNThjNmY0ZjYxZWE2YTg1MzkyYThmYmQ1YzczYzBjYTg1MjQ0OQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MzhlMzYxYzUyYzY2NzAyYjg1MWZjMzNiYmNhODQ2MWQyZThkYjBkZDdkNDgx
|
10
|
+
OWMzOTM0MjFiOTY3YjkxMzA4MzIwNzExNWIwMWFiNjk5OWE0NjJjZmI4MGU5
|
11
|
+
MmU0M2M1NDk2YzYxYzliOWY4YmIyZTBjYTJhYTBlYjVmNWQyMGE=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YTFmODdiNjkwNzcyZjViYTc1NjQzMmZhYjQyNDAyNTE0NjgyYTFjMThjNzdk
|
14
|
+
YThkYmJlZjQxZDBmOTQ2ZGMwZTRmZDQyY2ViMmIxYjhlOTYwMzk2YmQ5ODM5
|
15
|
+
MzMzM2QyNzA1MGZiOWQyMDk1YjZiYmE3YmVmYjFjNTI2ZDM0NDQ=
|
data/Guide.txt
CHANGED
@@ -3,64 +3,73 @@
|
|
3
3
|
If you want to know why this software exists, please read the README file of
|
4
4
|
ch.oddb.org at scm.ywesee.com
|
5
5
|
|
6
|
-
yus is only running
|
6
|
+
yus is only running under Ruby1.8 (Ruby 1.9 and 2.0 have problems in the gem needle which calls Threads.critical=)
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
ssh-keygen -t rsa
|
11
|
-
|
12
|
-
do _not_ set a password for the key otherwise yus-server will always
|
13
|
-
ask you for a password at startup-time. The password you set will be
|
14
|
-
with the sha256.rb.
|
8
|
+
You must have a working installation of Ruby 1.8 and git.
|
15
9
|
|
16
|
-
|
10
|
+
git clone https://github.com/zdavatz/yus.git
|
11
|
+
cd yus
|
12
|
+
gem install bundler # unless you already have bundler installed
|
13
|
+
bundle install
|
14
|
+
bundle exec rake gem_install
|
17
15
|
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
# Setup the necessary configuration files. In this example we use
|
17
|
+
# user_tom as username and domain.com as the domain-name.
|
18
|
+
# He must be reachable by email via user_tom@domain.com
|
19
|
+
# Please adapt this to your need!
|
21
20
|
|
22
|
-
|
21
|
+
sudo mkdir -p /etc/yus/data/
|
23
22
|
|
24
|
-
|
23
|
+
If you do not yet have a private key you will have to create one with
|
25
24
|
|
26
|
-
|
25
|
+
ssh-keygen -t rsa -f /etc/yus/user_tom
|
27
26
|
|
28
|
-
|
29
|
-
|
27
|
+
do _not_ set a password for the key otherwise yus-server will always
|
28
|
+
ask you for a password at startup-time. You will set a password later
|
29
|
+
using sha256.rb.
|
30
30
|
|
31
|
-
|
31
|
+
ssh-keygen should have created the following two files
|
32
|
+
/etc/yus/data/user_tom.pub
|
33
|
+
/etc/yus/data/user_tom
|
32
34
|
|
33
|
-
|
34
|
-
/etc/yus/data/yus.key
|
35
|
+
Create the file /etc/yus/data/user_tom.crt, by calling
|
35
36
|
|
36
|
-
|
37
|
+
openssl req -key /etc/yus/data/user_tom -out /etc/yus/data/user_tom.crt -new -x509 -batch -passin pass:''
|
37
38
|
|
38
|
-
|
39
|
+
Determine the SHA256 value of the root_pass (password for the yus root user, in this example hatakeyama). We
|
40
|
+
use the sha256.rb which is in the root of the yus checkout.
|
39
41
|
|
40
|
-
|
42
|
+
ruby sha256.rb hatakeyama
|
43
|
+
|
44
|
+
Create the file /etc/yus/yus.yml with the following content (using the output of the previous command)
|
41
45
|
|
42
|
-
|
43
|
-
root_name:
|
44
|
-
root_pass:
|
46
|
+
---
|
47
|
+
root_name: user_tom@domain.com
|
48
|
+
root_pass: 48714061119f3bb753a0c63dd4230f641ab79e58eb603fc263925c53580acdf1 # [the SHA2-hash of your password]
|
45
49
|
log_level: DEBUG
|
46
|
-
ssl_key:
|
47
|
-
ssl_cert: /etc/yus/data/
|
50
|
+
ssl_key: /etc/yus/data/user_tom # [path to an rsa private key]
|
51
|
+
ssl_cert: /etc/yus/data/user_tom.crt # [path to a ssl x509 certificate]
|
48
52
|
session_timeout: 3600
|
49
53
|
|
50
|
-
|
54
|
+
Setup the PostgresDB like this
|
55
|
+
|
56
|
+
sudo -iHu postgres
|
57
|
+
psql -c "create user yus with password 'hatakeyama';"
|
58
|
+
psql -c "create database yus with encoding 'utf-8' template template0;"
|
59
|
+
psql -c "grant all privileges on database yus to yus";
|
60
|
+
exit
|
61
|
+
|
62
|
+
Verify that you have a line in you postgres /etc/postgresql-<veryion>/pg_hba.conf like the following
|
63
|
+
local all all trust
|
51
64
|
|
52
|
-
|
65
|
+
If not you will get errors like this 'FATAL: Peer authentication failed for user "yus" (DBI::OperationalError)' while verifying
|
66
|
+
that you can connect to your new postgres database yus as user yus. When asked for the password answer with hatakeyama
|
53
67
|
|
54
|
-
|
55
|
-
require 'digest/sha2'
|
56
|
-
print "password: ", ARGV[0], "\n"
|
57
|
-
print "SHA256 encoding: ",Digest::SHA256.hexdigest(ARGV[0]),"\n"
|
68
|
+
psql --user=yus --host=localhost --password yus -c '\dT'
|
58
69
|
|
59
|
-
|
70
|
+
Now you should be able to start the yus-daemon
|
60
71
|
|
61
|
-
|
62
|
-
password: hatakeyama
|
63
|
-
SHA256 encoding: 48714061119f3bb753a0c63dd4230f641ab79e58eb603fc263925c53580acdf1
|
72
|
+
bin/yusd &
|
64
73
|
|
65
74
|
== Note
|
66
75
|
|
@@ -74,20 +83,13 @@ To create root_pass do
|
|
74
83
|
starts. root_pass and ssl_key are independent from each other. The password does
|
75
84
|
not have to be the same.
|
76
85
|
|
77
|
-
|
78
|
-
|
79
|
-
/etc/yus/yus.yml
|
80
|
-
|
81
|
-
for the yus server setup. When you start the yus server or you use yus admin
|
82
|
-
commands, the server asks you for the password.
|
86
|
+
Create a new user with
|
83
87
|
|
84
|
-
|
85
|
-
|
86
|
-
* openssl req -new -x509 -key .ssh/id_rsa -out .ssh/id_rsa.crt
|
88
|
+
yus_add_user user_tom@domain.com login org.oddb.RootUser
|
87
89
|
|
88
|
-
|
90
|
+
Verify that everthings is okay by calling
|
89
91
|
|
90
|
-
|
92
|
+
yus_show user_tom@domain.com
|
91
93
|
|
92
94
|
== NOTE
|
93
95
|
|
@@ -108,12 +110,8 @@ Create a new user with
|
|
108
110
|
> end
|
109
111
|
> }
|
110
112
|
> end
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
bin/yusd
|
115
|
-
|
116
|
-
is running. Then you have to grant
|
113
|
+
|
114
|
+
Then you have to grant
|
117
115
|
|
118
116
|
yus_grant zdavatz@ywesee.com edit yus.entities
|
119
117
|
|
@@ -158,28 +156,17 @@ For installing extensive user privileges for ch.oddb.org you need to do the foll
|
|
158
156
|
> become gray. The other box can be checked, but
|
159
157
|
> as a default of RootUser, the three privileges are checked.
|
160
158
|
|
161
|
-
To run the tests you
|
162
|
-
|
163
|
-
flexmock (0.8.6)
|
164
|
-
|
165
|
-
== IMPORTANT
|
159
|
+
To run the tests you call
|
166
160
|
|
167
|
-
|
168
|
-
|
169
|
-
also see: http://dev.ywesee.com/wiki.php/Michal/DayTwo#dbi
|
161
|
+
bundle install
|
162
|
+
bundle exec rake test
|
170
163
|
|
171
|
-
|
172
|
-
gem install odba
|
164
|
+
== The setup is explained by
|
173
165
|
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
createuser yus
|
178
|
-
createdb yus
|
179
|
-
exit
|
180
|
-
cd [yus-git-reposito]
|
181
|
-
ruby bin/yusd
|
166
|
+
* Masa in http://dev.ywesee.com/wiki.php/Masa/20101019-debug-importGkv#SetYus
|
167
|
+
* Michal in http://dev.ywesee.com/wiki.php/Michal/DayTwo#dbi
|
168
|
+
* Niklaus using a vagrant/puppet setup. See https://github.com/ngiger/vagrant-oddb_org
|
182
169
|
|
183
|
-
|
170
|
+
There exists a template to create the files under /etc/yus. Have a look at
|
184
171
|
|
185
|
-
*
|
172
|
+
* https://github.com/ngiger/vagrant-oddb_org/blob/master/static-modules/oddb_org/templates/yus_grant_user.rb.erb
|
data/History.txt
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
=== 1.0.2 / 01.10.2014
|
2
|
+
|
3
|
+
* Added bin/yus_dump to dump yus-database into data/yus_dump.yml
|
4
|
+
* Added concerned user and result when logging allowed?
|
5
|
+
* Improved unit-tests
|
6
|
+
* Made travis-ci pass for 1.8.7 and 2.1.2
|
7
|
+
|
1
8
|
=== 1.0.1 / 18.06.2013
|
2
9
|
|
3
10
|
* Rename pg driver name to Pg
|
data/bin/yus_add_user
CHANGED
data/bin/yus_delete_user
CHANGED
data/bin/yus_grant
CHANGED
data/bin/yus_passwd
CHANGED
data/bin/yus_show
CHANGED
data/bin/yusd
CHANGED
data/lib/yus/server.rb
CHANGED
data/lib/yus/session.rb
CHANGED
@@ -4,6 +4,9 @@
|
|
4
4
|
require 'drb'
|
5
5
|
require 'thread'
|
6
6
|
require 'yus/entity'
|
7
|
+
require 'pp'
|
8
|
+
require 'yaml'
|
9
|
+
|
7
10
|
begin
|
8
11
|
require 'encoding/character/utf-8'
|
9
12
|
rescue LoadError
|
@@ -30,6 +33,27 @@ module Yus
|
|
30
33
|
}
|
31
34
|
touch!
|
32
35
|
end
|
36
|
+
def dump_to_yaml(yaml_name=nil)
|
37
|
+
yaml_name ||= File.expand_path(File.join(__FILE__, '..', '..', '..', 'data', 'yus_dump.yml'))
|
38
|
+
FileUtils.makedirs(File.dirname(yaml_name))
|
39
|
+
if entities.is_a?(Hash) # when running unit tests, where MockPersistence uses a Hash
|
40
|
+
File.open(yaml_name, 'w') { |f| YAML.dump(@needle.persistence, f) }
|
41
|
+
else
|
42
|
+
File.open(yaml_name, 'w') {
|
43
|
+
|fh|
|
44
|
+
ids = entities.collect { |item| item.odba_id }
|
45
|
+
ids.each { |odba_id|
|
46
|
+
begin
|
47
|
+
yaml = YAML.dump(ODBA.cache.fetch(odba_id, nil))
|
48
|
+
fh.puts yaml
|
49
|
+
fh.puts
|
50
|
+
rescue
|
51
|
+
end
|
52
|
+
}
|
53
|
+
}
|
54
|
+
info "dumped #{entities.size} entities to #{yaml_name}"
|
55
|
+
end
|
56
|
+
end
|
33
57
|
def create_entity(name, valid_until=nil, valid_from=Time.now)
|
34
58
|
info("create_entity(name=#{name}, valid_until=#{valid_until}, valid_from=#{valid_from})")
|
35
59
|
entity = nil
|
@@ -63,9 +87,6 @@ module Yus
|
|
63
87
|
allow_or_fail('edit', 'yus.entities')
|
64
88
|
user = find_or_fail(name)
|
65
89
|
group = find_or_fail(groupname)
|
66
|
-
puts group.inspect
|
67
|
-
puts user.leave(group).inspect
|
68
|
-
puts user.inspect
|
69
90
|
save(user, group)
|
70
91
|
}
|
71
92
|
touch!
|
@@ -270,8 +291,9 @@ module Yus
|
|
270
291
|
super(needle)
|
271
292
|
end
|
272
293
|
def allowed?(*args)
|
273
|
-
|
274
|
-
@user.allowed?(
|
294
|
+
res = @user.allowed?(*args)
|
295
|
+
debug("#{@user.name} allowed?(#{args.join(', ')}) returns #{res}")
|
296
|
+
res
|
275
297
|
end
|
276
298
|
def name
|
277
299
|
@user.name
|
data/test/suite.rb
CHANGED
@@ -3,6 +3,13 @@
|
|
3
3
|
|
4
4
|
$: << File.dirname(File.expand_path(__FILE__))
|
5
5
|
|
6
|
+
if /^1\.8/.match(RUBY_VERSION)
|
7
|
+
gem 'minitest'
|
8
|
+
require 'minitest/autorun'
|
9
|
+
else
|
10
|
+
require 'test/unit'
|
11
|
+
end
|
12
|
+
|
6
13
|
Dir.foreach(File.dirname(__FILE__)) { |file|
|
7
14
|
require file if /^test_.*\.rb$/o.match(file)
|
8
15
|
}
|
data/test/test_entity.rb
CHANGED
@@ -4,11 +4,12 @@
|
|
4
4
|
|
5
5
|
$: << File.expand_path('../lib', File.dirname(__FILE__))
|
6
6
|
|
7
|
-
|
7
|
+
gem 'minitest'
|
8
|
+
require 'minitest/autorun'
|
8
9
|
require 'yus/entity'
|
9
10
|
|
10
11
|
module Yus
|
11
|
-
class TestEntity <
|
12
|
+
class TestEntity <Minitest::Test
|
12
13
|
def setup
|
13
14
|
@user = Entity.new('user')
|
14
15
|
end
|
@@ -58,15 +59,11 @@ module Yus
|
|
58
59
|
group1 = Entity.new('A Group')
|
59
60
|
group2 = Entity.new('Another Group')
|
60
61
|
assert_equal([], @user.affiliations)
|
61
|
-
|
62
|
-
@user.join(group1)
|
63
|
-
}
|
62
|
+
@user.join(group1)
|
64
63
|
assert_raises(CircularAffiliationError) {
|
65
64
|
group1.join(@user)
|
66
65
|
}
|
67
|
-
|
68
|
-
group1.join(group2)
|
69
|
-
}
|
66
|
+
group1.join(group2)
|
70
67
|
assert_raises(CircularAffiliationError) {
|
71
68
|
group2.join(@user)
|
72
69
|
}
|
data/test/test_privilege.rb
CHANGED
@@ -3,11 +3,12 @@
|
|
3
3
|
|
4
4
|
$: << File.expand_path('../lib', File.dirname(__FILE__))
|
5
5
|
|
6
|
-
|
6
|
+
gem 'minitest'
|
7
|
+
require 'minitest/autorun'
|
7
8
|
require 'yus/privilege'
|
8
9
|
|
9
10
|
module Yus
|
10
|
-
class TestPrivilege <
|
11
|
+
class TestPrivilege <Minitest::Test
|
11
12
|
def setup
|
12
13
|
@privilege = Privilege.new
|
13
14
|
end
|
data/test/test_server.rb
CHANGED
@@ -3,7 +3,6 @@
|
|
3
3
|
|
4
4
|
$: << File.expand_path('../lib', File.dirname(__FILE__))
|
5
5
|
|
6
|
-
require 'test/unit'
|
7
6
|
require 'yus/server'
|
8
7
|
require 'flexmock'
|
9
8
|
|
@@ -11,7 +10,7 @@ module Yus
|
|
11
10
|
class Server
|
12
11
|
public :authenticate, :clean
|
13
12
|
end
|
14
|
-
class TestServer < Test
|
13
|
+
class TestServer < Minitest::Test
|
15
14
|
def setup
|
16
15
|
@config = FlexMock.new
|
17
16
|
@config.should_receive(:cleaner_interval).and_return { 100000000 }
|
@@ -50,10 +49,8 @@ module Yus
|
|
50
49
|
true
|
51
50
|
}
|
52
51
|
@persistence.should_receive(:find_entity).times(1).and_return { user }
|
53
|
-
|
54
|
-
|
55
|
-
assert_equal(user, result)
|
56
|
-
}
|
52
|
+
result = @server.authenticate('name', 'password')
|
53
|
+
assert_equal(user, result)
|
57
54
|
end
|
58
55
|
def test_autosession
|
59
56
|
@server.autosession('domain') { |session|
|
@@ -74,12 +71,10 @@ module Yus
|
|
74
71
|
}
|
75
72
|
@persistence.should_receive(:find_entity).times(1).and_return { user }
|
76
73
|
@persistence.should_receive(:save_entity).times(1)
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
assert_equal([session], @server.instance_variable_get('@sessions'))
|
82
|
-
}
|
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'))
|
83
78
|
end
|
84
79
|
def test_logout
|
85
80
|
needle = FlexMock.new
|
@@ -110,7 +105,7 @@ module Yus
|
|
110
105
|
assert_equal([], sessions)
|
111
106
|
end
|
112
107
|
end
|
113
|
-
class TestServerCleaner < Test
|
108
|
+
class TestServerCleaner < Minitest::Test
|
114
109
|
def test_autoclean
|
115
110
|
config = FlexMock.new
|
116
111
|
config.should_receive(:cleaner_interval).and_return { 0.5 }
|
data/test/test_session.rb
CHANGED
@@ -3,16 +3,19 @@
|
|
3
3
|
|
4
4
|
$: << File.expand_path('../lib', File.dirname(__FILE__))
|
5
5
|
|
6
|
-
|
6
|
+
gem "minitest"
|
7
|
+
require "minitest/autorun"
|
7
8
|
require 'flexmock'
|
8
9
|
require 'yus/session'
|
9
10
|
require 'digest/sha2'
|
11
|
+
require 'fileutils'
|
12
|
+
require File.expand_path(File.dirname(__FILE__)+'/helpers.rb')
|
10
13
|
|
11
14
|
module Yus
|
12
15
|
class Session
|
13
16
|
public :touch!
|
14
17
|
end
|
15
|
-
class TestAutoSession < Test
|
18
|
+
class TestAutoSession < Minitest::Test
|
16
19
|
def setup
|
17
20
|
@config = FlexMock.new
|
18
21
|
@config.should_receive(:session_timeout).and_return { 0.5 }
|
@@ -41,9 +44,7 @@ module Yus
|
|
41
44
|
}
|
42
45
|
@persistence.should_receive(:find_entity, 1).times(1).and_return { user }
|
43
46
|
res = nil
|
44
|
-
|
45
|
-
res = @session.get_entity_preference('name', 'preference_key', 'domain')
|
46
|
-
}
|
47
|
+
res = @session.get_entity_preference('name', 'preference_key', 'domain')
|
47
48
|
assert_nil(res)
|
48
49
|
end
|
49
50
|
def test_get_entity_preference__success
|
@@ -55,9 +56,7 @@ module Yus
|
|
55
56
|
}
|
56
57
|
@persistence.should_receive(:find_entity, 1).times(1).and_return { user }
|
57
58
|
res = nil
|
58
|
-
|
59
|
-
res = @session.get_entity_preference('name', 'preference_key', 'domain')
|
60
|
-
}
|
59
|
+
res = @session.get_entity_preference('name', 'preference_key', 'domain')
|
61
60
|
assert_equal('value', res)
|
62
61
|
end
|
63
62
|
def test_get_entity_preferences__no_user
|
@@ -75,9 +74,7 @@ module Yus
|
|
75
74
|
}
|
76
75
|
@persistence.should_receive(:find_entity, 1).times(1).and_return { user }
|
77
76
|
res = nil
|
78
|
-
|
79
|
-
res = @session.get_entity_preferences('name', ['preference_key'], 'domain')
|
80
|
-
}
|
77
|
+
res = @session.get_entity_preferences('name', ['preference_key'], 'domain')
|
81
78
|
assert_equal({'preference_key' => nil}, res)
|
82
79
|
end
|
83
80
|
def test_get_entity_preferences__success
|
@@ -89,9 +86,7 @@ module Yus
|
|
89
86
|
}
|
90
87
|
@persistence.should_receive(:find_entity, 1).times(1).and_return { user }
|
91
88
|
res = nil
|
92
|
-
|
93
|
-
res = @session.get_entity_preferences('name', ['preference_key'], 'domain')
|
94
|
-
}
|
89
|
+
res = @session.get_entity_preferences('name', ['preference_key'], 'domain')
|
95
90
|
assert_equal({'preference_key' => 'value'}, res)
|
96
91
|
end
|
97
92
|
def test_set_entity_preference__no_user
|
@@ -176,7 +171,6 @@ module Yus
|
|
176
171
|
false
|
177
172
|
}
|
178
173
|
@persistence.should_receive(:find_entity, 1).times(1).and_return { user }
|
179
|
-
res = nil
|
180
174
|
assert_raises(NotPrivilegedError) {
|
181
175
|
@session.reset_entity_password('name', 'token', 'password')
|
182
176
|
}
|
@@ -200,9 +194,7 @@ module Yus
|
|
200
194
|
@persistence.should_receive(:save_entity, 1).times(1).and_return { |entity|
|
201
195
|
assert_equal(user, entity)
|
202
196
|
}
|
203
|
-
|
204
|
-
@session.reset_entity_password('name', 'token', 'password')
|
205
|
-
}
|
197
|
+
@session.reset_entity_password('name', 'token', 'password')
|
206
198
|
end
|
207
199
|
def test_grant__no_user
|
208
200
|
@persistence.should_receive(:find_entity).and_return { |name|
|
@@ -229,16 +221,24 @@ module Yus
|
|
229
221
|
@session.grant('username', 'action', 'key')
|
230
222
|
end
|
231
223
|
end
|
232
|
-
class TestEntitySession < Test
|
224
|
+
class TestEntitySession < Minitest::Test
|
225
|
+
HexDigestSample = 'cleartext'
|
233
226
|
def setup
|
234
|
-
@config = FlexMock.new
|
227
|
+
@config = FlexMock.new('config')
|
235
228
|
@config.should_receive(:session_timeout).and_return { 0.5 }
|
236
|
-
@
|
237
|
-
@
|
238
|
-
@
|
229
|
+
@config.should_receive(:token_lifetime).and_return { 0.2 }
|
230
|
+
@digest = FlexMock.new('digest')
|
231
|
+
@digest.should_receive(:hexdigest).and_return { HexDigestSample }
|
232
|
+
@config.should_receive(:digest).by_default.and_return {@digest}
|
233
|
+
@user = FlexMock.new('user')
|
234
|
+
@user.should_receive(:set_token).and_return { 'set_token' }
|
235
|
+
@user.should_receive(:name).and_return { 'name' }
|
236
|
+
@persistence = FlexMock.new('persistence')
|
237
|
+
@persistence.should_receive(:save_entity)
|
238
|
+
@logger = FlexMock.new('logger')
|
239
239
|
@logger.should_receive(:info).and_return {}
|
240
240
|
@logger.should_receive(:debug).and_return {}
|
241
|
-
@needle = FlexMock.new
|
241
|
+
@needle = FlexMock.new('needle')
|
242
242
|
@needle.should_receive(:persistence).and_return { @persistence }
|
243
243
|
@needle.should_receive(:config).and_return { @config }
|
244
244
|
@needle.should_receive(:logger).and_return { @logger }
|
@@ -282,6 +282,10 @@ module Yus
|
|
282
282
|
}
|
283
283
|
@session.create_entity('name')
|
284
284
|
end
|
285
|
+
def test_generate_token
|
286
|
+
assert_equal(false, @session.expired?)
|
287
|
+
assert_equal(HexDigestSample, @session.generate_token)
|
288
|
+
end
|
285
289
|
def test_create_entity__duplicate
|
286
290
|
@user.should_receive(:allowed?).and_return { |action, key|
|
287
291
|
assert_equal('edit', action)
|
@@ -317,9 +321,7 @@ module Yus
|
|
317
321
|
true
|
318
322
|
}
|
319
323
|
@persistence.should_receive(:entities).and_return { [] }
|
320
|
-
|
321
|
-
assert_equal([], @session.entities)
|
322
|
-
}
|
324
|
+
assert_equal([], @session.entities)
|
323
325
|
end
|
324
326
|
def test_find_entity__not_allowed
|
325
327
|
@user.should_receive(:allowed?).and_return { |action, key|
|
@@ -787,9 +789,7 @@ module Yus
|
|
787
789
|
nil
|
788
790
|
}
|
789
791
|
res = nil
|
790
|
-
|
791
|
-
res = @session.get_preference('preference_key')
|
792
|
-
}
|
792
|
+
res = @session.get_preference('preference_key')
|
793
793
|
assert_nil(res)
|
794
794
|
end
|
795
795
|
def test_get_entity_preference__success
|
@@ -799,27 +799,25 @@ module Yus
|
|
799
799
|
'value'
|
800
800
|
}
|
801
801
|
res = nil
|
802
|
-
|
803
|
-
res = @session.get_preference('preference_key')
|
804
|
-
}
|
802
|
+
res = @session.get_preference('preference_key')
|
805
803
|
assert_equal('value', res)
|
806
804
|
end
|
807
805
|
def test_ping
|
808
806
|
assert_equal(true, @session.ping)
|
809
807
|
end
|
810
808
|
end
|
811
|
-
class TestRootSession < Test
|
809
|
+
class TestRootSession < Minitest::Test
|
812
810
|
def setup
|
813
|
-
@config = FlexMock.new
|
811
|
+
@config = FlexMock.new('config')
|
814
812
|
@config.should_receive(:session_timeout).and_return { 0.5 }
|
815
|
-
@
|
816
|
-
@
|
813
|
+
@needle = FlexMock.new('needle')
|
814
|
+
@persistence = MockPersistence.new
|
815
|
+
@logger = FlexMock.new('logger')
|
817
816
|
@logger.should_receive(:info).and_return {}
|
818
|
-
@logger.should_receive(:debug).and_return {}
|
819
|
-
@needle = FlexMock.new
|
820
817
|
@needle.should_receive(:persistence).and_return { @persistence }
|
821
|
-
@needle.should_receive(:
|
822
|
-
@needle.should_receive(:
|
818
|
+
@needle.should_receive(:logger).and_return { @logger }.by_default
|
819
|
+
@needle.should_receive(:config).and_return { @config }.by_default
|
820
|
+
@config.should_receive(:session_timeout).and_return { 0.5 }
|
823
821
|
@session = RootSession.new(@needle)
|
824
822
|
end
|
825
823
|
def test_valid
|
@@ -832,5 +830,80 @@ module Yus
|
|
832
830
|
@config.should_receive(:root_name).and_return { 'root_name' }
|
833
831
|
assert_equal('root_name', @session.name)
|
834
832
|
end
|
833
|
+
def test_delete_entity
|
834
|
+
entity_name = 'entity_name'
|
835
|
+
entity = @session.create_entity(entity_name, 'entity_pass')
|
836
|
+
assert_equal(entity, @session.find_entity(entity_name))
|
837
|
+
@session.delete_entity(entity_name)
|
838
|
+
assert_nil(@session.find_entity(entity_name))
|
839
|
+
end
|
840
|
+
def test_last_login
|
841
|
+
entity_name = 'entity_name'
|
842
|
+
entity = @session.create_entity(entity_name, 'entity_pass')
|
843
|
+
domain = 'domain'
|
844
|
+
entity.login(domain)
|
845
|
+
assert_equal(entity, @session.find_entity(entity_name))
|
846
|
+
#require 'pry'; binding.pry
|
847
|
+
assert_in_delta(Time.now.to_f, @session.last_login(entity_name, domain).to_f)
|
848
|
+
end
|
849
|
+
def test_show
|
850
|
+
assert_raises(UnknownEntityError) {
|
851
|
+
@session.show('unkown_name')
|
852
|
+
}
|
853
|
+
entity_name = 'entity_name'
|
854
|
+
@session.create_entity(entity_name, 'entity_pass')
|
855
|
+
assert_kind_of(String, @session.show(entity_name))
|
856
|
+
assert(@session.show(entity_name).index(entity_name) > 0)
|
857
|
+
end
|
858
|
+
|
859
|
+
def setup_for_dump
|
860
|
+
assert_raises(UnknownEntityError) {
|
861
|
+
@session.show('unkown_name')
|
862
|
+
}
|
863
|
+
@entity_name = 'entity_name'
|
864
|
+
entity_name2 = 'second_name'
|
865
|
+
password = 'entity_pass'
|
866
|
+
groupname = 'a_yus_group'
|
867
|
+
@session.create_entity(@entity_name, password)
|
868
|
+
@session.create_entity(entity_name2, password)
|
869
|
+
@session.create_entity(groupname, password)
|
870
|
+
assert_kind_of(String, @session.show(@entity_name))
|
871
|
+
assert(@session.show(@entity_name).index(@entity_name) > 0)
|
872
|
+
assert(@session.show(entity_name2).index(entity_name2) > 0)
|
873
|
+
@session.affiliate(@entity_name, groupname)
|
874
|
+
@session.grant(@entity_name, 'action', 'key')
|
875
|
+
|
876
|
+
@needle = FlexMock.new('needle')
|
877
|
+
@needle.should_receive(:persistence).and_return { @persistence }
|
878
|
+
@needle.should_receive(:config).and_return { @config }
|
879
|
+
@needle.should_receive(:logger).and_return { @logger }
|
880
|
+
end
|
881
|
+
|
882
|
+
def test_dump_to_named_yaml
|
883
|
+
setup_for_dump
|
884
|
+
tmpdir = File.expand_path(File.join(__FILE__, '../tmp'))
|
885
|
+
outFile = File.join(tmpdir, 'yus_dump.yaml')
|
886
|
+
assert(@session.dump_to_yaml(outFile))
|
887
|
+
assert(File.exist?(outFile))
|
888
|
+
assert(File.size(outFile) > 0)
|
889
|
+
dump_content = IO.read(outFile)
|
890
|
+
# puts "#{outFile} is #{File.size(outFile)} bytes lang and contains \n#{dump_content}"
|
891
|
+
refute_nil(dump_content)
|
892
|
+
refute_nil(dump_content.index(@entity_name))
|
893
|
+
FileUtils.rm_rf(tmpdir)
|
894
|
+
skip("Tests saving preferences")
|
895
|
+
end
|
896
|
+
|
897
|
+
def test_dump_to_default
|
898
|
+
setup_for_dump
|
899
|
+
assert(@session.dump_to_yaml)
|
900
|
+
outFile = File.expand_path(File.join(__FILE__, '..', '..', 'data', 'yus_dump.yml'))
|
901
|
+
assert(File.exist?(outFile), "outfile #{outFile} should exist")
|
902
|
+
assert(File.size(outFile) > 0)
|
903
|
+
dump_content = IO.read(outFile)
|
904
|
+
# puts "#{outFile} is #{File.size(outFile)} bytes lang and contains \n#{dump_content}"
|
905
|
+
refute_nil(dump_content)
|
906
|
+
refute_nil(dump_content.index(@entity_name))
|
907
|
+
end
|
835
908
|
end
|
836
909
|
end
|
metadata
CHANGED
@@ -1,48 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Yasuhiro Asaka, Zeno R.R. Davatz
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-10-01 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rdoc
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ~>
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version: '
|
19
|
+
version: '4.0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ~>
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
26
|
+
version: '4.0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: hoe
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
31
|
- - ~>
|
36
32
|
- !ruby/object:Gem::Version
|
37
|
-
version: '
|
33
|
+
version: '3.6'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
38
|
- - ~>
|
44
39
|
- !ruby/object:Gem::Version
|
45
|
-
version: '
|
40
|
+
version: '3.6'
|
46
41
|
description: ! 'ywesee user server. Works with the ywesee webframework and all the
|
47
42
|
ywesee
|
48
43
|
|
@@ -62,6 +57,7 @@ extra_rdoc_files:
|
|
62
57
|
- History.txt
|
63
58
|
- README.txt
|
64
59
|
files:
|
60
|
+
- .gemtest
|
65
61
|
- Guide.txt
|
66
62
|
- History.txt
|
67
63
|
- LICENSE
|
@@ -87,9 +83,9 @@ files:
|
|
87
83
|
- test/test_privilege.rb
|
88
84
|
- test/test_server.rb
|
89
85
|
- test/test_session.rb
|
90
|
-
- .gemtest
|
91
86
|
homepage: http://scm.ywesee.com/?p=yus/.git;a=summary
|
92
87
|
licenses: []
|
88
|
+
metadata: {}
|
93
89
|
post_install_message:
|
94
90
|
rdoc_options:
|
95
91
|
- --main
|
@@ -97,22 +93,20 @@ rdoc_options:
|
|
97
93
|
require_paths:
|
98
94
|
- lib
|
99
95
|
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
-
none: false
|
101
96
|
requirements:
|
102
97
|
- - ! '>='
|
103
98
|
- !ruby/object:Gem::Version
|
104
99
|
version: '0'
|
105
100
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
-
none: false
|
107
101
|
requirements:
|
108
102
|
- - ! '>='
|
109
103
|
- !ruby/object:Gem::Version
|
110
104
|
version: '0'
|
111
105
|
requirements: []
|
112
106
|
rubyforge_project: yus
|
113
|
-
rubygems_version:
|
107
|
+
rubygems_version: 2.3.0
|
114
108
|
signing_key:
|
115
|
-
specification_version:
|
109
|
+
specification_version: 4
|
116
110
|
summary: ywesee user server
|
117
111
|
test_files:
|
118
112
|
- test/test_entity.rb
|