socialcast 1.3.16 → 1.3.17

Sign up to get free protection for your applications and to get access to all the features.
@@ -19,8 +19,8 @@ describe Socialcast::CommandLine::ProvisionUser do
19
19
 
20
20
  let(:ldap) do
21
21
  ldap_instance = double(Net::LDAP, :auth => nil, :encryption => nil)
22
- ldap_instance.should_receive(:open).and_yield
23
- Net::LDAP.should_receive(:new).and_return(ldap_instance)
22
+ expect(ldap_instance).to receive(:open).and_yield
23
+ expect(Net::LDAP).to receive(:new).and_return(ldap_instance)
24
24
  ldap_instance
25
25
  end
26
26
 
@@ -28,40 +28,40 @@ describe Socialcast::CommandLine::ProvisionUser do
28
28
  let(:result) { '' }
29
29
 
30
30
  before do
31
- Zlib::GzipWriter.stub(:open).and_yield(result)
32
- Socialcast::CommandLine.stub(:credentials).and_return(credentials)
33
- File.stub(:open).with(/users.xml.gz/, anything).and_yield(result)
31
+ allow(Zlib::GzipWriter).to receive(:open).and_yield(result)
32
+ allow(Socialcast::CommandLine).to receive(:credentials).and_return(credentials)
33
+ allow(File).to receive(:open).with(/users.xml.gz/, anything).and_yield(result)
34
34
  end
35
35
 
36
36
  context "when the entry has an email" do
37
37
  before do
38
38
  entry = create_entry 'user', :mail => 'user@example.com', :givenName => 'first name', :sn => 'last name'
39
- ldap.should_receive(:search).once.with(hash_including(:attributes => ['givenName', 'sn', 'mail', 'isMemberOf'])).and_yield(entry)
40
- RestClient::Resource.any_instance.should_receive(:post).once.with(hash_including(:file => result), { :accept => :json })
39
+ expect(ldap).to receive(:search).once.with(hash_including(:attributes => ['givenName', 'sn', 'mail', 'isMemberOf'])).and_yield(entry)
40
+ expect_any_instance_of(RestClient::Resource).to receive(:post).once.with(hash_including(:file => result), { :accept => :json })
41
41
 
42
42
  Socialcast::CommandLine::ProvisionUser.new(ldap_default_config, {}).provision
43
43
  end
44
44
  it "puts the user in the output file" do
45
- result.should =~ /user@example.com/
45
+ expect(result).to match(/user@example.com/)
46
46
  end
47
47
  end
48
48
  context "when the entry has a unique_identifier" do
49
49
  before do
50
50
  entry = create_entry 'user', :uid => 'userID', :givenName => 'first name', :sn => 'last name'
51
- ldap.should_receive(:search).once.with(hash_including(:attributes => ['givenName', 'sn', 'uid', 'isMemberOf'])).and_yield(entry)
52
- RestClient::Resource.any_instance.should_receive(:post).once.with(hash_including(:file => result), { :accept => :json })
51
+ expect(ldap).to receive(:search).once.with(hash_including(:attributes => ['givenName', 'sn', 'uid', 'isMemberOf'])).and_yield(entry)
52
+ expect_any_instance_of(RestClient::Resource).to receive(:post).once.with(hash_including(:file => result), { :accept => :json })
53
53
 
54
54
  Socialcast::CommandLine::ProvisionUser.new(ldap_with_unique_identifier_config, {}).provision
55
55
  end
56
56
  it "puts the user in the output file" do
57
- result.should =~ /userID/
57
+ expect(result).to match(/userID/)
58
58
  end
59
59
  end
60
60
  context "when the entry has no email or unique_identifier" do
61
61
  before do
62
62
  entry = create_entry 'user', :mail => '', :givenName => 'first name', :sn => 'last name'
63
- ldap.should_receive(:search).once.with(hash_including(:attributes => ['givenName', 'sn', 'mail', 'isMemberOf'])).and_yield(entry)
64
- RestClient::Resource.any_instance.should_not_receive(:post)
63
+ expect(ldap).to receive(:search).once.with(hash_including(:attributes => ['givenName', 'sn', 'mail', 'isMemberOf'])).and_yield(entry)
64
+ expect_any_instance_of(RestClient::Resource).not_to receive(:post)
65
65
  end
66
66
  it "does not put the user in the output file" do
67
67
  expect do
@@ -79,25 +79,25 @@ describe Socialcast::CommandLine::ProvisionUser do
79
79
  <roles type="array"/>
80
80
  </user>]
81
81
  end
82
- result.gsub(/\s/, '').should == %Q[
82
+ expect(result.gsub(/\s/, '')).to eq(%Q[
83
83
  <?xml version="1.0" encoding="UTF-8"?>
84
84
  <export>
85
85
  <users type="array">
86
86
  #{users}
87
87
  </users>
88
88
  </export>
89
- ].gsub(/\s/, '')
89
+ ].gsub(/\s/, ''))
90
90
  end
