crowd-client 0.0.5 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. data/crowd-client.gemspec +3 -1
  2. data/lib/crowd-client.rb +2 -2
  3. data/lib/crowd-client/exceptions.rb +2 -1
  4. data/lib/crowd-client/group.rb +42 -0
  5. data/lib/crowd-client/user.rb +121 -0
  6. data/lib/crowd-client/version.rb +1 -1
  7. data/spec/cassettes/Crowd_Client/_in_group_/should_confirm_users_are_in_groups.yml +69 -0
  8. data/spec/cassettes/Crowd_Client/_login/should_authenticate_and_return_a_session_token.yml +42 -0
  9. data/spec/cassettes/Crowd_Client/_login/should_raise_Crowd_Client_Exception_AuthenticationFailed_if_authentication_fails.yml +40 -0
  10. data/spec/cassettes/Crowd_Client/_login/should_raise_Crowd_Client_Exception_InactiveAccount_if_an_account_is_inactive.yml +40 -0
  11. data/spec/cassettes/Crowd_Client/_logout/should_logout_the_current_session.yml +143 -0
  12. data/spec/cassettes/Crowd_Client/_user_groups_username_/should_return_the_groups_of_the_user.yml +36 -0
  13. data/spec/cassettes/Crowd_Client/_user_token_/should_return_the_expanded_user.yml +75 -0
  14. data/spec/cassettes/Crowd_Client/_valid_session_/should_validate_the_current_session.yml +79 -0
  15. data/spec/cassettes/Crowd_Client_Group/_add_user/missing_group/should_raise_Exception_NotFound_for_missing_group.yml +104 -0
  16. data/spec/cassettes/Crowd_Client_Group/_add_user/should_add_the_user.yml +139 -0
  17. data/spec/cassettes/Crowd_Client_Group/_add_user/should_raise_Exception_NotFound_for_missing_user.yml +106 -0
  18. data/spec/cassettes/Crowd_Client_Group/_remove_user/should_remove_the_user.yml +168 -0
  19. data/spec/cassettes/Crowd_Client_Group/_users/should_return_all_of_the_users_in_the_group.yml +36 -0
  20. data/spec/cassettes/Crowd_Client_User/Creating_a_user/should_create_a_user_with_attributes.yml +102 -0
  21. data/spec/cassettes/Crowd_Client_User/Get_groups_for_user/should_be_in_the_group.yml +36 -0
  22. data/spec/cassettes/Crowd_Client_User/Update_user/should_update_user_properties.yml +133 -0
  23. data/spec/cassettes/Crowd_Client_User/_destroy/should_delete_the_user.yml +102 -0
  24. data/spec/cassettes/Crowd_Client_User/authenticate/should_return_false_if_the_password_is_invalid.yml +40 -0
  25. data/spec/cassettes/Crowd_Client_User/authenticate/should_return_true_if_the_password_is_valid.yml +38 -0
  26. data/spec/cassettes/Crowd_Client_User/change_password/should_allow_the_user_to_set_a_new_password.yml +135 -0
  27. data/spec/cassettes/Crowd_Client_User/display_name/.yml +36 -0
  28. data/spec/cassettes/Crowd_Client_User/email/.yml +36 -0
  29. data/spec/crowd-client_group_spec.rb +50 -0
  30. data/spec/crowd-client_spec.rb +0 -3
  31. data/spec/crowd-client_user_spec.rb +75 -0
  32. data/spec/spec_helper.rb +16 -2
  33. metadata +89 -19
  34. data/spec/cassettes/Crowd_Client.yml +0 -358
