@@ -29,6 +29,8 class Redmine::ApiTest::HttpBasicLoginTest < Redmine::ApiTest::Base | |||
|
29 | 29 | def setup |
|
30 | 30 | Setting.rest_api_enabled = '1' |
|
31 | 31 | Setting.login_required = '1' |
|
32 | project = Project.find('onlinestore') | |
|
33 | EnabledModule.create(:project => project, :name => 'news') | |
|
32 | 34 | end |
|
33 | 35 | |
|
34 | 36 | def teardown |
@@ -36,19 +38,6 class Redmine::ApiTest::HttpBasicLoginTest < Redmine::ApiTest::Base | |||
|
36 | 38 | Setting.login_required = '0' |
|
37 | 39 | end |
|
38 | 40 | |
|
39 | # Using the NewsController because it's a simple API. | |
|
40 | context "get /news" do | |
|
41 | setup do | |
|
42 | project = Project.find('onlinestore') | |
|
43 | EnabledModule.create(:project => project, :name => 'news') | |
|
44 | end | |
|
45 | ||
|
46 | context "in :xml format" do | |
|
47 | should_allow_http_basic_auth_with_username_and_password(:get, "/projects/onlinestore/news.xml") | |
|
48 | end | |
|
49 | ||
|
50 | context "in :json format" do | |
|
51 | should_allow_http_basic_auth_with_username_and_password(:get, "/projects/onlinestore/news.json") | |
|
52 | end | |
|
53 | end | |
|
41 | should_allow_http_basic_auth_with_username_and_password(:get, "/projects/onlinestore/news.xml") | |
|
42 | should_allow_http_basic_auth_with_username_and_password(:get, "/projects/onlinestore/news.json") | |
|
54 | 43 | end |
@@ -36,15 +36,6 class Redmine::ApiTest::HttpBasicLoginWithApiTokenTest < Redmine::ApiTest::Base | |||
|
36 | 36 | Setting.login_required = '0' |
|
37 | 37 | end |
|
38 | 38 | |
|
39 | # Using the NewsController because it's a simple API. | |
|
40 | context "get /news" do | |
|
41 | ||
|
42 | context "in :xml format" do | |
|
43 | should_allow_http_basic_auth_with_key(:get, "/news.xml") | |
|
44 | end | |
|
45 | ||
|
46 | context "in :json format" do | |
|
47 | should_allow_http_basic_auth_with_key(:get, "/news.json") | |
|
48 | end | |
|
49 | end | |
|
39 | should_allow_http_basic_auth_with_key(:get, "/news.xml") | |
|
40 | should_allow_http_basic_auth_with_key(:get, "/news.json") | |
|
50 | 41 | end |
This diff has been collapsed as it changes many lines, (811 lines changed) Show them Hide them | |||
@@ -48,98 +48,117 class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base | |||
|
48 | 48 | Setting.rest_api_enabled = '1' |
|
49 | 49 | end |
|
50 | 50 | |
|
51 | context "/issues" do | |
|
52 | # Use a private project to make sure auth is really working and not just | |
|
53 | # only showing public issues. | |
|
54 |
|
|
|
55 | ||
|
56 | should "contain metadata" do | |
|
57 | get '/issues.xml' | |
|
51 | # Use a private project to make sure auth is really working and not just | |
|
52 | # only showing public issues. | |
|
53 | should_allow_api_authentication(:get, "/projects/private-child/issues.xml") | |
|
54 | should_allow_api_authentication(:get, "/projects/private-child/issues.json") | |
|
55 | ||
|
56 | should_allow_api_authentication(:get, "/issues/6.xml") | |
|
57 | should_allow_api_authentication(:get, "/issues/6.json") | |
|
58 | ||
|
59 | should_allow_api_authentication( | |
|
60 | :post, | |
|
61 | '/issues.xml', | |
|
62 | {:issue => {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}}, | |
|
63 | {:success_code => :created} | |
|
64 | ) | |
|
65 | should_allow_api_authentication(:post, | |
|
66 | '/issues.json', | |
|
67 | {:issue => {:project_id => 1, :subject => 'API test', | |
|
68 | :tracker_id => 2, :status_id => 3}}, | |
|
69 | {:success_code => :created}) | |
|
70 | ||
|
71 | should_allow_api_authentication(:put, | |
|
72 | '/issues/6.xml', | |
|
73 | {:issue => {:subject => 'API update', :notes => 'A new note'}}, | |
|
74 | {:success_code => :ok}) | |
|
75 | should_allow_api_authentication(:put, | |
|
76 | '/issues/6.json', | |
|
77 | {:issue => {:subject => 'API update', :notes => 'A new note'}}, | |
|
78 | {:success_code => :ok}) | |
|
79 | ||
|
80 | should_allow_api_authentication(:delete, | |
|
81 | '/issues/6.xml', | |
|
82 | {}, | |
|
83 | {:success_code => :ok}) | |
|
84 | should_allow_api_authentication(:delete, | |
|
85 | '/issues/6.json', | |
|
86 | {}, | |
|
87 | {:success_code => :ok}) | |
|
88 | ||
|
89 | test "GET /issues.xml should contain metadata" do | |
|
90 | get '/issues.xml' | |
|
91 | assert_select 'issues[type=array][total_count=?][limit="25"][offset="0"]', | |
|
92 | assigns(:issue_count).to_s | |
|
93 | end | |
|
58 | 94 | |
|
59 | assert_select 'issues[type=array][total_count=?][limit="25"][offset="0"]', assigns(:issue_count).to_s | |
|
60 | end | |
|
95 | test "GET /issues.xml with nometa param should not contain metadata" do | |
|
96 | get '/issues.xml?nometa=1' | |
|
97 | assert_select 'issues[type=array]:not([total_count]):not([limit]):not([offset])' | |
|
98 | end | |
|
61 | 99 | |
|
62 | context "with offset and limit" do | |
|
63 | should "use the params" do | |
|
64 | get '/issues.xml?offset=2&limit=3' | |
|
100 | test "GET /issues.xml with nometa header should not contain metadata" do | |
|
101 | get '/issues.xml', {}, {'X-Redmine-Nometa' => '1'} | |
|
102 | assert_select 'issues[type=array]:not([total_count]):not([limit]):not([offset])' | |
|
103 | end | |
|
65 | 104 | |
|
66 | assert_equal 3, assigns(:limit) | |
|
67 | assert_equal 2, assigns(:offset) | |
|
68 | assert_select 'issues issue', 3 | |
|
69 | end | |
|
70 | end | |
|
105 | test "GET /issues.xml with offset and limit" do | |
|
106 | get '/issues.xml?offset=2&limit=3' | |
|
71 | 107 | |
|
72 | context "with nometa param" do | |
|
73 | should "not contain metadata" do | |
|
74 | get '/issues.xml?nometa=1' | |
|
108 | assert_equal 3, assigns(:limit) | |
|
109 | assert_equal 2, assigns(:offset) | |
|
110 | assert_select 'issues issue', 3 | |
|
111 | end | |
|
75 | 112 | |
|
76 | assert_select 'issues[type=array]:not([total_count]):not([limit]):not([offset])' | |
|
77 | end | |
|
78 | end | |
|
113 | test "GET /issues.xml with relations" do | |
|
114 | get '/issues.xml?include=relations' | |
|
79 | 115 | |
|
80 | context "with nometa header" do | |
|
81 | should "not contain metadata" do | |
|
82 | get '/issues.xml', {}, {'X-Redmine-Nometa' => '1'} | |
|
116 | assert_response :success | |
|
117 | assert_equal 'application/xml', @response.content_type | |
|
83 | 118 | |
|
84 | assert_select 'issues[type=array]:not([total_count]):not([limit]):not([offset])' | |
|
85 | end | |
|
119 | assert_select 'issue id:content(3)' do | |
|
120 | assert_select '~ relations relation', 1 | |
|
121 | assert_select '~ relations relation[id="2"][issue_id="2"][issue_to_id="3"][relation_type=relates]' | |
|
86 | 122 | end |
|
87 | 123 | |
|
88 | context "with relations" do | |
|
89 | should "display relations" do | |
|
90 | get '/issues.xml?include=relations' | |
|
91 | ||
|
92 | assert_response :success | |
|
93 | assert_equal 'application/xml', @response.content_type | |
|
124 | assert_select 'issue id:content(1)' do | |
|
125 | assert_select '~ relations' | |
|
126 | assert_select '~ relations relation', 0 | |
|
127 | end | |
|
128 | end | |
|
94 | 129 | |
|
95 | assert_select 'issue id:content(3)' do | |
|
96 | assert_select '~ relations relation', 1 | |
|
97 | assert_select '~ relations relation[id="2"][issue_id="2"][issue_to_id="3"][relation_type=relates]' | |
|
98 | end | |
|
130 | test "GET /issues.xml with invalid query params" do | |
|
131 | get '/issues.xml', {:f => ['start_date'], :op => {:start_date => '='}} | |
|
99 | 132 | |
|
100 | assert_select 'issue id:content(1)' do | |
|
101 | assert_select '~ relations' | |
|
102 | assert_select '~ relations relation', 0 | |
|
103 |
|
|
|
104 | end | |
|
105 | end | |
|
133 | assert_response :unprocessable_entity | |
|
134 | assert_equal 'application/xml', @response.content_type | |
|
135 | assert_select 'errors error', :text => "Start date can't be blank" | |
|
136 | end | |
|
106 | 137 | |
|
107 | context "with invalid query params" do | |
|
108 | should "return errors" do | |
|
109 | get '/issues.xml', {:f => ['start_date'], :op => {:start_date => '='}} | |
|
138 | test "GET /issues.xml with custom field filter" do | |
|
139 | get '/issues.xml', | |
|
140 | {:set_filter => 1, :f => ['cf_1'], :op => {:cf_1 => '='}, :v => {:cf_1 => ['MySQL']}} | |
|
110 | 141 | |
|
111 | assert_response :unprocessable_entity | |
|
112 | assert_equal 'application/xml', @response.content_type | |
|
113 | assert_select 'errors error', :text => "Start date can't be blank" | |
|
114 | end | |
|
115 | end | |
|
142 | expected_ids = Issue.visible. | |
|
143 | joins(:custom_values). | |
|
144 | where(:custom_values => {:custom_field_id => 1, :value => 'MySQL'}).map(&:id) | |
|
145 | assert expected_ids.any? | |
|
116 | 146 | |
|
117 | context "with custom field filter" do | |
|
118 | should "show only issues with the custom field value" do | |
|
119 | get '/issues.xml', | |
|
120 | {:set_filter => 1, :f => ['cf_1'], :op => {:cf_1 => '='}, | |
|
121 | :v => {:cf_1 => ['MySQL']}} | |
|
122 | expected_ids = Issue.visible. | |
|
123 | joins(:custom_values). | |
|
124 | where(:custom_values => {:custom_field_id => 1, :value => 'MySQL'}).map(&:id) | |
|
125 | assert_select 'issues > issue > id', :count => expected_ids.count do |ids| | |
|
126 | ids.each { |id| assert expected_ids.delete(id.children.first.content.to_i) } | |
|
127 | end | |
|
128 | end | |
|
147 | assert_select 'issues > issue > id', :count => expected_ids.count do |ids| | |
|
148 | ids.each { |id| assert expected_ids.delete(id.children.first.content.to_i) } | |
|
129 | 149 | end |
|
150 | end | |
|
130 | 151 | |
|
131 |
|
|
|
132 | should "show only issues with the custom field value" do | |
|
133 | get '/issues.xml', { :cf_1 => 'MySQL' } | |
|
152 | test "GET /issues.xml with custom field filter (shorthand method)" do | |
|
153 | get '/issues.xml', {:cf_1 => 'MySQL'} | |
|
134 | 154 | |
|
135 |
|
|
|
136 |
|
|
|
137 |
|
|
|
155 | expected_ids = Issue.visible. | |
|
156 | joins(:custom_values). | |
|
157 | where(:custom_values => {:custom_field_id => 1, :value => 'MySQL'}).map(&:id) | |
|
158 | assert expected_ids.any? | |
|
138 | 159 | |
|
139 |
|
|
|
140 |
|
|
|
141 | end | |
|
142 | end | |
|
160 | assert_select 'issues > issue > id', :count => expected_ids.count do |ids| | |
|
161 | ids.each { |id| assert expected_ids.delete(id.children.first.content.to_i) } | |
|
143 | 162 | end |
|
144 | 163 | end |
|
145 | 164 | |
@@ -171,234 +190,163 class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base | |||
|
171 | 190 | assert_select 'issues>issue', :count => 2 |
|
172 | 191 | end |
|
173 | 192 | |
|
174 | context "/index.json" do | |
|
175 | should_allow_api_authentication(:get, "/projects/private-child/issues.json") | |
|
176 | end | |
|
193 | test "GET /issues.xml with filter" do | |
|
194 | get '/issues.xml?status_id=5' | |
|
177 | 195 | |
|
178 | context "/index.xml with filter" do | |
|
179 | should "show only issues with the status_id" do | |
|
180 | get '/issues.xml?status_id=5' | |
|
196 | expected_ids = Issue.visible.where(:status_id => 5).map(&:id) | |
|
197 | assert expected_ids.any? | |
|
181 | 198 | |
|
182 | expected_ids = Issue.visible.where(:status_id => 5).map(&:id) | |
|
183 | ||
|
184 | assert_select 'issues > issue > id', :count => expected_ids.count do |ids| | |
|
185 | ids.each { |id| assert expected_ids.delete(id.children.first.content.to_i) } | |
|
186 | end | |
|
199 | assert_select 'issues > issue > id', :count => expected_ids.count do |ids| | |
|
200 | ids.each { |id| assert expected_ids.delete(id.children.first.content.to_i) } | |
|
187 | 201 | end |
|
188 | 202 | end |
|
189 | 203 | |
|
190 |
|
|
|
191 | should "show only issues with the status_id" do | |
|
192 | get '/issues.json?status_id=5' | |
|
193 | ||
|
194 | json = ActiveSupport::JSON.decode(response.body) | |
|
195 | status_ids_used = json['issues'].collect {|j| j['status']['id'] } | |
|
196 | assert_equal 3, status_ids_used.length | |
|
197 | assert status_ids_used.all? {|id| id == 5 } | |
|
198 | end | |
|
204 | test "GET /issues.json with filter" do | |
|
205 | get '/issues.json?status_id=5' | |
|
199 | 206 | |
|
207 | json = ActiveSupport::JSON.decode(response.body) | |
|
208 | status_ids_used = json['issues'].collect {|j| j['status']['id'] } | |
|
209 | assert_equal 3, status_ids_used.length | |
|
210 | assert status_ids_used.all? {|id| id == 5 } | |
|
200 | 211 | end |
|
201 | 212 | |
|
202 | # Issue 6 is on a private project | |
|
203 | context "/issues/6.xml" do | |
|
204 | should_allow_api_authentication(:get, "/issues/6.xml") | |
|
205 | end | |
|
213 | test "GET /issues/:id.xml with journals" do | |
|
214 | get '/issues/1.xml?include=journals' | |
|
206 | 215 | |
|
207 | context "/issues/6.json" do | |
|
208 | should_allow_api_authentication(:get, "/issues/6.json") | |
|
216 | assert_select 'issue journals[type=array]' do | |
|
217 | assert_select 'journal[id="1"]' do | |
|
218 | assert_select 'details[type=array]' do | |
|
219 | assert_select 'detail[name=status_id]' do | |
|
220 | assert_select 'old_value', :text => '1' | |
|
221 | assert_select 'new_value', :text => '2' | |
|
222 | end | |
|
223 | end | |
|
224 | end | |
|
225 | end | |
|
209 | 226 | end |
|
210 | 227 | |
|
211 |
|
|
|
212 | context "with journals" do | |
|
213 | context ".xml" do | |
|
214 | should "display journals" do | |
|
215 | get '/issues/1.xml?include=journals' | |
|
228 | test "GET /issues/:id.xml with custom fields" do | |
|
229 | get '/issues/3.xml' | |
|
216 | 230 | |
|
217 |
|
|
|
218 |
|
|
|
219 | assert_select 'details[type=array]' do | |
|
220 | assert_select 'detail[name=status_id]' do | |
|
221 | assert_select 'old_value', :text => '1' | |
|
222 | assert_select 'new_value', :text => '2' | |
|
223 | end | |
|
224 | end | |
|
225 | end | |
|
226 | end | |
|
227 | end | |
|
231 | assert_select 'issue custom_fields[type=array]' do | |
|
232 | assert_select 'custom_field[id="1"]' do | |
|
233 | assert_select 'value', :text => 'MySQL' | |
|
228 | 234 | end |
|
229 | 235 | end |
|
236 | assert_nothing_raised do | |
|
237 | Hash.from_xml(response.body).to_xml | |
|
238 | end | |
|
239 | end | |
|
230 | 240 | |
|
231 |
|
|
|
232 | context ".xml" do | |
|
233 | should "display custom fields" do | |
|
234 | get '/issues/3.xml' | |
|
241 | test "GET /issues/:id.xml with multi custom fields" do | |
|
242 | field = CustomField.find(1) | |
|
243 | field.update_attribute :multiple, true | |
|
244 | issue = Issue.find(3) | |
|
245 | issue.custom_field_values = {1 => ['MySQL', 'Oracle']} | |
|
246 | issue.save! | |
|
235 | 247 | |
|
236 | assert_select 'issue custom_fields[type=array]' do | |
|
237 | assert_select 'custom_field[id="1"]' do | |
|
238 | assert_select 'value', :text => 'MySQL' | |
|
239 | end | |
|
240 | end | |
|
248 | get '/issues/3.xml' | |
|
249 | assert_response :success | |
|
241 | 250 | |
|
242 | assert_nothing_raised do | |
|
243 | Hash.from_xml(response.body).to_xml | |
|
244 | end | |
|
245 | end | |
|
251 | assert_select 'issue custom_fields[type=array]' do | |
|
252 | assert_select 'custom_field[id="1"]' do | |
|
253 | assert_select 'value[type=array] value', 2 | |
|
246 | 254 | end |
|
247 | 255 | end |
|
256 | xml = Hash.from_xml(response.body) | |
|
257 | custom_fields = xml['issue']['custom_fields'] | |
|
258 | assert_kind_of Array, custom_fields | |
|
259 | field = custom_fields.detect {|f| f['id'] == '1'} | |
|
260 | assert_kind_of Hash, field | |
|
261 | assert_equal ['MySQL', 'Oracle'], field['value'].sort | |
|
262 | end | |
|
248 | 263 | |
|
249 |
|
|
|
250 | setup do | |
|
251 | field = CustomField.find(1) | |
|
252 | field.update_attribute :multiple, true | |
|
253 | issue = Issue.find(3) | |
|
254 | issue.custom_field_values = {1 => ['MySQL', 'Oracle']} | |
|
255 | issue.save! | |
|
256 | end | |
|
264 | test "GET /issues/:id.json with multi custom fields" do | |
|
265 | field = CustomField.find(1) | |
|
266 | field.update_attribute :multiple, true | |
|
267 | issue = Issue.find(3) | |
|
268 | issue.custom_field_values = {1 => ['MySQL', 'Oracle']} | |
|
269 | issue.save! | |
|
257 | 270 | |
|
258 | context ".xml" do | |
|
259 | should "display custom fields" do | |
|
260 | get '/issues/3.xml' | |
|
261 | assert_response :success | |
|
271 | get '/issues/3.json' | |
|
272 | assert_response :success | |
|
262 | 273 | |
|
263 | assert_select 'issue custom_fields[type=array]' do | |
|
264 | assert_select 'custom_field[id="1"]' do | |
|
265 | assert_select 'value[type=array] value', 2 | |
|
266 | end | |
|
267 | end | |
|
274 | json = ActiveSupport::JSON.decode(response.body) | |
|
275 | custom_fields = json['issue']['custom_fields'] | |
|
276 | assert_kind_of Array, custom_fields | |
|
277 | field = custom_fields.detect {|f| f['id'] == 1} | |
|
278 | assert_kind_of Hash, field | |
|
279 | assert_equal ['MySQL', 'Oracle'], field['value'].sort | |
|
280 | end | |
|
268 | 281 | |
|
269 | xml = Hash.from_xml(response.body) | |
|
270 | custom_fields = xml['issue']['custom_fields'] | |
|
271 | assert_kind_of Array, custom_fields | |
|
272 | field = custom_fields.detect {|f| f['id'] == '1'} | |
|
273 | assert_kind_of Hash, field | |
|
274 | assert_equal ['MySQL', 'Oracle'], field['value'].sort | |
|
275 | end | |
|
276 | end | |
|
282 | test "GET /issues/:id.xml with empty value for multi custom field" do | |
|
283 | field = CustomField.find(1) | |
|
284 | field.update_attribute :multiple, true | |
|
285 | issue = Issue.find(3) | |
|
286 | issue.custom_field_values = {1 => ['']} | |
|
287 | issue.save! | |
|
277 | 288 | |
|
278 | context ".json" do | |
|
279 | should "display custom fields" do | |
|
280 | get '/issues/3.json' | |
|
281 | assert_response :success | |
|
282 | json = ActiveSupport::JSON.decode(response.body) | |
|
283 | custom_fields = json['issue']['custom_fields'] | |
|
284 | assert_kind_of Array, custom_fields | |
|
285 | field = custom_fields.detect {|f| f['id'] == 1} | |
|
286 | assert_kind_of Hash, field | |
|
287 | assert_equal ['MySQL', 'Oracle'], field['value'].sort | |
|
288 | end | |
|
289 | end | |
|
290 | end | |
|
289 | get '/issues/3.xml' | |
|
291 | 290 | |
|
292 | context "with empty value for multi custom field" do | |
|
293 | setup do | |
|
294 | field = CustomField.find(1) | |
|
295 | field.update_attribute :multiple, true | |
|
296 | issue = Issue.find(3) | |
|
297 | issue.custom_field_values = {1 => ['']} | |
|
298 | issue.save! | |
|
291 | assert_select 'issue custom_fields[type=array]' do | |
|
292 | assert_select 'custom_field[id="1"]' do | |
|
293 | assert_select 'value[type=array]:empty' | |
|
299 | 294 | end |
|
295 | end | |
|
296 | xml = Hash.from_xml(response.body) | |
|
297 | custom_fields = xml['issue']['custom_fields'] | |
|
298 | assert_kind_of Array, custom_fields | |
|
299 | field = custom_fields.detect {|f| f['id'] == '1'} | |
|
300 | assert_kind_of Hash, field | |
|
301 | assert_equal [], field['value'] | |
|
302 | end | |
|
300 | 303 | |
|
301 | context ".xml" do | |
|
302 | should "display custom fields" do | |
|
303 | get '/issues/3.xml' | |
|
304 | test "GET /issues/:id.json with empty value for multi custom field" do | |
|
305 | field = CustomField.find(1) | |
|
306 | field.update_attribute :multiple, true | |
|
307 | issue = Issue.find(3) | |
|
308 | issue.custom_field_values = {1 => ['']} | |
|
309 | issue.save! | |
|
304 | 310 | |
|
305 | assert_select 'issue custom_fields[type=array]' do | |
|
306 | assert_select 'custom_field[id="1"]' do | |
|
307 | assert_select 'value[type=array]:empty' | |
|
308 | end | |
|
309 | end | |
|
311 | get '/issues/3.json' | |
|
312 | assert_response :success | |
|
313 | json = ActiveSupport::JSON.decode(response.body) | |
|
314 | custom_fields = json['issue']['custom_fields'] | |
|
315 | assert_kind_of Array, custom_fields | |
|
316 | field = custom_fields.detect {|f| f['id'] == 1} | |
|
317 | assert_kind_of Hash, field | |
|
318 | assert_equal [], field['value'].sort | |
|
319 | end | |
|
310 | 320 | |
|
311 | xml = Hash.from_xml(response.body) | |
|
312 | custom_fields = xml['issue']['custom_fields'] | |
|
313 | assert_kind_of Array, custom_fields | |
|
314 | field = custom_fields.detect {|f| f['id'] == '1'} | |
|
315 | assert_kind_of Hash, field | |
|
316 | assert_equal [], field['value'] | |
|
317 | end | |
|
318 | end | |
|
321 | test "GET /issues/:id.xml with attachments" do | |
|
322 | get '/issues/3.xml?include=attachments' | |
|
319 | 323 | |
|
320 | context ".json" do | |
|
321 | should "display custom fields" do | |
|
322 | get '/issues/3.json' | |
|
323 | assert_response :success | |
|
324 | json = ActiveSupport::JSON.decode(response.body) | |
|
325 | custom_fields = json['issue']['custom_fields'] | |
|
326 | assert_kind_of Array, custom_fields | |
|
327 | field = custom_fields.detect {|f| f['id'] == 1} | |
|
328 | assert_kind_of Hash, field | |
|
329 | assert_equal [], field['value'].sort | |
|
330 | end | |
|
324 | assert_select 'issue attachments[type=array]' do | |
|
325 | assert_select 'attachment', 5 | |
|
326 | assert_select 'attachment id:content(4)' do | |
|
327 | assert_select '~ filename', :text => 'source.rb' | |
|
328 | assert_select '~ content_url', :text => 'http://www.example.com/attachments/download/4/source.rb' | |
|
331 | 329 | end |
|
332 | 330 | end |
|
331 | end | |
|
333 | 332 | |
|
334 | context "with attachments" do | |
|
335 | context ".xml" do | |
|
336 | should "display attachments" do | |
|
337 | get '/issues/3.xml?include=attachments' | |
|
338 | ||
|
339 | assert_select 'issue attachments[type=array]' do | |
|
340 | assert_select 'attachment', 5 | |
|
341 | assert_select 'attachment id:content(4)' do | |
|
342 | assert_select '~ filename', :text => 'source.rb' | |
|
343 | assert_select '~ content_url', :text => 'http://www.example.com/attachments/download/4/source.rb' | |
|
344 | end | |
|
345 | end | |
|
346 | end | |
|
347 | end | |
|
348 | end | |
|
333 | test "GET /issues/:id.xml with subtasks" do | |
|
334 | issue = Issue.generate_with_descendants!(:project_id => 1) | |
|
335 | get "/issues/#{issue.id}.xml?include=children" | |
|
349 | 336 | |
|
350 | context "with subtasks" do | |
|
351 | setup do | |
|
352 | @c1 = Issue.create!( | |
|
353 | :status_id => 1, :subject => "child c1", | |
|
354 | :tracker_id => 1, :project_id => 1, :author_id => 1, | |
|
355 | :parent_issue_id => 1 | |
|
356 | ) | |
|
357 | @c2 = Issue.create!( | |
|
358 | :status_id => 1, :subject => "child c2", | |
|
359 | :tracker_id => 1, :project_id => 1, :author_id => 1, | |
|
360 | :parent_issue_id => 1 | |
|
361 | ) | |
|
362 | @c3 = Issue.create!( | |
|
363 | :status_id => 1, :subject => "child c3", | |
|
364 | :tracker_id => 1, :project_id => 1, :author_id => 1, | |
|
365 | :parent_issue_id => @c1.id | |
|
366 | ) | |
|
367 | end | |
|
337 | assert_select 'issue children[type=array]' do | |
|
338 | assert_select 'issue', 2 | |
|
339 | assert_select 'issue children', 1 | |
|
340 | end | |
|
341 | end | |
|
368 | 342 | |
|
369 | context ".xml" do | |
|
370 | should "display children" do | |
|
371 |
|
|
|
372 | ||
|
373 | assert_select 'issue children[type=array]' do | |
|
374 | assert_select 'issue', 2 | |
|
375 | assert_select 'issue[id=?]', @c1.id.to_s do | |
|
376 | assert_select 'subject', :text => 'child c1' | |
|
377 | assert_select 'children' do | |
|
378 | assert_select 'issue[id=?]', @c3.id.to_s | |
|
379 | end | |
|
380 | end | |
|
381 | end | |
|
382 | end | |
|
343 | test "GET /issues/:id.json with subtasks" do | |
|
344 | issue = Issue.generate_with_descendants!(:project_id => 1) | |
|
345 | get "/issues/#{issue.id}.json?include=children" | |
|
383 | 346 | |
|
384 | context ".json" do | |
|
385 | should "display children" do | |
|
386 | get '/issues/1.json?include=children' | |
|
387 | ||
|
388 | json = ActiveSupport::JSON.decode(response.body) | |
|
389 | assert_equal([ | |
|
390 | { | |
|
391 | 'id' => @c1.id, 'subject' => 'child c1', 'tracker' => {'id' => 1, 'name' => 'Bug'}, | |
|
392 | 'children' => [{'id' => @c3.id, 'subject' => 'child c3', | |
|
393 | 'tracker' => {'id' => 1, 'name' => 'Bug'} }] | |
|
394 | }, | |
|
395 | { 'id' => @c2.id, 'subject' => 'child c2', 'tracker' => {'id' => 1, 'name' => 'Bug'} } | |
|
396 | ], | |
|
397 | json['issue']['children']) | |
|
398 | end | |
|
399 | end | |
|
400 | end | |
|
401 | end | |
|
347 | json = ActiveSupport::JSON.decode(response.body) | |
|
348 | assert_equal 2, json['issue']['children'].size | |
|
349 | assert_equal 1, json['issue']['children'].select {|child| child.key?('children')}.size | |
|
402 | 350 | end |
|
403 | 351 | |
|
404 | 352 | def test_show_should_include_issue_attributes |
@@ -421,29 +369,21 class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base | |||
|
421 | 369 | end |
|
422 | 370 | end |
|
423 | 371 | |
|
424 | context "POST /issues.xml" do | |
|
425 | should_allow_api_authentication( | |
|
426 | :post, | |
|
427 | '/issues.xml', | |
|
428 | {:issue => {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}}, | |
|
429 | {:success_code => :created} | |
|
430 | ) | |
|
431 | should "create an issue with the attributes" do | |
|
432 | assert_difference('Issue.count') do | |
|
433 | post '/issues.xml', | |
|
434 | {:issue => {:project_id => 1, :subject => 'API test', | |
|
435 | :tracker_id => 2, :status_id => 3}}, credentials('jsmith') | |
|
436 | end | |
|
437 | issue = Issue.order('id DESC').first | |
|
438 | assert_equal 1, issue.project_id | |
|
439 | assert_equal 2, issue.tracker_id | |
|
440 | assert_equal 3, issue.status_id | |
|
441 | assert_equal 'API test', issue.subject | |
|
442 | ||
|
443 | assert_response :created | |
|
444 | assert_equal 'application/xml', @response.content_type | |
|
445 | assert_select 'issue > id', :text => issue.id.to_s | |
|
372 | test "POST /issues.xml should create an issue with the attributes" do | |
|
373 | assert_difference('Issue.count') do | |
|
374 | post '/issues.xml', | |
|
375 | {:issue => {:project_id => 1, :subject => 'API test', | |
|
376 | :tracker_id => 2, :status_id => 3}}, credentials('jsmith') | |
|
446 | 377 | end |
|
378 | issue = Issue.order('id DESC').first | |
|
379 | assert_equal 1, issue.project_id | |
|
380 | assert_equal 2, issue.tracker_id | |
|
381 | assert_equal 3, issue.status_id | |
|
382 | assert_equal 'API test', issue.subject | |
|
383 | ||
|
384 | assert_response :created | |
|
385 | assert_equal 'application/xml', @response.content_type | |
|
386 | assert_select 'issue > id', :text => issue.id.to_s | |
|
447 | 387 | end |
|
448 | 388 | |
|
449 | 389 | test "POST /issues.xml with watcher_user_ids should create issue with watchers" do |
@@ -458,246 +398,139 class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base | |||
|
458 | 398 | assert_equal [1, 3], issue.watcher_user_ids.sort |
|
459 | 399 | end |
|
460 | 400 | |
|
461 |
|
|
|
462 | should "have an errors tag" do | |
|
463 | assert_no_difference('Issue.count') do | |
|
464 | post '/issues.xml', {:issue => {:project_id => 1}}, credentials('jsmith') | |
|
465 | end | |
|
466 | ||
|
467 | assert_select 'errors error', :text => "Subject can't be blank" | |
|
468 | end | |
|
469 | end | |
|
470 | ||
|
471 | context "POST /issues.json" do | |
|
472 | should_allow_api_authentication(:post, | |
|
473 | '/issues.json', | |
|
474 | {:issue => {:project_id => 1, :subject => 'API test', | |
|
475 | :tracker_id => 2, :status_id => 3}}, | |
|
476 | {:success_code => :created}) | |
|
477 | ||
|
478 | should "create an issue with the attributes" do | |
|
479 | assert_difference('Issue.count') do | |
|
480 | post '/issues.json', | |
|
481 | {:issue => {:project_id => 1, :subject => 'API test', | |
|
482 | :tracker_id => 2, :status_id => 3}}, | |
|
483 | credentials('jsmith') | |
|
484 | end | |
|
485 | ||
|
486 | issue = Issue.order('id DESC').first | |
|
487 | assert_equal 1, issue.project_id | |
|
488 | assert_equal 2, issue.tracker_id | |
|
489 | assert_equal 3, issue.status_id | |
|
490 | assert_equal 'API test', issue.subject | |
|
401 | test "POST /issues.xml with failure should return errors" do | |
|
402 | assert_no_difference('Issue.count') do | |
|
403 | post '/issues.xml', {:issue => {:project_id => 1}}, credentials('jsmith') | |
|
491 | 404 | end |
|
492 | 405 | |
|
406 | assert_select 'errors error', :text => "Subject can't be blank" | |
|
493 | 407 | end |
|
494 | 408 | |
|
495 |
|
|
|
496 | should "have an errors element" do | |
|
497 | assert_no_difference('Issue.count') do | |
|
498 |
|
|
|
499 | end | |
|
500 | ||
|
501 | json = ActiveSupport::JSON.decode(response.body) | |
|
502 | assert json['errors'].include?("Subject can't be blank") | |
|
503 | end | |
|
504 | end | |
|
505 | ||
|
506 | # Issue 6 is on a private project | |
|
507 | context "PUT /issues/6.xml" do | |
|
508 | setup do | |
|
509 | @parameters = {:issue => {:subject => 'API update', :notes => 'A new note'}} | |
|
510 | end | |
|
511 | ||
|
512 | should_allow_api_authentication(:put, | |
|
513 | '/issues/6.xml', | |
|
514 | {:issue => {:subject => 'API update', :notes => 'A new note'}}, | |
|
515 | {:success_code => :ok}) | |
|
516 | ||
|
517 | should "not create a new issue" do | |
|
518 | assert_no_difference('Issue.count') do | |
|
519 | put '/issues/6.xml', @parameters, credentials('jsmith') | |
|
520 | end | |
|
521 | end | |
|
522 | ||
|
523 | should "create a new journal" do | |
|
524 | assert_difference('Journal.count') do | |
|
525 | put '/issues/6.xml', @parameters, credentials('jsmith') | |
|
526 | end | |
|
527 | end | |
|
528 | ||
|
529 | should "add the note to the journal" do | |
|
530 | put '/issues/6.xml', @parameters, credentials('jsmith') | |
|
531 | ||
|
532 | journal = Journal.last | |
|
533 | assert_equal "A new note", journal.notes | |
|
534 | end | |
|
535 | ||
|
536 | should "update the issue" do | |
|
537 | put '/issues/6.xml', @parameters, credentials('jsmith') | |
|
538 | ||
|
539 | issue = Issue.find(6) | |
|
540 | assert_equal "API update", issue.subject | |
|
409 | test "POST /issues.json should create an issue with the attributes" do | |
|
410 | assert_difference('Issue.count') do | |
|
411 | post '/issues.json', | |
|
412 | {:issue => {:project_id => 1, :subject => 'API test', | |
|
413 | :tracker_id => 2, :status_id => 3}}, | |
|
414 | credentials('jsmith') | |
|
541 | 415 | end |
|
542 | 416 | |
|
417 | issue = Issue.order('id DESC').first | |
|
418 | assert_equal 1, issue.project_id | |
|
419 | assert_equal 2, issue.tracker_id | |
|
420 | assert_equal 3, issue.status_id | |
|
421 | assert_equal 'API test', issue.subject | |
|
543 | 422 | end |
|
544 | 423 | |
|
545 | context "PUT /issues/3.xml with custom fields" do | |
|
546 | setup do | |
|
547 | @parameters = { | |
|
548 | :issue => {:custom_fields => [{'id' => '1', 'value' => 'PostgreSQL' }, | |
|
549 | {'id' => '2', 'value' => '150'}]} | |
|
550 | } | |
|
424 | test "POST /issues.json with failure should return errors" do | |
|
425 | assert_no_difference('Issue.count') do | |
|
426 | post '/issues.json', {:issue => {:project_id => 1}}, credentials('jsmith') | |
|
551 | 427 | end |
|
552 | 428 | |
|
553 | should "update custom fields" do | |
|
554 | assert_no_difference('Issue.count') do | |
|
555 | put '/issues/3.xml', @parameters, credentials('jsmith') | |
|
556 | end | |
|
557 | ||
|
558 | issue = Issue.find(3) | |
|
559 | assert_equal '150', issue.custom_value_for(2).value | |
|
560 | assert_equal 'PostgreSQL', issue.custom_value_for(1).value | |
|
561 | end | |
|
429 | json = ActiveSupport::JSON.decode(response.body) | |
|
430 | assert json['errors'].include?("Subject can't be blank") | |
|
562 | 431 | end |
|
563 | 432 | |
|
564 |
|
|
|
565 | setup do | |
|
566 | field = CustomField.find(1) | |
|
567 | field.update_attribute :multiple, true | |
|
568 | @parameters = { | |
|
569 | :issue => {:custom_fields => [{'id' => '1', 'value' => ['MySQL', 'PostgreSQL'] }, | |
|
570 | {'id' => '2', 'value' => '150'}]} | |
|
571 | } | |
|
433 | test "PUT /issues/:id.xml" do | |
|
434 | assert_difference('Journal.count') do | |
|
435 | put '/issues/6.xml', | |
|
436 | {:issue => {:subject => 'API update', :notes => 'A new note'}}, | |
|
437 | credentials('jsmith') | |
|
572 | 438 | end |
|
573 | 439 | |
|
574 | should "update custom fields" do | |
|
575 | assert_no_difference('Issue.count') do | |
|
576 | put '/issues/3.xml', @parameters, credentials('jsmith') | |
|
577 | end | |
|
578 | ||
|
579 | issue = Issue.find(3) | |
|
580 | assert_equal '150', issue.custom_value_for(2).value | |
|
581 | assert_equal ['MySQL', 'PostgreSQL'], issue.custom_field_value(1).sort | |
|
582 | end | |
|
440 | issue = Issue.find(6) | |
|
441 | assert_equal "API update", issue.subject | |
|
442 | journal = Journal.last | |
|
443 | assert_equal "A new note", journal.notes | |
|
583 | 444 | end |
|
584 | 445 | |
|
585 |
|
|
|
586 | setup do | |
|
587 | @parameters = {:issue => {:project_id => 2, :subject => 'Project changed'}} | |
|
588 | end | |
|
589 | ||
|
590 | should "update project" do | |
|
591 | assert_no_difference('Issue.count') do | |
|
592 | put '/issues/3.xml', @parameters, credentials('jsmith') | |
|
593 | end | |
|
594 | ||
|
595 | issue = Issue.find(3) | |
|
596 | assert_equal 2, issue.project_id | |
|
597 | assert_equal 'Project changed', issue.subject | |
|
598 | end | |
|
446 | test "PUT /issues/:id.xml with custom fields" do | |
|
447 | put '/issues/3.xml', | |
|
448 | {:issue => {:custom_fields => [ | |
|
449 | {'id' => '1', 'value' => 'PostgreSQL' }, | |
|
450 | {'id' => '2', 'value' => '150'} | |
|
451 | ]}}, | |
|
452 | credentials('jsmith') | |
|
453 | ||
|
454 | issue = Issue.find(3) | |
|
455 | assert_equal '150', issue.custom_value_for(2).value | |
|
456 | assert_equal 'PostgreSQL', issue.custom_value_for(1).value | |
|
599 | 457 | end |
|
600 | 458 | |
|
601 |
|
|
|
602 | setup do | |
|
603 | @parameters = {:issue => {:subject => ''}} | |
|
604 | end | |
|
605 | ||
|
606 | should "not create a new issue" do | |
|
607 | assert_no_difference('Issue.count') do | |
|
608 | put '/issues/6.xml', @parameters, credentials('jsmith') | |
|
609 | end | |
|
610 | end | |
|
611 | ||
|
612 | should "not create a new journal" do | |
|
613 | assert_no_difference('Journal.count') do | |
|
614 | put '/issues/6.xml', @parameters, credentials('jsmith') | |
|
615 | end | |
|
616 | end | |
|
459 | test "PUT /issues/:id.xml with multi custom fields" do | |
|
460 | field = CustomField.find(1) | |
|
461 | field.update_attribute :multiple, true | |
|
617 | 462 | |
|
618 | should "have an errors tag" do | |
|
619 | put '/issues/6.xml', @parameters, credentials('jsmith') | |
|
463 | put '/issues/3.xml', | |
|
464 | {:issue => {:custom_fields => [ | |
|
465 | {'id' => '1', 'value' => ['MySQL', 'PostgreSQL'] }, | |
|
466 | {'id' => '2', 'value' => '150'} | |
|
467 | ]}}, | |
|
468 | credentials('jsmith') | |
|
620 | 469 | |
|
621 | assert_select 'errors error', :text => "Subject can't be blank" | |
|
622 | end | |
|
470 | issue = Issue.find(3) | |
|
471 | assert_equal '150', issue.custom_value_for(2).value | |
|
472 | assert_equal ['MySQL', 'PostgreSQL'], issue.custom_field_value(1).sort | |
|
623 | 473 | end |
|
624 | 474 | |
|
625 |
|
|
|
626 | setup do | |
|
627 | @parameters = {:issue => {:subject => 'API update', :notes => 'A new note'}} | |
|
628 | end | |
|
629 | ||
|
630 | should_allow_api_authentication(:put, | |
|
631 | '/issues/6.json', | |
|
632 | {:issue => {:subject => 'API update', :notes => 'A new note'}}, | |
|
633 | {:success_code => :ok}) | |
|
475 | test "PUT /issues/:id.xml with project change" do | |
|
476 | put '/issues/3.xml', | |
|
477 | {:issue => {:project_id => 2, :subject => 'Project changed'}}, | |
|
478 | credentials('jsmith') | |
|
634 | 479 | |
|
635 | should "update the issue" do | |
|
636 | assert_no_difference('Issue.count') do | |
|
637 | assert_difference('Journal.count') do | |
|
638 | put '/issues/6.json', @parameters, credentials('jsmith') | |
|
480 | issue = Issue.find(3) | |
|
481 | assert_equal 2, issue.project_id | |
|
482 | assert_equal 'Project changed', issue.subject | |
|
483 | end | |
|
639 | 484 | |
|
640 | assert_response :ok | |
|
641 | assert_equal '', response.body | |
|
642 | end | |
|
643 | end | |
|
485 | test "PUT /issues/:id.xml with failed update" do | |
|
486 | put '/issues/6.xml', {:issue => {:subject => ''}}, credentials('jsmith') | |
|
644 | 487 | |
|
645 | issue = Issue.find(6) | |
|
646 | assert_equal "API update", issue.subject | |
|
647 | journal = Journal.last | |
|
648 | assert_equal "A new note", journal.notes | |
|
649 | end | |
|
488 | assert_response :unprocessable_entity | |
|
489 | assert_select 'errors error', :text => "Subject can't be blank" | |
|
650 | 490 | end |
|
651 | 491 | |
|
652 |
|
|
|
653 | should "return errors" do | |
|
654 | assert_no_difference('Issue.count') do | |
|
655 | assert_no_difference('Journal.count') do | |
|
656 | put '/issues/6.json', {:issue => {:subject => ''}}, credentials('jsmith') | |
|
657 | ||
|
658 | assert_response :unprocessable_entity | |
|
659 | end | |
|
660 | end | |
|
492 | test "PUT /issues/:id.json" do | |
|
493 | assert_difference('Journal.count') do | |
|
494 | put '/issues/6.json', | |
|
495 | {:issue => {:subject => 'API update', :notes => 'A new note'}}, | |
|
496 | credentials('jsmith') | |
|
661 | 497 | |
|
662 | json = ActiveSupport::JSON.decode(response.body) | |
|
663 | assert json['errors'].include?("Subject can't be blank") | |
|
498 | assert_response :ok | |
|
499 | assert_equal '', response.body | |
|
664 | 500 | end |
|
501 | ||
|
502 | issue = Issue.find(6) | |
|
503 | assert_equal "API update", issue.subject | |
|
504 | journal = Journal.last | |
|
505 | assert_equal "A new note", journal.notes | |
|
665 | 506 | end |
|
666 | 507 | |
|
667 | context "DELETE /issues/1.xml" do | |
|
668 | should_allow_api_authentication(:delete, | |
|
669 | '/issues/6.xml', | |
|
670 | {}, | |
|
671 | {:success_code => :ok}) | |
|
508 | test "PUT /issues/:id.json with failed update" do | |
|
509 | put '/issues/6.json', {:issue => {:subject => ''}}, credentials('jsmith') | |
|
672 | 510 | |
|
673 | should "delete the issue" do | |
|
674 | assert_difference('Issue.count', -1) do | |
|
675 | delete '/issues/6.xml', {}, credentials('jsmith') | |
|
511 | assert_response :unprocessable_entity | |
|
512 | json = ActiveSupport::JSON.decode(response.body) | |
|
513 | assert json['errors'].include?("Subject can't be blank") | |
|
514 | end | |
|
676 | 515 | |
|
677 | assert_response :ok | |
|
678 | assert_equal '', response.body | |
|
679 | end | |
|
516 | test "DELETE /issues/:id.xml" do | |
|
517 | assert_difference('Issue.count', -1) do | |
|
518 | delete '/issues/6.xml', {}, credentials('jsmith') | |
|
680 | 519 | |
|
681 | assert_nil Issue.find_by_id(6) | |
|
520 | assert_response :ok | |
|
521 | assert_equal '', response.body | |
|
682 | 522 | end |
|
523 | assert_nil Issue.find_by_id(6) | |
|
683 | 524 | end |
|
684 | 525 | |
|
685 |
|
|
|
686 | should_allow_api_authentication(:delete, | |
|
687 | '/issues/6.json', | |
|
688 | {}, | |
|
689 | {:success_code => :ok}) | |
|
690 | ||
|
691 | should "delete the issue" do | |
|
692 | assert_difference('Issue.count', -1) do | |
|
693 | delete '/issues/6.json', {}, credentials('jsmith') | |
|
526 | test "DELETE /issues/:id.json" do | |
|
527 | assert_difference('Issue.count', -1) do | |
|
528 | delete '/issues/6.json', {}, credentials('jsmith') | |
|
694 | 529 | |
|
695 |
|
|
|
696 |
|
|
|
697 | end | |
|
698 | ||
|
699 | assert_nil Issue.find_by_id(6) | |
|
530 | assert_response :ok | |
|
531 | assert_equal '', response.body | |
|
700 | 532 | end |
|
533 | assert_nil Issue.find_by_id(6) | |
|
701 | 534 | end |
|
702 | 535 | |
|
703 | 536 | test "POST /issues/:id/watchers.xml should add watcher" do |
@@ -601,97 +601,62 class UserTest < ActiveSupport::TestCase | |||
|
601 | 601 | end |
|
602 | 602 | |
|
603 | 603 | if ldap_configured? |
|
604 |
|
|
|
605 | context "with failed connection to the LDAP server" do | |
|
606 | should "return nil" do | |
|
607 | @auth_source = AuthSourceLdap.find(1) | |
|
608 | AuthSource.any_instance.stubs(:initialize_ldap_con).raises(Net::LDAP::LdapError, 'Cannot connect') | |
|
604 | test "#try_to_login using LDAP with failed connection to the LDAP server" do | |
|
605 | auth_source = AuthSourceLdap.find(1) | |
|
606 | AuthSource.any_instance.stubs(:initialize_ldap_con).raises(Net::LDAP::LdapError, 'Cannot connect') | |
|
609 | 607 | |
|
610 |
|
|
|
611 |
|
|
|
612 | end | |
|
608 | assert_equal nil, User.try_to_login('edavis', 'wrong') | |
|
609 | end | |
|
613 | 610 | |
|
614 | context "with an unsuccessful authentication" do | |
|
615 | should "return nil" do | |
|
616 | assert_equal nil, User.try_to_login('edavis', 'wrong') | |
|
617 | end | |
|
618 | end | |
|
611 | test "#try_to_login using LDAP" do | |
|
612 | assert_equal nil, User.try_to_login('edavis', 'wrong') | |
|
613 | end | |
|
619 | 614 | |
|
620 |
|
|
|
621 | setup do | |
|
622 | @auth_source = AuthSourceLdap.find(1) | |
|
623 | @auth_source.account = "uid=$login,ou=Person,dc=redmine,dc=org" | |
|
624 | @auth_source.account_password = '' | |
|
625 | @auth_source.save! | |
|
615 | test "#try_to_login using LDAP binding with user's account" do | |
|
616 | auth_source = AuthSourceLdap.find(1) | |
|
617 | auth_source.account = "uid=$login,ou=Person,dc=redmine,dc=org" | |
|
618 | auth_source.account_password = '' | |
|
619 | auth_source.save! | |
|
626 | 620 | |
|
627 |
|
|
|
628 |
|
|
|
629 |
|
|
|
630 | end | |
|
621 | ldap_user = User.new(:mail => 'example1@redmine.org', :firstname => 'LDAP', :lastname => 'user', :auth_source_id => 1) | |
|
622 | ldap_user.login = 'example1' | |
|
623 | ldap_user.save! | |
|
631 | 624 | |
|
632 | context "with a successful authentication" do | |
|
633 | should "return the user" do | |
|
634 | assert_equal @ldap_user, User.try_to_login('example1', '123456') | |
|
635 | end | |
|
636 | end | |
|
625 | assert_equal @ldap_user, User.try_to_login('example1', '123456') | |
|
626 | assert_nil User.try_to_login('example1', '11111') | |
|
627 | end | |
|
637 | 628 | |
|
638 | context "with an unsuccessful authentication" do | |
|
639 | should "return nil" do | |
|
640 | assert_nil User.try_to_login('example1', '11111') | |
|
641 | end | |
|
642 | end | |
|
629 | test "#try_to_login using LDAP on the fly registration" do | |
|
630 | AuthSourceLdap.find(1).update_attribute :onthefly_register, true | |
|
631 | ||
|
632 | assert_difference('User.count') do | |
|
633 | assert User.try_to_login('edavis', '123456') | |
|
643 | 634 | end |
|
644 | 635 | |
|
645 | context "on the fly registration" do | |
|
646 | setup do | |
|
647 | @auth_source = AuthSourceLdap.find(1) | |
|
648 | @auth_source.update_attribute :onthefly_register, true | |
|
649 | end | |
|
636 | assert_no_difference('User.count') do | |
|
637 | assert User.try_to_login('edavis', '123456') | |
|
638 | end | |
|
650 | 639 | |
|
651 | context "with a successful authentication" do | |
|
652 | should "create a new user account if it doesn't exist" do | |
|
653 | assert_difference('User.count') do | |
|
654 | user = User.try_to_login('edavis', '123456') | |
|
655 | assert !user.admin? | |
|
656 | end | |
|
657 | end | |
|
658 | ||
|
659 | should "retrieve existing user" do | |
|
660 | user = User.try_to_login('edavis', '123456') | |
|
661 | user.admin = true | |
|
662 | user.save! | |
|
663 | ||
|
664 | assert_no_difference('User.count') do | |
|
665 | user = User.try_to_login('edavis', '123456') | |
|
666 | assert user.admin? | |
|
667 | end | |
|
668 | end | |
|
669 | end | |
|
640 | assert_nil User.try_to_login('example1', '11111') | |
|
641 | end | |
|
670 | 642 | |
|
671 | context "binding with user's account" do | |
|
672 | setup do | |
|
673 | @auth_source = AuthSourceLdap.find(1) | |
|
674 | @auth_source.account = "uid=$login,ou=Person,dc=redmine,dc=org" | |
|
675 | @auth_source.account_password = '' | |
|
676 | @auth_source.save! | |
|
677 | end | |
|
678 | ||
|
679 | context "with a successful authentication" do | |
|
680 | should "create a new user account if it doesn't exist" do | |
|
681 | assert_difference('User.count') do | |
|
682 | user = User.try_to_login('example1', '123456') | |
|
683 | assert_kind_of User, user | |
|
684 | end | |
|
685 | end | |
|
686 | end | |
|
687 | ||
|
688 | context "with an unsuccessful authentication" do | |
|
689 | should "return nil" do | |
|
690 | assert_nil User.try_to_login('example1', '11111') | |
|
691 | end | |
|
692 | end | |
|
693 | end | |
|
643 | test "#try_to_login using LDAP on the fly registration and binding with user's account" do | |
|
644 | auth_source = AuthSourceLdap.find(1) | |
|
645 | auth_source.update_attribute :onthefly_register, true | |
|
646 | auth_source = AuthSourceLdap.find(1) | |
|
647 | auth_source.account = "uid=$login,ou=Person,dc=redmine,dc=org" | |
|
648 | auth_source.account_password = '' | |
|
649 | auth_source.save! | |
|
650 | ||
|
651 | assert_difference('User.count') do | |
|
652 | assert User.try_to_login('example1', '123456') | |
|
694 | 653 | end |
|
654 | ||
|
655 | assert_no_difference('User.count') do | |
|
656 | assert User.try_to_login('edavis', '123456') | |
|
657 | end | |
|
658 | ||
|
659 | assert_nil User.try_to_login('example1', '11111') | |
|
695 | 660 | end |
|
696 | 661 | |
|
697 | 662 | else |
General Comments 0
You need to be logged in to leave comments.
Login now