91
91
  end
92
92
 
93
93
  before do
94
- RestClient::Resource.any_instance.should_receive(:post).once.with(hash_including(:file => result), { :accept => :json })
94
+ expect_any_instance_of(RestClient::Resource).to receive(:post).once.with(hash_including(:file => result), { :accept => :json })
95
95
  end
96
96
 
97
97
  context "with mappings at the global level" do
98
98
  before do
99
99
  entry = create_entry 'user', :mail => 'user@example.com', :givenName => 'first name', :sn => 'last name'
100
- ldap.should_receive(:search).once.with(hash_including(:attributes => ['givenName', 'sn', 'mail', 'isMemberOf'])).and_yield(entry)
100
+ expect(ldap).to receive(:search).once.with(hash_including(:attributes => ['givenName', 'sn', 'mail', 'isMemberOf'])).and_yield(entry)
101
101
 
102
102
  Socialcast::CommandLine::ProvisionUser.new(ldap_default_config, {}).provision
103
103
  end
@@ -117,16 +117,16 @@ describe Socialcast::CommandLine::ProvisionUser do
117
117
  provision_instance = Socialcast::CommandLine::ProvisionUser.new(ldap_multiple_connection_mapping_config, {})
118
118
 
119
119
  ldap_instance1 = double(Net::LDAP, :encryption => nil, :auth => nil)
120
- ldap_instance1.should_receive(:open).and_yield
121
- Net::LDAP.should_receive(:new).once.ordered.and_return(ldap_instance1)
120
+ expect(ldap_instance1).to receive(:open).and_yield
121
+ expect(Net::LDAP).to receive(:new).once.ordered.and_return(ldap_instance1)
122
122
  entry1 = create_entry 'user', :mailCon => 'user@example.com', :givenName => 'first name', :sn => 'last name'
123
- ldap_instance1.should_receive(:search).once.with(hash_including(:attributes => ['mailCon', 'isMemberOf'])).and_yield(entry1)
123
+ expect(ldap_instance1).to receive(:search).once.with(hash_including(:attributes => ['mailCon', 'isMemberOf'])).and_yield(entry1)
124
124
 
125
125
  ldap_instance2 = double(Net::LDAP, :encryption => nil, :auth => nil)
126
- ldap_instance2.should_receive(:open).and_yield
127
- Net::LDAP.should_receive(:new).once.ordered.and_return(ldap_instance2)
126
+ expect(ldap_instance2).to receive(:open).and_yield
127
+ expect(Net::LDAP).to receive(:new).once.ordered.and_return(ldap_instance2)
128
128
  entry2 = create_entry 'user', :mailCon2 => 'user2@example.com', :firstName => 'first name2', :sn => 'last name2'
129
- ldap_instance2.should_receive(:search).once.with(hash_including(:attributes => ['mailCon2', 'firstName', 'isMemberOf'])).and_yield(entry2)
129
+ expect(ldap_instance2).to receive(:search).once.with(hash_including(:attributes => ['mailCon2', 'firstName', 'isMemberOf'])).and_yield(entry2)
130
130
 
131
131
  provision_instance.provision
132
132
  end
@@ -148,7 +148,7 @@ describe Socialcast::CommandLine::ProvisionUser do
148
148
  context "with custom attribute mappings" do
149
149
  before do
150
150
  entry = create_entry 'user', :mail => 'user@example.com', :custom_ldap1 => 'custom value 1', :custom_ldap2 => 'custom value 2'
151
- ldap.should_receive(:search).once.with(hash_including(:attributes => ['custom_ldap1', 'custom_ldap2', 'mail', 'isMemberOf'])).and_yield(entry)
151
+ expect(ldap).to receive(:search).once.with(hash_including(:attributes => ['custom_ldap1', 'custom_ldap2', 'mail', 'isMemberOf'])).and_yield(entry)
152
152
 
153
153
  Socialcast::CommandLine::ProvisionUser.new(ldap_with_custom_attributes_config, {}).provision
154
154
  end
@@ -177,13 +177,13 @@ describe Socialcast::CommandLine::ProvisionUser do
177
177
  provision_instance = Socialcast::CommandLine::ProvisionUser.new(ldap_with_manager_attribute_config, {})
178
178
 
179
179
  ldap_instance = double(Net::LDAP, :encryption => nil, :auth => nil)
180
- ldap_instance.should_receive(:open).and_yield
181
- Net::LDAP.should_receive(:new).once.and_return(ldap_instance)
180
+ expect(ldap_instance).to receive(:open).and_yield
181
+ expect(Net::LDAP).to receive(:new).once.and_return(ldap_instance)
182
182
 
