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
@@ -1,100 +1,175 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Socialcast::CommandLine::ProvisionPhoto do
|
4
|
-
let(:
|
4
|
+
let!(:ldap_with_profile_photo_config) { YAML.load_file(File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'ldap_with_profile_photo.yml')) }
|
5
|
+
let!(:ldap_multiple_connection_mapping_config) { YAML.load_file(File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'ldap_with_multiple_connection_mappings.yml')) }
|
6
|
+
|
7
|
+
let(:ldap) do
|
8
|
+
ldap_instance = double(Net::LDAP, :auth => nil, :encryption => nil)
|
9
|
+
ldap_instance.should_receive(:open).and_yield(ldap_instance)
|
10
|
+
Net::LDAP.should_receive(:new).and_return(ldap_instance)
|
11
|
+
ldap_instance
|
12
|
+
end
|
5
13
|
|
6
14
|
context '#sync' do
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
'
|
20
|
-
|
15
|
+
context "with a single ldap connection" do
|
16
|
+
let(:options) { {} }
|
17
|
+
subject(:sync_photos) { Socialcast::CommandLine::ProvisionPhoto.new(ldap_with_profile_photo_config, options).sync }
|
18
|
+
let(:user_search_resource) { double(:user_search_resource) }
|
19
|
+
let(:user_submit_resource) { double(:user_submit_resource) }
|
20
|
+
let(:is_community_default) { true }
|
21
|
+
let(:data_fingerprint) { '5d41402abc4b2a76b9719d911017c592' }
|
22
|
+
let(:search_api_response) do
|
23
|
+
{
|
24
|
+
'users' => [
|
25
|
+
{
|
26
|
+
'id' => 7,
|
27
|
+
'avatars' => {
|
28
|
+
'is_community_default' => is_community_default,
|
29
|
+
'data_fingerprint' => data_fingerprint
|
30
|
+
}
|
21
31
|
}
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
26
|
-
before do
|
27
|
-
entry = create_entry :mail => 'user@example.com', :givenName => 'first name', :sn => 'last name', :jpegPhoto => photo_data
|
28
|
-
Net::LDAP.any_instance.should_receive(:search).once.with(hash_including(:attributes => ['givenName', 'sn', 'mail', 'jpegPhoto', 'memberof'])).and_yield(entry)
|
29
|
-
Socialcast::CommandLine.stub(:resource_for_path).with('/api/users/search', anything).and_return(user_search_resource)
|
30
|
-
end
|
31
|
-
|
32
|
-
context 'for when it does successfully post the photo' do
|
32
|
+
]
|
33
|
+
}
|
34
|
+
end
|
33
35
|
before do
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
uploaded_data = data[:user][:profile_photo][:data]
|
38
|
-
uploaded_data.path.should =~ /\.png\Z/
|
39
|
-
end
|
40
|
-
Socialcast::CommandLine.stub(:resource_for_path).with('/api/users/7', anything).and_return(user_resource)
|
36
|
+
entry = create_entry 'user', :mail => 'user@example.com', :jpegPhoto => photo_data
|
37
|
+
ldap.should_receive(:search).once.with(hash_including(:attributes => ['mail', 'jpegPhoto'])).and_yield(entry)
|
38
|
+
Socialcast::CommandLine.stub(:resource_for_path).with('/api/users/search', anything).and_return(user_search_resource)
|
41
39
|
end
|
42
|
-
|
43
|
-
|
40
|
+
|
41
|
+
context 'for when it does successfully post the photo' do
|
44
42
|
before do
|
45
|
-
|
46
|
-
|
43
|
+
user_search_resource.should_receive(:get).and_return(search_api_response.to_json)
|
44
|
+
user_resource = double(:user_resource)
|
45
|
+
user_resource.should_receive(:put) do |data|
|
46
|
+
uploaded_data = data[:user][:profile_photo][:data]
|
47
|
+
uploaded_data.path.should =~ /\.png\Z/
|
48
|
+
end
|
49
|
+
Socialcast::CommandLine.stub(:resource_for_path).with('/api/users/7', anything).and_return(user_resource)
|
50
|
+
end
|
51
|
+
context 'for a binary file' do
|
52
|
+
let(:photo_data) { "\x89PNGabc" }
|
53
|
+
before do
|
54
|
+
RestClient.should_not_receive(:get)
|
55
|
+
sync_photos
|
56
|
+
end
|
57
|
+
it 'uses the original binary to upload the photo' do end
|
58
|
+
end
|
59
|
+
context 'for an image file' do
|
60
|
+
let(:photo_data) { "http://socialcast.com/someimage.png" }
|
61
|
+
before do
|
62
|
+
RestClient.should_receive(:get).with(photo_data).and_return("\x89PNGabc")
|
63
|
+
sync_photos
|
64
|
+
end
|
65
|
+
it 'downloads the image form the web to upload the photo' do end
|
47
66
|
end
|
48
|
-
it 'uses the original binary to upload the photo' do end
|
49
67
|
end
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
68
|
+
|
69
|
+
context 'for when it does not successfully post the photo' do
|
70
|
+
context 'for an image file' do
|
71
|
+
let(:photo_data) { "http://socialcast.com/someimage.png" }
|
72
|
+
before do
|
73
|
+
user_search_resource.should_receive(:get).and_return(search_api_response.to_json)
|
74
|
+
RestClient.should_receive(:get).with(photo_data).and_raise(RestClient::ResourceNotFound)
|
75
|
+
sync_photos
|
76
|
+
end
|
77
|
+
it 'tries to download the image from the web and rescues 404' do end
|
55
78
|
end
|
56
|
-
it 'downloads the image form the web to upload the photo' do end
|
57
79
|
end
|
58
|
-
end
|
59
80
|
|
60
|
-
|
61
|
-
|
62
|
-
let(:photo_data) { "
|
63
|
-
before
|
64
|
-
|
65
|
-
|
66
|
-
|
81
|
+
context 'when there is already a photo set' do
|
82
|
+
let(:is_community_default) { false }
|
83
|
+
let(:photo_data) { "\x89PNGabc" }
|
84
|
+
before { user_search_resource.should_receive(:get).and_return(search_api_response.to_json) }
|
85
|
+
context 'for a regular sync' do
|
86
|
+
before do
|
87
|
+
sync_photos
|
88
|
+
Socialcast::CommandLine.should_not_receive(:resource_for_path)
|
89
|
+
end
|
90
|
+
it 'does not post the new photo' do end
|
91
|
+
end
|
92
|
+
context 'when they do a force sync' do
|
93
|
+
let(:options) { { :force_sync => true } }
|
94
|
+
before do
|
95
|
+
Socialcast::CommandLine.should_receive(:resource_for_path).with('/api/users/7', {}).and_return(user_submit_resource)
|
96
|
+
user_submit_resource.should_receive(:put).and_return(true)
|
97
|
+
sync_photos
|
98
|
+
end
|
99
|
+
it 'submits the photo anyways' do end
|
67
100
|
end
|
68
|
-
it 'tries to download the image from the web and rescues 404' do end
|
69
101
|
end
|
70
102
|
end
|
71
103
|
|
72
|
-
context
|
73
|
-
let(:
|
74
|
-
let(:
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
104
|
+
context "with multiple ldap connections" do
|
105
|
+
let(:user_search_resource) { double(:user_search_resource) }
|
106
|
+
let(:search_api_response1) do
|
107
|
+
{
|
108
|
+
'users' => [
|
109
|
+
{
|
110
|
+
'id' => 7,
|
111
|
+
'avatars' => {
|
112
|
+
'is_community_default' => true
|
113
|
+
}
|
114
|
+
}
|
115
|
+
]
|
116
|
+
}
|
82
117
|
end
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
118
|
+
let(:search_api_response2) do
|
119
|
+
{
|
120
|
+
'users' => [
|
121
|
+
{
|
122
|
+
'id' => 8,
|
123
|
+
'avatars' => {
|
124
|
+
'is_community_default' => true
|
125
|
+
}
|
126
|
+
}
|
127
|
+
]
|
128
|
+
}
|
129
|
+
end
|
130
|
+
|
131
|
+
let(:sync_photos) { Socialcast::CommandLine::ProvisionPhoto.new(ldap_multiple_connection_mapping_config, {}).sync }
|
132
|
+
let(:binary_photo_data) { "\x89PNGabc".force_encoding('binary') }
|
133
|
+
before do
|
134
|
+
ldap_instance1 = double(Net::LDAP, :encryption => nil, :auth => nil)
|
135
|
+
ldap_instance1.should_receive(:open).and_yield(ldap_instance1)
|
136
|
+
Net::LDAP.should_receive(:new).once.ordered.and_return(ldap_instance1)
|
137
|
+
entry1 = create_entry 'user', :mailCon => 'user@example.com', :photoCon => binary_photo_data
|
138
|
+
ldap_instance1.should_receive(:search).once.with(hash_including(:attributes => ['mailCon', 'photoCon'])).and_yield(entry1)
|
139
|
+
|
140
|
+
ldap_instance2 = double(Net::LDAP, :encryption => nil, :auth => nil)
|
141
|
+
ldap_instance2.should_receive(:open).and_yield(ldap_instance2)
|
142
|
+
Net::LDAP.should_receive(:new).once.ordered.and_return(ldap_instance2)
|
143
|
+
entry2 = create_entry 'user', :mailCon2 => 'user2@example.com', :photoCon2 => binary_photo_data
|
144
|
+
ldap_instance2.should_receive(:search).once.with(hash_including(:attributes => ['mailCon2', 'photoCon2'])).and_yield(entry2)
|
145
|
+
|
146
|
+
Socialcast::CommandLine.stub(:resource_for_path).with('/api/users/search', anything).and_return(user_search_resource)
|
147
|
+
|
148
|
+
user_search_resource.should_receive(:get).once.and_return(search_api_response1.to_json)
|
149
|
+
user_search_resource.should_receive(:get).once.and_return(search_api_response2.to_json)
|
150
|
+
|
151
|
+
user_resource1 = double(:user_resource)
|
152
|
+
user_resource1.should_receive(:put) do |data|
|
153
|
+
uploaded_data = data[:user][:profile_photo][:data]
|
154
|
+
uploaded_data.path.should =~ /\.png\Z/
|
155
|
+
end
|
156
|
+
Socialcast::CommandLine.stub(:resource_for_path).with('/api/users/7', anything).and_return(user_resource1)
|
157
|
+
|
158
|
+
user_resource2 = double(:user_resource)
|
159
|
+
user_resource2.should_receive(:put) do |data|
|
160
|
+
uploaded_data = data[:user][:profile_photo][:data]
|
161
|
+
uploaded_data.path.should =~ /\.png\Z/
|
89
162
|
end
|
90
|
-
|
163
|
+
Socialcast::CommandLine.stub(:resource_for_path).with('/api/users/8', anything).and_return(user_resource2)
|
164
|
+
|
165
|
+
sync_photos
|
91
166
|
end
|
167
|
+
it 'uses attributes from each connection' do end
|
92
168
|
end
|
93
169
|
end
|
94
170
|
|
95
|
-
|
96
171
|
context '.binary_to_content_type' do
|
97
|
-
subject { Socialcast::CommandLine::ProvisionPhoto.new(
|
172
|
+
subject { Socialcast::CommandLine::ProvisionPhoto.new(ldap_with_profile_photo_config, {}).send(:binary_to_content_type, binary_photo_data) }
|
98
173
|
let(:file_dir) { File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'test_images') }
|
99
174
|
let(:binary_photo_data) { File.open(File.join(file_dir, image_name), 'rb') { |file| file.read } }
|
100
175
|
context 'with a jpg' do
|
@@ -13,7 +13,16 @@ describe Socialcast::CommandLine::ProvisionUser do
|
|
13
13
|
let!(:ldap_with_manager_attribute_config) { YAML.load_file(File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'ldap_with_manager_attribute.yml')) }
|
14
14
|
let!(:ldap_with_roles_without_account_type_config) { YAML.load_file(File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'ldap_with_roles_without_account_type.yml')) }
|
15
15
|
let!(:ldap_with_unique_identifier_config) { YAML.load_file(File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'ldap_with_unique_identifier.yml')) }
|
16
|
+
let!(:ldap_with_profile_photo_config) { YAML.load_file(File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'ldap_with_profile_photo.yml')) }
|
16
17
|
let!(:ldap_without_account_type_or_roles_config) { YAML.load_file(File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'ldap_without_account_type_or_roles.yml')) }
|
18
|
+
let!(:ldap_without_options_config) { YAML.load_file(File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'ldap_without_options.yml')) }
|
19
|
+
|
20
|
+
let(:ldap) do
|
21
|
+
ldap_instance = double(Net::LDAP, :auth => nil, :encryption => nil)
|
22
|
+
ldap_instance.should_receive(:open).and_yield(ldap_instance)
|
23
|
+
Net::LDAP.should_receive(:new).and_return(ldap_instance)
|
24
|
+
ldap_instance
|
25
|
+
end
|
17
26
|
|
18
27
|
describe "#provision" do
|
19
28
|
let(:result) { '' }
|
@@ -26,8 +35,8 @@ describe Socialcast::CommandLine::ProvisionUser do
|
|
26
35
|
|
27
36
|
context "when the entry has an email" do
|
28
37
|
before do
|
29
|
-
entry = create_entry :mail => 'user@example.com', :givenName => 'first name', :sn => 'last name'
|
30
|
-
|
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)
|
31
40
|
RestClient::Resource.any_instance.should_receive(:post).once.with(hash_including(:file => result), { :accept => :json })
|
32
41
|
|
33
42
|
Socialcast::CommandLine::ProvisionUser.new(ldap_default_config, {}).provision
|
@@ -38,8 +47,8 @@ describe Socialcast::CommandLine::ProvisionUser do
|
|
38
47
|
end
|
39
48
|
context "when the entry has a unique_identifier" do
|
40
49
|
before do
|
41
|
-
entry = create_entry :uid => 'userID', :givenName => 'first name', :sn => 'last name'
|
42
|
-
|
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)
|
43
52
|
RestClient::Resource.any_instance.should_receive(:post).once.with(hash_including(:file => result), { :accept => :json })
|
44
53
|
|
45
54
|
Socialcast::CommandLine::ProvisionUser.new(ldap_with_unique_identifier_config, {}).provision
|
@@ -50,8 +59,8 @@ describe Socialcast::CommandLine::ProvisionUser do
|
|
50
59
|
end
|
51
60
|
context "when the entry has no email or unique_identifier" do
|
52
61
|
before do
|
53
|
-
entry = create_entry :mail => '', :givenName => 'first name', :sn => 'last name'
|
54
|
-
|
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)
|
55
64
|
RestClient::Resource.any_instance.should_not_receive(:post)
|
56
65
|
end
|
57
66
|
it "does not put the user in the output file" do
|
@@ -87,8 +96,8 @@ describe Socialcast::CommandLine::ProvisionUser do
|
|
87
96
|
|
88
97
|
context "with mappings at the global level" do
|
89
98
|
before do
|
90
|
-
entry = create_entry :mail => 'user@example.com', :givenName => 'first name', :sn => 'last name'
|
91
|
-
|
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)
|
92
101
|
|
93
102
|
Socialcast::CommandLine::ProvisionUser.new(ldap_default_config, {}).provision
|
94
103
|
end
|
@@ -108,13 +117,15 @@ describe Socialcast::CommandLine::ProvisionUser do
|
|
108
117
|
provision_instance = Socialcast::CommandLine::ProvisionUser.new(ldap_multiple_connection_mapping_config, {})
|
109
118
|
|
110
119
|
ldap_instance1 = double(Net::LDAP, :encryption => nil, :auth => nil)
|
120
|
+
ldap_instance1.should_receive(:open).and_yield(ldap_instance1)
|
111
121
|
Net::LDAP.should_receive(:new).once.ordered.and_return(ldap_instance1)
|
112
|
-
entry1 = create_entry :mailCon => 'user@example.com', :givenName => 'first name', :sn => 'last name'
|
122
|
+
entry1 = create_entry 'user', :mailCon => 'user@example.com', :givenName => 'first name', :sn => 'last name'
|
113
123
|
ldap_instance1.should_receive(:search).once.with(hash_including(:attributes => ['mailCon', 'isMemberOf'])).and_yield(entry1)
|
114
124
|
|
115
125
|
ldap_instance2 = double(Net::LDAP, :encryption => nil, :auth => nil)
|
126
|
+
ldap_instance2.should_receive(:open).and_yield(ldap_instance2)
|
116
127
|
Net::LDAP.should_receive(:new).once.ordered.and_return(ldap_instance2)
|
117
|
-
entry2 = create_entry :mailCon2 => 'user2@example.com', :firstName => 'first name2', :sn => 'last name2'
|
128
|
+
entry2 = create_entry 'user', :mailCon2 => 'user2@example.com', :firstName => 'first name2', :sn => 'last name2'
|
118
129
|
ldap_instance2.should_receive(:search).once.with(hash_including(:attributes => ['mailCon2', 'firstName', 'isMemberOf'])).and_yield(entry2)
|
119
130
|
|
120
131
|
provision_instance.provision
|
@@ -136,8 +147,8 @@ describe Socialcast::CommandLine::ProvisionUser do
|
|
136
147
|
|
137
148
|
context "with custom attribute mappings" do
|
138
149
|
before do
|
139
|
-
entry = create_entry :mail => 'user@example.com', :custom_ldap1 => 'custom value 1', :custom_ldap2 => 'custom value 2'
|
140
|
-
|
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)
|
141
152
|
|
142
153
|
Socialcast::CommandLine::ProvisionUser.new(ldap_with_custom_attributes_config, {}).provision
|
143
154
|
end
|
@@ -166,17 +177,18 @@ describe Socialcast::CommandLine::ProvisionUser do
|
|
166
177
|
provision_instance = Socialcast::CommandLine::ProvisionUser.new(ldap_with_manager_attribute_config, {})
|
167
178
|
|
168
179
|
ldap_instance = double(Net::LDAP, :encryption => nil, :auth => nil)
|
180
|
+
ldap_instance.should_receive(:open).and_yield(ldap_instance)
|
169
181
|
Net::LDAP.should_receive(:new).once.and_return(ldap_instance)
|
170
182
|
|
171
|
-
user_entry = create_entry :mail => 'user@example.com', :ldap_manager => 'cn=theboss,dc=example,dc=com'
|
172
|
-
manager_entry = create_entry :mail => 'boss@example.com'
|
173
|
-
ldap_instance.should_receive(:search).once.ordered.
|
174
|
-
ldap_instance.should_receive(:search).once.ordered.and_yield(manager_entry)
|
183
|
+
user_entry = create_entry 'user', :mail => 'user@example.com', :ldap_manager => 'cn=theboss,dc=example,dc=com'
|
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)
|
175
187
|
|
176
188
|
provision_instance.provision
|
177
189
|
end
|
178
190
|
let(:expected_attribute_xml) do
|
179
|
-
%Q[<contact-info>
|
191
|
+
[%Q[<contact-info>
|
180
192
|
<email>user@example.com</email>
|
181
193
|
</contact-info>
|
182
194
|
<custom-fields type="array">
|
@@ -185,7 +197,17 @@ describe Socialcast::CommandLine::ProvisionUser do
|
|
185
197
|
<label>manager_email</label>
|
186
198
|
<value>boss@example.com</value>
|
187
199
|
</custom-field>
|
188
|
-
</custom-fields>]
|
200
|
+
</custom-fields>],
|
201
|
+
%Q[<contact-info>
|
202
|
+
<email>boss@example.com</email>
|
203
|
+
</contact-info>
|
204
|
+
<custom-fields type="array">
|
205
|
+
<custom-field>
|
206
|
+
<id>manager_email</id>
|
207
|
+
<label>manager_email</label>
|
208
|
+
<value nil="true"/>
|
209
|
+
</custom-field>
|
210
|
+
</custom-fields>]]
|
189
211
|
end
|
190
212
|
it_behaves_like "attributes are mapped properly"
|
191
213
|
end
|
@@ -193,8 +215,8 @@ describe Socialcast::CommandLine::ProvisionUser do
|
|
193
215
|
context "with an ldap mapping that has the same name as a class" do
|
194
216
|
before do
|
195
217
|
module TestLdapAttributeMapping end
|
196
|
-
entry = create_entry :test_ldap_attribute_mapping => 'user@example.com'
|
197
|
-
|
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)
|
198
220
|
|
199
221
|
Socialcast::CommandLine::ProvisionUser.new(ldap_with_class_ldap_attribute_config, {}).provision
|
200
222
|
end
|
@@ -209,6 +231,42 @@ describe Socialcast::CommandLine::ProvisionUser do
|
|
209
231
|
end
|
210
232
|
it_behaves_like "attributes are mapped properly"
|
211
233
|
end
|
234
|
+
|
235
|
+
context "without options specified" do
|
236
|
+
before do
|
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)
|
239
|
+
|
240
|
+
Socialcast::CommandLine::ProvisionUser.new(ldap_without_options_config, {}).provision
|
241
|
+
end
|
242
|
+
let(:expected_attribute_xml) do
|
243
|
+
%Q[<first-name>first name</first-name>
|
244
|
+
<last-name>last name</last-name>
|
245
|
+
<contact-info>
|
246
|
+
<email>user@example.com</email>
|
247
|
+
</contact-info>
|
248
|
+
<custom-fields type="array"/>]
|
249
|
+
end
|
250
|
+
it_behaves_like "attributes are mapped properly"
|
251
|
+
end
|
252
|
+
|
253
|
+
context "with profile_photo attribute mappings" do
|
254
|
+
before do
|
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)
|
257
|
+
|
258
|
+
Socialcast::CommandLine::ProvisionUser.new(ldap_with_profile_photo_config, {}).provision
|
259
|
+
end
|
260
|
+
let(:expected_attribute_xml) do
|
261
|
+
%Q[<first-name>first name</first-name>
|
262
|
+
<last-name>last name</last-name>
|
263
|
+
<contact-info>
|
264
|
+
<email>user@example.com</email>
|
265
|
+
</contact-info>
|
266
|
+
<custom-fields type="array"/>]
|
267
|
+
end
|
268
|
+
it_behaves_like "attributes are mapped properly"
|
269
|
+
end
|
212
270
|
end
|
213
271
|
context "permission attribute mappings" do
|
214
272
|
shared_examples "permission attributes are mapped properly" do
|
@@ -235,7 +293,7 @@ describe Socialcast::CommandLine::ProvisionUser do
|
|
235
293
|
end
|
236
294
|
end
|
237
295
|
|
238
|
-
let(:entry) { create_entry :mail => 'user@example.com', :givenName => 'first name', :sn => 'last name', :isMemberOf => ldap_groups }
|
296
|
+
let(:entry) { create_entry 'user', :mail => 'user@example.com', :givenName => 'first name', :sn => 'last name', :isMemberOf => ldap_groups }
|
239
297
|
let(:ldap_group_attribute) { 'isMemberOf' }
|
240
298
|
|
241
299
|
before do
|
@@ -245,7 +303,7 @@ describe Socialcast::CommandLine::ProvisionUser do
|
|
245
303
|
context "with roles for an external contributor" do
|
246
304
|
let(:ldap_groups) { ["cn=External,dc=example,dc=com", "cn=SbiAdmins,dc=example,dc=com", "cn=TownHallAdmins,dc=example,dc=com"] }
|
247
305
|
before do
|
248
|
-
|
306
|
+
ldap.should_receive(:search).once.with(hash_including(:attributes => ['givenName', 'sn', 'mail', ldap_group_attribute])).and_yield(entry)
|
249
307
|
Socialcast::CommandLine::ProvisionUser.new(ldap_default_config, {}).provision
|
250
308
|
end
|
251
309
|
let(:expected_permission_xml) do
|
@@ -257,7 +315,7 @@ describe Socialcast::CommandLine::ProvisionUser do
|
|
257
315
|
context "with roles for a member" do
|
258
316
|
let(:ldap_groups) { ["cn=SbiAdmins,dc=example,dc=com", "cn=TownHallAdmins,dc=example,dc=com"] }
|
259
317
|
before do
|
260
|
-
|
318
|
+
ldap.should_receive(:search).once.with(hash_including(:attributes => ['givenName', 'sn', 'mail', ldap_group_attribute])).and_yield(entry)
|
261
319
|
Socialcast::CommandLine::ProvisionUser.new(ldap_default_config, {}).provision
|
262
320
|
end
|
263
321
|
let(:expected_permission_xml) do
|
@@ -273,7 +331,7 @@ describe Socialcast::CommandLine::ProvisionUser do
|
|
273
331
|
context "with account_types mapping and no role mappings" do
|
274
332
|
let(:ldap_groups) { ["cn=SbiAdmins,dc=example,dc=com", "cn=TownHallAdmins,dc=example,dc=com"] }
|
275
333
|
before do
|
276
|
-
|
334
|
+
ldap.should_receive(:search).once.with(hash_including(:attributes => ['givenName', 'sn', 'mail', ldap_group_attribute])).and_yield(entry)
|
277
335
|
Socialcast::CommandLine::ProvisionUser.new(ldap_with_account_type_without_roles_config, {}).provision
|
278
336
|
end
|
279
337
|
let(:expected_permission_xml) do
|
@@ -285,7 +343,7 @@ describe Socialcast::CommandLine::ProvisionUser do
|
|
285
343
|
context "with role mappings and no account_type mapping" do
|
286
344
|
let(:ldap_groups) { ["cn=SbiAdmins,dc=example,dc=com", "cn=TownHallAdmins,dc=example,dc=com"] }
|
287
345
|
before do
|
288
|
-
|
346
|
+
ldap.should_receive(:search).once.with(hash_including(:attributes => ['givenName', 'sn', 'mail', ldap_group_attribute])).and_yield(entry)
|
289
347
|
Socialcast::CommandLine::ProvisionUser.new(ldap_with_roles_without_account_type_config, {}).provision
|
290
348
|
end
|
291
349
|
let(:expected_permission_xml) do
|
@@ -301,7 +359,7 @@ describe Socialcast::CommandLine::ProvisionUser do
|
|
301
359
|
context "without account_type or roles mappings" do
|
302
360
|
let(:ldap_groups) { ["cn=SbiAdmins,dc=example,dc=com", "cn=TownHallAdmins,dc=example,dc=com"] }
|
303
361
|
before do
|
304
|
-
|
362
|
+
ldap.should_receive(:search).once.with(hash_including(:attributes => ['givenName', 'sn', 'mail', ldap_group_attribute])).and_yield(entry)
|
305
363
|
Socialcast::CommandLine::ProvisionUser.new(ldap_without_account_type_or_roles_config, {}).provision
|
306
364
|
end
|
307
365
|
let(:expected_permission_xml) do
|
@@ -317,13 +375,15 @@ describe Socialcast::CommandLine::ProvisionUser do
|
|
317
375
|
provision_instance = Socialcast::CommandLine::ProvisionUser.new(ldap_multiple_connection_permission_mapping_config, {})
|
318
376
|
|
319
377
|
ldap_instance1 = double(Net::LDAP, :encryption => nil, :auth => nil)
|
378
|
+
ldap_instance1.should_receive(:open).and_yield(ldap_instance1)
|
320
379
|
Net::LDAP.should_receive(:new).once.ordered.and_return(ldap_instance1)
|
321
|
-
entry1 = create_entry :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"]
|
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"]
|
322
381
|
ldap_instance1.should_receive(:search).once.with(hash_including(:attributes => ['givenName', 'sn', 'mail', 'memberOf'])).and_yield(entry1)
|
323
382
|
|
324
383
|
ldap_instance2 = double(Net::LDAP, :encryption => nil, :auth => nil)
|
384
|
+
ldap_instance2.should_receive(:open).and_yield(ldap_instance2)
|
325
385
|
Net::LDAP.should_receive(:new).once.ordered.and_return(ldap_instance2)
|
326
|
-
entry2 = create_entry :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"]
|
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"]
|
327
387
|
ldap_instance2.should_receive(:search).once.with(hash_including(:attributes => ['givenName', 'sn', 'mail', 'member'])).and_yield(entry2)
|
328
388
|
|
329
389
|
provision_instance.provision
|
@@ -348,12 +408,13 @@ describe Socialcast::CommandLine::ProvisionUser do
|
|
348
408
|
|
349
409
|
provision_instance = Socialcast::CommandLine::ProvisionUser.new(ldap_blank_basedn_config, {})
|
350
410
|
|
351
|
-
root_entry = create_entry(:namingcontexts => ['dc=foo,dc=com', 'dc=bar,dc=com'])
|
411
|
+
root_entry = create_entry('domain', :namingcontexts => ['dc=foo,dc=com', 'dc=bar,dc=com'])
|
352
412
|
ldap_instance = double(Net::LDAP, :encryption => nil, :auth => nil)
|
353
413
|
ldap_instance.should_receive(:search_root_dse).once.and_return(root_entry)
|
414
|
+
ldap_instance.should_receive(:open).and_yield(ldap_instance)
|
354
415
|
Net::LDAP.should_receive(:new).once.and_return(ldap_instance)
|
355
416
|
|
356
|
-
user_entry = create_entry :mail => 'user@example.com', :givenName => 'first name', :sn => 'last name'
|
417
|
+
user_entry = create_entry 'user', :mail => 'user@example.com', :givenName => 'first name', :sn => 'last name'
|
357
418
|
ldap_instance.should_receive(:search).once.ordered.with(hash_including(:base => 'dc=foo,dc=com', :attributes => ['givenName', 'sn', 'mail', 'isMemberOf']))
|
358
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)
|
359
420
|
|
@@ -368,8 +429,8 @@ describe Socialcast::CommandLine::ProvisionUser do
|
|
368
429
|
describe "#each_user_hash" do
|
369
430
|
let(:provision_instance) { Socialcast::CommandLine::ProvisionUser.new(ldap_default_config) }
|
370
431
|
before do
|
371
|
-
entry = create_entry :mail => 'user@example.com', :givenName => 'first name', :sn => 'last name'
|
372
|
-
|
432
|
+
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)
|
373
434
|
end
|
374
435
|
it do
|
375
436
|
expect do |blk|
|
@@ -390,10 +451,10 @@ describe Socialcast::CommandLine::ProvisionUser do
|
|
390
451
|
describe "#fetch_user_hash" do
|
391
452
|
context "when the first connector returns the entry" do
|
392
453
|
let(:provision_instance) { Socialcast::CommandLine::ProvisionUser.new(ldap_multiple_connection_mapping_config, {}) }
|
393
|
-
let(:entry) { create_entry :mailCon => 'user@example.com' }
|
454
|
+
let(:entry) { create_entry 'user', :mailCon => 'user@example.com' }
|
394
455
|
before do
|
395
456
|
filter = Net::LDAP::Filter.construct('(&(mail=*)(mailCon=user@example.com))')
|
396
|
-
|
457
|
+
ldap.should_receive(:search).once
|
397
458
|
.with(hash_including(:attributes => ['mailCon', 'isMemberOf'], :filter => filter))
|
398
459
|
.and_yield(entry)
|
399
460
|
end
|
@@ -410,15 +471,17 @@ describe Socialcast::CommandLine::ProvisionUser do
|
|
410
471
|
end
|
411
472
|
context "when another connector returns the entry" do
|
412
473
|
let(:provision_instance) { Socialcast::CommandLine::ProvisionUser.new(ldap_multiple_connection_mapping_config, {}) }
|
413
|
-
let(:entry) { create_entry :mailCon2 => 'user@example.com', :firstName => 'first name' }
|
474
|
+
let(:entry) { create_entry 'user', :mailCon2 => 'user@example.com', :firstName => 'first name' }
|
414
475
|
before do
|
415
476
|
ldap_instance1 = double(Net::LDAP, :auth => nil)
|
477
|
+
ldap_instance1.should_receive(:open).and_yield(ldap_instance1)
|
416
478
|
Net::LDAP.should_receive(:new).once.ordered.and_return(ldap_instance1)
|
417
479
|
filter1 = Net::LDAP::Filter.construct('(&(mail=*)(mailCon=user@example.com))')
|
418
480
|
ldap_instance1.should_receive(:search).once.ordered
|
419
481
|
.with(hash_including(:attributes => ['mailCon', 'isMemberOf'], :filter => filter1))
|
420
482
|
|
421
483
|
ldap_instance2 = double(Net::LDAP, :auth => nil)
|
484
|
+
ldap_instance2.should_receive(:open).and_yield(ldap_instance2)
|
422
485
|
Net::LDAP.should_receive(:new).once.ordered.and_return(ldap_instance2)
|
423
486
|
filter2 = Net::LDAP::Filter.construct('(&(mail=*)(mailCon2=user@example.com))')
|
424
487
|
ldap_instance2.should_receive(:search).once.ordered
|
@@ -442,12 +505,14 @@ describe Socialcast::CommandLine::ProvisionUser do
|
|
442
505
|
let(:provision_instance) { Socialcast::CommandLine::ProvisionUser.new(ldap_multiple_connection_mapping_config, {}) }
|
443
506
|
before do
|
444
507
|
ldap_instance1 = double(Net::LDAP, :auth => nil)
|
508
|
+
ldap_instance1.should_receive(:open).and_yield(ldap_instance1)
|
445
509
|
Net::LDAP.should_receive(:new).once.ordered.and_return(ldap_instance1)
|
446
510
|
filter1 = Net::LDAP::Filter.construct('(&(mail=*)(mailCon=user@example.com))')
|
447
511
|
ldap_instance1.should_receive(:search)
|
448
512
|
.with(hash_including(:attributes => ['mailCon', 'isMemberOf'], :filter => filter1))
|
449
513
|
|
450
514
|
ldap_instance2 = double(Net::LDAP, :auth => nil)
|
515
|
+
ldap_instance2.should_receive(:open).and_yield(ldap_instance2)
|
451
516
|
Net::LDAP.should_receive(:new).once.ordered.and_return(ldap_instance2)
|
452
517
|
filter2 = Net::LDAP::Filter.construct('(&(mail=*)(mailCon2=user@example.com))')
|
453
518
|
ldap_instance2.should_receive(:search).once.ordered
|