3 class CompressedRequestsTest < ActionDispatch::IntegrationTest
4 def test_no_compression
6 changeset = create(:changeset, :user => user)
10 relation = create(:relation)
11 other_relation = create(:relation)
12 # Create some tags, since we test that they are removed later
13 create(:node_tag, :node => node)
14 create(:way_tag, :way => way)
15 create(:relation_tag, :relation => relation)
17 # simple diff to change a node, way and relation by removing
22 <node id='#{node.id}' lon='0' lat='0' changeset='#{changeset.id}' version='1'/>
23 <way id='#{way.id}' changeset='#{changeset.id}' version='1'>
24 <nd ref='#{node.id}'/>
28 <relation id='#{relation.id}' changeset='#{changeset.id}' version='1'>
29 <member type='way' role='some' ref='#{way.id}'/>
30 <member type='node' role='some' ref='#{node.id}'/>
31 <member type='relation' role='some' ref='#{other_relation.id}'/>
38 post "/api/0.6/changeset/#{changeset.id}/upload",
40 :headers => bearer_authorization_header(user).merge(
41 "HTTP_CONTENT_TYPE" => "application/xml"
43 assert_response :success,
44 "can't upload an uncompressed diff to changeset: #{@response.body}"
46 # check that the changes made it into the database
47 assert_equal 0, Node.find(node.id).tags.size, "node #{node.id} should now have no tags"
48 assert_equal 0, Way.find(way.id).tags.size, "way #{way.id} should now have no tags"
49 assert_equal 0, Relation.find(relation.id).tags.size, "relation #{relation.id} should now have no tags"
52 def test_gzip_compression
54 changeset = create(:changeset, :user => user)
58 relation = create(:relation)
59 other_relation = create(:relation)
60 # Create some tags, since we test that they are removed later
61 create(:node_tag, :node => node)
62 create(:way_tag, :way => way)
63 create(:relation_tag, :relation => relation)
65 # simple diff to change a node, way and relation by removing
70 <node id='#{node.id}' lon='0' lat='0' changeset='#{changeset.id}' version='1'/>
71 <way id='#{way.id}' changeset='#{changeset.id}' version='1'>
72 <nd ref='#{node.id}'/>
76 <relation id='#{relation.id}' changeset='#{changeset.id}' version='1'>
77 <member type='way' role='some' ref='#{way.id}'/>
78 <member type='node' role='some' ref='#{node.id}'/>
79 <member type='relation' role='some' ref='#{other_relation.id}'/>
86 post "/api/0.6/changeset/#{changeset.id}/upload",
87 :params => gzip_content(diff),
88 :headers => bearer_authorization_header(user).merge(
89 "HTTP_CONTENT_ENCODING" => "gzip",
90 "HTTP_CONTENT_TYPE" => "application/xml"
92 assert_response :success,
93 "can't upload a gzip compressed diff to changeset: #{@response.body}"
95 # check that the changes made it into the database
96 assert_equal 0, Node.find(node.id).tags.size, "node #{node.id} should now have no tags"
97 assert_equal 0, Way.find(way.id).tags.size, "way #{way.id} should now have no tags"
98 assert_equal 0, Relation.find(relation.id).tags.size, "relation #{relation.id} should now have no tags"
101 def test_deflate_compression
103 changeset = create(:changeset, :user => user)
107 relation = create(:relation)
108 other_relation = create(:relation)
109 # Create some tags, since we test that they are removed later
110 create(:node_tag, :node => node)
111 create(:way_tag, :way => way)
112 create(:relation_tag, :relation => relation)
114 # simple diff to change a node, way and relation by removing
119 <node id='#{node.id}' lon='0' lat='0' changeset='#{changeset.id}' version='1'/>
120 <way id='#{way.id}' changeset='#{changeset.id}' version='1'>
121 <nd ref='#{node.id}'/>
125 <relation id='#{relation.id}' changeset='#{changeset.id}' version='1'>
126 <member type='way' role='some' ref='#{way.id}'/>
127 <member type='node' role='some' ref='#{node.id}'/>
128 <member type='relation' role='some' ref='#{other_relation.id}'/>
135 post "/api/0.6/changeset/#{changeset.id}/upload",
136 :params => deflate_content(diff),
137 :headers => bearer_authorization_header(user).merge(
138 "HTTP_CONTENT_ENCODING" => "deflate",
139 "HTTP_CONTENT_TYPE" => "application/xml"
141 assert_response :success,
142 "can't upload a deflate compressed diff to changeset: #{@response.body}"
144 # check that the changes made it into the database
145 assert_equal 0, Node.find(node.id).tags.size, "node #{node.id} should now have no tags"
146 assert_equal 0, Way.find(way.id).tags.size, "way #{way.id} should now have no tags"
147 assert_equal 0, Relation.find(relation.id).tags.size, "relation #{relation.id} should now have no tags"
150 def test_invalid_compression
152 changeset = create(:changeset, :user => user)
155 post "/api/0.6/changeset/#{changeset.id}/upload",
157 :headers => bearer_authorization_header(user).merge(
158 "HTTP_CONTENT_ENCODING" => "unknown",
159 "HTTP_CONTENT_TYPE" => "application/xml"
161 assert_response :unsupported_media_type
166 def gzip_content(uncompressed)
167 compressed = StringIO.new
168 gz = Zlib::GzipWriter.new(compressed)
169 gz.write(uncompressed)
174 def deflate_content(uncompressed)
175 Zlib::Deflate.deflate(uncompressed)