183
183
  user_entry = create_entry 'user', :mail => 'user@example.com', :ldap_manager => 'cn=theboss,dc=example,dc=com'
184
184
  manager_entry = create_entry 'theboss', :mail => 'boss@example.com'
185
- ldap_instance.should_receive(:search).once.ordered.and_yield(user_entry).and_yield(manager_entry)
186
- ldap_instance.should_receive(:search).once.ordered.and_yield(user_entry).and_yield(manager_entry)
185
+ expect(ldap_instance).to receive(:search).once.ordered.and_yield(user_entry).and_yield(manager_entry)
186
+ expect(ldap_instance).to receive(:search).once.ordered.and_yield(user_entry).and_yield(manager_entry)
187
187
 
188
188
  provision_instance.provision
189
189
  end
@@ -216,7 +216,7 @@ describe Socialcast::CommandLine::ProvisionUser do
216
216
  before do
217
217
  module TestLdapAttributeMapping end
218
218
  entry = create_entry 'user', :test_ldap_attribute_mapping => 'user@example.com'
219
- ldap.should_receive(:search).once.with(hash_including(:attributes => ['test_ldap_attribute_mapping', 'isMemberOf'])).and_yield(entry)
219
+ expect(ldap).to receive(:search).once.with(hash_including(:attributes => ['test_ldap_attribute_mapping', 'isMemberOf'])).and_yield(entry)
220
220
 
221
221
  Socialcast::CommandLine::ProvisionUser.new(ldap_with_class_ldap_attribute_config, {}).provision
222
222
  end
@@ -235,7 +235,7 @@ describe Socialcast::CommandLine::ProvisionUser do
235
235
  context "without options specified" do
236
236
  before do
237
237
  entry = create_entry 'user', :mail => 'user@example.com', :givenName => 'first name', :sn => 'last name'
238
- ldap.should_receive(:search).once.with(hash_including(:attributes => ['givenName', 'sn', 'mail', 'isMemberOf'])).and_yield(entry)
238
+ expect(ldap).to receive(:search).once.with(hash_including(:attributes => ['givenName', 'sn', 'mail', 'isMemberOf'])).and_yield(entry)
239
239
 
240
240
  Socialcast::CommandLine::ProvisionUser.new(ldap_without_options_config, {}).provision
241
241
  end
@@ -253,7 +253,7 @@ describe Socialcast::CommandLine::ProvisionUser do
253
253
  context "with profile_photo attribute mappings" do
254
254
  before do
255
255
  entry = create_entry 'user', :mail => 'user@example.com', :givenName => 'first name', :sn => 'last name'
256
- ldap.should_receive(:search).once.with(hash_including(:attributes => ['givenName', 'sn', 'mail', 'memberof'])).and_yield(entry)
256
+ expect(ldap).to receive(:search).once.with(hash_including(:attributes => ['givenName', 'sn', 'mail', 'memberof'])).and_yield(entry)
257
257
 
258
258
  Socialcast::CommandLine::ProvisionUser.new(ldap_with_profile_photo_config, {}).provision
259
259
  end
@@ -282,14 +282,14 @@ describe Socialcast::CommandLine::ProvisionUser do
282
282
  #{permission_xml}
283
283
  </user>]
284
284
  end
285
- result.gsub(/\s/, '').should == %Q[
285
+ expect(result.gsub(/\s/, '')).to eq(%Q[
286
286
  <?xml version="1.0" encoding="UTF-8"?>
287
287
  <export>
288
288
  <users type="array">
289
289
  #{users}
290
290
  </users>
291
291
  </export>
292
- ].gsub(/\s/, '')
292
+ ].gsub(/\s/, ''))
293
293
  end
294
294
  end
295
295
 
@@ -297,13 +297,13 @@ describe Socialcast::CommandLine::ProvisionUser do
297
297
  let(:ldap_group_attribute) { 'isMemberOf' }
298
298
 
299
299
  before do
300
- RestClient::Resource.any_instance.should_receive(:post).once.with(hash_including(:file => result), { :accept => :json })
300
+ expect_any_instance_of(RestClient::Resource).to receive(:post).once.with(hash_including(:file => result), { :accept => :json })
301
301
  end
302
302
 
303
303
  context "with roles for an external contributor" do
304
304
  let(:ldap_groups) { ["cn=External,dc=example,dc=com", "cn=SbiAdmins,dc=example,dc=com", "cn=TownHallAdmins,dc=example,dc=com"] }
305
305
  before do
306
- ldap.should_receive(:search).once.with(hash_including(:attributes => ['givenName', 'sn', 'mail', ldap_group_attribute])).and_yield(entry)
306
+ expect(ldap).to receive(:search).once.with(hash_including(:attributes => ['givenName', 'sn', 'mail', ldap_group_attribute])).and_yield(entry)
307
307
  Socialcast::CommandLine::ProvisionUser.new(ldap_default_config, {}).provision
