ucb_confluence 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.svnignore +6 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +37 -0
- data/INTERNALS.md +12 -0
- data/README.md +41 -0
- data/Rakefile +21 -0
- data/TODO.md +8 -0
- data/bin/ucb_confluence +84 -0
- data/config/.svnignore +1 -0
- data/config/config.skel.yml +21 -0
- data/lib/confluence.rb +57 -0
- data/lib/confluence/config.rb +31 -0
- data/lib/confluence/conn.rb +35 -0
- data/lib/confluence/group.rb +56 -0
- data/lib/confluence/jobs/disable_expired_users.rb +87 -0
- data/lib/confluence/jobs/ist_ldap_sync.rb +154 -0
- data/lib/confluence/user.rb +312 -0
- data/lib/confluence/version.rb +3 -0
- data/spec/confluence/config_spec.rb +18 -0
- data/spec/confluence/confluence_spec.rb +21 -0
- data/spec/confluence/conn_spec.rb +9 -0
- data/spec/confluence/group_spec.rb +45 -0
- data/spec/confluence/jobs/disable_expired_users_spec.rb +51 -0
- data/spec/confluence/jobs/ist_ldap_sync_spec.rb +77 -0
- data/spec/confluence/user_spec.rb +221 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +12 -0
- data/ucb_confluence.gemspec +31 -0
- metadata +197 -0
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe Confluence::Config do
|
5
|
+
before(:all) do
|
6
|
+
@config_yml = "#{Confluence.root()}/config/config.yml"
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
it "should load its configuration" do
|
11
|
+
config = Confluence::Config.new(@config_yml)
|
12
|
+
config[:server_url].should match(/http/)
|
13
|
+
config[:ldap_url].should match(/ldap/)
|
14
|
+
config[:username].should_not be_nil
|
15
|
+
config[:password].should_not be_nil
|
16
|
+
config[:user_default_password].should_not be_nil
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe Confluence do
|
5
|
+
before(:all) do
|
6
|
+
Confluence.config = Confluence::Config.new("#{Confluence.root()}/config/config.yml")
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
it "should initialize" do
|
11
|
+
Confluence.conn.should be_a(Confluence::Conn)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should set ROOT" do
|
15
|
+
File.expand_path(File.dirname(__FILE__) + '/../../').should == Confluence.root()
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should configure logging" do
|
19
|
+
Confluence.logger.should_not be_nil
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe Confluence::Conn do
|
5
|
+
it "should connect to confluence" do
|
6
|
+
config = Confluence::Config.new("#{Confluence.root()}/config/config.yml")
|
7
|
+
Confluence::Conn.new(config).should be_a(Confluence::Conn)
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe Confluence::Group do
|
5
|
+
before(:all) do
|
6
|
+
Confluence.config = Confluence::Config.new("#{Confluence.root()}/config/config.yml")
|
7
|
+
Confluence::Group.delete("atestgroup") if Confluence::Group.all.include?("atestgroup")
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
it "should get all groups" do
|
12
|
+
Confluence::Group.all.should_not be_empty
|
13
|
+
end
|
14
|
+
|
15
|
+
context "create()" do
|
16
|
+
it "should create a group" do
|
17
|
+
Confluence::Group.all.should_not include("atestgroup")
|
18
|
+
Confluence::Group.create("atestgroup").should be_true
|
19
|
+
Confluence::Group.all.should include("atestgroup")
|
20
|
+
Confluence::Group.delete("atestgroup")
|
21
|
+
Confluence::Group.all.should_not include("atestgroup")
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should not create a group if the group already exists" do
|
25
|
+
Confluence::Group.create("atestgroup")
|
26
|
+
Confluence::Group.all.should include("atestgroup")
|
27
|
+
Confluence::Group.create("atestgroup").should be_false
|
28
|
+
Confluence::Group.delete("atestgroup")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "delete()" do
|
33
|
+
it "should delete a group" do
|
34
|
+
Confluence::Group.create("atestgroup")
|
35
|
+
Confluence::Group.all.should include("atestgroup")
|
36
|
+
Confluence::Group.delete("atestgroup").should be_true
|
37
|
+
Confluence::Group.all.should_not include("atestgroup")
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should not delete a group if the group does not exist" do
|
41
|
+
Confluence::Group.all.should_not include("atestgroup")
|
42
|
+
Confluence::Group.delete("atestgroup").should be_false
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe Confluence::Jobs::DisableExpiredUsers do
|
5
|
+
before(:all) do
|
6
|
+
Confluence.config = Confluence::Config.new("#{Confluence.root()}/config/config.yml")
|
7
|
+
end
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
@job = Confluence::Jobs::DisableExpiredUsers.new
|
11
|
+
|
12
|
+
user = Confluence::User.find_by_name("n1")
|
13
|
+
user.delete() if user
|
14
|
+
|
15
|
+
@user = Confluence::User.new({:name => "n1", :fullname => "fn1", :email => "e@b.e"})
|
16
|
+
end
|
17
|
+
|
18
|
+
after(:each) do
|
19
|
+
@user.delete()
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
context "#disable_expired_users()" do
|
24
|
+
it "should disable users no longer in LDAP" do
|
25
|
+
@user.save()
|
26
|
+
@job.stub!(:confluence_user_names).and_return([@user.name])
|
27
|
+
@job.stub!(:find_in_confluence).and_return(@user)
|
28
|
+
@job.stub!(:find_in_ldap).and_return(nil)
|
29
|
+
|
30
|
+
@user.disabled?.should be_false
|
31
|
+
@job.disable_expired_users()
|
32
|
+
@user.disabled?.should be_true
|
33
|
+
@user.groups.should be_empty
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should disable user's LDAP considers expired" do
|
37
|
+
ldap_user = mock("user1", {:ldap_uid => "n1", :first_name => "f1",
|
38
|
+
:last_name => "l1", :email => "e1"})
|
39
|
+
@user.save()
|
40
|
+
@job.stub!(:confluence_user_names).and_return([@user.name])
|
41
|
+
@job.stub!(:find_in_confluence).and_return(@user)
|
42
|
+
@job.stub!(:find_in_ldap).and_return(ldap_user)
|
43
|
+
@job.stub!(:eligible_for_confluence?).and_return(false)
|
44
|
+
|
45
|
+
@user.disabled?.should be_false
|
46
|
+
@job.disable_expired_users()
|
47
|
+
@user.disabled?.should be_true
|
48
|
+
@user.groups.should be_empty
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe Confluence::Jobs::IstLdapSync do
|
5
|
+
before(:all) do
|
6
|
+
Confluence.config = Confluence::Config.new("#{Confluence.root()}/config/config.yml")
|
7
|
+
end
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
@job = Confluence::Jobs::IstLdapSync.new
|
11
|
+
|
12
|
+
user = Confluence::User.find_by_name("n1")
|
13
|
+
user.delete() if user
|
14
|
+
|
15
|
+
@user = Confluence::User.new({:name => "n1", :fullname => "fn1", :email => "e@b.e"})
|
16
|
+
end
|
17
|
+
|
18
|
+
after(:each) do
|
19
|
+
@user.delete()
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
context "#sync_ist_from_ldap()" do
|
24
|
+
it "should add IST users found in LDAP to Confluence" do
|
25
|
+
ldap_user = mock("user1", {:uid => "n1", :first_name => "f1",
|
26
|
+
:last_name => "l1", :email => "e1"})
|
27
|
+
@job.stub!(:ist_people).and_return([ldap_user])
|
28
|
+
@job.stub!(:eligible_for_confluence?).and_return(true)
|
29
|
+
@job.stub!(:find_or_new_user).and_return(@user)
|
30
|
+
|
31
|
+
Confluence::User.exists?(@user.name).should be_false
|
32
|
+
@job.sync_ist_from_ldap()
|
33
|
+
@user = Confluence::User.find_by_name(@user.name)
|
34
|
+
@user.groups.should have(2).records
|
35
|
+
@user.groups.should include(Confluence::User::DEFAULT_GROUP)
|
36
|
+
@user.groups.should include(Confluence::Jobs::IstLdapSync::IST_GROUP)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should give new IST users found in LDAP membership to the IST_GROUP" do
|
40
|
+
ldap_user = mock("user1", {:uid => "n1", :first_name => "f1",
|
41
|
+
:last_name => "l1", :email => "e1"})
|
42
|
+
@job.stub!(:ist_people).and_return([ldap_user])
|
43
|
+
@job.stub!(:eligible_for_confluence?).and_return(true)
|
44
|
+
@job.stub!(:find_or_new_user).and_return(@user)
|
45
|
+
|
46
|
+
|
47
|
+
@user.save()
|
48
|
+
Confluence::User.exists?(@user.name).should be_true
|
49
|
+
@user.groups.should have(1).record
|
50
|
+
@user.groups.should include(Confluence::User::DEFAULT_GROUP)
|
51
|
+
|
52
|
+
@job.sync_ist_from_ldap()
|
53
|
+
@user.groups.should have(2).records
|
54
|
+
@user.groups.should include(Confluence::User::DEFAULT_GROUP)
|
55
|
+
@user.groups.should include(Confluence::Jobs::IstLdapSync::IST_GROUP)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
context "#sync_ist_from_confluence()" do
|
61
|
+
it "should remove users from IST group" do
|
62
|
+
ldap_user = mock("user1", {:uid => "n1", :first_name => "f1",
|
63
|
+
:last_name => "l1", :email => "e1"})
|
64
|
+
@user.save()
|
65
|
+
@job.stub!(:confluence_user_names).and_return([@user.name])
|
66
|
+
@job.stub!(:find_in_confluence).and_return(@user)
|
67
|
+
@job.stub!(:find_in_ldap).and_return(ldap_user)
|
68
|
+
@job.stub!(:eligible_for_confluence?).and_return(true)
|
69
|
+
@job.stub!(:in_ist?).and_return(false)
|
70
|
+
|
71
|
+
@user.disabled?.should be_false
|
72
|
+
@job.sync_ist_from_confluence()
|
73
|
+
@user.groups.should have(1).record
|
74
|
+
@user.groups.should_not include(Confluence::Jobs::IstLdapSync::IST_GROUP)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,221 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe Confluence::User do
|
5
|
+
before(:all) do
|
6
|
+
Confluence.config = Confluence::Config.new("#{Confluence.root()}/config/config.yml")
|
7
|
+
|
8
|
+
@user = Confluence::User.new({
|
9
|
+
:name => "111111",
|
10
|
+
:fullname => "Test Dude",
|
11
|
+
:email => "test_dude@berkeley.edu"
|
12
|
+
})
|
13
|
+
@user.save
|
14
|
+
|
15
|
+
@group = "test-group"
|
16
|
+
Confluence::Group.create(@group)
|
17
|
+
end
|
18
|
+
|
19
|
+
after(:all) do
|
20
|
+
@user.delete()
|
21
|
+
Confluence::Group.delete(@group)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should find all users" do
|
25
|
+
Confluence::User.all_names.should_not be_empty
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should initialize a user" do
|
29
|
+
attrs = {:name => 'n', :fullname => 'fn', :email => 'e'}
|
30
|
+
u = Confluence::User.new(attrs)
|
31
|
+
u.name.should == 'n'
|
32
|
+
u.fullname.should == 'fn'
|
33
|
+
u.email.should == 'e'
|
34
|
+
|
35
|
+
attrs = {'name' => 'n', 'fullname' => 'fn', 'email' => 'e'}
|
36
|
+
u = Confluence::User.new(attrs)
|
37
|
+
u.name.should == 'n'
|
38
|
+
u.fullname.should == 'fn'
|
39
|
+
u.email.should == 'e'
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should find_by_name" do
|
43
|
+
user = Confluence::User.find_by_name(@user.name)
|
44
|
+
user.should be_a(Confluence::User)
|
45
|
+
user.name.should == @user.name
|
46
|
+
user.email.should == @user.email
|
47
|
+
user.fullname.should == @user.fullname
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should format when sent to_s" do
|
51
|
+
user = Confluence::User.new(@user)
|
52
|
+
user.to_s.should == "name=#{@user[:name]}, fullname=#{@user[:fullname]}, email=#{@user[:email]}"
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should allow attributes to be access with Hash interface" do
|
56
|
+
name = "111111"
|
57
|
+
fullname = "Test Dude"
|
58
|
+
email = "test_dude@berkeley.edu"
|
59
|
+
@user[:name].should == name
|
60
|
+
@user[:fullname].should == fullname
|
61
|
+
@user[:email].should == email
|
62
|
+
|
63
|
+
@user["name"].should == name
|
64
|
+
@user["fullname"].should == fullname
|
65
|
+
@user["email"].should == email
|
66
|
+
|
67
|
+
@user[:bad_att].should == nil
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should save a user's attributes" do
|
71
|
+
# Confluence::User.find_by_name("name").delete
|
72
|
+
Confluence::User.exists?("name").should_not be_true
|
73
|
+
# New User
|
74
|
+
user = Confluence::User.new({:name => "name", :email => "email", :fullname => "fullname"})
|
75
|
+
user.should be_new_record
|
76
|
+
|
77
|
+
user.save
|
78
|
+
user.should_not be_new_record
|
79
|
+
user = Confluence::User.find_by_name(user.name)
|
80
|
+
user.should_not be_new_record
|
81
|
+
user.email.should == "email"
|
82
|
+
user.name.should == "name"
|
83
|
+
user.fullname.should == "fullname"
|
84
|
+
|
85
|
+
# Update attributes
|
86
|
+
user.email = "emailx"
|
87
|
+
user.fullname = "fullnamex"
|
88
|
+
user.save
|
89
|
+
|
90
|
+
user = Confluence::User.find_by_name(user.name)
|
91
|
+
user.email.should == "emailx"
|
92
|
+
user.name.should == "name"
|
93
|
+
user.fullname.should == "fullnamex"
|
94
|
+
user.delete
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
describe Confluence::User, "class methods" do
|
100
|
+
before(:all) do
|
101
|
+
Confluence.config = Confluence::Config.new("#{Confluence.root()}/config/config.yml")
|
102
|
+
|
103
|
+
@user1 = Confluence::User.new({
|
104
|
+
:name => "1",
|
105
|
+
:fullname => "Test Dude",
|
106
|
+
:email => "test_dude@berkeley.edu"
|
107
|
+
})
|
108
|
+
@user1.save()
|
109
|
+
|
110
|
+
@user2 = Confluence::User.new({
|
111
|
+
:name => "2",
|
112
|
+
:fullname => "Test Dude (ACCOUNT DISABLED)",
|
113
|
+
:email => "test_dude@berkeley.edu"
|
114
|
+
})
|
115
|
+
@user2.save()
|
116
|
+
end
|
117
|
+
|
118
|
+
after(:all)do
|
119
|
+
u = Confluence::User.find_by_name("1")
|
120
|
+
u.delete() if u
|
121
|
+
|
122
|
+
u = Confluence::User.find_by_name("2")
|
123
|
+
u.delete() if u
|
124
|
+
end
|
125
|
+
|
126
|
+
context "expired()" do
|
127
|
+
it "should return all users that have disabled accounts" do
|
128
|
+
expired_names = Confluence::User.expired.map { |u| u.name }
|
129
|
+
expired_names.should_not include(@user1.name)
|
130
|
+
expired_names.should include(@user2.name)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
context "active()" do
|
135
|
+
it "should return all users that have enabled accounts" do
|
136
|
+
active_names = Confluence::User.active.map { |u| u.name }
|
137
|
+
active_names.should include(@user1.name)
|
138
|
+
active_names.should_not include(@user2.name)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
|
144
|
+
|
145
|
+
|
146
|
+
describe Confluence::User, "ldap integration" do
|
147
|
+
before(:all) do
|
148
|
+
Confluence.config = Confluence::Config.new("#{Confluence.root()}/config/config.yml")
|
149
|
+
|
150
|
+
@ldap_user = "322586"
|
151
|
+
u = Confluence::User.find_by_name(@ldap_user)
|
152
|
+
u.delete if u
|
153
|
+
end
|
154
|
+
|
155
|
+
after(:all)do
|
156
|
+
u = Confluence::User.find_by_name(@ldap_user)
|
157
|
+
u.delete() if u
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should find_or_create_from_ldap" do
|
161
|
+
Confluence::User.find_by_name(@ldap_user).should be_nil
|
162
|
+
Confluence::User.find_or_create_from_ldap(@ldap_user)
|
163
|
+
user = Confluence::User.find_by_name(@ldap_user)
|
164
|
+
user.should_not be_nil
|
165
|
+
UCB::LDAP::Person.should_not_receive(:find_by_uid)
|
166
|
+
Confluence::User.find_or_create_from_ldap(@ldap_user).should_not be_nil
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should raise error if find_or_create_from_ldap can't find user in ldap" do
|
170
|
+
lambda { Confluence::User.find_or_create_from_ldap("q") }.should raise_error
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
|
175
|
+
describe Confluence::User, "group management" do
|
176
|
+
before(:all) do
|
177
|
+
Confluence.config = Confluence::Config.new("#{Confluence.root()}/config/config.yml")
|
178
|
+
|
179
|
+
@user = Confluence::User.new({
|
180
|
+
:name => "111111",
|
181
|
+
:fullname => "Test Dude",
|
182
|
+
:email => "test_dude@berkeley.edu"
|
183
|
+
})
|
184
|
+
@user.save
|
185
|
+
|
186
|
+
@group = "test-group"
|
187
|
+
Confluence::Group.create(@group)
|
188
|
+
end
|
189
|
+
|
190
|
+
after(:all) do
|
191
|
+
@user.delete
|
192
|
+
Confluence::Group.delete(@group)
|
193
|
+
end
|
194
|
+
|
195
|
+
it "should return a user's groups" do
|
196
|
+
@user.should have(1).groups
|
197
|
+
end
|
198
|
+
|
199
|
+
it "should add a user to a group" do
|
200
|
+
@user.groups.should_not include(@group)
|
201
|
+
@user.join_group(@group).should be_true
|
202
|
+
@user.groups.should include(@group)
|
203
|
+
@user.leave_group(@group)
|
204
|
+
end
|
205
|
+
|
206
|
+
it "should gracefully handle bad groups names for join_group" do
|
207
|
+
@user.join_group("badgroup").should be_false
|
208
|
+
end
|
209
|
+
|
210
|
+
context "leave_group()" do
|
211
|
+
it "should be false if user is not in the group" do
|
212
|
+
@user.leave_group("badgroup").should be_false
|
213
|
+
end
|
214
|
+
|
215
|
+
it "should be true if user is in the group" do
|
216
|
+
@user.join_group(@group)
|
217
|
+
@user.leave_group(@group).should be_true
|
218
|
+
@user.groups.should_not include(@group)
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|