| 1 |
#!/usr/bin/env python |
| 2 |
# |
| 3 |
# mod_dav_svn_tests.py: testing mod_dav_svn |
| 4 |
# |
| 5 |
# Subversion is a tool for revision control. |
| 6 |
# See http://subversion.apache.org for more information. |
| 7 |
# |
| 8 |
# ==================================================================== |
| 9 |
# Licensed to the Apache Software Foundation (ASF) under one |
| 10 |
# or more contributor license agreements. See the NOTICE file |
| 11 |
# distributed with this work for additional information |
| 12 |
# regarding copyright ownership. The ASF licenses this file |
| 13 |
# to you under the Apache License, Version 2.0 (the |
| 14 |
# "License"); you may not use this file except in compliance |
| 15 |
# with the License. You may obtain a copy of the License at |
| 16 |
# |
| 17 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 18 |
# |
| 19 |
# Unless required by applicable law or agreed to in writing, |
| 20 |
# software distributed under the License is distributed on an |
| 21 |
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 22 |
# KIND, either express or implied. See the License for the |
| 23 |
# specific language governing permissions and limitations |
| 24 |
# under the License. |
| 25 |
###################################################################### |
| 26 |
|
| 27 |
# General modules |
| 28 |
import os, logging, base64, functools |
| 29 |
|
| 30 |
try: |
| 31 |
# Python <3.0 |
| 32 |
import httplib |
| 33 |
except ImportError: |
| 34 |
# Python >=3.0 |
| 35 |
import http.client as httplib |
| 36 |
|
| 37 |
logger = logging.getLogger() |
| 38 |
|
| 39 |
# Our testing module |
| 40 |
import svntest |
| 41 |
|
| 42 |
# (abbreviation) |
| 43 |
Skip = svntest.testcase.Skip_deco |
| 44 |
SkipUnless = svntest.testcase.SkipUnless_deco |
| 45 |
XFail = svntest.testcase.XFail_deco |
| 46 |
Issues = svntest.testcase.Issues_deco |
| 47 |
Issue = svntest.testcase.Issue_deco |
| 48 |
Wimp = svntest.testcase.Wimp_deco |
| 49 |
|
| 50 |
###################################################################### |
| 51 |
# Helper routines |
| 52 |
|
| 53 |
def compare(lhs, rhs): |
| 54 |
"""Implements cmp() for Python 2 and 3 alike""" |
| 55 |
if lhs == None: |
| 56 |
if rhs == None: |
| 57 |
return 0 |
| 58 |
else: |
| 59 |
return -1 |
| 60 |
else: |
| 61 |
if rhs == None: |
| 62 |
return 1 |
| 63 |
else: |
| 64 |
return (lhs > rhs) - (lhs < rhs) |
| 65 |
|
| 66 |
def compare_dict(lhs, rhs): |
| 67 |
"""Implements dictionary comparison for Python 2 and 3 alike""" |
| 68 |
lhs_sorted = sorted(lhs, key=lambda x:sorted(x.keys())) |
| 69 |
rhs_sorted = sorted(rhs, key=lambda x:sorted(x.keys())) |
| 70 |
return (lhs_sorted > rhs_sorted) - (lhs_sorted < rhs_sorted) |
| 71 |
|
| 72 |
def compare_xml_elem(a, b): |
| 73 |
"""Recursively compare two xml.etree.ElementTree.Element objects. |
| 74 |
Return a 3-tuple made out of (cmp, elem_a, elem_b), where cmp is |
| 75 |
the integer result of the comparison (negative, zero or positive), |
| 76 |
and elem_a and elem_b point to mismatching elements. Iff cmp is |
| 77 |
zero, elem_a and elem_b are None. """ |
| 78 |
|
| 79 |
# Compare tags, attributes, inner text, tail attribute and the |
| 80 |
# number of child elements. |
| 81 |
res = compare(a.tag, b.tag) |
| 82 |
if res != 0: |
| 83 |
return res, a, b |
| 84 |
# Don't care about the order of the attributes. |
| 85 |
res = compare_dict(a.attrib, b.attrib) |
| 86 |
if res != 0: |
| 87 |
return res, a, b |
| 88 |
res = compare(a.text, b.text) |
| 89 |
if res != 0: |
| 90 |
return res, a, b |
| 91 |
res = compare(a.tail, b.tail) |
| 92 |
if res != 0: |
| 93 |
return res, a, b |
| 94 |
res = compare(len(a), len(b)) |
| 95 |
if res != 0: |
| 96 |
return res, a, b |
| 97 |
|
| 98 |
# Prior to recursing, order child elements using the same comparator. |
| 99 |
# Right now we don't care about the order of the elements. For instance, |
| 100 |
# <D:response>'s in PROPFIND *need* to be compared without a particular |
| 101 |
# order, since the server returns them in an unstable order of the hash |
| 102 |
# iteration. |
| 103 |
def sortcmp(x, y): |
| 104 |
return compare_xml_elem(x, y)[0] |
| 105 |
|
| 106 |
a_children = sorted(list(a), key=functools.cmp_to_key(sortcmp)) |
| 107 |
b_children = sorted(list(b), key=functools.cmp_to_key(sortcmp)) |
| 108 |
|
| 109 |
for a_child, b_child in zip(a_children, b_children): |
| 110 |
res = compare_xml_elem(a_child, b_child) |
| 111 |
if res[0] != 0: |
| 112 |
return res |
| 113 |
|
| 114 |
# Elements are equal. |
| 115 |
return 0, None, None |
| 116 |
|
| 117 |
def verify_xml_response(expected_xml, actual_xml): |
| 118 |
"""Parse and compare two XML responses, raise svntest.Failure |
| 119 |
in case EXPECTED_XML doesn't match ACTUAL_XML. """ |
| 120 |
|
| 121 |
import xml.etree.ElementTree as ET |
| 122 |
|
| 123 |
expected_root = ET.fromstring(expected_xml) |
| 124 |
actual_root = ET.fromstring(actual_xml) |
| 125 |
res, expected_elem, actual_elem = compare_xml_elem(expected_root, |
| 126 |
actual_root) |
| 127 |
if res != 0: |
| 128 |
# The actual response doesn't match our expectations; dump it for |
| 129 |
# debugging purposes, and highlight the mismatching xml element. |
| 130 |
logger.warn("Response:\n%s" % actual_xml) |
| 131 |
raise svntest.Failure("Unexpected response part\n" |
| 132 |
" Expected: '%s'\n Actual: '%s'\n" |
| 133 |
% (ET.tostring(expected_elem), |
| 134 |
ET.tostring(actual_elem))) |
| 135 |
|
| 136 |
###################################################################### |
| 137 |
# Tests |
| 138 |
|
| 139 |
@SkipUnless(svntest.main.is_ra_type_dav) |
| 140 |
def cache_control_header(sbox): |
| 141 |
"verify 'Cache-Control' headers on responses" |
| 142 |
|
| 143 |
sbox.build(create_wc=False, read_only=True) |
| 144 |
|
| 145 |
headers = { |
| 146 |
'Authorization': 'Basic ' + base64.b64encode(b'jconstant:rayjandom').decode(), |
| 147 |
} |
| 148 |
|
| 149 |
h = svntest.main.create_http_connection(sbox.repo_url) |
| 150 |
|
| 151 |
# GET /repos/iota |
| 152 |
# Response depends on the youngest revision in the repository, and |
| 153 |
# can't be cached; expect to see Cache-Control: max-age=0. |
| 154 |
h.request('GET', sbox.repo_url + '/iota', None, headers) |
| 155 |
r = h.getresponse() |
| 156 |
if r.status != httplib.OK: |
| 157 |
raise svntest.Failure('Request failed: %d %s' % (r.status, r.reason)) |
| 158 |
svntest.verify.compare_and_display_lines(None, 'Cache-Control', |
| 159 |
'max-age=0', |
| 160 |
r.getheader('Cache-Control')) |
| 161 |
r.read() |
| 162 |
|
| 163 |
# GET /repos/A/ |
| 164 |
# Response depends on the youngest revision in the repository, and |
| 165 |
# can't be cached; expect to see Cache-Control: max-age=0. |
| 166 |
h.request('GET', sbox.repo_url + '/A/', None, headers) |
| 167 |
r = h.getresponse() |
| 168 |
if r.status != httplib.OK: |
| 169 |
raise svntest.Failure('Request failed: %d %s' % (r.status, r.reason)) |
| 170 |
svntest.verify.compare_and_display_lines(None, 'Cache-Control', |
| 171 |
'max-age=0', |
| 172 |
r.getheader('Cache-Control')) |
| 173 |
r.read() |
| 174 |
|
| 175 |
# GET /repos/A/?p=1 |
| 176 |
# Response for a pegged directory is a subject for authz filtering, and |
| 177 |
# can't be cached; expect to see Cache-Control: max-age=0. |
| 178 |
h.request('GET', sbox.repo_url + '/A/?p=1', None, headers) |
| 179 |
r = h.getresponse() |
| 180 |
if r.status != httplib.OK: |
| 181 |
raise svntest.Failure('Request failed: %d %s' % (r.status, r.reason)) |
| 182 |
svntest.verify.compare_and_display_lines(None, 'Cache-Control', |
| 183 |
'max-age=0', |
| 184 |
r.getheader('Cache-Control')) |
| 185 |
r.read() |
| 186 |
|
| 187 |
# GET /repos/iota?r=1 |
| 188 |
# Response for a file URL with ?r=WORKINGREV is mutable, because the |
| 189 |
# line of history for this file can be replaced in the future (hence, |
| 190 |
# the same request will start producing another response). Expect to |
| 191 |
# see Cache-Control: max-age=0. |
| 192 |
h.request('GET', sbox.repo_url + '/iota?r=1', None, headers) |
| 193 |
r = h.getresponse() |
| 194 |
if r.status != httplib.OK: |
| 195 |
raise svntest.Failure('Request failed: %d %s' % (r.status, r.reason)) |
| 196 |
svntest.verify.compare_and_display_lines(None, 'Cache-Control', |
| 197 |
'max-age=0', |
| 198 |
r.getheader('Cache-Control')) |
| 199 |
r.read() |
| 200 |
|
| 201 |
# GET /repos/iota?p=1 |
| 202 |
# Response for a pegged file is immutable; expect to see Cache-Control |
| 203 |
# with non-zero max-age. |
| 204 |
h.request('GET', sbox.repo_url + '/iota?p=1', None, headers) |
| 205 |
r = h.getresponse() |
| 206 |
if r.status != httplib.OK: |
| 207 |
raise svntest.Failure('Request failed: %d %s' % (r.status, r.reason)) |
| 208 |
svntest.verify.compare_and_display_lines(None, 'Cache-Control', |
| 209 |
'max-age=604800', |
| 210 |
r.getheader('Cache-Control')) |
| 211 |
r.read() |
| 212 |
|
| 213 |
# GET /repos/iota?p=1&r=1 |
| 214 |
# Response for a file URL with both ?p=PEG_REV and ?r=WORKINGREV is |
| 215 |
# immutable; expect to see Cache-Control with non-zero max-age. |
| 216 |
h.request('GET', sbox.repo_url + '/iota?p=1&r=1', None, headers) |
| 217 |
r = h.getresponse() |
| 218 |
if r.status != httplib.OK: |
| 219 |
raise svntest.Failure('Request failed: %d %s' % (r.status, r.reason)) |
| 220 |
svntest.verify.compare_and_display_lines(None, 'Cache-Control', |
| 221 |
'max-age=604800', |
| 222 |
r.getheader('Cache-Control')) |
| 223 |
r.read() |
| 224 |
|
| 225 |
|
| 226 |
# GET /repos/!svn/rvr/1/iota |
| 227 |
# Response is immutable; expect to see Cache-Control with non-zero max-age. |
| 228 |
h.request('GET', sbox.repo_url + '/!svn/rvr/1/iota', None, headers) |
| 229 |
r = h.getresponse() |
| 230 |
if r.status != httplib.OK: |
| 231 |
raise svntest.Failure('Request failed: %d %s' % (r.status, r.reason)) |
| 232 |
svntest.verify.compare_and_display_lines(None, 'Cache-Control', |
| 233 |
'max-age=604800', |
| 234 |
r.getheader('Cache-Control')) |
| 235 |
r.read() |
| 236 |
|
| 237 |
|
| 238 |
@SkipUnless(svntest.main.is_ra_type_dav) |
| 239 |
def simple_propfind(sbox): |
| 240 |
"verify simple PROPFIND responses" |
| 241 |
|
| 242 |
sbox.build(create_wc=False, read_only=True) |
| 243 |
repo_uripath = '/' + svntest.wc.svn_uri_quote( |
| 244 |
svntest.main.pristine_greek_repos_dir.replace(os.path.sep, '/')) |
| 245 |
h = svntest.main.create_http_connection(sbox.repo_url) |
| 246 |
|
| 247 |
# PROPFIND /repos/!svn/rvr/1, Depth = 0 |
| 248 |
headers = { |
| 249 |
'Authorization': 'Basic ' + base64.b64encode(b'jconstant:rayjandom').decode(), |
| 250 |
'Depth': '0', |
| 251 |
} |
| 252 |
req_body = ( |
| 253 |
'<?xml version="1.0" encoding="utf-8"?>\n' |
| 254 |
'<propfind xmlns="DAV:">\n' |
| 255 |
'<prop><resourcetype xmlns="DAV:"/></prop>\n' |
| 256 |
'</propfind>\n' |
| 257 |
) |
| 258 |
h.request('PROPFIND', sbox.repo_url + '/!svn/rvr/1', req_body, headers) |
| 259 |
r = h.getresponse() |
| 260 |
if r.status != httplib.MULTI_STATUS: |
| 261 |
raise svntest.Failure('Unexpected status: %d %s' % (r.status, r.reason)) |
| 262 |
|
| 263 |
expected_response = ( |
| 264 |
'<?xml version="1.0" encoding="utf-8"?>\n' |
| 265 |
'<D:multistatus xmlns:D="DAV:" xmlns:ns0="DAV:">\n' |
| 266 |
'<D:response xmlns:lp1="DAV:" ' |
| 267 |
'xmlns:lp2="http://subversion.tigris.org/xmlns/dav/">\n' |
| 268 |
'<D:href>' + repo_uripath + '/!svn/rvr/1/</D:href>\n' |
| 269 |
'<D:propstat>\n' |
| 270 |
'<D:prop>\n' |
| 271 |
'<lp1:resourcetype><D:collection/></lp1:resourcetype>\n' |
| 272 |
'</D:prop>\n' |
| 273 |
'<D:status>HTTP/1.1 200 OK</D:status>\n' |
| 274 |
'</D:propstat>\n' |
| 275 |
'</D:response>\n' |
| 276 |
'</D:multistatus>\n' |
| 277 |
) |
| 278 |
actual_response = r.read() |
| 279 |
verify_xml_response(expected_response, actual_response) |
| 280 |
|
| 281 |
# PROPFIND /repos/!svn/rvr/1, Depth = 1 |
| 282 |
headers = { |
| 283 |
'Authorization': 'Basic ' + base64.b64encode(b'jconstant:rayjandom').decode(), |
| 284 |
'Depth': '1', |
| 285 |
} |
| 286 |
req_body = ( |
| 287 |
'<?xml version="1.0" encoding="utf-8"?>\n' |
| 288 |
'<propfind xmlns="DAV:">\n' |
| 289 |
'<prop><resourcetype xmlns="DAV:"/></prop>\n' |
| 290 |
'</propfind>\n' |
| 291 |
) |
| 292 |
h.request('PROPFIND', sbox.repo_url + '/!svn/rvr/1', req_body, headers) |
| 293 |
r = h.getresponse() |
| 294 |
if r.status != httplib.MULTI_STATUS: |
| 295 |
raise svntest.Failure('Unexpected status: %d %s' % (r.status, r.reason)) |
| 296 |
|
| 297 |
expected_response = ( |
| 298 |
'<?xml version="1.0" encoding="utf-8"?>\n' |
| 299 |
'<D:multistatus xmlns:D="DAV:" xmlns:ns0="DAV:">\n' |
| 300 |
'<D:response xmlns:lp1="DAV:" ' |
| 301 |
'xmlns:lp2="http://subversion.tigris.org/xmlns/dav/">\n' |
| 302 |
'<D:href>' + repo_uripath + '/!svn/rvr/1/</D:href>\n' |
| 303 |
'<D:propstat>\n' |
| 304 |
'<D:prop>\n' |
| 305 |
'<lp1:resourcetype><D:collection/></lp1:resourcetype>\n' |
| 306 |
'</D:prop>\n' |
| 307 |
'<D:status>HTTP/1.1 200 OK</D:status>\n' |
| 308 |
'</D:propstat>\n' |
| 309 |
'</D:response>\n' |
| 310 |
'<D:response xmlns:lp1="DAV:" ' |
| 311 |
'xmlns:lp2="http://subversion.tigris.org/xmlns/dav/">\n' |
| 312 |
'<D:href>' + repo_uripath + '/!svn/rvr/1/A/</D:href>\n' |
| 313 |
'<D:propstat>\n' |
| 314 |
'<D:prop>\n' |
| 315 |
'<lp1:resourcetype><D:collection/></lp1:resourcetype>\n' |
| 316 |
'</D:prop>\n' |
| 317 |
'<D:status>HTTP/1.1 200 OK</D:status>\n' |
| 318 |
'</D:propstat>\n' |
| 319 |
'</D:response>\n' |
| 320 |
'<D:response xmlns:lp1="DAV:" ' |
| 321 |
'xmlns:lp2="http://subversion.tigris.org/xmlns/dav/">\n' |
| 322 |
'<D:href>' + repo_uripath + '/!svn/rvr/1/iota</D:href>\n' |
| 323 |
'<D:propstat>\n' |
| 324 |
'<D:prop>\n' |
| 325 |
'<lp1:resourcetype/>\n' |
| 326 |
'</D:prop>\n' |
| 327 |
'<D:status>HTTP/1.1 200 OK</D:status>\n' |
| 328 |
'</D:propstat>\n' |
| 329 |
'</D:response>\n' |
| 330 |
'</D:multistatus>\n' |
| 331 |
) |
| 332 |
actual_response = r.read() |
| 333 |
verify_xml_response(expected_response, actual_response) |
| 334 |
|
| 335 |
# PROPFIND /repos/!svn/rvr/1/A/B/F, Depth = 1 |
| 336 |
headers = { |
| 337 |
'Authorization': 'Basic ' + base64.b64encode(b'jconstant:rayjandom').decode(), |
| 338 |
'Depth': '1', |
| 339 |
} |
| 340 |
req_body = ( |
| 341 |
'<?xml version="1.0" encoding="utf-8"?>\n' |
| 342 |
'<propfind xmlns="DAV:">\n' |
| 343 |
'<prop><resourcetype xmlns="DAV:"/></prop>\n' |
| 344 |
'</propfind>\n' |
| 345 |
) |
| 346 |
h.request('PROPFIND', sbox.repo_url + '/!svn/rvr/1/A/B/F', req_body, headers) |
| 347 |
r = h.getresponse() |
| 348 |
if r.status != httplib.MULTI_STATUS: |
| 349 |
raise svntest.Failure('Unexpected status: %d %s' % (r.status, r.reason)) |
| 350 |
|
| 351 |
expected_response = ( |
| 352 |
'<?xml version="1.0" encoding="utf-8"?>\n' |
| 353 |
'<D:multistatus xmlns:D="DAV:" xmlns:ns0="DAV:">\n' |
| 354 |
'<D:response xmlns:lp1="DAV:" ' |
| 355 |
'xmlns:lp2="http://subversion.tigris.org/xmlns/dav/">\n' |
| 356 |
'<D:href>' + repo_uripath + '/!svn/rvr/1/A/B/F/</D:href>\n' |
| 357 |
'<D:propstat>\n' |
| 358 |
'<D:prop>\n' |
| 359 |
'<lp1:resourcetype><D:collection/></lp1:resourcetype>\n' |
| 360 |
'</D:prop>\n' |
| 361 |
'<D:status>HTTP/1.1 200 OK</D:status>\n' |
| 362 |
'</D:propstat>\n' |
| 363 |
'</D:response>\n' |
| 364 |
'</D:multistatus>\n' |
| 365 |
) |
| 366 |
actual_response = r.read() |
| 367 |
verify_xml_response(expected_response, actual_response) |
| 368 |
|
| 369 |
# PROPFIND /repos/!svn/rvr/1/iota, Depth = 0 |
| 370 |
headers = { |
| 371 |
'Authorization': 'Basic ' + base64.b64encode(b'jconstant:rayjandom').decode(), |
| 372 |
'Depth': '0', |
| 373 |
} |
| 374 |
req_body = ( |
| 375 |
'<?xml version="1.0" encoding="utf-8"?>\n' |
| 376 |
'<propfind xmlns="DAV:">\n' |
| 377 |
'<prop><resourcetype xmlns="DAV:"/></prop>\n' |
| 378 |
'</propfind>\n' |
| 379 |
) |
| 380 |
h.request('PROPFIND', sbox.repo_url + '/!svn/rvr/1/iota', req_body, headers) |
| 381 |
r = h.getresponse() |
| 382 |
if r.status != httplib.MULTI_STATUS: |
| 383 |
raise svntest.Failure('Unexpected status: %d %s' % (r.status, r.reason)) |
| 384 |
|
| 385 |
expected_response = ( |
| 386 |
'<?xml version="1.0" encoding="utf-8"?>\n' |
| 387 |
'<D:multistatus xmlns:D="DAV:" xmlns:ns0="DAV:">\n' |
| 388 |
'<D:response xmlns:lp1="DAV:" ' |
| 389 |
'xmlns:lp2="http://subversion.tigris.org/xmlns/dav/">\n' |
| 390 |
'<D:href>' + repo_uripath + '/!svn/rvr/1/iota</D:href>\n' |
| 391 |
'<D:propstat>\n' |
| 392 |
'<D:prop>\n' |
| 393 |
'<lp1:resourcetype/>\n' |
| 394 |
'</D:prop>\n' |
| 395 |
'<D:status>HTTP/1.1 200 OK</D:status>\n' |
| 396 |
'</D:propstat>\n' |
| 397 |
'</D:response>\n' |
| 398 |
'</D:multistatus>\n' |
| 399 |
) |
| 400 |
actual_response = r.read() |
| 401 |
verify_xml_response(expected_response, actual_response) |
| 402 |
|
| 403 |
|
| 404 |
@SkipUnless(svntest.main.is_ra_type_dav) |
| 405 |
def propfind_multiple_props(sbox): |
| 406 |
"verify multi-prop PROPFIND response" |
| 407 |
|
| 408 |
sbox.build(create_wc=False, read_only=True) |
| 409 |
repo_uripath = '/' + svntest.wc.svn_uri_quote( |
| 410 |
svntest.main.pristine_greek_repos_dir.replace(os.path.sep, '/')) |
| 411 |
h = svntest.main.create_http_connection(sbox.repo_url) |
| 412 |
|
| 413 |
# PROPFIND /repos/!svn/rvr/1/iota, Depth = 0 |
| 414 |
headers = { |
| 415 |
'Authorization': 'Basic ' + base64.b64encode(b'jconstant:rayjandom').decode(), |
| 416 |
'Depth': '0', |
| 417 |
} |
| 418 |
req_body = ( |
| 419 |
'<?xml version="1.0" encoding="utf-8" ?>\n' |
| 420 |
'<D:propfind xmlns:D="DAV:">\n' |
| 421 |
'<D:prop xmlns:S="http://subversion.tigris.org/xmlns/dav/">\n' |
| 422 |
'<D:resourcetype/>\n' |
| 423 |
'<S:md5-checksum/>\n' |
| 424 |
'</D:prop>\n' |
| 425 |
'</D:propfind>\n' |
| 426 |
) |
| 427 |
h.request('PROPFIND', sbox.repo_url + '/!svn/rvr/1/iota', req_body, headers) |
| 428 |
r = h.getresponse() |
| 429 |
if r.status != httplib.MULTI_STATUS: |
| 430 |
raise svntest.Failure('Unexpected status: %d %s' % (r.status, r.reason)) |
| 431 |
|
| 432 |
expected_response = ( |
| 433 |
'<?xml version="1.0" encoding="utf-8"?>\n' |
| 434 |
'<D:multistatus xmlns:D="DAV:" ' |
| 435 |
'xmlns:ns1="http://subversion.tigris.org/xmlns/dav/" ' |
| 436 |
'xmlns:ns0="DAV:">\n' |
| 437 |
'<D:response xmlns:lp1="DAV:" ' |
| 438 |
'xmlns:lp2="http://subversion.tigris.org/xmlns/dav/">\n' |
| 439 |
'<D:href>' + repo_uripath + '/!svn/rvr/1/iota</D:href>\n' |
| 440 |
'<D:propstat>\n' |
| 441 |
'<D:prop>\n' |
| 442 |
'<lp1:resourcetype/>\n' |
| 443 |
'<lp2:md5-checksum>' |
| 444 |
'2d18c5e57e84c5b8a5e9a6e13fa394dc' |
| 445 |
'</lp2:md5-checksum>\n' |
| 446 |
'</D:prop>\n' |
| 447 |
'<D:status>HTTP/1.1 200 OK</D:status>\n' |
| 448 |
'</D:propstat>\n' |
| 449 |
'</D:response>\n' |
| 450 |
'</D:multistatus>\n' |
| 451 |
) |
| 452 |
actual_response = r.read() |
| 453 |
verify_xml_response(expected_response, actual_response) |
| 454 |
|
| 455 |
|
| 456 |
@SkipUnless(svntest.main.is_ra_type_dav) |
| 457 |
def propfind_404(sbox): |
| 458 |
"verify PROPFIND for non-existing property" |
| 459 |
|
| 460 |
sbox.build(create_wc=False, read_only=True) |
| 461 |
repo_uripath = '/' + svntest.wc.svn_uri_quote( |
| 462 |
svntest.main.pristine_greek_repos_dir.replace(os.path.sep, '/')) |
| 463 |
h = svntest.main.create_http_connection(sbox.repo_url) |
| 464 |
|
| 465 |
# PROPFIND /repos/!svn/rvr/1, Depth = 0 |
| 466 |
headers = { |
| 467 |
'Authorization': 'Basic ' + base64.b64encode(b'jconstant:rayjandom').decode(), |
| 468 |
'Depth': '0', |
| 469 |
} |
| 470 |
req_body = ( |
| 471 |
'<?xml version="1.0" encoding="utf-8"?>\n' |
| 472 |
'<propfind xmlns="DAV:">\n' |
| 473 |
'<prop><nonexistingprop xmlns="DAV:"/></prop>\n' |
| 474 |
'</propfind>\n' |
| 475 |
) |
| 476 |
h.request('PROPFIND', sbox.repo_url + '/!svn/rvr/1', req_body, headers) |
| 477 |
r = h.getresponse() |
| 478 |
if r.status != httplib.MULTI_STATUS: |
| 479 |
raise svntest.Failure('Unexpected status: %d %s' % (r.status, r.reason)) |
| 480 |
|
| 481 |
expected_response = ( |
| 482 |
'<?xml version="1.0" encoding="utf-8"?>\n' |
| 483 |
'<D:multistatus xmlns:D="DAV:" xmlns:ns0="DAV:">\n' |
| 484 |
'<D:response xmlns:g0="DAV:">\n' |
| 485 |
'<D:href>' + repo_uripath + '/!svn/rvr/1/</D:href>\n' |
| 486 |
'<D:propstat>\n' |
| 487 |
'<D:prop>\n' |
| 488 |
'<g0:nonexistingprop/>\n' |
| 489 |
'</D:prop>\n' |
| 490 |
'<D:status>HTTP/1.1 404 Not Found</D:status>\n' |
| 491 |
'</D:propstat>\n' |
| 492 |
'</D:response>\n' |
| 493 |
'</D:multistatus>\n' |
| 494 |
) |
| 495 |
actual_response = r.read() |
| 496 |
verify_xml_response(expected_response, actual_response) |
| 497 |
|
| 498 |
|
| 499 |
@SkipUnless(svntest.main.is_ra_type_dav) |
| 500 |
def propfind_allprop(sbox): |
| 501 |
"verify allprop PROPFIND response" |
| 502 |
|
| 503 |
sbox.build() |
| 504 |
repo_uripath = '/' + svntest.wc.svn_uri_quote( |
| 505 |
sbox.repo_dir.replace(os.path.sep, '/')) |
| 506 |
svntest.actions.enable_revprop_changes(sbox.repo_dir) |
| 507 |
# Ensure stable date and uuid |
| 508 |
svntest.main.run_svnadmin('setuuid', sbox.repo_dir, |
| 509 |
'd7130b12-92f6-45c9-9217-b9f0472c3fab') |
| 510 |
svntest.actions.run_and_verify_svn(None, [], |
| 511 |
'propset', '--revprop', '-r', '1', |
| 512 |
'svn:date', '2015-01-01T00:00:00.0Z', |
| 513 |
sbox.wc_dir) |
| 514 |
|
| 515 |
h = svntest.main.create_http_connection(sbox.repo_url) |
| 516 |
|
| 517 |
# PROPFIND /repos/!svn/rvr/1, Depth = 0 |
| 518 |
headers = { |
| 519 |
'Authorization': 'Basic ' + base64.b64encode(b'jconstant:rayjandom').decode(), |
| 520 |
'Depth': '0', |
| 521 |
} |
| 522 |
req_body = ( |
| 523 |
'<?xml version="1.0" encoding="utf-8"?>\n' |
| 524 |
'<propfind xmlns="DAV:">\n' |
| 525 |
'<allprop/>\n' |
| 526 |
'</propfind>\n' |
| 527 |
) |
| 528 |
h.request('PROPFIND', sbox.repo_url + '/!svn/rvr/1', req_body, headers) |
| 529 |
r = h.getresponse() |
| 530 |
if r.status != httplib.MULTI_STATUS: |
| 531 |
raise svntest.Failure('Unexpected status: %d %s' % (r.status, r.reason)) |
| 532 |
|
| 533 |
expected_response = ( |
| 534 |
'<?xml version="1.0" encoding="utf-8"?>\n' |
| 535 |
'<D:multistatus xmlns:D="DAV:" xmlns:ns0="DAV:">\n' |
| 536 |
'<D:response xmlns:S="http://subversion.tigris.org/xmlns/svn/" ' |
| 537 |
'xmlns:C="http://subversion.tigris.org/xmlns/custom/" ' |
| 538 |
'xmlns:V="http://subversion.tigris.org/xmlns/dav/" ' |
| 539 |
'xmlns:lp1="DAV:" ' |
| 540 |
'xmlns:lp2="http://subversion.tigris.org/xmlns/dav/">\n' |
| 541 |
'<D:href>' + repo_uripath + '/!svn/rvr/1/</D:href>\n' |
| 542 |
'<D:propstat>\n' |
| 543 |
'<D:prop>\n' |
| 544 |
'<lp1:resourcetype><D:collection/></lp1:resourcetype>\n' |
| 545 |
'<lp1:getcontenttype>' + |
| 546 |
'text/html; charset=UTF-8' + |
| 547 |
'</lp1:getcontenttype>\n' |
| 548 |
'<lp1:getetag>W/"1//"</lp1:getetag>\n' |
| 549 |
'<lp1:creationdate>2015-01-01T00:00:00.0Z</lp1:creationdate>\n' |
| 550 |
'<lp1:getlastmodified>' + |
| 551 |
'Thu, 01 Jan 2015 00:00:00 GMT' + |
| 552 |
'</lp1:getlastmodified>\n' |
| 553 |
'<lp1:checked-in>' |
| 554 |
'<D:href>' + repo_uripath + '/!svn/ver/1/</D:href>' |
| 555 |
'</lp1:checked-in>\n' |
| 556 |
'<lp1:version-controlled-configuration>' |
| 557 |
'<D:href>' + repo_uripath + '/!svn/vcc/default</D:href>' |
| 558 |
'</lp1:version-controlled-configuration>\n' |
| 559 |
'<lp1:version-name>1</lp1:version-name>\n' |
| 560 |
'<lp1:creator-displayname>jrandom</lp1:creator-displayname>\n' |
| 561 |
'<lp2:baseline-relative-path/>\n' |
| 562 |
'<lp2:repository-uuid>' + |
| 563 |
'd7130b12-92f6-45c9-9217-b9f0472c3fab' + |
| 564 |
'</lp2:repository-uuid>\n' |
| 565 |
'<lp2:deadprop-count>0</lp2:deadprop-count>\n' |
| 566 |
'<D:lockdiscovery/>\n' |
| 567 |
'</D:prop>\n' |
| 568 |
'<D:status>HTTP/1.1 200 OK</D:status>\n' |
| 569 |
'</D:propstat>\n' |
| 570 |
'</D:response>\n' |
| 571 |
'</D:multistatus>\n' |
| 572 |
) |
| 573 |
actual_response = r.read() |
| 574 |
verify_xml_response(expected_response, actual_response) |
| 575 |
|
| 576 |
|
| 577 |
@SkipUnless(svntest.main.is_ra_type_dav) |
| 578 |
def propfind_propname(sbox): |
| 579 |
"verify propname PROPFIND response" |
| 580 |
|
| 581 |
sbox.build() |
| 582 |
sbox.simple_propset('a', 'b', 'iota') |
| 583 |
sbox.simple_commit() |
| 584 |
repo_uripath = '/' + svntest.wc.svn_uri_quote( |
| 585 |
sbox.repo_dir.replace(os.path.sep, '/')) |
| 586 |
|
| 587 |
h = svntest.main.create_http_connection(sbox.repo_url) |
| 588 |
|
| 589 |
# PROPFIND /repos/!svn/rvr/2/iota, Depth = 0 |
| 590 |
headers = { |
| 591 |
'Authorization': 'Basic ' + base64.b64encode(b'jconstant:rayjandom').decode(), |
| 592 |
'Depth': '0', |
| 593 |
} |
| 594 |
req_body = ( |
| 595 |
'<?xml version="1.0" encoding="utf-8"?>\n' |
| 596 |
'<propfind xmlns="DAV:">\n' |
| 597 |
'<propname/>\n' |
| 598 |
'</propfind>\n' |
| 599 |
) |
| 600 |
h.request('PROPFIND', sbox.repo_url + '/!svn/rvr/2/iota', req_body, headers) |
| 601 |
r = h.getresponse() |
| 602 |
if r.status != httplib.MULTI_STATUS: |
| 603 |
raise svntest.Failure('Unexpected status: %d %s' % (r.status, r.reason)) |
| 604 |
|
| 605 |
expected_response = ( |
| 606 |
'<?xml version="1.0" encoding="utf-8"?>\n' |
| 607 |
'<D:multistatus xmlns:D="DAV:" xmlns:ns0="DAV:">\n' |
| 608 |
'<D:response xmlns:S="http://subversion.tigris.org/xmlns/svn/" ' |
| 609 |
'xmlns:C="http://subversion.tigris.org/xmlns/custom/" ' |
| 610 |
'xmlns:V="http://subversion.tigris.org/xmlns/dav/" ' |
| 611 |
'xmlns:lp1="DAV:" ' |
| 612 |
'xmlns:lp2="http://subversion.tigris.org/xmlns/dav/">\n' |
| 613 |
'<D:href>' + repo_uripath + '/!svn/rvr/2/iota</D:href>\n' |
| 614 |
'<D:propstat>\n' |
| 615 |
'<D:prop>\n' |
| 616 |
'<C:a/>\n' |
| 617 |
'<lp1:resourcetype/>\n' |
| 618 |
'<lp1:getcontentlength/>\n' |
| 619 |
'<lp1:getcontenttype/>\n' |
| 620 |
'<lp1:getetag/>\n' |
| 621 |
'<lp1:creationdate/>\n' |
| 622 |
'<lp1:getlastmodified/>\n' |
| 623 |
'<lp1:checked-in/>\n' |
| 624 |
'<lp1:version-controlled-configuration/>\n' |
| 625 |
'<lp1:version-name/>\n' |
| 626 |
'<lp1:creator-displayname/>\n' |
| 627 |
'<lp2:baseline-relative-path/>\n' |
| 628 |
'<lp2:md5-checksum/>\n' |
| 629 |
'<lp2:repository-uuid/>\n' |
| 630 |
'<lp2:deadprop-count/>\n' |
| 631 |
'<lp2:sha1-checksum/>\n' |
| 632 |
'<D:supportedlock/>\n' |
| 633 |
'<D:lockdiscovery/>\n' |
| 634 |
'</D:prop>\n' |
| 635 |
'<D:status>HTTP/1.1 200 OK</D:status>\n' |
| 636 |
'</D:propstat>\n' |
| 637 |
'</D:response>\n' |
| 638 |
'</D:multistatus>\n' |
| 639 |
) |
| 640 |
actual_response = r.read() |
| 641 |
verify_xml_response(expected_response, actual_response) |
| 642 |
|
| 643 |
@SkipUnless(svntest.main.is_ra_type_dav) |
| 644 |
def last_modified_header(sbox): |
| 645 |
"verify 'Last-Modified' header on 'external' GETs" |
| 646 |
|
| 647 |
sbox.build(create_wc=False, read_only=True) |
| 648 |
|
| 649 |
headers = { |
| 650 |
'Authorization': 'Basic ' + base64.b64encode(b'jconstant:rayjandom').decode(), |
| 651 |
} |
| 652 |
|
| 653 |
h = svntest.main.create_http_connection(sbox.repo_url) |
| 654 |
|
| 655 |
# GET /repos/iota |
| 656 |
# Expect to see a Last-Modified header. |
| 657 |
h.request('GET', sbox.repo_url + '/iota', None, headers) |
| 658 |
r = h.getresponse() |
| 659 |
if r.status != httplib.OK: |
| 660 |
raise svntest.Failure('Request failed: %d %s' % (r.status, r.reason)) |
| 661 |
svntest.verify.compare_and_display_lines(None, 'Last-Modified', |
| 662 |
svntest.verify.RegexOutput('.+'), |
| 663 |
r.getheader('Last-Modified')) |
| 664 |
r.read() |
| 665 |
|
| 666 |
# HEAD /repos/iota |
| 667 |
# Expect to see a Last-Modified header. |
| 668 |
h.request('HEAD', sbox.repo_url + '/iota', None, headers) |
| 669 |
r = h.getresponse() |
| 670 |
if r.status != httplib.OK: |
| 671 |
raise svntest.Failure('Request failed: %d %s' % (r.status, r.reason)) |
| 672 |
svntest.verify.compare_and_display_lines(None, 'Last-Modified', |
| 673 |
svntest.verify.RegexOutput('.+'), |
| 674 |
r.getheader('Last-Modified')) |
| 675 |
r.read() |
| 676 |
|
| 677 |
# GET /repos/!svn/rvr/1/iota |
| 678 |
# There should not be a Last-Modified header (it's costly and not useful, |
| 679 |
# see r1724790) |
| 680 |
h.request('GET', sbox.repo_url + '/!svn/rvr/1/iota', None, headers) |
| 681 |
r = h.getresponse() |
| 682 |
if r.status != httplib.OK: |
| 683 |
raise svntest.Failure('Request failed: %d %s' % (r.status, r.reason)) |
| 684 |
last_modified = r.getheader('Last-Modified') |
| 685 |
if last_modified: |
| 686 |
raise svntest.Failure('Unexpected Last-Modified header: %s' % last_modified) |
| 687 |
r.read() |
| 688 |
|
| 689 |
@SkipUnless(svntest.main.is_ra_type_dav) |
| 690 |
def create_name_with_control_chars(sbox): |
| 691 |
"test creating items with control chars in names" |
| 692 |
|
| 693 |
sbox.build(create_wc=False) |
| 694 |
|
| 695 |
h = svntest.main.create_http_connection(sbox.repo_url) |
| 696 |
|
| 697 |
# POST /repos/!svn/me |
| 698 |
# Create a new transaction. |
| 699 |
req_body = ( |
| 700 |
'(create-txn-with-props ' |
| 701 |
'(svn:txn-client-compat-version 6 1.14.4 ' |
| 702 |
'svn:txn-user-agent 45 SVN/1.14.4 (x86-microsoft-windows) serf/1.3.9 ' |
| 703 |
'svn:log 0 ))' |
| 704 |
) |
| 705 |
headers = { |
| 706 |
'Authorization': 'Basic ' + base64.b64encode(b'jconstant:rayjandom').decode(), |
| 707 |
'Content-Type': 'application/vnd.svn-skel', |
| 708 |
} |
| 709 |
h.request('POST', sbox.repo_url + '/!svn/me', req_body, headers) |
| 710 |
r = h.getresponse() |
| 711 |
if r.status != httplib.CREATED: |
| 712 |
raise svntest.Failure('Unexpected status: %d %s' % (r.status, r.reason)) |
| 713 |
txn_name = r.getheader('SVN-Txn-Name') |
| 714 |
r.read() |
| 715 |
|
| 716 |
# MKCOL /repos/!svn/txn/TXN_NAME/tab%09name |
| 717 |
# Must fail with a 400 Bad Request. |
| 718 |
headers = { |
| 719 |
'Authorization': 'Basic ' + base64.b64encode(b'jconstant:rayjandom').decode(), |
| 720 |
} |
| 721 |
h.request('MKCOL', sbox.repo_url + '/!svn/txr/' + txn_name + '/tab%09name', None, headers) |
| 722 |
r = h.getresponse() |
| 723 |
if r.status != httplib.BAD_REQUEST: |
| 724 |
raise svntest.Failure('Unexpected status: %d %s' % (r.status, r.reason)) |
| 725 |
r.read() |
| 726 |
|
| 727 |
# PUT /repos/!svn/txn/TXN_NAME/tab%09name |
| 728 |
# Must fail with a 400 Bad Request. |
| 729 |
headers = { |
| 730 |
'Authorization': 'Basic ' + base64.b64encode(b'jconstant:rayjandom').decode(), |
| 731 |
} |
| 732 |
h.request('PUT', sbox.repo_url + '/!svn/txr/' + txn_name + '/tab%09name', None, headers) |
| 733 |
r = h.getresponse() |
| 734 |
if r.status != httplib.BAD_REQUEST: |
| 735 |
raise svntest.Failure('Unexpected status: %d %s' % (r.status, r.reason)) |
| 736 |
r.read() |
| 737 |
|
| 738 |
# COPY /repos/!svn/rvr/1/iota -> /repos/!svn/txn/TXN_NAME/tab%09name |
| 739 |
# Must fail with a 400 Bad Request. |
| 740 |
headers = { |
| 741 |
'Authorization': 'Basic ' + base64.b64encode(b'jconstant:rayjandom').decode(), |
| 742 |
'Destination': sbox.repo_url + '/!svn/txr/' + txn_name + '/tab%09name' |
| 743 |
} |
| 744 |
h.request('COPY', sbox.repo_url + '/!svn/rvr/1/iota', None, headers) |
| 745 |
r = h.getresponse() |
| 746 |
if r.status != httplib.BAD_REQUEST: |
| 747 |
raise svntest.Failure('Unexpected status: %d %s' % (r.status, r.reason)) |
| 748 |
r.read() |
| 749 |
|
| 750 |
|
| 751 |
######################################################################## |
| 752 |
# Run the tests |
| 753 |
|
| 754 |
|
| 755 |
# list all tests here, starting with None: |
| 756 |
test_list = [ None, |
| 757 |
cache_control_header, |
| 758 |
simple_propfind, |
| 759 |
propfind_multiple_props, |
| 760 |
propfind_404, |
| 761 |
propfind_allprop, |
| 762 |
propfind_propname, |
| 763 |
last_modified_header, |
| 764 |
create_name_with_control_chars, |
| 765 |
] |
| 766 |
serial_only = True |
| 767 |
|
| 768 |
if __name__ == '__main__': |
| 769 |
svntest.main.run_tests(test_list) |
| 770 |
# NOTREACHED |
| 771 |
|
| 772 |
|
| 773 |
### End of file. |