308
308
  end
309
309
  let(:expected_permission_xml) do
@@ -315,7 +315,7 @@ describe Socialcast::CommandLine::ProvisionUser do
315
315
  context "with roles for a member" do
316
316
  let(:ldap_groups) { ["cn=SbiAdmins,dc=example,dc=com", "cn=TownHallAdmins,dc=example,dc=com"] }
317
317
  before do
318
- ldap.should_receive(:search).once.with(hash_including(:attributes => ['givenName', 'sn', 'mail', ldap_group_attribute])).and_yield(entry)
318
+ expect(ldap).to receive(:search).once.with(hash_including(:attributes => ['givenName', 'sn', 'mail', ldap_group_attribute])).and_yield(entry)
319
319
  Socialcast::CommandLine::ProvisionUser.new(ldap_default_config, {}).provision
320
320
  end
321
321
  let(:expected_permission_xml) do
@@ -331,7 +331,7 @@ describe Socialcast::CommandLine::ProvisionUser do
331
331
  context "with account_types mapping and no role mappings" do
332
332
  let(:ldap_groups) { ["cn=SbiAdmins,dc=example,dc=com", "cn=TownHallAdmins,dc=example,dc=com"] }
333
333
  before do
334
- ldap.should_receive(:search).once.with(hash_including(:attributes => ['givenName', 'sn', 'mail', ldap_group_attribute])).and_yield(entry)
334
+ expect(ldap).to receive(:search).once.with(hash_including(:attributes => ['givenName', 'sn', 'mail', ldap_group_attribute])).and_yield(entry)
335
335
  Socialcast::CommandLine::ProvisionUser.new(ldap_with_account_type_without_roles_config, {}).provision
336
336
  end
337
337
  let(:expected_permission_xml) do
@@ -343,7 +343,7 @@ describe Socialcast::CommandLine::ProvisionUser do
343
343
  context "with role mappings and no account_type mapping" do
344
344
  let(:ldap_groups) { ["cn=SbiAdmins,dc=example,dc=com", "cn=TownHallAdmins,dc=example,dc=com"] }
345
345
  before do
346
- ldap.should_receive(:search).once.with(hash_including(:attributes => ['givenName', 'sn', 'mail', ldap_group_attribute])).and_yield(entry)
346
+ expect(ldap).to receive(:search).once.with(hash_including(:attributes => ['givenName', 'sn', 'mail', ldap_group_attribute])).and_yield(entry)
347
347
  Socialcast::CommandLine::ProvisionUser.new(ldap_with_roles_without_account_type_config, {}).provision
348
348
  end
349
349
  let(:expected_permission_xml) do
@@ -359,7 +359,7 @@ describe Socialcast::CommandLine::ProvisionUser do
359
359
  context "without account_type or roles mappings" do
360
360
  let(:ldap_groups) { ["cn=SbiAdmins,dc=example,dc=com", "cn=TownHallAdmins,dc=example,dc=com"] }
361
361
  before do
362
- ldap.should_receive(:search).once.with(hash_including(:attributes => ['givenName', 'sn', 'mail', ldap_group_attribute])).and_yield(entry)
362
+ expect(ldap).to receive(:search).once.with(hash_including(:attributes => ['givenName', 'sn', 'mail', ldap_group_attribute])).and_yield(entry)
363
363
  Socialcast::CommandLine::ProvisionUser.new(ldap_without_account_type_or_roles_config, {}).provision
364
364
  end
365
365
  let(:expected_permission_xml) do
@@ -375,16 +375,16 @@ describe Socialcast::CommandLine::ProvisionUser do
375
375
  provision_instance = Socialcast::CommandLine::ProvisionUser.new(ldap_multiple_connection_permission_mapping_config, {})
376
376
 
377
377
  ldap_instance1 = double(Net::LDAP, :encryption => nil, :auth => nil)
378
- ldap_instance1.should_receive(:open).and_yield
379
- Net::LDAP.should_receive(:new).once.ordered.and_return(ldap_instance1)
378
+ expect(ldap_instance1).to receive(:open).and_yield
379
+ expect(Net::LDAP).to receive(:new).once.ordered.and_return(ldap_instance1)
380
380
  entry1 = create_entry 'user', :mail => 'user@example.com', :givenName => 'first name', :sn => 'last name', :memberOf => ["cn=External,dc=example,dc=com", "cn=SbiAdmins,dc=example,dc=com", "cn=TownHallAdmins,dc=example,dc=com"]
