]> git.openstreetmap.org Git - rails.git/blob - test/controllers/api/nodes_controller_test.rb
More controller test refactoring
[rails.git] / test / controllers / api / nodes_controller_test.rb
1 require "test_helper"
2
3 module Api
4   class NodesControllerTest < ActionDispatch::IntegrationTest
5     ##
6     # test all routes which lead to this controller
7     def test_routes
8       assert_routing(
9         { :path => "/api/0.6/node/create", :method => :put },
10         { :controller => "api/nodes", :action => "create" }
11       )
12       assert_routing(
13         { :path => "/api/0.6/node/1", :method => :get },
14         { :controller => "api/nodes", :action => "show", :id => "1" }
15       )
16       assert_routing(
17         { :path => "/api/0.6/node/1.json", :method => :get },
18         { :controller => "api/nodes", :action => "show", :id => "1", :format => "json" }
19       )
20       assert_routing(
21         { :path => "/api/0.6/node/1", :method => :put },
22         { :controller => "api/nodes", :action => "update", :id => "1" }
23       )
24       assert_routing(
25         { :path => "/api/0.6/node/1", :method => :delete },
26         { :controller => "api/nodes", :action => "delete", :id => "1" }
27       )
28       assert_routing(
29         { :path => "/api/0.6/nodes", :method => :get },
30         { :controller => "api/nodes", :action => "index" }
31       )
32       assert_routing(
33         { :path => "/api/0.6/nodes.json", :method => :get },
34         { :controller => "api/nodes", :action => "index", :format => "json" }
35       )
36     end
37
38     def test_create
39       private_user = create(:user, :data_public => false)
40       private_changeset = create(:changeset, :user => private_user)
41       user = create(:user)
42       changeset = create(:changeset, :user => user)
43
44       # create a node with random lat/lon
45       lat = rand(-50..50) + rand
46       lon = rand(-50..50) + rand
47
48       ## First try with no auth
49       # create a minimal xml file
50       xml = "<osm><node lat='#{lat}' lon='#{lon}' changeset='#{changeset.id}'/></osm>"
51       assert_difference("OldNode.count", 0) do
52         put node_create_path, :params => xml
53       end
54       # hope for unauthorized
55       assert_response :unauthorized, "node upload did not return unauthorized status"
56
57       ## Now try with the user which doesn't have their data public
58       auth_header = basic_authorization_header private_user.email, "test"
59
60       # create a minimal xml file
61       xml = "<osm><node lat='#{lat}' lon='#{lon}' changeset='#{private_changeset.id}'/></osm>"
62       assert_difference("Node.count", 0) do
63         put node_create_path, :params => xml, :headers => auth_header
64       end
65       # hope for success
66       assert_require_public_data "node create did not return forbidden status"
67
68       ## Now try with the user that has the public data
69       auth_header = basic_authorization_header user.email, "test"
70
71       # create a minimal xml file
72       xml = "<osm><node lat='#{lat}' lon='#{lon}' changeset='#{changeset.id}'/></osm>"
73       put node_create_path, :params => xml, :headers => auth_header
74       # hope for success
75       assert_response :success, "node upload did not return success status"
76
77       # read id of created node and search for it
78       nodeid = @response.body
79       checknode = Node.find(nodeid)
80       assert_not_nil checknode, "uploaded node not found in data base after upload"
81       # compare values
82       assert_in_delta lat * 10000000, checknode.latitude, 1, "saved node does not match requested latitude"
83       assert_in_delta lon * 10000000, checknode.longitude, 1, "saved node does not match requested longitude"
84       assert_equal changeset.id, checknode.changeset_id, "saved node does not belong to changeset that it was created in"
85       assert checknode.visible, "saved node is not visible"
86     end
87
88     def test_create_invalid_xml
89       ## Only test public user here, as test_create should cover what's the forbiddens
90       ## that would occur here
91
92       user = create(:user)
93       changeset = create(:changeset, :user => user)
94
95       auth_header = basic_authorization_header user.email, "test"
96       lat = 3.434
97       lon = 3.23
98
99       # test that the upload is rejected when xml is valid, but osm doc isn't
100       xml = "<create/>"
101       put node_create_path, :params => xml, :headers => auth_header
102       assert_response :bad_request, "node upload did not return bad_request status"
103       assert_equal "Cannot parse valid node from xml string <create/>. XML doesn't contain an osm/node element.", @response.body
104
105       # test that the upload is rejected when no lat is supplied
106       # create a minimal xml file
107       xml = "<osm><node lon='#{lon}' changeset='#{changeset.id}'/></osm>"
108       put node_create_path, :params => xml, :headers => auth_header
109       # hope for success
110       assert_response :bad_request, "node upload did not return bad_request status"
111       assert_equal "Cannot parse valid node from xml string <node lon=\"3.23\" changeset=\"#{changeset.id}\"/>. lat missing", @response.body
112
113       # test that the upload is rejected when no lon is supplied
114       # create a minimal xml file
115       xml = "<osm><node lat='#{lat}' changeset='#{changeset.id}'/></osm>"
116       put node_create_path, :params => xml, :headers => auth_header
117       # hope for success
118       assert_response :bad_request, "node upload did not return bad_request status"
119       assert_equal "Cannot parse valid node from xml string <node lat=\"3.434\" changeset=\"#{changeset.id}\"/>. lon missing", @response.body
120
121       # test that the upload is rejected when lat is non-numeric
122       # create a minimal xml file
123       xml = "<osm><node lat='abc' lon='#{lon}' changeset='#{changeset.id}'/></osm>"
124       put node_create_path, :params => xml, :headers => auth_header
125       # hope for success
126       assert_response :bad_request, "node upload did not return bad_request status"
127       assert_equal "Cannot parse valid node from xml string <node lat=\"abc\" lon=\"#{lon}\" changeset=\"#{changeset.id}\"/>. lat not a number", @response.body
128
129       # test that the upload is rejected when lon is non-numeric
130       # create a minimal xml file
131       xml = "<osm><node lat='#{lat}' lon='abc' changeset='#{changeset.id}'/></osm>"
132       put node_create_path, :params => xml, :headers => auth_header
133       # hope for success
134       assert_response :bad_request, "node upload did not return bad_request status"
135       assert_equal "Cannot parse valid node from xml string <node lat=\"#{lat}\" lon=\"abc\" changeset=\"#{changeset.id}\"/>. lon not a number", @response.body
136
137       # test that the upload is rejected when we have a tag which is too long
138       xml = "<osm><node lat='#{lat}' lon='#{lon}' changeset='#{changeset.id}'><tag k='foo' v='#{'x' * 256}'/></node></osm>"
139       put node_create_path, :params => xml, :headers => auth_header
140       assert_response :bad_request, "node upload did not return bad_request status"
141       assert_equal ["NodeTag ", " v: is too long (maximum is 255 characters) (\"#{'x' * 256}\")"], @response.body.split(/[0-9]+,foo:/)
142     end
143
144     def test_show
145       # check that a visible node is returned properly
146       get api_node_path(create(:node))
147       assert_response :success
148
149       # check that an deleted node is not returned
150       get api_node_path(create(:node, :deleted))
151       assert_response :gone
152
153       # check chat a non-existent node is not returned
154       get api_node_path(:id => 0)
155       assert_response :not_found
156     end
157
158     # Ensure the lat/lon is formatted as a decimal e.g. not 4.0e-05
159     def test_lat_lon_xml_format
160       node = create(:node, :latitude => (0.00004 * OldNode::SCALE).to_i, :longitude => (0.00008 * OldNode::SCALE).to_i)
161
162       get api_node_path(node)
163       assert_match(/lat="0.0000400"/, response.body)
164       assert_match(/lon="0.0000800"/, response.body)
165     end
166
167     # this tests deletion restrictions - basic deletion is tested in the unit
168     # tests for node!
169     def test_delete
170       private_user = create(:user, :data_public => false)
171       private_user_changeset = create(:changeset, :user => private_user)
172       private_user_closed_changeset = create(:changeset, :closed, :user => private_user)
173       private_node = create(:node, :changeset => private_user_changeset)
174       private_deleted_node = create(:node, :deleted, :changeset => private_user_changeset)
175
176       ## first try to delete node without auth
177       delete api_node_path(private_node)
178       assert_response :unauthorized
179
180       ## now set auth for the non-data public user
181       auth_header = basic_authorization_header private_user.email, "test"
182
183       # try to delete with an invalid (closed) changeset
184       xml = update_changeset(xml_for_node(private_node), private_user_closed_changeset.id)
185       delete api_node_path(private_node), :params => xml.to_s, :headers => auth_header
186       assert_require_public_data("non-public user shouldn't be able to delete node")
187
188       # try to delete with an invalid (non-existent) changeset
189       xml = update_changeset(xml_for_node(private_node), 0)
190       delete api_node_path(private_node), :params => xml.to_s, :headers => auth_header
191       assert_require_public_data("shouldn't be able to delete node, when user's data is private")
192
193       # valid delete now takes a payload
194       xml = xml_for_node(private_node)
195       delete api_node_path(private_node), :params => xml.to_s, :headers => auth_header
196       assert_require_public_data("shouldn't be able to delete node when user's data isn't public'")
197
198       # this won't work since the node is already deleted
199       xml = xml_for_node(private_deleted_node)
200       delete api_node_path(private_deleted_node), :params => xml.to_s, :headers => auth_header
201       assert_require_public_data
202
203       # this won't work since the node never existed
204       delete api_node_path(:id => 0), :headers => auth_header
205       assert_require_public_data
206
207       ## these test whether nodes which are in-use can be deleted:
208       # in a way...
209       private_used_node = create(:node, :changeset => private_user_changeset)
210       create(:way_node, :node => private_used_node)
211
212       xml = xml_for_node(private_used_node)
213       delete api_node_path(private_used_node), :params => xml.to_s, :headers => auth_header
214       assert_require_public_data "shouldn't be able to delete a node used in a way (#{@response.body})"
215
216       # in a relation...
217       private_used_node2 = create(:node, :changeset => private_user_changeset)
218       create(:relation_member, :member => private_used_node2)
219
220       xml = xml_for_node(private_used_node2)
221       delete api_node_path(private_used_node2), :params => xml.to_s, :headers => auth_header
222       assert_require_public_data "shouldn't be able to delete a node used in a relation (#{@response.body})"
223
224       ## now setup for the public data user
225       user = create(:user, :data_public => true)
226       changeset = create(:changeset, :user => user)
227       closed_changeset = create(:changeset, :closed, :user => user)
228       node = create(:node, :changeset => changeset)
229       auth_header = basic_authorization_header user.email, "test"
230
231       # try to delete with an invalid (closed) changeset
232       xml = update_changeset(xml_for_node(node), closed_changeset.id)
233       delete api_node_path(node), :params => xml.to_s, :headers => auth_header
234       assert_response :conflict
235
236       # try to delete with an invalid (non-existent) changeset
237       xml = update_changeset(xml_for_node(node), 0)
238       delete api_node_path(node), :params => xml.to_s, :headers => auth_header
239       assert_response :conflict
240
241       # try to delete a node with a different ID
242       other_node = create(:node)
243       xml = xml_for_node(other_node)
244       delete api_node_path(node.id), :params => xml.to_s, :headers => auth_header
245       assert_response :bad_request,
246                       "should not be able to delete a node with a different ID from the XML"
247
248       # try to delete a node rubbish in the payloads
249       xml = "<delete/>"
250       delete api_node_path(node), :params => xml.to_s, :headers => auth_header
251       assert_response :bad_request,
252                       "should not be able to delete a node without a valid XML payload"
253
254       # valid delete now takes a payload
255       xml = xml_for_node(node)
256       delete api_node_path(node), :params => xml.to_s, :headers => auth_header
257       assert_response :success
258
259       # valid delete should return the new version number, which should
260       # be greater than the old version number
261       assert @response.body.to_i > node.version,
262              "delete request should return a new version number for node"
263
264       # deleting the same node twice doesn't work
265       xml = xml_for_node(node)
266       delete api_node_path(node), :params => xml.to_s, :headers => auth_header
267       assert_response :gone
268
269       # this won't work since the node never existed
270       delete api_node_path(:id => 0), :headers => auth_header
271       assert_response :not_found
272
273       ## these test whether nodes which are in-use can be deleted:
274       # in a way...
275       used_node = create(:node, :changeset => create(:changeset, :user => user))
276       way_node = create(:way_node, :node => used_node)
277       way_node2 = create(:way_node, :node => used_node)
278
279       xml = xml_for_node(used_node)
280       delete api_node_path(used_node), :params => xml.to_s, :headers => auth_header
281       assert_response :precondition_failed,
282                       "shouldn't be able to delete a node used in a way (#{@response.body})"
283       assert_equal "Precondition failed: Node #{used_node.id} is still used by ways #{way_node.way.id},#{way_node2.way.id}.", @response.body
284
285       # in a relation...
286       used_node2 = create(:node, :changeset => create(:changeset, :user => user))
287       relation_member = create(:relation_member, :member => used_node2)
288       relation_member2 = create(:relation_member, :member => used_node2)
289
290       xml = xml_for_node(used_node2)
291       delete api_node_path(used_node2), :params => xml.to_s, :headers => auth_header
292       assert_response :precondition_failed,
293                       "shouldn't be able to delete a node used in a relation (#{@response.body})"
294       assert_equal "Precondition failed: Node #{used_node2.id} is still used by relations #{relation_member.relation.id},#{relation_member2.relation.id}.", @response.body
295     end
296
297     ##
298     # tests whether the API works and prevents incorrect use while trying
299     # to update nodes.
300     def test_update
301       ## First test with no user credentials
302       # try and update a node without authorisation
303       # first try to delete node without auth
304       private_user = create(:user, :data_public => false)
305       private_node = create(:node, :changeset => create(:changeset, :user => private_user))
306       user = create(:user)
307       node = create(:node, :changeset => create(:changeset, :user => user))
308
309       xml = xml_for_node(node)
310       put api_node_path(node), :params => xml.to_s
311       assert_response :unauthorized
312
313       ## Second test with the private user
314
315       # setup auth
316       auth_header = basic_authorization_header private_user.email, "test"
317
318       ## trying to break changesets
319
320       # try and update in someone else's changeset
321       xml = update_changeset(xml_for_node(private_node),
322                              create(:changeset).id)
323       put api_node_path(private_node), :params => xml.to_s, :headers => auth_header
324       assert_require_public_data "update with other user's changeset should be forbidden when data isn't public"
325
326       # try and update in a closed changeset
327       xml = update_changeset(xml_for_node(private_node),
328                              create(:changeset, :closed, :user => private_user).id)
329       put api_node_path(private_node), :params => xml.to_s, :headers => auth_header
330       assert_require_public_data "update with closed changeset should be forbidden, when data isn't public"
331
332       # try and update in a non-existant changeset
333       xml = update_changeset(xml_for_node(private_node), 0)
334       put api_node_path(private_node), :params => xml.to_s, :headers => auth_header
335       assert_require_public_data "update with changeset=0 should be forbidden, when data isn't public"
336
337       ## try and submit invalid updates
338       xml = xml_attr_rewrite(xml_for_node(private_node), "lat", 91.0)
339       put api_node_path(private_node), :params => xml.to_s, :headers => auth_header
340       assert_require_public_data "node at lat=91 should be forbidden, when data isn't public"
341
342       xml = xml_attr_rewrite(xml_for_node(private_node), "lat", -91.0)
343       put api_node_path(private_node), :params => xml.to_s, :headers => auth_header
344       assert_require_public_data "node at lat=-91 should be forbidden, when data isn't public"
345
346       xml = xml_attr_rewrite(xml_for_node(private_node), "lon", 181.0)
347       put api_node_path(private_node), :params => xml.to_s, :headers => auth_header
348       assert_require_public_data "node at lon=181 should be forbidden, when data isn't public"
349
350       xml = xml_attr_rewrite(xml_for_node(private_node), "lon", -181.0)
351       put api_node_path(private_node), :params => xml.to_s, :headers => auth_header
352       assert_require_public_data "node at lon=-181 should be forbidden, when data isn't public"
353
354       ## finally, produce a good request which still won't work
355       xml = xml_for_node(private_node)
356       put api_node_path(private_node), :params => xml.to_s, :headers => auth_header
357       assert_require_public_data "should have failed with a forbidden when data isn't public"
358
359       ## Finally test with the public user
360
361       # try and update a node without authorisation
362       # first try to update node without auth
363       xml = xml_for_node(node)
364       put api_node_path(node.id), :params => xml.to_s, :headers => auth_header
365       assert_response :forbidden
366
367       # setup auth
368       auth_header = basic_authorization_header user.email, "test"
369
370       ## trying to break changesets
371
372       # try and update in someone else's changeset
373       xml = update_changeset(xml_for_node(node),
374                              create(:changeset).id)
375       put api_node_path(node), :params => xml.to_s, :headers => auth_header
376       assert_response :conflict, "update with other user's changeset should be rejected"
377
378       # try and update in a closed changeset
379       xml = update_changeset(xml_for_node(node),
380                              create(:changeset, :closed, :user => user).id)
381       put api_node_path(node), :params => xml.to_s, :headers => auth_header
382       assert_response :conflict, "update with closed changeset should be rejected"
383
384       # try and update in a non-existant changeset
385       xml = update_changeset(xml_for_node(node), 0)
386       put api_node_path(node), :params => xml.to_s, :headers => auth_header
387       assert_response :conflict, "update with changeset=0 should be rejected"
388
389       ## try and submit invalid updates
390       xml = xml_attr_rewrite(xml_for_node(node), "lat", 91.0)
391       put api_node_path(node), :params => xml.to_s, :headers => auth_header
392       assert_response :bad_request, "node at lat=91 should be rejected"
393
394       xml = xml_attr_rewrite(xml_for_node(node), "lat", -91.0)
395       put api_node_path(node), :params => xml.to_s, :headers => auth_header
396       assert_response :bad_request, "node at lat=-91 should be rejected"
397
398       xml = xml_attr_rewrite(xml_for_node(node), "lon", 181.0)
399       put api_node_path(node), :params => xml.to_s, :headers => auth_header
400       assert_response :bad_request, "node at lon=181 should be rejected"
401
402       xml = xml_attr_rewrite(xml_for_node(node), "lon", -181.0)
403       put api_node_path(node), :params => xml.to_s, :headers => auth_header
404       assert_response :bad_request, "node at lon=-181 should be rejected"
405
406       ## next, attack the versioning
407       current_node_version = node.version
408
409       # try and submit a version behind
410       xml = xml_attr_rewrite(xml_for_node(node),
411                              "version", current_node_version - 1)
412       put api_node_path(node), :params => xml.to_s, :headers => auth_header
413       assert_response :conflict, "should have failed on old version number"
414
415       # try and submit a version ahead
416       xml = xml_attr_rewrite(xml_for_node(node),
417                              "version", current_node_version + 1)
418       put api_node_path(node), :params => xml.to_s, :headers => auth_header
419       assert_response :conflict, "should have failed on skipped version number"
420
421       # try and submit total crap in the version field
422       xml = xml_attr_rewrite(xml_for_node(node),
423                              "version", "p1r4t3s!")
424       put api_node_path(node), :params => xml.to_s, :headers => auth_header
425       assert_response :conflict,
426                       "should not be able to put 'p1r4at3s!' in the version field"
427
428       ## try an update with the wrong ID
429       xml = xml_for_node(create(:node))
430       put api_node_path(node), :params => xml.to_s, :headers => auth_header
431       assert_response :bad_request,
432                       "should not be able to update a node with a different ID from the XML"
433
434       ## try an update with a minimal valid XML doc which isn't a well-formed OSM doc.
435       xml = "<update/>"
436       put api_node_path(node), :params => xml.to_s, :headers => auth_header
437       assert_response :bad_request,
438                       "should not be able to update a node with non-OSM XML doc."
439
440       ## finally, produce a good request which should work
441       xml = xml_for_node(node)
442       put api_node_path(node), :params => xml.to_s, :headers => auth_header
443       assert_response :success, "a valid update request failed"
444     end
445
446     ##
447     # test fetching multiple nodes
448     def test_index
449       node1 = create(:node)
450       node2 = create(:node, :deleted)
451       node3 = create(:node)
452       node4 = create(:node, :with_history, :version => 2)
453       node5 = create(:node, :deleted, :with_history, :version => 2)
454
455       # check error when no parameter provided
456       get nodes_path
457       assert_response :bad_request
458
459       # check error when no parameter value provided
460       get nodes_path, :params => { :nodes => "" }
461       assert_response :bad_request
462
463       # test a working call
464       get nodes_path, :params => { :nodes => "#{node1.id},#{node2.id},#{node3.id},#{node4.id},#{node5.id}" }
465       assert_response :success
466       assert_select "osm" do
467         assert_select "node", :count => 5
468         assert_select "node[id='#{node1.id}'][visible='true']", :count => 1
469         assert_select "node[id='#{node2.id}'][visible='false']", :count => 1
470         assert_select "node[id='#{node3.id}'][visible='true']", :count => 1
471         assert_select "node[id='#{node4.id}'][visible='true']", :count => 1
472         assert_select "node[id='#{node5.id}'][visible='false']", :count => 1
473       end
474
475       # test a working call with json format
476       get nodes_path, :params => { :nodes => "#{node1.id},#{node2.id},#{node3.id},#{node4.id},#{node5.id}", :format => "json" }
477
478       js = ActiveSupport::JSON.decode(@response.body)
479       assert_not_nil js
480       assert_equal 5, js["elements"].count
481       assert_equal 5, (js["elements"].count { |a| a["type"] == "node" })
482       assert_equal 1, (js["elements"].count { |a| a["id"] == node1.id && a["visible"].nil? })
483       assert_equal 1, (js["elements"].count { |a| a["id"] == node2.id && a["visible"] == false })
484       assert_equal 1, (js["elements"].count { |a| a["id"] == node3.id && a["visible"].nil? })
485       assert_equal 1, (js["elements"].count { |a| a["id"] == node4.id && a["visible"].nil? })
486       assert_equal 1, (js["elements"].count { |a| a["id"] == node5.id && a["visible"] == false })
487
488       # check error when a non-existent node is included
489       get nodes_path, :params => { :nodes => "#{node1.id},#{node2.id},#{node3.id},#{node4.id},#{node5.id},0" }
490       assert_response :not_found
491     end
492
493     ##
494     # test adding tags to a node
495     def test_duplicate_tags
496       existing_tag = create(:node_tag)
497       assert existing_tag.node.changeset.user.data_public
498       # setup auth
499       auth_header = basic_authorization_header existing_tag.node.changeset.user.email, "test"
500
501       # add an identical tag to the node
502       tag_xml = XML::Node.new("tag")
503       tag_xml["k"] = existing_tag.k
504       tag_xml["v"] = existing_tag.v
505
506       # add the tag into the existing xml
507       node_xml = xml_for_node(existing_tag.node)
508       node_xml.find("//osm/node").first << tag_xml
509
510       # try and upload it
511       put api_node_path(existing_tag.node), :params => node_xml.to_s, :headers => auth_header
512       assert_response :bad_request,
513                       "adding duplicate tags to a node should fail with 'bad request'"
514       assert_equal "Element node/#{existing_tag.node.id} has duplicate tags with key #{existing_tag.k}", @response.body
515     end
516
517     # test whether string injection is possible
518     def test_string_injection
519       private_user = create(:user, :data_public => false)
520       private_changeset = create(:changeset, :user => private_user)
521       user = create(:user)
522       changeset = create(:changeset, :user => user)
523
524       ## First try with the non-data public user
525       auth_header = basic_authorization_header private_user.email, "test"
526
527       # try and put something into a string that the API might
528       # use unquoted and therefore allow code injection...
529       xml = "<osm><node lat='0' lon='0' changeset='#{private_changeset.id}'>" \
530             '<tag k="#{@user.inspect}" v="0"/>' \
531             "</node></osm>"
532       put node_create_path, :params => xml, :headers => auth_header
533       assert_require_public_data "Shouldn't be able to create with non-public user"
534
535       ## Then try with the public data user
536       auth_header = basic_authorization_header user.email, "test"
537
538       # try and put something into a string that the API might
539       # use unquoted and therefore allow code injection...
540       xml = "<osm><node lat='0' lon='0' changeset='#{changeset.id}'>" \
541             '<tag k="#{@user.inspect}" v="0"/>' \
542             "</node></osm>"
543       put node_create_path, :params => xml, :headers => auth_header
544       assert_response :success
545       nodeid = @response.body
546
547       # find the node in the database
548       checknode = Node.find(nodeid)
549       assert_not_nil checknode, "node not found in data base after upload"
550
551       # and grab it using the api
552       get api_node_path(:id => nodeid)
553       assert_response :success
554       apinode = Node.from_xml(@response.body)
555       assert_not_nil apinode, "downloaded node is nil, but shouldn't be"
556
557       # check the tags are not corrupted
558       assert_equal checknode.tags, apinode.tags
559       assert_includes apinode.tags, "\#{@user.inspect}"
560     end
561
562     ##
563     # update the changeset_id of a node element
564     def update_changeset(xml, changeset_id)
565       xml_attr_rewrite(xml, "changeset", changeset_id)
566     end
567
568     ##
569     # update an attribute in the node element
570     def xml_attr_rewrite(xml, name, value)
571       xml.find("//osm/node").first[name] = value.to_s
572       xml
573     end
574
575     ##
576     # parse some xml
577     def xml_parse(xml)
578       parser = XML::Parser.string(xml)
579       parser.parse
580     end
581   end
582 end