@@ -0,0 +1,102 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://127.0.0.1:8095/crowd/rest/usermanagement/1/user
6
+ body: "{\"name\":\"delete@example.com\",\"active\":true,\"password\":{\"value\":\"test\"},\"first-name\":\"Delete\",\"last-name\":\"Me\",\"email\":\"delete@example.com\"}"
7
+ headers:
8
+ Accept:
9
+ - application/json
10
+ Authorization:
11
+ - Basic YXBwbGljYXRpb246cGFzc3dvcmQ=
12
+ Content-Type:
13
+ - application/json
14
+ Expect:
15
+ - ""
16
+ response:
17
+ status:
18
+ code: 201
19
+ message: Created
20
+ headers:
21
+ Server:
22
+ - Apache-Coyote/1.1
23
+ X-Embedded-Crowd-Version:
24
+ - Crowd/2.3.3
25
+ X-Crowd-User-Management-Version:
26
+ - "1.1"
27
+ Set-Cookie:
28
+ - JSESSIONID=328AE8A0D1E0CE16731D061CA7F180B5; Path=/crowd
29
+ Location:
30
+ - http://127.0.0.1:8095/crowd/rest/usermanagement/1/user?username=delete@example.com
31
+ Content-Type:
32
+ - application/json
33
+ Content-Length:
34
+ - "0"
35
+ Date:
36
+ - Wed, 21 Dec 2011 20:57:02 GMT
37
+ body: ""
38
+ http_version:
39
+ recorded_at: Wed, 21 Dec 2011 20:57:02 GMT
40
+ - request:
41
+ method: delete
42
+ uri: http://127.0.0.1:8095/crowd/rest/usermanagement/1/user?username=delete@example.com
43
+ body: ""
44
+ headers:
45
+ Accept:
46
+ - application/json
47
+ Authorization:
48
+ - Basic YXBwbGljYXRpb246cGFzc3dvcmQ=
49
+ Expect:
50
+ - ""
51
+ response:
52
+ status:
53
+ code: 204
54
+ message: No Content
55
+ headers:
56
+ Server:
57
+ - Apache-Coyote/1.1
58
+ X-Embedded-Crowd-Version:
59
+ - Crowd/2.3.3
60
+ X-Crowd-User-Management-Version:
61
+ - "1.1"
62
+ Set-Cookie:
63
+ - JSESSIONID=10A425BACE7AA24F07440D0F517417CF; Path=/crowd
64
+ Date:
65
+ - Wed, 21 Dec 2011 20:57:02 GMT
66
+ body: ""
67
+ http_version:
68
+ recorded_at: Wed, 21 Dec 2011 20:57:03 GMT
69
+ - request:
70
+ method: get
71
+ uri: http://127.0.0.1:8095/crowd/rest/usermanagement/1/user?username=delete@example.com
72
+ body: ""
73
+ headers:
74
+ Accept:
75
+ - application/json
76
+ Authorization:
77
+ - Basic YXBwbGljYXRpb246cGFzc3dvcmQ=
78
+ Expect:
79
+ - ""
80
+ response:
81
+ status:
82
+ code: 404
83
+ message: Not Found
84
+ headers:
85
+ Server:
86
+ - Apache-Coyote/1.1
87
+ X-Embedded-Crowd-Version:
88
+ - Crowd/2.3.3
89
+ X-Crowd-User-Management-Version:
90
+ - "1.1"
91
+ Set-Cookie:
92
+ - JSESSIONID=A6CCCD1B41478BAD6C7BFC70508AB540; Path=/crowd
93
+ Content-Type:
94
+ - application/json
95
+ Transfer-Encoding:
96
+ - chunked
97
+ Date:
98
+ - Wed, 21 Dec 2011 20:57:02 GMT
99
+ body: "{\"reason\":\"USER_NOT_FOUND\",\"message\":\"User <delete@example.com> does not exist\"}"
100
+ http_version:
101
+ recorded_at: Wed, 21 Dec 2011 20:57:03 GMT
102
+ recorded_with: VCR 2.0.0.rc1
@@ -0,0 +1,40 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://127.0.0.1:8095/crowd/rest/usermanagement/1/authentication?username=user@example.com
6
+ body: "{\"value\":\"invalid\"}"
7
+ headers:
8
+ Accept:
9
+ - application/json
10
+ Authorization:
11
+ - Basic YXBwbGljYXRpb246cGFzc3dvcmQ=
12
+ Content-Type:
13
+ - application/json
14
+ Expect:
15
+ - ""
16
+ response:
17
+ status:
18
+ code: 400
19
+ message: Bad Request
20
+ headers:
21
+ Server:
22
+ - Apache-Coyote/1.1
23
+ X-Embedded-Crowd-Version:
24
+ - Crowd/2.3.3
25
+ X-Crowd-User-Management-Version:
26
+ - "1.1"
27
+ Set-Cookie:
28
+ - JSESSIONID=59F82423DD849682B73BE15CB83D18F8; Path=/crowd
29
+ Content-Type:
30
+ - application/json
31
+ Transfer-Encoding:
32
+ - chunked
33
+ Date:
34
+ - Wed, 21 Dec 2011 20:57:01 GMT
35
+ Connection:
36
+ - close
37
+ body: "{\"reason\":\"INVALID_USER_AUTHENTICATION\",\"message\":\"Failed to authenticate principal, password was invalid\"}"
38
+ http_version:
39
+ recorded_at: Wed, 21 Dec 2011 20:57:02 GMT
40
+ recorded_with: VCR 2.0.0.rc1
@@ -0,0 +1,38 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://127.0.0.1:8095/crowd/rest/usermanagement/1/authentication?username=user@example.com
6
+ body: "{\"value\":\"password\"}"
7
+ headers:
8
+ Accept:
9
+ - application/json
10
+ Authorization:
11
+ - Basic YXBwbGljYXRpb246cGFzc3dvcmQ=
12
+ Content-Type:
13
+ - application/json
14
+ Expect:
15
+ - ""
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Server:
22
+ - Apache-Coyote/1.1
23
+ X-Embedded-Crowd-Version:
24
+ - Crowd/2.3.3
25
+ X-Crowd-User-Management-Version:
26
+ - "1.1"
27
+ Set-Cookie:
28
+ - JSESSIONID=AB2B51DB124F9C964BA6C8F34C33C1FA; Path=/crowd
29
+ Content-Type:
30
+ - application/json
31
+ Transfer-Encoding:
32
+ - chunked
33
+ Date:
34
+ - Wed, 21 Dec 2011 20:57:01 GMT
35
+ body: "{\"expand\":\"attributes\",\"link\":{\"href\":\"http://127.0.0.1:8095/crowd/rest/usermanagement/1/user?username=user@example.com\",\"rel\":\"self\"},\"name\":\"user@example.com\",\"first-name\":\"Example\",\"last-name\":\"User\",\"display-name\":\"Example User\",\"email\":\"user@example.com\",\"password\":{\"link\":{\"href\":\"http://127.0.0.1:8095/crowd/rest/usermanagement/1/user/password?username=user@example.com\",\"rel\":\"edit\"}},\"active\":true,\"attributes\":{\"attributes\":[],\"link\":{\"href\":\"http://127.0.0.1:8095/crowd/rest/usermanagement/1/user/attribute?username=user@example.com\",\"rel\":\"self\"}}}"
36
+ http_version:
37
+ recorded_at: Wed, 21 Dec 2011 20:57:02 GMT
38
+ recorded_with: VCR 2.0.0.rc1
@@ -0,0 +1,135 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://127.0.0.1:8095/crowd/rest/usermanagement/1/user
6
+ body: "{\"name\":\"change_pass@example.com\",\"active\":true,\"password\":{\"value\":\"test\"},\"first-name\":\"Change\",\"last-name\":\"Me\",\"email\":\"change_pass@example.com\"}"
7
+ headers:
8
+ Accept:
9
+ - application/json
10
+ Authorization:
11
+ - Basic YXBwbGljYXRpb246cGFzc3dvcmQ=
12
+ Content-Type:
13
+ - application/json
14
+ Expect:
15
+ - ""
16
+ response:
17
+ status:
18
+ code: 201
19
+ message: Created
20
+ headers:
21
+ Server:
22
+ - Apache-Coyote/1.1
23
+ X-Embedded-Crowd-Version:
24
+ - Crowd/2.3.3
25
+ X-Crowd-User-Management-Version:
26
+ - "1.1"
27
+ Set-Cookie:
28
+ - JSESSIONID=AF173F6A2C59B6E40750190C8F96F8BE; Path=/crowd
29
+ Location:
30
+ - http://127.0.0.1:8095/crowd/rest/usermanagement/1/user?username=change_pass@example.com
31
+ Content-Type:
32
+ - application/json
33
+ Content-Length:
34
+ - "0"
35
+ Date:
36
+ - Wed, 21 Dec 2011 20:57:02 GMT
37
+ body: ""
38
+ http_version:
39
+ recorded_at: Wed, 21 Dec 2011 20:57:02 GMT
40
+ - request:
41
+ method: put
42
+ uri: http://127.0.0.1:8095/crowd/rest/usermanagement/1/user/password?username=change_pass@example.com
43
+ body: "{\"value\":\"new_password\"}"
44
+ headers:
45
+ Accept:
46
+ - application/json
47
+ Authorization:
48
+ - Basic YXBwbGljYXRpb246cGFzc3dvcmQ=
49
+ Content-Type:
50
+ - application/json
51
+ Expect:
52
+ - ""
53
+ response:
54
+ status:
55
+ code: 204
56
+ message: No Content
57
+ headers:
58
+ Server:
59
+ - Apache-Coyote/1.1
60
+ X-Embedded-Crowd-Version:
61
+ - Crowd/2.3.3
62
+ X-Crowd-User-Management-Version:
63
+ - "1.1"
64
+ Set-Cookie:
65
+ - JSESSIONID=35FD5E2251EC6531573BE602B9831D9B; Path=/crowd
66
+ Date:
67
+ - Wed, 21 Dec 2011 20:57:02 GMT
68
+ body: ""
69
+ http_version:
70
+ recorded_at: Wed, 21 Dec 2011 20:57:02 GMT
71
+ - request:
72
+ method: post
73
+ uri: http://127.0.0.1:8095/crowd/rest/usermanagement/1/authentication?username=change_pass@example.com
74
+ body: "{\"value\":\"new_password\"}"
75
+ headers:
76
+ Accept:
77
+ - application/json
78
+ Authorization:
79
+ - Basic YXBwbGljYXRpb246cGFzc3dvcmQ=
80
+ Content-Type:
81
+ - application/json
82
+ Expect:
83
+ - ""
84
+ response:
85
+ status:
86
+ code: 200
87
+ message: OK
88
+ headers:
89
+ Server:
90
+ - Apache-Coyote/1.1
91
+ X-Embedded-Crowd-Version:
92
+ - Crowd/2.3.3
93
+ X-Crowd-User-Management-Version:
94
+ - "1.1"
95
+ Set-Cookie:
96
+ - JSESSIONID=AAC72A5B38C42E4963B4E47A4AF35058; Path=/crowd
97
+ Content-Type:
98
+ - application/json
99
+ Transfer-Encoding:
100
+ - chunked
101
+ Date:
102
+ - Wed, 21 Dec 2011 20:57:02 GMT
103
+ body: "{\"expand\":\"attributes\",\"link\":{\"href\":\"http://127.0.0.1:8095/crowd/rest/usermanagement/1/user?username=change_pass@example.com\",\"rel\":\"self\"},\"name\":\"change_pass@example.com\",\"first-name\":\"Change\",\"last-name\":\"Me\",\"display-name\":\"Change Me\",\"email\":\"change_pass@example.com\",\"password\":{\"link\":{\"href\":\"http://127.0.0.1:8095/crowd/rest/usermanagement/1/user/password?username=change_pass@example.com\",\"rel\":\"edit\"}},\"active\":true,\"attributes\":{\"attributes\":[],\"link\":{\"href\":\"http://127.0.0.1:8095/crowd/rest/usermanagement/1/user/attribute?username=change_pass@example.com\",\"rel\":\"self\"}}}"
104
+ http_version:
105
+ recorded_at: Wed, 21 Dec 2011 20:57:02 GMT
106
+ - request:
107
+ method: delete
108
+ uri: http://127.0.0.1:8095/crowd/rest/usermanagement/1/user?username=change_pass@example.com
109
+ body: ""
110
+ headers:
111
+ Accept:
112
+ - application/json
113
+ Authorization:
114
+ - Basic YXBwbGljYXRpb246cGFzc3dvcmQ=
115
+ Expect:
116
+ - ""
117
+ response:
118
+ status:
119
+ code: 204
120
+ message: No Content
121
+ headers:
122
+ Server:
123
+ - Apache-Coyote/1.1
124
+ X-Embedded-Crowd-Version:
125
+ - Crowd/2.3.3
126
+ X-Crowd-User-Management-Version:
127
+ - "1.1"
128
+ Set-Cookie:
129
+ - JSESSIONID=2FD51EA55B2BA964EBC6BD56EFE3DFF9; Path=/crowd
130
+ Date:
131
+ - Wed, 21 Dec 2011 20:57:02 GMT
132
+ body: ""
133
+ http_version:
134
+ recorded_at: Wed, 21 Dec 2011 20:57:02 GMT
135
+ recorded_with: VCR 2.0.0.rc1
@@ -0,0 +1,36 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://127.0.0.1:8095/crowd/rest/usermanagement/1/user?username=user@example.com
6
+ body: ""
7
+ headers:
8
+ Accept:
9
+ - application/json
10
+ Authorization:
11
+ - Basic YXBwbGljYXRpb246cGFzc3dvcmQ=
12
+ Expect:
13
+ - ""
14
+ response:
15
+ status:
16
+ code: 200
17
+ message: OK
18
+ headers:
19
+ Server:
20
+ - Apache-Coyote/1.1
21
+ X-Embedded-Crowd-Version:
22
+ - Crowd/2.3.3
23
+ X-Crowd-User-Management-Version:
24
+ - "1.1"
25
+ Set-Cookie:
26
+ - JSESSIONID=E100FB66EB0D519EF1C026C06A456369; Path=/crowd
27
+ Content-Type:
28
+ - application/json
29
+ Transfer-Encoding:
30
+ - chunked
31
+ Date:
32
+ - Wed, 21 Dec 2011 20:57:01 GMT
33
+ body: "{\"expand\":\"attributes\",\"link\":{\"href\":\"http://127.0.0.1:8095/crowd/rest/usermanagement/1/user?username=user@example.com\",\"rel\":\"self\"},\"name\":\"user@example.com\",\"first-name\":\"Example\",\"last-name\":\"User\",\"display-name\":\"Example User\",\"email\":\"user@example.com\",\"password\":{\"link\":{\"href\":\"http://127.0.0.1:8095/crowd/rest/usermanagement/1/user/password?username=user@example.com\",\"rel\":\"edit\"}},\"active\":true,\"attributes\":{\"attributes\":[],\"link\":{\"href\":\"http://127.0.0.1:8095/crowd/rest/usermanagement/1/user/attribute?username=user@example.com\",\"rel\":\"self\"}}}"
34
+ http_version:
35
+ recorded_at: Wed, 21 Dec 2011 20:57:01 GMT
36
+ recorded_with: VCR 2.0.0.rc1
@@ -0,0 +1,36 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://127.0.0.1:8095/crowd/rest/usermanagement/1/user?username=user@example.com
6
+ body: ""
7
+ headers:
8
+ Accept:
9
+ - application/json
10
+ Authorization:
11
+ - Basic YXBwbGljYXRpb246cGFzc3dvcmQ=
12
+ Expect:
13
+ - ""
14
+ response:
15
+ status:
16
+ code: 200
17
+ message: OK
18
+ headers:
19
+ Server:
20
+ - Apache-Coyote/1.1
21
+ X-Embedded-Crowd-Version:
22
+ - Crowd/2.3.3
23
+ X-Crowd-User-Management-Version:
24
+ - "1.1"
25
+ Set-Cookie:
26
+ - JSESSIONID=2148E801B32AE4684E8BFB8C8533CB90; Path=/crowd
27
+ Content-Type:
28
+ - application/json
29
+ Transfer-Encoding:
30
+ - chunked
31
+ Date:
32
+ - Wed, 21 Dec 2011 20:57:01 GMT
33
+ body: "{\"expand\":\"attributes\",\"link\":{\"href\":\"http://127.0.0.1:8095/crowd/rest/usermanagement/1/user?username=user@example.com\",\"rel\":\"self\"},\"name\":\"user@example.com\",\"first-name\":\"Example\",\"last-name\":\"User\",\"display-name\":\"Example User\",\"email\":\"user@example.com\",\"password\":{\"link\":{\"href\":\"http://127.0.0.1:8095/crowd/rest/usermanagement/1/user/password?username=user@example.com\",\"rel\":\"edit\"}},\"active\":true,\"attributes\":{\"attributes\":[],\"link\":{\"href\":\"http://127.0.0.1:8095/crowd/rest/usermanagement/1/user/attribute?username=user@example.com\",\"rel\":\"self\"}}}"
34
+ http_version:
35
+ recorded_at: Wed, 21 Dec 2011 20:57:01 GMT
36
+ recorded_with: VCR 2.0.0.rc1
@@ -0,0 +1,50 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require File.expand_path(File.dirname(__FILE__) + '/../lib/crowd-client/group')
3
+
4
+ describe Crowd::Client::Group do
5
+
6
+ subject { Crowd::Client::Group.new('MyGroup') }
7
+
8
+ describe "#add_user" do
9
+ before { @user = Crowd::Client::User.create :username => 'group_add@example.com', :password => 'test', :first_name => 'Group', :last_name => 'Add', :email => 'group_add@example.com' }
10
+ after { @user.destroy }
11
+
12
+ it "should add the user" do
13
+ subject.add_user(@user)
14
+ subject.users.should include(@user)
15
+ end
16
+
17
+ it "should raise Exception::NotFound for missing user" do
18
+ fake_user = Crowd::Client::User.new('fake')
19
+ expect { subject.add_user(fake_user) }.should raise_error Crowd::Client::Exception::NotFound, /User/
20
+ end
21
+
22
+ describe "missing group" do
23
+ subject { Crowd::Client::Group.new('FakeGroup') }
24
+
25
+ it "should raise Exception::NotFound for missing group" do
26
+ user = Crowd::Client::User.new('user@example.com')
27
+ expect { subject.add_user(user) }.should raise_error Crowd::Client::Exception::NotFound, /Group/
28
+ end
29
+ end
30
+ end
31
+
32
+ describe "#remove_user" do
33
+ before { @user = Crowd::Client::User.create :username => 'group_removal@example.com', :password => 'test', :first_name => 'Group', :last_name => 'Removal', :email => 'group_removal@example.com' }
34
+ after { @user.destroy }
35
+
36
+ it "should remove the user" do
37
+ subject.add_user(@user)
38
+ subject.remove_user(@user)
39
+ subject.users.should_not include(@user)
40
+ end
41
+ end
42
+
43
+ describe "#users" do
44
+ it "should return all of the users in the group" do
45
+ users = subject.users
46
+ users.size.should == 1
47
+ users.first.username.should == 'user@example.com'
48
+ end
49
+ end
50
+ end
@@ -3,8 +3,6 @@ require File.expand_path(File.dirname(__FILE__) + '/../lib/crowd-client')
3
3
 
4
4
  describe Crowd::Client do
5
5
 
6
- use_vcr_cassette
7
-
8
6
  describe "#config" do
9
7
  subject { Crowd::Client.config }
10
8
 
@@ -64,7 +62,6 @@ describe Crowd::Client do
64
62
  end
65
63
 
66
64
  describe "#logout" do
67
-
68
65
  it "should logout the current session" do
69
66
  token = subject.login('user@example.com', 'password')
70
67
  subject.valid_session?(token).should be_true