381
- ldap_instance1.should_receive(:search).once.with(hash_including(:attributes => ['givenName', 'sn', 'mail', 'memberOf'])).and_yield(entry1)
381
+ expect(ldap_instance1).to receive(:search).once.with(hash_including(:attributes => ['givenName', 'sn', 'mail', 'memberOf'])).and_yield(entry1)
382
382
 
383
383
  ldap_instance2 = double(Net::LDAP, :encryption => nil, :auth => nil)
384
- ldap_instance2.should_receive(:open).and_yield
385
- Net::LDAP.should_receive(:new).once.ordered.and_return(ldap_instance2)
384
+ expect(ldap_instance2).to receive(:open).and_yield
385
+ expect(Net::LDAP).to receive(:new).once.ordered.and_return(ldap_instance2)
386
386
  entry2 = create_entry 'user', :mail => 'user@example.com', :givenName => 'first name', :sn => 'last name', :member => ["cn=Contractors,dc=example,dc=com", "cn=SbiAdmins,dc=example,dc=com", "cn=TownHallAdmins,dc=example,dc=com"]
387
- ldap_instance2.should_receive(:search).once.with(hash_including(:attributes => ['givenName', 'sn', 'mail', 'member'])).and_yield(entry2)
387
+ expect(ldap_instance2).to receive(:search).once.with(hash_including(:attributes => ['givenName', 'sn', 'mail', 'member'])).and_yield(entry2)
388
388
 
389
389
  provision_instance.provision
390
390
  end
@@ -404,24 +404,50 @@ describe Socialcast::CommandLine::ProvisionUser do
404
404
 
405
405
  context "with no basedn configured" do
406
406
  before do
407
- RestClient::Resource.any_instance.should_receive(:post).once.with(hash_including(:file => result), { :accept => :json })
407
+ expect_any_instance_of(RestClient::Resource).to receive(:post).once.with(hash_including(:file => result), { :accept => :json })
408
408
 
409
409
  provision_instance = Socialcast::CommandLine::ProvisionUser.new(ldap_blank_basedn_config, {})
410
410
 
411
411
  root_entry = create_entry('domain', :namingcontexts => ['dc=foo,dc=com', 'dc=bar,dc=com'])
412
412
  ldap_instance = double(Net::LDAP, :encryption => nil, :auth => nil)
413
- ldap_instance.should_receive(:search_root_dse).once.and_return(root_entry)
414
- ldap_instance.should_receive(:open).and_yield
415
- Net::LDAP.should_receive(:new).once.and_return(ldap_instance)
413
+ expect(ldap_instance).to receive(:search_root_dse).once.and_return(root_entry)
414
+ expect(ldap_instance).to receive(:open).and_yield
415
+ expect(Net::LDAP).to receive(:new).once.and_return(ldap_instance)
416
416
 
417
417
  user_entry = create_entry 'user', :mail => 'user@example.com', :givenName => 'first name', :sn => 'last name'
418
- ldap_instance.should_receive(:search).once.ordered.with(hash_including(:base => 'dc=foo,dc=com', :attributes => ['givenName', 'sn', 'mail', 'isMemberOf']))
419
- ldap_instance.should_receive(:search).once.ordered.with(hash_including(:base => 'dc=bar,dc=com', :attributes => ['givenName', 'sn', 'mail', 'isMemberOf'])).and_yield(user_entry)
418
+ expect(ldap_instance).to receive(:search).once.ordered.with(hash_including(:base => 'dc=foo,dc=com', :attributes => ['givenName', 'sn', 'mail', 'isMemberOf']))
419
+ expect(ldap_instance).to receive(:search).once.ordered.with(hash_including(:base => 'dc=bar,dc=com', :attributes => ['givenName', 'sn', 'mail', 'isMemberOf'])).and_yield(user_entry)
420
420
 
421
421
  provision_instance.provision
422
422
  end
423
423
  it "searches all basedns and puts the user in the output file" do
424
- result.should =~ /user@example.com/
424
+ expect(result).to match(/user@example.com/)
425
+ end
426
+ end
427
+
428
+ context 'when a 401 response is received' do
429
+ before do
430
+ entry = create_entry 'user', :mail => 'user@example.com', :givenName => 'first name', :sn => 'last name'
431
+ expect(ldap).to receive(:search).once.with(hash_including(:attributes => ['givenName', 'sn', 'mail', 'isMemberOf'])).and_yield(entry)
432
+ stub_request(:post, "https://ryan%40socialcast.com:foo@test.staging.socialcast.com/api/users/provision").to_return(:status => 401)
433
+ end
434
+ it do
435
+ expect do
436
+ Socialcast::CommandLine::ProvisionUser.new(ldap_default_config, {}).provision
437
+ end.to raise_error Socialcast::CommandLine::ProvisionUser::ProvisionError, /Unauthorized/
438
+ end
439
+ end
440
+
441
+ context 'when a 403 response is received' do
442
+ before do
443
+ entry = create_entry 'user', :mail => 'user@example.com', :givenName => 'first name', :sn => 'last name'
444
+ expect(ldap).to receive(:search).once.with(hash_including(:attributes => ['givenName', 'sn', 'mail', 'isMemberOf'])).and_yield(entry)
445
+ stub_request(:post, "https://ryan%40socialcast.com:foo@test.staging.socialcast.com/api/users/provision").to_return(:status => 403)
446
+ end
447
+ it do
448
+ expect do
449
+ Socialcast::CommandLine::ProvisionUser.new(ldap_default_config, {}).provision
450
+ end.to raise_error Socialcast::CommandLine::ProvisionUser::ProvisionError, /Forbidden/
425
451
  end
