crowd_rest 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm 1.9.2@crowd_rest
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in crowd_rest.gemspec
4
+ gemspec
@@ -0,0 +1,35 @@
1
+ # Crowd Rest
2
+
3
+ A ruby client for [Atlassian's Crowd REST API](http://confluence.atlassian.com/display/CROWDDEV/Crowd+REST+APIs).
4
+
5
+ ## Installation
6
+
7
+ gem install crowd_rest
8
+
9
+ ## Usage
10
+
11
+ require 'crowd_rest'
12
+
13
+ CrowdRest.config do |c|
14
+ c.crowd_url = "http://127.0.0.1:8095"
15
+ c.app_name = "demo"
16
+ c.app_pass = "demo_pass"
17
+ end
18
+
19
+ # unsuccessful login
20
+ response = CrowdRest::Session.create("baduser", "badpass")
21
+ response.code # => 400
22
+ response.reason # => INVALID_USER_AUTHENTICATION
23
+
24
+ # successful log in
25
+ response = CrowdRest::Session.create("gooduser", "goodpass")
26
+ response.code # => 201
27
+ token = response.token # => the crowd sso token
28
+
29
+ # check for existing login session
30
+ response = CrowdRest::Session.find(token)
31
+ response.code # => 200
32
+
33
+ # get the user associated with a login session
34
+ response = CrowdRest::Session.find(token, :include => :user)
35
+ response.user['name'] # => "gooduser"
@@ -0,0 +1,17 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+
5
+ require 'rspec/core/rake_task'
6
+ desc "Run specs"
7
+ RSpec::Core::RakeTask.new(:spec) do |t|
8
+ t.rspec_opts = %w(--color)
9
+ end
10
+ namespace :spec do
11
+ desc "Run specs with output in documentation format"
12
+ RSpec::Core::RakeTask.new(:doc) do |t|
13
+ t.rspec_opts = ["--color", "--format d"]
14
+ end
15
+ end
16
+
17
+
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "crowd_rest/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "crowd_rest"
7
+ s.version = CrowdRest::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Justin Blake"]
10
+ s.email = ["justin@hentzia.com"]
11
+ s.homepage = "https://github.com/blaix/crowd_rest"
12
+ s.summary = %q{Ruby client for Atlassian's Crowd REST API}
13
+ s.description = %q{Ruby client for Atlassian's Crowd REST API. Word up.}
14
+
15
+ s.rubyforge_project = "crowd_rest"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency 'httparty'
23
+
24
+ s.add_development_dependency 'rspec'
25
+ s.add_development_dependency 'vcr'
26
+ s.add_development_dependency 'fakeweb'
27
+ end
@@ -0,0 +1,41 @@
1
+ require 'httparty'
2
+
3
+ module CrowdRest
4
+ include HTTParty
5
+
6
+ autoload :Session, 'crowd_rest/session'
7
+ headers 'Content-type' => 'text/xml'
8
+
9
+ class << self
10
+ attr_reader :app_name, :app_pass
11
+ end
12
+
13
+ def self.config
14
+ yield(self)
15
+ end
16
+
17
+ def self.crowd_url=(url)
18
+ base_uri("#{url}/crowd/rest/usermanagement/1")
19
+ end
20
+
21
+ def self.app_name=(app_name)
22
+ @app_name = app_name
23
+ do_basic_auth if credentials_set?
24
+ end
25
+
26
+ def self.app_pass=(app_pass)
27
+ @app_pass = app_pass
28
+ do_basic_auth if credentials_set?
29
+ end
30
+
31
+ private
32
+
33
+ def self.do_basic_auth
34
+ self.basic_auth(@app_name, @app_pass)
35
+ end
36
+
37
+ def self.credentials_set?
38
+ @app_name && !@app_name.empty? &&
39
+ @app_pass && !@app_pass.empty?
40
+ end
41
+ end
@@ -0,0 +1,40 @@
1
+ require 'ostruct'
2
+
3
+ module CrowdRest
4
+ class Session
5
+ def self.create(username, password)
6
+ body = "<authentication-context>
7
+ <username>#{username}</username>
8
+ <password>#{password}</password>
9
+ </authentication-context>"
10
+ response = CrowdRest.post("/session", :body => body)
11
+ normalize_response(response, 201) do |successful_response|
12
+ successful_response.token = response['session']['token']
13
+ end
14
+ end
15
+
16
+ def self.find(token, options = {})
17
+ request_user = options[:include] && options[:include] == :user
18
+ path = "/session/#{token}"
19
+ path << "?expand=user" if request_user
20
+ response = CrowdRest.get(path)
21
+ normalize_response(response) do |successful_response|
22
+ successful_response.user = response['session']['user']
23
+ end
24
+ end
25
+
26
+ private
27
+ def self.normalize_response(response, success_code = 200)
28
+ attributes = {
29
+ :code => response.code,
30
+ :body => response.body,
31
+ :reason => response['reason'],
32
+ :message => response['message']
33
+ }
34
+
35
+ norm_response = OpenStruct.new(attributes)
36
+ yield(norm_response) if response.code == success_code
37
+ norm_response
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,4 @@
1
+ module CrowdRest
2
+ VERSION = "0.0.1"
3
+ CROWD_VERSION = "2.2"
4
+ end
@@ -0,0 +1,308 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :post
5
+ uri: http://demo:demo_pass@127.0.0.1:8095/crowd/rest/usermanagement/1/session
6
+ body: |-
7
+ <authentication-context>
8
+ <username>crowduser</username>
9
+ <password>crowdpass</password>
10
+ </authentication-context>
11
+ headers:
12
+ content-type:
13
+ - text/xml
14
+ authorization:
15
+ - Basic ZGVtbzpkZW1vX3Bhc3M=
16
+ response: !ruby/struct:VCR::Response
17
+ status: !ruby/struct:VCR::ResponseStatus
18
+ code: 201
19
+ message: Created
20
+ headers:
21
+ server:
22
+ - Apache-Coyote/1.1
23
+ x-embedded-crowd-version:
24
+ - Crowd/2.2.4
25
+ x-crowd-user-management-version:
26
+ - "1"
27
+ set-cookie:
28
+ - JSESSIONID=97F202B9299BEEFC50D91A2F6067B09C; Path=/crowd
29
+ cache-control:
30
+ - no-cache, no-store, no-transform
31
+ location:
32
+ - http://127.0.0.1:8095/crowd/rest/usermanagement/1/session/vew1d0n2wdv805BwynIH3Q00
33
+ content-type:
34
+ - application/xml
35
+ content-length:
36
+ - "364"
37
+ date:
38
+ - Tue, 17 May 2011 21:33:57 GMT
39
+ body: <?xml version="1.0" encoding="UTF-8" standalone="yes"?><session expand="user"><token>vew1d0n2wdv805BwynIH3Q00</token><user name="crowduser"><link rel="self" href="http://127.0.0.1:8095/crowd/rest/usermanagement/1/user?username=crowduser"/></user><link rel="self" href="http://127.0.0.1:8095/crowd/rest/usermanagement/1/session/vew1d0n2wdv805BwynIH3Q00"/></session>
40
+ http_version: "1.1"
41
+ - !ruby/struct:VCR::HTTPInteraction
42
+ request: !ruby/struct:VCR::Request
43
+ method: :post
44
+ uri: http://demo:demo_pass@127.0.0.1:8095/crowd/rest/usermanagement/1/session
45
+ body: |-
46
+ <authentication-context>
47
+ <username>baduser</username>
48
+ <password>badpass</password>
49
+ </authentication-context>
50
+ headers:
51
+ content-type:
52
+ - text/xml
53
+ authorization:
54
+ - Basic ZGVtbzpkZW1vX3Bhc3M=
55
+ response: !ruby/struct:VCR::Response
56
+ status: !ruby/struct:VCR::ResponseStatus
57
+ code: 400
58
+ message: Bad Request
59
+ headers:
60
+ server:
61
+ - Apache-Coyote/1.1
62
+ x-embedded-crowd-version:
63
+ - Crowd/2.2.4
64
+ x-crowd-user-management-version:
65
+ - "1"
66
+ set-cookie:
67
+ - JSESSIONID=8A74186ED063D8E120D82B41EE0C483C; Path=/crowd
68
+ content-type:
69
+ - application/json
70
+ transfer-encoding:
71
+ - chunked
72
+ date:
73
+ - Tue, 17 May 2011 21:33:57 GMT
74
+ body: "{\"reason\":\"INVALID_USER_AUTHENTICATION\",\"message\":\"baduser\"}"
75
+ http_version: "1.1"
76
+ - !ruby/struct:VCR::HTTPInteraction
77
+ request: !ruby/struct:VCR::Request
78
+ method: :post
79
+ uri: http://demo:demo_pass@127.0.0.1:8095/crowd/rest/usermanagement/1/session
80
+ body: |-
81
+ <authentication-context>
82
+ <username>crowduser</username>
83
+ <password>crowdpass</password>
84
+ </authentication-context>
85
+ headers:
86
+ content-type:
87
+ - text/xml
88
+ authorization:
89
+ - Basic ZGVtbzpkZW1vX3Bhc3M=
90
+ response: !ruby/struct:VCR::Response
91
+ status: !ruby/struct:VCR::ResponseStatus
92
+ code: 201
93
+ message: Created
94
+ headers:
95
+ server:
96
+ - Apache-Coyote/1.1
97
+ x-embedded-crowd-version:
98
+ - Crowd/2.2.4
99
+ x-crowd-user-management-version:
100
+ - "1"
101
+ set-cookie:
102
+ - JSESSIONID=CDF0A341D6F4573D1EDC661B7489B1DE; Path=/crowd
103
+ cache-control:
104
+ - no-cache, no-store, no-transform
105
+ location:
106
+ - http://127.0.0.1:8095/crowd/rest/usermanagement/1/session/vew1d0n2wdv805BwynIH3Q00
107
+ content-type:
108
+ - application/xml
109
+ content-length:
110
+ - "364"
111
+ date:
112
+ - Tue, 17 May 2011 21:33:57 GMT
113
+ body: <?xml version="1.0" encoding="UTF-8" standalone="yes"?><session expand="user"><token>vew1d0n2wdv805BwynIH3Q00</token><user name="crowduser"><link rel="self" href="http://127.0.0.1:8095/crowd/rest/usermanagement/1/user?username=crowduser"/></user><link rel="self" href="http://127.0.0.1:8095/crowd/rest/usermanagement/1/session/vew1d0n2wdv805BwynIH3Q00"/></session>
114
+ http_version: "1.1"
115
+ - !ruby/struct:VCR::HTTPInteraction
116
+ request: !ruby/struct:VCR::Request
117
+ method: :get
118
+ uri: http://demo:demo_pass@127.0.0.1:8095/crowd/rest/usermanagement/1/session/vew1d0n2wdv805BwynIH3Q00
119
+ body:
120
+ headers:
121
+ content-type:
122
+ - text/xml
123
+ authorization:
124
+ - Basic ZGVtbzpkZW1vX3Bhc3M=
125
+ response: !ruby/struct:VCR::Response
126
+ status: !ruby/struct:VCR::ResponseStatus
127
+ code: 200
128
+ message: OK
129
+ headers:
130
+ server:
131
+ - Apache-Coyote/1.1
132
+ x-embedded-crowd-version:
133
+ - Crowd/2.2.4
134
+ x-crowd-user-management-version:
135
+ - "1"
136
+ set-cookie:
137
+ - JSESSIONID=88949BAF0A280647E63F1F00813F3226; Path=/crowd
138
+ content-type:
139
+ - application/xml
140
+ content-length:
141
+ - "777"
142
+ date:
143
+ - Tue, 17 May 2011 21:33:58 GMT
144
+ body: <?xml version="1.0" encoding="UTF-8" standalone="yes"?><session expand="user"><token>vew1d0n2wdv805BwynIH3Q00</token><user name="crowduser"><link rel="self" href="http://127.0.0.1:8095/crowd/rest/usermanagement/1/user?username=crowduser"/><first-name>Crowd</first-name><last-name>Test</last-name><display-name>Crowd Test</display-name><email>crowduser@test.com</email><password><link rel="edit" href="http://127.0.0.1:8095/crowd/rest/usermanagement/1/user/password?username=crowduser"/></password><active>true</active><attributes><link rel="self" href="http://127.0.0.1:8095/crowd/rest/usermanagement/1/user/attribute?username=crowduser"/></attributes></user><link rel="self" href="http://127.0.0.1:8095/crowd/rest/usermanagement/1/session/vew1d0n2wdv805BwynIH3Q00"/></session>
145
+ http_version: "1.1"
146
+ - !ruby/struct:VCR::HTTPInteraction
147
+ request: !ruby/struct:VCR::Request
148
+ method: :get
149
+ uri: http://demo:demo_pass@127.0.0.1:8095/crowd/rest/usermanagement/1/session/beefface
150
+ body:
151
+ headers:
152
+ content-type:
153
+ - text/xml
154
+ authorization:
155
+ - Basic ZGVtbzpkZW1vX3Bhc3M=
156
+ response: !ruby/struct:VCR::Response
157
+ status: !ruby/struct:VCR::ResponseStatus
158
+ code: 400
159
+ message: Bad Request
160
+ headers:
161
+ server:
162
+ - Apache-Coyote/1.1
163
+ x-embedded-crowd-version:
164
+ - Crowd/2.2.4
165
+ x-crowd-user-management-version:
166
+ - "1"
167
+ set-cookie:
168
+ - JSESSIONID=5A428FDB960F4B444090F7CDC4A573AE; Path=/crowd
169
+ content-type:
170
+ - application/json
171
+ transfer-encoding:
172
+ - chunked
173
+ date:
174
+ - Tue, 17 May 2011 21:33:58 GMT
175
+ body: "{\"reason\":\"INVALID_SSO_TOKEN\",\"message\":\"Failed to find entity of type [com.atlassian.crowd.model.token.Token] with identifier [beefface]\"}"
176
+ http_version: "1.1"
177
+ - !ruby/struct:VCR::HTTPInteraction
178
+ request: !ruby/struct:VCR::Request
179
+ method: :post
180
+ uri: http://demo:demo_pass@127.0.0.1:8095/crowd/rest/usermanagement/1/session
181
+ body: |-
182
+ <authentication-context>
183
+ <username>crowduser</username>
184
+ <password>crowdpass</password>
185
+ </authentication-context>
186
+ headers:
187
+ content-type:
188
+ - text/xml
189
+ authorization:
190
+ - Basic ZGVtbzpkZW1vX3Bhc3M=
191
+ response: !ruby/struct:VCR::Response
192
+ status: !ruby/struct:VCR::ResponseStatus
193
+ code: 201
194
+ message: Created
195
+ headers:
196
+ server:
197
+ - Apache-Coyote/1.1
198
+ x-embedded-crowd-version:
199
+ - Crowd/2.2.4
200
+ x-crowd-user-management-version:
201
+ - "1"
202
+ set-cookie:
203
+ - JSESSIONID=0221CFF6FA9246AC77638791F918A99F; Path=/crowd
204
+ cache-control:
205
+ - no-cache, no-store, no-transform
206
+ location:
207
+ - http://127.0.0.1:8095/crowd/rest/usermanagement/1/session/vew1d0n2wdv805BwynIH3Q00
208
+ content-type:
209
+ - application/xml
210
+ content-length:
211
+ - "364"
212
+ date:
213
+ - Tue, 17 May 2011 21:33:58 GMT
214
+ body: <?xml version="1.0" encoding="UTF-8" standalone="yes"?><session expand="user"><token>vew1d0n2wdv805BwynIH3Q00</token><user name="crowduser"><link rel="self" href="http://127.0.0.1:8095/crowd/rest/usermanagement/1/user?username=crowduser"/></user><link rel="self" href="http://127.0.0.1:8095/crowd/rest/usermanagement/1/session/vew1d0n2wdv805BwynIH3Q00"/></session>
215
+ http_version: "1.1"
216
+ - !ruby/struct:VCR::HTTPInteraction
217
+ request: !ruby/struct:VCR::Request
218
+ method: :get
219
+ uri: http://demo:demo_pass@127.0.0.1:8095/crowd/rest/usermanagement/1/session/vew1d0n2wdv805BwynIH3Q00?expand=user
220
+ body:
221
+ headers:
222
+ content-type:
223
+ - text/xml
224
+ authorization:
225
+ - Basic ZGVtbzpkZW1vX3Bhc3M=
226
+ response: !ruby/struct:VCR::Response
227
+ status: !ruby/struct:VCR::ResponseStatus
228
+ code: 200
229
+ message: OK
230
+ headers:
231
+ server:
232
+ - Apache-Coyote/1.1
233
+ x-embedded-crowd-version:
234
+ - Crowd/2.2.4
235
+ x-crowd-user-management-version:
236
+ - "1"
237
+ set-cookie:
238
+ - JSESSIONID=8CA8506E288F0AB3971BBADCE3B1ECB4; Path=/crowd
239
+ content-type:
240
+ - application/xml
241
+ content-length:
242
+ - "777"
243
+ date:
244
+ - Tue, 17 May 2011 21:33:59 GMT
245
+ body: <?xml version="1.0" encoding="UTF-8" standalone="yes"?><session expand="user"><token>vew1d0n2wdv805BwynIH3Q00</token><user name="crowduser"><link rel="self" href="http://127.0.0.1:8095/crowd/rest/usermanagement/1/user?username=crowduser"/><first-name>Crowd</first-name><last-name>Test</last-name><display-name>Crowd Test</display-name><email>crowduser@test.com</email><password><link rel="edit" href="http://127.0.0.1:8095/crowd/rest/usermanagement/1/user/password?username=crowduser"/></password><active>true</active><attributes><link rel="self" href="http://127.0.0.1:8095/crowd/rest/usermanagement/1/user/attribute?username=crowduser"/></attributes></user><link rel="self" href="http://127.0.0.1:8095/crowd/rest/usermanagement/1/session/vew1d0n2wdv805BwynIH3Q00"/></session>
246
+ http_version: "1.1"
247
+ - !ruby/struct:VCR::HTTPInteraction
248
+ request: !ruby/struct:VCR::Request
249
+ method: :get
250
+ uri: http://demo:demo_pass@127.0.0.1:8095/crowd/rest/usermanagement/1/search
251
+ body:
252
+ headers:
253
+ content-type:
254
+ - text/xml
255
+ authorization:
256
+ - Basic ZGVtbzpkZW1vX3Bhc3M=
257
+ response: !ruby/struct:VCR::Response
258
+ status: !ruby/struct:VCR::ResponseStatus
259
+ code: 415
260
+ message: Unsupported Media Type
261
+ headers:
262
+ server:
263
+ - Apache-Coyote/1.1
264
+ x-embedded-crowd-version:
265
+ - Crowd/2.2.4
266
+ x-crowd-user-management-version:
267
+ - "1"
268
+ set-cookie:
269
+ - JSESSIONID=53651C114D79062C45E7552387116844; Path=/crowd
270
+ content-type:
271
+ - text/html;charset=utf-8
272
+ content-length:
273
+ - "1051"
274
+ date:
275
+ - Tue, 17 May 2011 21:33:59 GMT
276
+ body: "<html><head><title>Apache Tomcat/6.0.32 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 415 - </h1><HR size=\"1\" noshade=\"noshade\"><p><b>type</b> Status report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>The server refused this request because the request entity is in a format not supported by the requested resource for the requested method ().</u></p><HR size=\"1\" noshade=\"noshade\"><h3>Apache Tomcat/6.0.32</h3></body></html>"
277
+ http_version: "1.1"
278
+ - !ruby/struct:VCR::HTTPInteraction
279
+ request: !ruby/struct:VCR::Request
280
+ method: :get
281
+ uri: http://badname:badpass@127.0.0.1:8095/crowd/rest/usermanagement/1/search
282
+ body:
283
+ headers:
284
+ content-type:
285
+ - text/xml
286
+ authorization:
287
+ - Basic YmFkbmFtZTpiYWRwYXNz
288
+ response: !ruby/struct:VCR::Response
289
+ status: !ruby/struct:VCR::ResponseStatus
290
+ code: 401
291
+ message: Unauthorized
292
+ headers:
293
+ server:
294
+ - Apache-Coyote/1.1
295
+ x-embedded-crowd-version:
296
+ - Crowd/2.2.4
297
+ x-crowd-user-management-version:
298
+ - "1"
299
+ www-authenticate:
300
+ - BASIC realm="Crowd REST Service"
301
+ content-type:
302
+ - text/plain;charset=UTF-8
303
+ transfer-encoding:
304
+ - chunked
305
+ date:
306
+ - Tue, 17 May 2011 21:33:59 GMT
307
+ body: Application failed to authenticate
308
+ http_version: "1.1"
@@ -0,0 +1,78 @@
1
+ require "spec_helper"
2
+
3
+ describe CrowdRest::Session do
4
+ shared_examples "a failed request" do
5
+ it "includes a failure reason in the response" do
6
+ @response.reason.should_not be_nil
7
+ end
8
+
9
+ it "includes a failure message in the response" do
10
+ @response.message.should_not be_nil
11
+ end
12
+ end
13
+
14
+ describe ".create" do
15
+ context "given valid user credentials" do
16
+ before(:all) do
17
+ @response = CrowdRest::Session.create("crowduser", "crowdpass")
18
+ end
19
+
20
+ it "creates a new session" do
21
+ @response.code.should == 201
22
+ end
23
+
24
+ it "includes the sso token in the response" do
25
+ @response.token.should_not be_nil
26
+ end
27
+ end
28
+
29
+ context "given invalid user credentials" do
30
+ before(:all) do
31
+ @response = CrowdRest::Session.create("baduser", "badpass")
32
+ end
33
+
34
+ it_behaves_like "a failed request"
35
+
36
+ it "does not create a new session" do
37
+ @response.code.should_not == 201
38
+ end
39
+ end
40
+ end
41
+
42
+ describe ".find(token)" do
43
+ context "given a valid session token" do
44
+ before(:all) do
45
+ login = CrowdRest::Session.create("crowduser", "crowdpass")
46
+ @response = CrowdRest::Session.find(login.token)
47
+ end
48
+
49
+ it "responds successfuly" do
50
+ @response.code.should == 200
51
+ end
52
+ end
53
+
54
+ context "given an invalid session token" do
55
+ before(:all) do
56
+ @response = CrowdRest::Session.find("beefface")
57
+ end
58
+
59
+ it_behaves_like "a failed request"
60
+
61
+ it "does not respond successfuly" do
62
+ @response.code.should_not == 200
63
+ end
64
+ end
65
+ end
66
+
67
+ describe ".find(token, :include => :user)" do
68
+ before(:all) do
69
+ login = CrowdRest::Session.create("crowduser", "crowdpass")
70
+ @response = CrowdRest::Session.find(login.token, :include => :user)
71
+ end
72
+
73
+ it "includes the user in the response" do
74
+ @response.user.should_not be_nil
75
+ @response.user['name'].should == "crowduser"
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,30 @@
1
+ require "spec_helper"
2
+
3
+ describe CrowdRest do
4
+ context "given valid app credentials" do
5
+ it "will not get an '401 Unauthorized' response" do
6
+ # valid params are set in spec_helper
7
+ response = CrowdRest.get("/search")
8
+ response.code.should_not == 401
9
+ end
10
+ end
11
+
12
+ context "given invalid app credentials" do
13
+ before(:all) do
14
+ @old_app_name = CrowdRest.app_name
15
+ @old_app_pass = CrowdRest.app_pass
16
+ CrowdRest.app_name = "badname"
17
+ CrowdRest.app_pass = "badpass"
18
+ end
19
+
20
+ after(:all) do
21
+ CrowdRest.app_name = @old_app_name
22
+ CrowdRest.app_pass = @old_app_pass
23
+ end
24
+
25
+ it "will get an '401 Unauthorized' response" do
26
+ response = CrowdRest.get("/search")
27
+ response.code.should == 401
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,35 @@
1
+ require "rubygems"
2
+ require "bundler/setup"
3
+
4
+ require "rspec"
5
+ require "vcr"
6
+
7
+ require "crowd_rest"
8
+
9
+ CrowdRest.config do |c|
10
+ c.crowd_url = "http://127.0.0.1:8095"
11
+ c.app_name = "demo"
12
+ c.app_pass = "demo_pass"
13
+ end
14
+
15
+ VCR.config do |c|
16
+ c.cassette_library_dir = File.expand_path("cassette_library", File.dirname(__FILE__))
17
+ c.stub_with :fakeweb
18
+ c.ignore_localhost = false
19
+ end
20
+
21
+ if ENV['DONT_FAKE']
22
+ puts "VCR: Will record all http requests made during this test run..."
23
+ record_type = :all
24
+ at_exit { VCR.eject_cassette }
25
+ else
26
+ puts "VCR: Using previously recorded http requests. " +
27
+ "Run with DONT_FAKE=1 to hit local crowd server and record new requests."
28
+ record_type = :none
29
+ end
30
+
31
+ VCR.insert_cassette('test_data', :record => record_type)
32
+
33
+ RSpec.configure do |config|
34
+ config.extend VCR::RSpec::Macros
35
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: crowd_rest
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Justin Blake
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-05-18 00:00:00 -04:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: httparty
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "0"
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: "0"
36
+ type: :development
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: vcr
40
+ prerelease: false
41
+ requirement: &id003 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: "0"
47
+ type: :development
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: fakeweb
51
+ prerelease: false
52
+ requirement: &id004 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ type: :development
59
+ version_requirements: *id004
60
+ description: Ruby client for Atlassian's Crowd REST API. Word up.
61
+ email:
62
+ - justin@hentzia.com
63
+ executables: []
64
+
65
+ extensions: []
66
+
67
+ extra_rdoc_files: []
68
+
69
+ files:
70
+ - .gitignore
71
+ - .rvmrc
72
+ - Gemfile
73
+ - README.md
74
+ - Rakefile
75
+ - crowd_rest.gemspec
76
+ - lib/crowd_rest.rb
77
+ - lib/crowd_rest/session.rb
78
+ - lib/crowd_rest/version.rb
79
+ - spec/cassette_library/test_data.yml
80
+ - spec/crowd_rest/session_spec.rb
81
+ - spec/crowd_rest_spec.rb
82
+ - spec/spec_helper.rb
83
+ has_rdoc: true
84
+ homepage: https://github.com/blaix/crowd_rest
85
+ licenses: []
86
+
87
+ post_install_message:
88
+ rdoc_options: []
89
+
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: "0"
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: "0"
104
+ requirements: []
105
+
106
+ rubyforge_project: crowd_rest
107
+ rubygems_version: 1.6.2
108
+ signing_key:
109
+ specification_version: 3
110
+ summary: Ruby client for Atlassian's Crowd REST API
111
+ test_files:
112
+ - spec/cassette_library/test_data.yml
113
+ - spec/crowd_rest/session_spec.rb
114
+ - spec/crowd_rest_spec.rb
115
+ - spec/spec_helper.rb