simple_crowd 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/simple_crowd/client.rb +34 -27
- data/lib/simple_crowd/version.rb +1 -1
- data/test/test_client.rb +41 -37
- metadata +3 -3
data/lib/simple_crowd/client.rb
CHANGED
@@ -35,7 +35,7 @@ module SimpleCrowd
|
|
35
35
|
}.merge(no_validation_factors)}
|
36
36
|
end
|
37
37
|
end
|
38
|
-
response.to_hash[:authenticate_application_response][:out][:token].to_s
|
38
|
+
clean_response(response.to_hash[:authenticate_application_response][:out])[:token].to_s.dup
|
39
39
|
end
|
40
40
|
|
41
41
|
# Authenticate user by name/pass and retrieve login token
|
@@ -59,9 +59,8 @@ module SimpleCrowd
|
|
59
59
|
# NOTE: call will return true even if token is invalid
|
60
60
|
# @return [Boolean] success (does not guarantee valid token)
|
61
61
|
def invalidate_user_token token
|
62
|
-
simple_soap_call :invalidate_principal_token, token
|
63
|
-
|
64
|
-
end
|
62
|
+
simple_soap_call :invalidate_principal_token, token
|
63
|
+
true
|
65
64
|
end
|
66
65
|
|
67
66
|
def is_valid_user_token? token, factors = nil
|
@@ -86,27 +85,23 @@ module SimpleCrowd
|
|
86
85
|
end
|
87
86
|
|
88
87
|
def update_group group, description, active
|
89
|
-
simple_soap_call :update_group, group, description, active
|
90
|
-
|
91
|
-
end
|
88
|
+
simple_soap_call :update_group, group, description, active
|
89
|
+
true
|
92
90
|
end
|
93
91
|
|
94
92
|
def add_user_to_group user, group
|
95
|
-
simple_soap_call :add_principal_to_group, user, group
|
96
|
-
|
97
|
-
end
|
93
|
+
simple_soap_call :add_principal_to_group, user, group
|
94
|
+
true
|
98
95
|
end
|
99
96
|
|
100
97
|
def remove_user_from_group user, group
|
101
|
-
simple_soap_call :remove_principal_from_group, user, group
|
102
|
-
|
103
|
-
end
|
98
|
+
simple_soap_call :remove_principal_from_group, user, group
|
99
|
+
true
|
104
100
|
end
|
105
101
|
|
106
102
|
def reset_user_password name
|
107
|
-
simple_soap_call :reset_principal_credential, name
|
108
|
-
|
109
|
-
end
|
103
|
+
simple_soap_call :reset_principal_credential, name
|
104
|
+
true
|
110
105
|
end
|
111
106
|
|
112
107
|
def find_all_user_names
|
@@ -165,16 +160,14 @@ module SimpleCrowd
|
|
165
160
|
end
|
166
161
|
|
167
162
|
def remove_user name
|
168
|
-
simple_soap_call :remove_principal, name
|
169
|
-
|
170
|
-
end
|
163
|
+
simple_soap_call :remove_principal, name
|
164
|
+
true
|
171
165
|
end
|
172
166
|
|
173
167
|
def update_user_credential user, credential, encrypted = false
|
174
168
|
simple_soap_call :update_principal_credential, user,
|
175
|
-
{'auth:credential' => credential, 'auth:encryptedCredential' => encrypted}
|
176
|
-
|
177
|
-
end
|
169
|
+
{'auth:credential' => credential, 'auth:encryptedCredential' => encrypted}
|
170
|
+
true
|
178
171
|
end
|
179
172
|
|
180
173
|
# Only supports single value attributes
|
@@ -185,9 +178,8 @@ module SimpleCrowd
|
|
185
178
|
def update_user_attribute user, name, value
|
186
179
|
return unless (name.is_a?(String) || name.is_a?(Symbol)) && (value.is_a?(String) || value.is_a?(Array))
|
187
180
|
soap_attr = SimpleCrowd::Mappers::SoapAttributes.produce({name => value})
|
188
|
-
simple_soap_call :update_principal_attribute, user, soap_attr['int:SOAPAttribute'][0]
|
189
|
-
|
190
|
-
end
|
181
|
+
simple_soap_call :update_principal_attribute, user, soap_attr['int:SOAPAttribute'][0]
|
182
|
+
true
|
191
183
|
end
|
192
184
|
alias_method :add_user_attribute, :update_user_attribute
|
193
185
|
|
@@ -245,8 +237,23 @@ module SimpleCrowd
|
|
245
237
|
end
|
246
238
|
end
|
247
239
|
end
|
248
|
-
|
249
|
-
|
240
|
+
response_hash = clean_response response.to_hash[:"#{action}_response"][:out]
|
241
|
+
# If a block is given then call it and pass in the response, otherwise get the default out value
|
242
|
+
block_given? ? yield(response_hash) : response_hash
|
243
|
+
end
|
244
|
+
|
245
|
+
# Savon returns strings with embedded SOAP/XML attributes. These don't serialize
|
246
|
+
# well and users shouldn't care that we use SOAP. Remove these attributes.
|
247
|
+
def clean_response(r)
|
248
|
+
case r
|
249
|
+
when Hash
|
250
|
+
r.each {|k,v| r[k] = clean_response(v)}
|
251
|
+
when Array
|
252
|
+
r = r.map {|v| clean_response(v)}
|
253
|
+
when Nori::StringWithAttributes
|
254
|
+
r = r.to_s
|
255
|
+
end
|
256
|
+
r
|
250
257
|
end
|
251
258
|
|
252
259
|
def convert_soap_errors
|
data/lib/simple_crowd/version.rb
CHANGED
data/test/test_client.rb
CHANGED
@@ -2,6 +2,10 @@ require 'helper'
|
|
2
2
|
|
3
3
|
class TestClient < Test::Unit::TestCase
|
4
4
|
CROWD_CONFIG = YAML.load_file($CROWD_CONFIG_PATH)['crowd']
|
5
|
+
TEST_USER="test"
|
6
|
+
TEST_PASSWORD="test"
|
7
|
+
TEST_GROUP="Testing"
|
8
|
+
TEST_EMAIL="test@testing.com"
|
5
9
|
context "A Client" do
|
6
10
|
setup do
|
7
11
|
@client = SimpleCrowd::Client.new({:service_url => CROWD_CONFIG['service_url'],
|
@@ -42,31 +46,31 @@ class TestClient < Test::Unit::TestCase
|
|
42
46
|
assert_requested :post, @service_url, :times => 2
|
43
47
|
end
|
44
48
|
should "authenticate user" do
|
45
|
-
token = @client.authenticate_user
|
49
|
+
token = @client.authenticate_user TEST_USER, TEST_PASSWORD
|
46
50
|
token.should_not be nil
|
47
51
|
token.length.should == 24
|
48
52
|
|
49
53
|
assert_requested :post, @service_url, :times => 2
|
50
54
|
end
|
51
55
|
should "authenticate user with validation factors" do
|
52
|
-
token = @client.authenticate_user
|
56
|
+
token = @client.authenticate_user TEST_USER, TEST_PASSWORD, {:test_factor => "test1234"}
|
53
57
|
token.should_not be nil
|
54
58
|
token.length.should == 24
|
55
59
|
|
56
60
|
assert_requested :post, @service_url, :times => 2
|
57
61
|
end
|
58
62
|
should "create user token without password" do
|
59
|
-
token = @client.create_user_token
|
63
|
+
token = @client.create_user_token TEST_USER
|
60
64
|
token.should_not be nil
|
61
65
|
token.length.should == 24
|
62
66
|
|
63
67
|
assert_requested :post, @service_url, :times => 2
|
64
68
|
end
|
65
69
|
should "return same user token with or without password" do
|
66
|
-
token_with_pass = @client.authenticate_user
|
70
|
+
token_with_pass = @client.authenticate_user TEST_USER, TEST_PASSWORD
|
67
71
|
token_with_pass.should_not be nil
|
68
72
|
token_with_pass.length.should == 24
|
69
|
-
token_without_pass = @client.create_user_token
|
73
|
+
token_without_pass = @client.create_user_token TEST_USER
|
70
74
|
token_without_pass.should_not be nil
|
71
75
|
token_with_pass.length.should == 24
|
72
76
|
|
@@ -75,7 +79,7 @@ class TestClient < Test::Unit::TestCase
|
|
75
79
|
assert_requested :post, @service_url, :times => 3
|
76
80
|
end
|
77
81
|
should "validate user token" do
|
78
|
-
token = @client.authenticate_user
|
82
|
+
token = @client.authenticate_user TEST_USER, TEST_PASSWORD
|
79
83
|
valid = @client.is_valid_user_token? token
|
80
84
|
valid.should be true
|
81
85
|
invalid = @client.is_valid_user_token?(token + "void")
|
@@ -83,15 +87,15 @@ class TestClient < Test::Unit::TestCase
|
|
83
87
|
assert_requested :post, @service_url, :times => 4
|
84
88
|
end
|
85
89
|
should "validate user token with factors" do
|
86
|
-
token = @client.authenticate_user
|
90
|
+
token = @client.authenticate_user TEST_USER, TEST_PASSWORD, {"Random-Number" => 6375}
|
87
91
|
@client.is_valid_user_token?(token).should be false
|
88
92
|
@client.is_valid_user_token?(token, {"Random-Number" => 6375}).should be true
|
89
|
-
token2 = @client.authenticate_user
|
93
|
+
token2 = @client.authenticate_user TEST_USER, TEST_PASSWORD
|
90
94
|
@client.is_valid_user_token?(token2, {"Random-Number" => 48289}).should be false
|
91
95
|
assert_requested :post, @service_url, :times => 6
|
92
96
|
end
|
93
97
|
should "invalidate user token (logout)" do
|
94
|
-
token = @client.authenticate_user
|
98
|
+
token = @client.authenticate_user TEST_USER, TEST_PASSWORD
|
95
99
|
@client.is_valid_user_token?(token).should be true
|
96
100
|
|
97
101
|
# Invalidate nonexistant token
|
@@ -117,24 +121,24 @@ class TestClient < Test::Unit::TestCase
|
|
117
121
|
}
|
118
122
|
stub_request(:post, @service_url).to_return(:body => response, :status => 200)
|
119
123
|
|
120
|
-
@client.reset_user_password(
|
124
|
+
@client.reset_user_password(TEST_USER).should be true
|
121
125
|
end
|
122
126
|
should "find all user names" do
|
123
127
|
names = @client.find_all_user_names
|
124
128
|
names.should_not be nil
|
125
129
|
names.is_a?(Array).should be true
|
126
130
|
names.empty?.should be false
|
127
|
-
names.include?(
|
131
|
+
names.include?(TEST_USER).should be true
|
128
132
|
end
|
129
133
|
should "find user by name" do
|
130
|
-
user = @client.find_user_by_name
|
134
|
+
user = @client.find_user_by_name TEST_USER
|
131
135
|
user.should_not be nil
|
132
136
|
[:id, :username, :description, :active, :directory_id, :first_name, :last_name, :email].each {|v| user.key?(v).should be true}
|
133
137
|
[:id, :username, :active, :directory_id].each {|v| user[v].should_not be nil}
|
134
138
|
assert_requested :post, @service_url, :times => 2
|
135
139
|
end
|
136
140
|
should "find user by token" do
|
137
|
-
token = @client.authenticate_user
|
141
|
+
token = @client.authenticate_user TEST_USER, TEST_PASSWORD
|
138
142
|
user = @client.find_user_by_token token
|
139
143
|
user.should_not be nil
|
140
144
|
user.first_name.should == "Test"
|
@@ -142,22 +146,22 @@ class TestClient < Test::Unit::TestCase
|
|
142
146
|
assert_requested :post, @service_url, :times => 3
|
143
147
|
end
|
144
148
|
should "find username by token" do
|
145
|
-
token = @client.authenticate_user
|
149
|
+
token = @client.authenticate_user TEST_USER, TEST_PASSWORD
|
146
150
|
user = @client.find_username_by_token token
|
147
151
|
user.should_not be nil
|
148
152
|
user.length.should > 0
|
149
|
-
user.should ==
|
153
|
+
user.should == TEST_USER
|
150
154
|
|
151
155
|
assert_requested :post, @service_url, :times => 3
|
152
156
|
end
|
153
157
|
should "find user by email" do
|
154
|
-
user = @client.find_user_by_email
|
158
|
+
user = @client.find_user_by_email TEST_EMAIL
|
155
159
|
user.should_not be nil
|
156
160
|
user.first_name.should == "Test"
|
157
161
|
user.last_name.should == "User"
|
158
162
|
|
159
163
|
# partial searches should return nothing
|
160
|
-
user = @client.find_user_by_email
|
164
|
+
user = @client.find_user_by_email TEST_EMAIL
|
161
165
|
user.should be nil
|
162
166
|
|
163
167
|
assert_requested :post, @service_url, :times => 3
|
@@ -170,10 +174,10 @@ class TestClient < Test::Unit::TestCase
|
|
170
174
|
assert_requested :post, @service_url, :times => 2
|
171
175
|
end
|
172
176
|
should "search users" do
|
173
|
-
users = @client.search_users({'principal.email' =>
|
177
|
+
users = @client.search_users({'principal.email' => TEST_EMAIL})
|
174
178
|
users.should_not be nil
|
175
179
|
users.empty?.should_not be true
|
176
|
-
users.all?{|u| u.email ==
|
180
|
+
users.all?{|u| u.email == TEST_EMAIL }.should be true
|
177
181
|
|
178
182
|
users = @client.search_users({'principal.fullname' => "Test"})
|
179
183
|
users.should_not be nil
|
@@ -188,11 +192,11 @@ class TestClient < Test::Unit::TestCase
|
|
188
192
|
assert_requested :post, @service_url, :times => 2
|
189
193
|
end
|
190
194
|
should "update user credential" do
|
191
|
-
@client.authenticate_user(
|
192
|
-
@client.update_user_credential(
|
193
|
-
lambda {@client.authenticate_user(
|
194
|
-
@client.authenticate_user(
|
195
|
-
@client.update_user_credential(
|
195
|
+
@client.authenticate_user(TEST_USER, TEST_PASSWORD).should_not be nil
|
196
|
+
@client.update_user_credential(TEST_USER, "testupdate").should be true
|
197
|
+
lambda {@client.authenticate_user(TEST_USER, TEST_PASSWORD)}.should raise_error
|
198
|
+
@client.authenticate_user(TEST_USER, "testupdate").should_not be nil
|
199
|
+
@client.update_user_credential(TEST_USER, TEST_PASSWORD).should be true
|
196
200
|
end
|
197
201
|
should "add/remove user" do
|
198
202
|
localuser = FactoryGirl.build(:user)
|
@@ -284,7 +288,7 @@ class TestClient < Test::Unit::TestCase
|
|
284
288
|
assert_requested :post, @service_url, :times => 2
|
285
289
|
end
|
286
290
|
should "find group by name" do
|
287
|
-
group = @client.find_group_by_name(
|
291
|
+
group = @client.find_group_by_name(TEST_GROUP)
|
288
292
|
group.should_not be nil
|
289
293
|
assert_requested :post, @service_url, :times => 2
|
290
294
|
end
|
@@ -293,13 +297,13 @@ class TestClient < Test::Unit::TestCase
|
|
293
297
|
names.should_not be nil
|
294
298
|
names.is_a?(Array).should be true
|
295
299
|
names.empty?.should be false
|
296
|
-
names.include?(
|
300
|
+
names.include?(TEST_GROUP).should be true
|
297
301
|
end
|
298
302
|
should "add/remove user from group" do
|
299
|
-
@client.add_user_to_group(
|
300
|
-
@client.is_group_member?(
|
301
|
-
@client.remove_user_from_group(
|
302
|
-
@client.is_group_member?(
|
303
|
+
@client.add_user_to_group(TEST_USER, TEST_GROUP).should be true
|
304
|
+
@client.is_group_member?(TEST_GROUP, TEST_USER).should be true
|
305
|
+
@client.remove_user_from_group(TEST_USER, TEST_GROUP).should be true
|
306
|
+
@client.is_group_member?(TEST_GROUP, TEST_USER).should be false
|
303
307
|
assert_requested :post, @service_url, :times => 5
|
304
308
|
end
|
305
309
|
# should "add/remove attribute from group" do
|
@@ -307,17 +311,17 @@ class TestClient < Test::Unit::TestCase
|
|
307
311
|
# @client.remove_attribute_from_group("test", "tmpattribute").should be true
|
308
312
|
# end
|
309
313
|
should "update group" do
|
310
|
-
@client.find_group_by_name(
|
311
|
-
@client.update_group(
|
312
|
-
updated_group = @client.find_group_by_name(
|
314
|
+
@client.find_group_by_name(TEST_GROUP).active.should be true
|
315
|
+
@client.update_group(TEST_GROUP, "Test Description", false).should be true
|
316
|
+
updated_group = @client.find_group_by_name(TEST_GROUP)
|
313
317
|
updated_group.active.should be false
|
314
318
|
updated_group.description.should == "Test Description"
|
315
|
-
@client.update_group(
|
319
|
+
@client.update_group(TEST_GROUP, "", true).should be true
|
316
320
|
end
|
317
321
|
should "check if user is group member" do
|
318
|
-
@client.add_user_to_group(
|
319
|
-
@client.is_group_member?(
|
320
|
-
@client.is_group_member?("nonexistantgroup",
|
322
|
+
@client.add_user_to_group(TEST_USER, TEST_GROUP).should be true
|
323
|
+
@client.is_group_member?(TEST_GROUP, TEST_USER).should be true
|
324
|
+
@client.is_group_member?("nonexistantgroup", TEST_USER).should be false
|
321
325
|
assert_requested :post, @service_url, :times => 4
|
322
326
|
end
|
323
327
|
should "accept cached app token" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_crowd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-05-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: savon
|
@@ -124,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
124
|
version: '0'
|
125
125
|
requirements: []
|
126
126
|
rubyforge_project: simple_crowd
|
127
|
-
rubygems_version: 1.8.
|
127
|
+
rubygems_version: 1.8.24
|
128
128
|
signing_key:
|
129
129
|
specification_version: 3
|
130
130
|
summary: Simple Atlassian Crowd client using REST and SOAP APIs where needed.
|