426
452
  end
427
453
  end
@@ -430,7 +456,7 @@ describe Socialcast::CommandLine::ProvisionUser do
430
456
  let(:provision_instance) { Socialcast::CommandLine::ProvisionUser.new(ldap_default_config) }
431
457
  before do
432
458
  entry = create_entry 'user', :mail => 'user@example.com', :givenName => 'first name', :sn => 'last name'
433
- ldap.should_receive(:search).once.with(hash_including(:attributes => ['givenName', 'sn', 'mail', 'isMemberOf'])).and_yield(entry)
459
+ expect(ldap).to receive(:search).once.with(hash_including(:attributes => ['givenName', 'sn', 'mail', 'isMemberOf'])).and_yield(entry)
434
460
  end
435
461
  it do
436
462
  expect do |blk|
@@ -454,19 +480,19 @@ describe Socialcast::CommandLine::ProvisionUser do
454
480
  let(:entry) { create_entry 'user', :mailCon => 'user@example.com' }
455
481
  before do
456
482
  filter = Net::LDAP::Filter.construct('(&(mail=*)(mailCon=user@example.com))')
457
- ldap.should_receive(:search).once
483
+ expect(ldap).to receive(:search).once
458
484
  .with(hash_including(:attributes => ['mailCon', 'isMemberOf'], :filter => filter))
459
485
  .and_yield(entry)
460
486
  end
461
487
  it "returns the entry" do
462
- provision_instance.fetch_user_hash('user@example.com', :identifying_field => 'email').should == {
488
+ expect(provision_instance.fetch_user_hash('user@example.com', :identifying_field => 'email')).to eq({
463
489
  'account_type' => 'member',
464
490
  'contact_info' => {
465
491
  'email' => 'user@example.com'
466
492
  },
467
493
  'custom_fields' => [],
468
494
  'roles' => []
469
- }
495
+ })
470
496
  end
471
497
  end
472
498
  context "when another connector returns the entry" do
@@ -474,23 +500,23 @@ describe Socialcast::CommandLine::ProvisionUser do
474
500
  let(:entry) { create_entry 'user', :mailCon2 => 'user@example.com', :firstName => 'first name' }
475
501
  before do
476
502
  ldap_instance1 = double(Net::LDAP, :auth => nil)
477
- ldap_instance1.should_receive(:open).and_yield
478
- Net::LDAP.should_receive(:new).once.ordered.and_return(ldap_instance1)
503
+ expect(ldap_instance1).to receive(:open).and_yield
504
+ expect(Net::LDAP).to receive(:new).once.ordered.and_return(ldap_instance1)
479
505
  filter1 = Net::LDAP::Filter.construct('(&(mail=*)(mailCon=user@example.com))')
480
- ldap_instance1.should_receive(:search).once.ordered
506
+ expect(ldap_instance1).to receive(:search).once.ordered
481
507
  .with(hash_including(:attributes => ['mailCon', 'isMemberOf'], :filter => filter1))
482
508
 
483
509
  ldap_instance2 = double(Net::LDAP, :auth => nil)
484
- ldap_instance2.should_receive(:open).and_yield
485
- Net::LDAP.should_receive(:new).once.ordered.and_return(ldap_instance2)
510
+ expect(ldap_instance2).to receive(:open).and_yield
511
+ expect(Net::LDAP).to receive(:new).once.ordered.and_return(ldap_instance2)
486
512
  filter2 = Net::LDAP::Filter.construct('(&(mail=*)(mailCon2=user@example.com))')
487
- ldap_instance2.should_receive(:search).once.ordered
513
+ expect(ldap_instance2).to receive(:search).once.ordered
488
514
  .with(hash_including(:attributes => ['mailCon2', 'firstName', 'isMemberOf'], :filter => filter2))
489
515
  .and_yield(entry)
490
516
 
491
517
  end
492
518
  it "returns the entry" do
