socialcast 1.3.8 → 1.3.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/socialcast/command_line/ldap_connector.rb +95 -42
- data/lib/socialcast/command_line/provision_photo.rb +8 -8
- data/lib/socialcast/command_line/provision_user.rb +4 -4
- data/lib/socialcast/command_line/provisioner.rb +3 -11
- data/lib/socialcast/command_line/version.rb +1 -1
- data/spec/fixtures/ldap_with_multiple_connection_mappings.yml +2 -0
- data/spec/fixtures/ldap_with_profile_photo.yml +12 -0
- data/spec/fixtures/ldap_without_options.yml +34 -0
- data/spec/socialcast/command_line/cli_spec.rb +37 -41
- data/spec/socialcast/command_line/ldap_connector_spec.rb +354 -84
- data/spec/socialcast/command_line/provision_photo_spec.rb +147 -72
- data/spec/socialcast/command_line/provision_user_spec.rb +100 -35
- data/spec/spec_helper.rb +2 -2
- metadata +4 -2
@@ -46,8 +46,14 @@ describe Socialcast::CommandLine::LDAPConnector do
|
|
46
46
|
}
|
47
47
|
end
|
48
48
|
|
49
|
-
|
50
|
-
|
49
|
+
let(:ldap) { double(Net::LDAP, :open => nil, :encryption => nil, :auth => nil) }
|
50
|
+
|
51
|
+
before do
|
52
|
+
Net::LDAP.stub(:new).and_return(ldap)
|
53
|
+
end
|
54
|
+
|
55
|
+
def create_entry(cn, entry_attributes)
|
56
|
+
Net::LDAP::Entry.new("cn=#{cn},dc=example,dc=com").tap do |e|
|
51
57
|
entry_attributes.each_pair do |attr, value|
|
52
58
|
e[attr] = value
|
53
59
|
end
|
@@ -55,11 +61,11 @@ describe Socialcast::CommandLine::LDAPConnector do
|
|
55
61
|
end
|
56
62
|
|
57
63
|
describe "#each_user_hash" do
|
58
|
-
context "
|
59
|
-
let(:connector) { Socialcast::CommandLine::LDAPConnector.new('connection_1', ldap_config) }
|
60
|
-
let(:entry) { create_entry(:mail => 'user@example.com', :givenName => 'first name', :sn => 'last name') }
|
64
|
+
context "when the entry has an email" do
|
65
|
+
let(:connector) { Socialcast::CommandLine::LDAPConnector.new('connection_1', ldap_config, ldap) }
|
66
|
+
let(:entry) { create_entry('user', :mail => 'user@example.com', :givenName => 'first name', :sn => 'last name') }
|
61
67
|
before do
|
62
|
-
|
68
|
+
ldap.should_receive(:search).once.with(hash_including(:attributes => ['givenName', 'sn', 'mail', 'isMemberOf'])).and_yield(entry)
|
63
69
|
end
|
64
70
|
it do
|
65
71
|
expect do |blk|
|
@@ -76,12 +82,253 @@ describe Socialcast::CommandLine::LDAPConnector do
|
|
76
82
|
}))
|
77
83
|
end
|
78
84
|
end
|
85
|
+
|
86
|
+
context("when the entry does not have a unique_identifier or email") do
|
87
|
+
let(:connector) { Socialcast::CommandLine::LDAPConnector.new('connection_1', ldap_config, ldap) }
|
88
|
+
let(:entry) { create_entry('user', :mail => nil, :givenName => 'first name', :sn => 'last name') }
|
89
|
+
before do
|
90
|
+
ldap.should_receive(:search).once.with(hash_including(:attributes => ['givenName', 'sn', 'mail', 'isMemberOf'])).and_yield(entry)
|
91
|
+
end
|
92
|
+
it 'does not yield the entry' do
|
93
|
+
expect do |blk|
|
94
|
+
connector.each_user_hash(&blk)
|
95
|
+
end.not_to yield_control
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context("when the entry has a unique_identifier") do
|
100
|
+
let(:mappings) do
|
101
|
+
{
|
102
|
+
"first_name" => "givenName",
|
103
|
+
"last_name" => "sn",
|
104
|
+
"unique_identifier" => "uid"
|
105
|
+
}
|
106
|
+
end
|
107
|
+
let(:connector) { Socialcast::CommandLine::LDAPConnector.new('connection_1', ldap_config, ldap) }
|
108
|
+
let(:entry) { create_entry('user', :uid => 'unique identifier', :givenName => 'first name', :sn => 'last name') }
|
109
|
+
before do
|
110
|
+
ldap.should_receive(:search).once.with(hash_including(:attributes => ['givenName', 'sn', 'uid', 'isMemberOf'])).and_yield(entry)
|
111
|
+
end
|
112
|
+
it do
|
113
|
+
expect do |blk|
|
114
|
+
connector.each_user_hash(&blk)
|
115
|
+
end.to yield_with_args(HashWithIndifferentAccess.new({
|
116
|
+
'first_name' => 'first name',
|
117
|
+
'last_name' => 'last name',
|
118
|
+
'unique_identifier' => 'unique identifier',
|
119
|
+
'contact_info' => {},
|
120
|
+
'custom_fields' => [],
|
121
|
+
'account_type' => 'member',
|
122
|
+
'roles' => []
|
123
|
+
}))
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
context "when the entry has a profile photo" do
|
128
|
+
let(:connector) { Socialcast::CommandLine::LDAPConnector.new('connection_1', ldap_config, ldap) }
|
129
|
+
let(:entry) { create_entry('user', :mail => 'user@example.com', :givenName => 'first name', :sn => 'last name') }
|
130
|
+
let(:mappings) do
|
131
|
+
{
|
132
|
+
"first_name" => "givenName",
|
133
|
+
"last_name" => "sn",
|
134
|
+
"email" => "mail",
|
135
|
+
"profile_photo" => "jpegPhoto"
|
136
|
+
}
|
137
|
+
end
|
138
|
+
before do
|
139
|
+
ldap.should_receive(:search).once.with(hash_including(:attributes => ['givenName', 'sn', 'mail', 'isMemberOf'])).and_yield(entry)
|
140
|
+
end
|
141
|
+
it "does not retrieve the profile photo data from ldap" do
|
142
|
+
expect do |blk|
|
143
|
+
connector.each_user_hash(&blk)
|
144
|
+
end.to yield_with_args(HashWithIndifferentAccess.new({
|
145
|
+
'first_name' => 'first name',
|
146
|
+
'last_name' => 'last name',
|
147
|
+
'contact_info' => {
|
148
|
+
'email' => 'user@example.com',
|
149
|
+
},
|
150
|
+
'custom_fields' => [],
|
151
|
+
'account_type' => 'member',
|
152
|
+
'roles' => []
|
153
|
+
}))
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
context "when the entry has a manager" do
|
158
|
+
let(:connector) { Socialcast::CommandLine::LDAPConnector.new('connection_1', ldap_config, ldap) }
|
159
|
+
let(:employee_entry) { create_entry('user', :mail => 'user@example.com', :givenName => 'first name', :sn => 'last name', :manager_dn => 'cn=manager,dc=example,dc=com') }
|
160
|
+
let(:manager_entry) { create_entry('manager', :mail => 'manager@example.com', :givenName => 'manager first name', :sn => 'manager last name') }
|
161
|
+
let(:employee_mail_entry) { create_entry('user', :mail => 'user@example.com') }
|
162
|
+
let(:manager_mail_entry) { create_entry('manager', :mail => 'manager@example.com') }
|
163
|
+
let(:mappings) do
|
164
|
+
{
|
165
|
+
"first_name" => "givenName",
|
166
|
+
"last_name" => "sn",
|
167
|
+
"email" => "mail",
|
168
|
+
"manager" => "manager_dn"
|
169
|
+
}
|
170
|
+
end
|
171
|
+
before do
|
172
|
+
ldap.should_receive(:search).once.ordered.with(hash_including(:attributes => ['mail']))
|
173
|
+
.and_yield(employee_mail_entry)
|
174
|
+
.and_yield(manager_mail_entry)
|
175
|
+
ldap.should_receive(:search).once.ordered.with(hash_including(:attributes => ['givenName', 'sn', 'mail', 'manager_dn', 'isMemberOf']))
|
176
|
+
.and_yield(employee_entry)
|
177
|
+
.and_yield(manager_entry)
|
178
|
+
end
|
179
|
+
it do
|
180
|
+
expect do |blk|
|
181
|
+
connector.each_user_hash(&blk)
|
182
|
+
end.to yield_successive_args(HashWithIndifferentAccess.new({
|
183
|
+
'first_name' => 'first name',
|
184
|
+
'last_name' => 'last name',
|
185
|
+
'contact_info' => {
|
186
|
+
'email' => 'user@example.com',
|
187
|
+
},
|
188
|
+
'custom_fields' => [{
|
189
|
+
"id" => "manager_email",
|
190
|
+
"label" => "manager_email",
|
191
|
+
"value" => "manager@example.com"
|
192
|
+
}],
|
193
|
+
'account_type' => 'member',
|
194
|
+
'roles' => []
|
195
|
+
}),
|
196
|
+
HashWithIndifferentAccess.new({
|
197
|
+
'first_name' => 'manager first name',
|
198
|
+
'last_name' => 'manager last name',
|
199
|
+
'contact_info' => {
|
200
|
+
'email' => 'manager@example.com',
|
201
|
+
},
|
202
|
+
'custom_fields' => [{
|
203
|
+
"id" => "manager_email",
|
204
|
+
"label" => "manager_email",
|
205
|
+
"value" => nil
|
206
|
+
}],
|
207
|
+
|
208
|
+
'account_type' => 'member',
|
209
|
+
'roles' => []
|
210
|
+
}))
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
context "with multiple manager entries" do
|
215
|
+
let(:connector) { Socialcast::CommandLine::LDAPConnector.new('connection_1', ldap_config, ldap) }
|
216
|
+
let(:employee_entry1) { create_entry('user1', :mail => 'user1@example.com', :givenName => 'first name1', :sn => 'last name1', :manager_dn => 'cn=manager1,dc=example,dc=com') }
|
217
|
+
let(:employee_entry2) { create_entry('user2', :mail => 'user2@example.com', :givenName => 'first name2', :sn => 'last name2', :manager_dn => 'cn=manager2,dc=example,dc=com') }
|
218
|
+
let(:employee_entry3) { create_entry('user3', :mail => 'user3@example.com', :givenName => 'first name3', :sn => 'last name3', :manager_dn => 'cn=manager1,dc=example,dc=com') }
|
219
|
+
let(:employee_mail_entry1) { create_entry('user1', :mail => 'user1@example.com') }
|
220
|
+
let(:employee_mail_entry2) { create_entry('user2', :mail => 'user2@example.com') }
|
221
|
+
let(:employee_mail_entry3) { create_entry('user3', :mail => 'user3@example.com') }
|
222
|
+
let(:manager_entry1) { create_entry('manager1', :mail => 'manager1@example.com', :givenName => 'manager first name1', :sn => 'manager last name1') }
|
223
|
+
let(:manager_entry2) { create_entry('manager2', :mail => 'manager2@example.com', :givenName => 'manager first name2', :sn => 'manager last name2') }
|
224
|
+
let(:manager_mail_entry1) { create_entry('manager1', :mail => 'manager1@example.com') }
|
225
|
+
let(:manager_mail_entry2) { create_entry('manager2', :mail => 'manager2@example.com') }
|
226
|
+
let(:mappings) do
|
227
|
+
{
|
228
|
+
"first_name" => "givenName",
|
229
|
+
"last_name" => "sn",
|
230
|
+
"email" => "mail",
|
231
|
+
"manager" => "manager_dn"
|
232
|
+
}
|
233
|
+
end
|
234
|
+
before do
|
235
|
+
ldap.should_receive(:search).once.ordered.with(hash_including(:attributes => ['mail']))
|
236
|
+
.and_yield(employee_mail_entry1)
|
237
|
+
.and_yield(employee_mail_entry2)
|
238
|
+
.and_yield(employee_mail_entry3)
|
239
|
+
.and_yield(manager_mail_entry1)
|
240
|
+
.and_yield(manager_mail_entry2)
|
241
|
+
|
242
|
+
ldap.should_receive(:search).once.ordered.with(hash_including(:attributes => ['givenName', 'sn', 'mail', 'manager_dn', 'isMemberOf']))
|
243
|
+
.and_yield(employee_entry1)
|
244
|
+
.and_yield(employee_entry2)
|
245
|
+
.and_yield(employee_entry3)
|
246
|
+
.and_yield(manager_entry1)
|
247
|
+
.and_yield(manager_entry2)
|
248
|
+
end
|
249
|
+
it do
|
250
|
+
expect do |blk|
|
251
|
+
connector.each_user_hash(&blk)
|
252
|
+
end.to yield_successive_args(HashWithIndifferentAccess.new({
|
253
|
+
'first_name' => 'first name1',
|
254
|
+
'last_name' => 'last name1',
|
255
|
+
'contact_info' => {
|
256
|
+
'email' => 'user1@example.com',
|
257
|
+
},
|
258
|
+
'custom_fields' => [{
|
259
|
+
"id" => "manager_email",
|
260
|
+
"label" => "manager_email",
|
261
|
+
"value" => "manager1@example.com"
|
262
|
+
}],
|
263
|
+
'account_type' => 'member',
|
264
|
+
'roles' => []
|
265
|
+
}),
|
266
|
+
HashWithIndifferentAccess.new({
|
267
|
+
'first_name' => 'first name2',
|
268
|
+
'last_name' => 'last name2',
|
269
|
+
'contact_info' => {
|
270
|
+
'email' => 'user2@example.com',
|
271
|
+
},
|
272
|
+
'custom_fields' => [{
|
273
|
+
"id" => "manager_email",
|
274
|
+
"label" => "manager_email",
|
275
|
+
"value" => "manager2@example.com"
|
276
|
+
}],
|
277
|
+
'account_type' => 'member',
|
278
|
+
'roles' => []
|
279
|
+
}),
|
280
|
+
HashWithIndifferentAccess.new({
|
281
|
+
'first_name' => 'first name3',
|
282
|
+
'last_name' => 'last name3',
|
283
|
+
'contact_info' => {
|
284
|
+
'email' => 'user3@example.com',
|
285
|
+
},
|
286
|
+
'custom_fields' => [{
|
287
|
+
"id" => "manager_email",
|
288
|
+
"label" => "manager_email",
|
289
|
+
"value" => "manager1@example.com"
|
290
|
+
}],
|
291
|
+
'account_type' => 'member',
|
292
|
+
'roles' => []
|
293
|
+
}),
|
294
|
+
HashWithIndifferentAccess.new({
|
295
|
+
'first_name' => 'manager first name1',
|
296
|
+
'last_name' => 'manager last name1',
|
297
|
+
'contact_info' => {
|
298
|
+
'email' => 'manager1@example.com',
|
299
|
+
},
|
300
|
+
'custom_fields' => [{
|
301
|
+
"id" => "manager_email",
|
302
|
+
"label" => "manager_email",
|
303
|
+
"value" => nil
|
304
|
+
}],
|
305
|
+
'account_type' => 'member',
|
306
|
+
'roles' => []
|
307
|
+
}),
|
308
|
+
HashWithIndifferentAccess.new({
|
309
|
+
'first_name' => 'manager first name2',
|
310
|
+
'last_name' => 'manager last name2',
|
311
|
+
'contact_info' => {
|
312
|
+
'email' => 'manager2@example.com',
|
313
|
+
},
|
314
|
+
'custom_fields' => [{
|
315
|
+
"id" => "manager_email",
|
316
|
+
"label" => "manager_email",
|
317
|
+
"value" => nil
|
318
|
+
}],
|
319
|
+
'account_type' => 'member',
|
320
|
+
'roles' => []
|
321
|
+
})
|
322
|
+
)
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
79
326
|
context "with attribute mappings at the connection level" do
|
80
|
-
let(:connector) { Socialcast::CommandLine::LDAPConnector.new('connection_1', ldap_config) }
|
327
|
+
let(:connector) { Socialcast::CommandLine::LDAPConnector.new('connection_1', ldap_config, ldap) }
|
81
328
|
before do
|
82
329
|
connection.merge!({ "mappings" => { "email" => "mailConnection" } })
|
83
|
-
entry = create_entry :mailConnection => 'user@example.com'
|
84
|
-
|
330
|
+
entry = create_entry 'user', :mailConnection => 'user@example.com'
|
331
|
+
ldap.should_receive(:search).once.with(hash_including(:attributes => ['mailConnection', 'isMemberOf'])).and_yield(entry)
|
85
332
|
end
|
86
333
|
it do
|
87
334
|
expect do |blk|
|
@@ -97,7 +344,7 @@ describe Socialcast::CommandLine::LDAPConnector do
|
|
97
344
|
end
|
98
345
|
end
|
99
346
|
context "with permission mappings at the connection level" do
|
100
|
-
let(:connector) { Socialcast::CommandLine::LDAPConnector.new('connection_1', ldap_config) }
|
347
|
+
let(:connector) { Socialcast::CommandLine::LDAPConnector.new('connection_1', ldap_config, ldap) }
|
101
348
|
let(:ldap_groups) { ["cn=External,dc=example,dc=com", "cn=BizAdmins,dc=example,dc=com", "cn=TownHallAdmins,dc=example,dc=com"] }
|
102
349
|
before do
|
103
350
|
connection.merge!({
|
@@ -113,8 +360,8 @@ describe Socialcast::CommandLine::LDAPConnector do
|
|
113
360
|
}
|
114
361
|
}
|
115
362
|
})
|
116
|
-
entry = create_entry :mail => 'user@example.com', :givenName => 'first name', :sn => 'last name', :memberOf => ldap_groups
|
117
|
-
|
363
|
+
entry = create_entry 'user', :mail => 'user@example.com', :givenName => 'first name', :sn => 'last name', :memberOf => ldap_groups
|
364
|
+
ldap.should_receive(:search).once.with(hash_including(:attributes => ['givenName', 'sn', 'mail', 'memberOf'])).and_yield(entry)
|
118
365
|
end
|
119
366
|
it do
|
120
367
|
expect do |blk|
|
@@ -132,15 +379,15 @@ describe Socialcast::CommandLine::LDAPConnector do
|
|
132
379
|
end
|
133
380
|
end
|
134
381
|
context "with external ldap group memberships" do
|
135
|
-
let(:connector) { Socialcast::CommandLine::LDAPConnector.new('connection_1', ldap_config) }
|
382
|
+
let(:connector) { Socialcast::CommandLine::LDAPConnector.new('connection_1', ldap_config, ldap) }
|
136
383
|
let(:entry) do
|
137
|
-
create_entry(:mail => 'user@example.com',
|
384
|
+
create_entry('user', :mail => 'user@example.com',
|
138
385
|
:givenName => 'first name',
|
139
386
|
:sn => 'last name',
|
140
387
|
:isMemberOf => ["cn=External,dc=example,dc=com", "cn=TownHallAdmins,dc=example,dc=com"])
|
141
388
|
end
|
142
389
|
before do
|
143
|
-
|
390
|
+
ldap.should_receive(:search).once.with(hash_including(:attributes => ['givenName', 'sn', 'mail', 'isMemberOf'])).and_yield(entry)
|
144
391
|
end
|
145
392
|
it "sets the account_type to 'external' and does not include roles" do
|
146
393
|
expect do |blk|
|
@@ -157,15 +404,15 @@ describe Socialcast::CommandLine::LDAPConnector do
|
|
157
404
|
end
|
158
405
|
end
|
159
406
|
context "with role ldap group memberships" do
|
160
|
-
let(:connector) { Socialcast::CommandLine::LDAPConnector.new('connection_1', ldap_config) }
|
407
|
+
let(:connector) { Socialcast::CommandLine::LDAPConnector.new('connection_1', ldap_config, ldap) }
|
161
408
|
let(:entry) do
|
162
|
-
create_entry(:mail => 'user@example.com',
|
409
|
+
create_entry('user', :mail => 'user@example.com',
|
163
410
|
:givenName => 'first name',
|
164
411
|
:sn => 'last name',
|
165
412
|
:isMemberOf => ["cn=TownHallAdmins,dc=example,dc=com", "cn=SbiAdmins,dc=example,dc=com"])
|
166
413
|
end
|
167
414
|
before do
|
168
|
-
|
415
|
+
ldap.should_receive(:search).once.with(hash_including(:attributes => ['givenName', 'sn', 'mail', 'isMemberOf'])).and_yield(entry)
|
169
416
|
end
|
170
417
|
it "sets the account_type to 'member' and includes roles" do
|
171
418
|
expect do |blk|
|
@@ -189,37 +436,34 @@ describe Socialcast::CommandLine::LDAPConnector do
|
|
189
436
|
"unique_identifier" => "gid"
|
190
437
|
}
|
191
438
|
end
|
192
|
-
let(:connector) { Socialcast::CommandLine::LDAPConnector.new('connection_1', ldap_config) }
|
439
|
+
let(:connector) { Socialcast::CommandLine::LDAPConnector.new('connection_1', ldap_config, ldap) }
|
193
440
|
let(:group_entry1) do
|
194
|
-
create_entry(:dn => "cn=Sales,dc=example,dc=com", :gid => "sales_group_id")
|
441
|
+
create_entry('group1', :dn => "cn=Sales,dc=example,dc=com", :gid => "sales_group_id")
|
195
442
|
end
|
196
443
|
let(:group_entry2) do
|
197
|
-
create_entry(:dn => "cn=IT,dc=example,dc=com", :gid => "it_group_id")
|
444
|
+
create_entry('group2', :dn => "cn=IT,dc=example,dc=com", :gid => "it_group_id")
|
198
445
|
end
|
199
446
|
let(:group_entry3) do
|
200
|
-
create_entry(:dn => "cn=SFOffice,dc=example,dc=com", :gid => "sf_office_group_id")
|
447
|
+
create_entry('group3', :dn => "cn=SFOffice,dc=example,dc=com", :gid => "sf_office_group_id")
|
201
448
|
end
|
202
449
|
let(:user_entry) do
|
203
|
-
create_entry(:mail => 'user@example.com',
|
450
|
+
create_entry('user', :mail => 'user@example.com',
|
204
451
|
:givenName => 'first name',
|
205
452
|
:sn => 'last name',
|
206
453
|
:isMemberOf => ["cn=SFOffice,dc=example,dc=com", "cn=Sales,dc=example,dc=com"])
|
207
454
|
end
|
208
455
|
before do
|
209
|
-
|
210
|
-
Net::LDAP.should_receive(:new).once.and_return(ldap_instance)
|
211
|
-
|
212
|
-
ldap_instance.should_receive(:search).once.ordered.with(
|
456
|
+
ldap.should_receive(:search).once.ordered.with(
|
213
457
|
:return_result => false,
|
214
|
-
:filter => "(
|
458
|
+
:filter => "(objectClass=groupOfUniqueNames)",
|
215
459
|
:base => "dc=example,dc=com",
|
216
|
-
:attributes => [
|
460
|
+
:attributes => ["gid"]).and_yield(group_entry1).and_yield(group_entry2).and_yield(group_entry3)
|
217
461
|
|
218
|
-
|
462
|
+
ldap.should_receive(:search).once.ordered.with(
|
219
463
|
:return_result => false,
|
220
|
-
:filter => "(
|
464
|
+
:filter => "(mail=*)",
|
221
465
|
:base => "dc=example,dc=com",
|
222
|
-
:attributes => [
|
466
|
+
:attributes => ['givenName', 'sn', 'mail', 'isMemberOf']).and_yield(user_entry)
|
223
467
|
end
|
224
468
|
it "includes group memberships" do
|
225
469
|
expect do |blk|
|
@@ -239,50 +483,97 @@ describe Socialcast::CommandLine::LDAPConnector do
|
|
239
483
|
end
|
240
484
|
end
|
241
485
|
|
242
|
-
describe "#
|
243
|
-
context
|
244
|
-
let(:connector) { Socialcast::CommandLine::LDAPConnector.new('connection_1', ldap_config) }
|
245
|
-
let(:entry) { create_entry(:mail => 'user@example.com', :
|
486
|
+
describe "#each_photo_hash" do
|
487
|
+
context "when the entry has an email and photo" do
|
488
|
+
let(:connector) { Socialcast::CommandLine::LDAPConnector.new('connection_1', ldap_config, ldap) }
|
489
|
+
let(:entry) { create_entry('user', :mail => 'user@example.com', :jpegPhoto => "photo") }
|
490
|
+
let(:mappings) do
|
491
|
+
{
|
492
|
+
"first_name" => "givenName",
|
493
|
+
"last_name" => "sn",
|
494
|
+
"email" => "mail",
|
495
|
+
"profile_photo" => "jpegPhoto"
|
496
|
+
}
|
497
|
+
end
|
246
498
|
before do
|
247
|
-
|
499
|
+
ldap.should_receive(:search).once.with(hash_including(:attributes => ['mail', 'jpegPhoto'])).and_yield(entry)
|
248
500
|
end
|
249
501
|
it do
|
250
502
|
expect do |blk|
|
251
|
-
connector.
|
252
|
-
end.to yield_with_args(
|
503
|
+
connector.each_photo_hash(&blk)
|
504
|
+
end.to yield_with_args(HashWithIndifferentAccess.new({
|
505
|
+
'email' => 'user@example.com',
|
506
|
+
'profile_photo' => "photo"
|
507
|
+
}))
|
253
508
|
end
|
254
509
|
end
|
255
|
-
context
|
510
|
+
context "when the entry does not have an email" do
|
511
|
+
let(:connector) { Socialcast::CommandLine::LDAPConnector.new('connection_1', ldap_config, ldap) }
|
512
|
+
let(:entry) { create_entry('user', :mail => '', :jpegPhoto => "photo") }
|
256
513
|
let(:mappings) do
|
257
514
|
{
|
258
515
|
"first_name" => "givenName",
|
259
516
|
"last_name" => "sn",
|
260
|
-
"
|
517
|
+
"email" => "mail",
|
518
|
+
"unique_identifief" => "uid",
|
519
|
+
"profile_photo" => "jpegPhoto"
|
261
520
|
}
|
262
521
|
end
|
263
|
-
let(:connector) { Socialcast::CommandLine::LDAPConnector.new('connection_1', ldap_config) }
|
264
|
-
let(:entry) { create_entry(:uid => 'unique identifier', :givenName => 'first name', :sn => 'last name') }
|
265
522
|
before do
|
266
|
-
|
523
|
+
ldap.should_receive(:search).once.with(hash_including(:attributes => ['mail', 'jpegPhoto'])).and_yield(entry)
|
267
524
|
end
|
268
|
-
it do
|
525
|
+
it 'does not yield' do
|
269
526
|
expect do |blk|
|
270
|
-
connector.
|
271
|
-
end.
|
527
|
+
connector.each_photo_hash(&blk)
|
528
|
+
end.not_to yield_control
|
272
529
|
end
|
273
530
|
end
|
274
|
-
|
275
|
-
|
276
|
-
let(:
|
531
|
+
|
532
|
+
context "when the entry does not have a photo" do
|
533
|
+
let(:connector) { Socialcast::CommandLine::LDAPConnector.new('connection_1', ldap_config, ldap) }
|
534
|
+
let(:entry) { create_entry('user', :mail => 'user@example.com', :jpegPhoto => "") }
|
535
|
+
let(:mappings) do
|
536
|
+
{
|
537
|
+
"first_name" => "givenName",
|
538
|
+
"last_name" => "sn",
|
539
|
+
"email" => "mail",
|
540
|
+
"unique_identifief" => "uid",
|
541
|
+
"profile_photo" => "jpegPhoto"
|
542
|
+
}
|
543
|
+
end
|
277
544
|
before do
|
278
|
-
|
545
|
+
ldap.should_receive(:search).once.with(hash_including(:attributes => ['mail', 'jpegPhoto'])).and_yield(entry)
|
279
546
|
end
|
280
|
-
it 'does not yield
|
547
|
+
it 'does not yield' do
|
281
548
|
expect do |blk|
|
282
|
-
connector.
|
549
|
+
connector.each_photo_hash(&blk)
|
283
550
|
end.not_to yield_control
|
284
551
|
end
|
285
552
|
end
|
553
|
+
|
554
|
+
context "when the entry has a binary photo with incorrect encoding" do
|
555
|
+
let(:connector) { Socialcast::CommandLine::LDAPConnector.new('connection_1', ldap_config, ldap) }
|
556
|
+
let(:entry) { create_entry('user', :mail => 'user@example.com', :jpegPhoto => "\x89PNGabc") }
|
557
|
+
let(:mappings) do
|
558
|
+
{
|
559
|
+
"first_name" => "givenName",
|
560
|
+
"last_name" => "sn",
|
561
|
+
"email" => "mail",
|
562
|
+
"profile_photo" => "jpegPhoto"
|
563
|
+
}
|
564
|
+
end
|
565
|
+
before do
|
566
|
+
ldap.should_receive(:search).once.with(hash_including(:attributes => ['mail', 'jpegPhoto'])).and_yield(entry)
|
567
|
+
end
|
568
|
+
it "does not raise an error" do
|
569
|
+
expect do |blk|
|
570
|
+
connector.each_photo_hash(&blk)
|
571
|
+
end.to yield_with_args(HashWithIndifferentAccess.new({
|
572
|
+
'email' => 'user@example.com',
|
573
|
+
'profile_photo' => "\x89PNGabc"
|
574
|
+
}))
|
575
|
+
end
|
576
|
+
end
|
286
577
|
end
|
287
578
|
|
288
579
|
describe "#fetch_user_hash" do
|
@@ -294,11 +585,11 @@ describe Socialcast::CommandLine::LDAPConnector do
|
|
294
585
|
"unique_identifier" => "uid"
|
295
586
|
}
|
296
587
|
end
|
297
|
-
let(:connector) { Socialcast::CommandLine::LDAPConnector.new('connection_1', ldap_config) }
|
298
|
-
let(:entry) { create_entry :uid => 'unique identifier', :givenName => 'first name', :sn => 'last name' }
|
588
|
+
let(:connector) { Socialcast::CommandLine::LDAPConnector.new('connection_1', ldap_config, ldap) }
|
589
|
+
let(:entry) { create_entry 'user', :uid => 'unique identifier', :givenName => 'first name', :sn => 'last name' }
|
299
590
|
before do
|
300
591
|
filter = Net::LDAP::Filter.construct('(&(mail=*)(uid=unique identifier))')
|
301
|
-
|
592
|
+
ldap.should_receive(:search).once
|
302
593
|
.with(hash_including(:attributes => ['givenName', 'sn', 'uid', 'isMemberOf'], :filter => filter))
|
303
594
|
.and_yield(entry)
|
304
595
|
end
|
@@ -315,11 +606,11 @@ describe Socialcast::CommandLine::LDAPConnector do
|
|
315
606
|
end
|
316
607
|
end
|
317
608
|
context "specifying an identifying field" do
|
318
|
-
let(:connector) { Socialcast::CommandLine::LDAPConnector.new('connection_1', ldap_config) }
|
319
|
-
let(:entry) { create_entry :mail => 'user@example.com', :givenName => 'first name', :sn => 'last name' }
|
609
|
+
let(:connector) { Socialcast::CommandLine::LDAPConnector.new('connection_1', ldap_config, ldap) }
|
610
|
+
let(:entry) { create_entry 'user', :mail => 'user@example.com', :givenName => 'first name', :sn => 'last name' }
|
320
611
|
before do
|
321
612
|
filter = Net::LDAP::Filter.construct('(&(mail=*)(mail=user@example.com))')
|
322
|
-
|
613
|
+
ldap.should_receive(:search).once
|
323
614
|
.with(hash_including(:attributes => ['givenName', 'sn', 'mail', 'isMemberOf'], :filter => filter))
|
324
615
|
.and_yield(entry)
|
325
616
|
end
|
@@ -339,11 +630,11 @@ describe Socialcast::CommandLine::LDAPConnector do
|
|
339
630
|
|
340
631
|
context "without a filter specified" do
|
341
632
|
let(:filter) { "" }
|
342
|
-
let(:connector) { Socialcast::CommandLine::LDAPConnector.new('connection_1', ldap_config) }
|
343
|
-
let(:entry) { create_entry :mail => 'user@example.com', :givenName => 'first name', :sn => 'last name' }
|
633
|
+
let(:connector) { Socialcast::CommandLine::LDAPConnector.new('connection_1', ldap_config, ldap) }
|
634
|
+
let(:entry) { create_entry 'user', :mail => 'user@example.com', :givenName => 'first name', :sn => 'last name' }
|
344
635
|
before do
|
345
636
|
filter = Net::LDAP::Filter.construct('(&(objectclass=*)(mail=user@example.com))')
|
346
|
-
|
637
|
+
ldap.should_receive(:search).once
|
347
638
|
.with(hash_including(:attributes => ['givenName', 'sn', 'mail', 'isMemberOf'], :filter => filter))
|
348
639
|
.and_yield(entry)
|
349
640
|
end
|
@@ -362,27 +653,6 @@ describe Socialcast::CommandLine::LDAPConnector do
|
|
362
653
|
end
|
363
654
|
end
|
364
655
|
|
365
|
-
describe '#dereference_mail' do
|
366
|
-
context "called on directreport entry" do
|
367
|
-
let(:entry) do
|
368
|
-
Net::LDAP::Entry.new("cn=directreport,dc=example,dc=com").tap do |e|
|
369
|
-
e[:mail] = 'directreport@example.com'
|
370
|
-
e[:manager] = 'cn=bossman,dc=example,dc=com'
|
371
|
-
end
|
372
|
-
end
|
373
|
-
let(:ldap) { double(Net::LDAP, :encryption => nil, :auth => nil) }
|
374
|
-
before do
|
375
|
-
Net::LDAP.should_receive(:new).and_return(ldap)
|
376
|
-
manager_entry = Net::LDAP::Entry.new("cn=bossman,dc=example,dc=com")
|
377
|
-
manager_entry[:mail] = 'bossman@example.com'
|
378
|
-
ldap.should_receive(:search).with(:base => "cn=bossman,dc=example,dc=com", :scope => 0).and_yield(manager_entry)
|
379
|
-
end
|
380
|
-
it "will return bossman email" do
|
381
|
-
Socialcast::CommandLine::LDAPConnector.new('connection_1', ldap_config).send(:dereference_mail, entry, 'manager', 'mail').should == "bossman@example.com"
|
382
|
-
end
|
383
|
-
end
|
384
|
-
end
|
385
|
-
|
386
656
|
describe "#grab" do
|
387
657
|
let(:mappings) do
|
388
658
|
{
|
@@ -391,7 +661,7 @@ describe Socialcast::CommandLine::LDAPConnector do
|
|
391
661
|
"email" => "mail"
|
392
662
|
}
|
393
663
|
end
|
394
|
-
let(:connector) { Socialcast::CommandLine::LDAPConnector.new('connection_1', ldap_config) }
|
664
|
+
let(:connector) { Socialcast::CommandLine::LDAPConnector.new('connection_1', ldap_config, ldap) }
|
395
665
|
let(:entry) do
|
396
666
|
Net::LDAP::Entry.new("cn=sean,dc=example,dc=com").tap do |e|
|
397
667
|
e[:mail] = 'sean@example.com'
|