493
- provision_instance.fetch_user_hash('user@example.com', :identifying_field => 'email').should == {
519
+ expect(provision_instance.fetch_user_hash('user@example.com', :identifying_field => 'email')).to eq({
494
520
  'account_type' => 'member',
495
521
  'contact_info' => {
496
522
  'email' => 'user@example.com'
@@ -498,28 +524,28 @@ describe Socialcast::CommandLine::ProvisionUser do
498
524
  'first_name' => 'first name',
499
525
  'custom_fields' => [],
500
526
  'roles' => []
501
- }
527
+ })
502
528
  end
503
529
  end
504
530
  context "when no connectors return the entry" do
505
531
  let(:provision_instance) { Socialcast::CommandLine::ProvisionUser.new(ldap_multiple_connection_mapping_config, {}) }
506
532
  before do
507
533
  ldap_instance1 = double(Net::LDAP, :auth => nil)
508
- ldap_instance1.should_receive(:open).and_yield
509
- Net::LDAP.should_receive(:new).once.ordered.and_return(ldap_instance1)
534
+ expect(ldap_instance1).to receive(:open).and_yield
535
+ expect(Net::LDAP).to receive(:new).once.ordered.and_return(ldap_instance1)
510
536
  filter1 = Net::LDAP::Filter.construct('(&(mail=*)(mailCon=user@example.com))')
511
- ldap_instance1.should_receive(:search)
537
+ expect(ldap_instance1).to receive(:search)
512
538
  .with(hash_including(:attributes => ['mailCon', 'isMemberOf'], :filter => filter1))
513
539
 
514
540
  ldap_instance2 = double(Net::LDAP, :auth => nil)
515
- ldap_instance2.should_receive(:open).and_yield
516
- Net::LDAP.should_receive(:new).once.ordered.and_return(ldap_instance2)
541
+ expect(ldap_instance2).to receive(:open).and_yield
542
+ expect(Net::LDAP).to receive(:new).once.ordered.and_return(ldap_instance2)
517
543
  filter2 = Net::LDAP::Filter.construct('(&(mail=*)(mailCon2=user@example.com))')
518
- ldap_instance2.should_receive(:search).once.ordered
544
+ expect(ldap_instance2).to receive(:search).once.ordered
519
545
  .with(hash_including(:attributes => ['mailCon2', 'firstName', 'isMemberOf'], :filter => filter2))
520
546
  end
521
547
  it "returns nil" do
522
- provision_instance.fetch_user_hash('user@example.com', :identifying_field => 'email').should be_nil
548
+ expect(provision_instance.fetch_user_hash('user@example.com', :identifying_field => 'email')).to be_nil
523
549
  end
524
550
  end
525
551
  end
@@ -4,7 +4,7 @@ describe Socialcast::CommandLine do
4
4
 
5
5
  let(:custom_file) { File.join(File.dirname(__FILE__), '..', 'fixtures', 'custom_credentials.yml') }
6
6
  let(:stubbed_credentials) { File.join(File.dirname(__FILE__), '..', 'fixtures') }
7
- before { Socialcast::CommandLine.stub(:config_dir).and_return(stubbed_credentials) }
7
+ before { allow(Socialcast::CommandLine).to receive(:config_dir).and_return(stubbed_credentials) }
8
8
  let!(:orig_credentials) { Socialcast::CommandLine.credentials }
9
9
 
10
10
  describe '.credentials_file' do
@@ -24,10 +24,10 @@ describe Socialcast::CommandLine do
24
24
  describe 'with ENV variable' do
25
25
  before { ENV['SC_CREDENTIALS_FILE'] = custom_file }
26
26
  after { ENV['SC_CREDENTIALS_FILE'] = nil }
27
- it { subject[:user].should == 'mike@socialcast.com' }
27
+ it { expect(subject[:user]).to eq('mike@socialcast.com') }
28
28
  end
29
29
  describe 'without ENV variable' do
30
- it { subject[:user].should == 'ryan@socialcast.com' }
30
+ it { expect(subject[:user]).to eq('ryan@socialcast.com') }
31
31
  end
32
32
  end
33
33
 
@@ -37,29 +37,51 @@ describe Socialcast::CommandLine do
37
37
  after { Socialcast::CommandLine.credentials = orig_credentials }
38
38
  subject { Socialcast::CommandLine.credentials }
39
39
  context 'modifies the credentials file with the options content' do
40
- it { subject[:user].should == 'mike@socialcast.com' }
40
+ it { expect(subject[:user]).to eq('mike@socialcast.com') }
41
41
  end
42
42
  context 'only changes the content provided' do
43
43
  let(:options) { { :api_client_secret => 'mysecret', :api_client_identifier => 'my_id' } }
44
- it { subject[:api_client_identifier].should == 'my_id' }
45
- it { subject[:user].should == 'ryan@socialcast.com' }
44
+ it { expect(subject[:api_client_identifier]).to eq('my_id') }
45
+ it { expect(subject[:user]).to eq('ryan@socialcast.com') }
46
46
  end
47
47
  end
48
48
 
49
49
  describe '.resource_for_path' do
50
50
  let(:path) { '/mypath' }
51
51
  let(:url) { "https://test.staging.socialcast.com#{path}" }
52
- before do
53
- RestClient::Resource.should_receive(:new).with(url, options)
54
- Socialcast::CommandLine.resource_for_path(path, options)
55
- end
56
52
  context 'when using basic auth' do
57
53
  let(:options) { { :user => Socialcast::CommandLine.credentials[:user], :password => Socialcast::CommandLine.credentials[:password] } }
54
+ before do
55
+ expect(RestClient::Resource).to receive(:new).with(url, options)
56
+ Socialcast::CommandLine.resource_for_path(path, options)
57
+ end
58
58
  it 'sends user email and password' do end
59
59
  end
60
60
  context 'when using an external system' do
61
61
  let(:options) { { :external_system => true, :headers => { :Authorization=>"SocialcastApiClient my_id:mysecret" } } }
62
+ before do
63
+ expect(RestClient::Resource).to receive(:new).with(url, options)
64
+ Socialcast::CommandLine.resource_for_path(path, options)
65
+ end
62
66
  it 'sends external system credentials' do end
63
67
  end
68
+ context 'when options["skip_ssl_validation"] == false' do
69
+ let(:options) { { 'skip_ssl_validation' => false, :user => Socialcast::CommandLine.credentials[:user], :password => Socialcast::CommandLine.credentials[:password] } }
70
+ before do
71
+ received_options = { :user => Socialcast::CommandLine.credentials[:user], :password => Socialcast::CommandLine.credentials[:password] }
72
+ expect(RestClient::Resource).to receive(:new).with(url, received_options)
73
+ Socialcast::CommandLine.resource_for_path(path, options)
74
+ end
75
+ it 'does not send skip ssl validation option' do end
76
+ end
77
+ context 'when options["skip_ssl_validation"] == true' do
78
+ let(:options) { { 'skip_ssl_validation' => true, :user => Socialcast::CommandLine.credentials[:user], :password => Socialcast::CommandLine.credentials[:password] } }
79
+ before do
80
+ received_options = { :verify_ssl => OpenSSL::SSL::VERIFY_NONE, :user => Socialcast::CommandLine.credentials[:user], :password => Socialcast::CommandLine.credentials[:password] }
81
+ expect(RestClient::Resource).to receive(:new).with(url, received_options)
82
+ Socialcast::CommandLine.resource_for_path(path, options)
83
+ end
84
+ it 'sends skip ssl validation option' do end
85
+ end
64
86
  end
65
87
  end
data/spec/spec_helper.rb CHANGED
@@ -3,7 +3,6 @@ require 'bundler/setup'
3
3
  require 'webmock/rspec'
4
4
  require 'rspec/mocks'
5
5
  require 'pry'
6
- RSpec::Mocks::setup(Object.new)
7
6
 
8
7
  require_relative '../lib/socialcast'
9
8
 
@@ -12,7 +11,7 @@ RSpec.configure do |config|
12
11
 
13
12
  config.before do
14
13
  stubbed_credentials = File.join(File.dirname(__FILE__), '..', 'fixtures')
15
- Socialcast::CommandLine.stub(:config_dir).and_return(stubbed_credentials)
14
+ allow(Socialcast::CommandLine).to receive(:config_dir).and_return(stubbed_credentials)
16
15
  end
17
16
 
18
17
  def create_entry(cn, entry_attributes)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: socialcast
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.16
4
+ version: 1.3.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Sonnek
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-04-27 00:00:00.000000000 Z
13
+ date: 2015-06-30 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rest-client
@@ -140,14 +140,14 @@ dependencies:
140
140
  requirements:
141
141
  - - "~>"
142
142
  - !ruby/object:Gem::Version
143
- version: '2.11'
143
+ version: '3.3'
144
144
  type: :development
145
145
  prerelease: false
146
146
  version_requirements: !ruby/object:Gem::Requirement
147
147
  requirements:
148
148
  - - "~>"
149
149
  - !ruby/object:Gem::Version
150
- version: '2.11'
150
+ version: '3.3'
151
151
  - !ruby/object:Gem::Dependency
152
152
  name: webmock
153
153
  requirement: !ruby/object:Gem::Requirement
@@ -280,7 +280,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
280
280
  version: '0'
281
281
  requirements: []
282
282
  rubyforge_project: socialcast
283
- rubygems_version: 2.4.4
283
+ rubygems_version: 2.4.8
284
284
  signing_key:
285
285
  specification_version: 4
286
286
  summary: command line interface to socialcast api