Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Commit

Permalink
Make sure pseudo-requests use the right host/port for from the origin…
Browse files Browse the repository at this point in the history
…al request. Clean-up properly after a sharing test.

git-svn-id: https://svn.calendarserver.org/repository/calendarserver/CalDAVTester/trunk@14711 e27351fd-9f3e-4f54-a53b-843176b1656c
  • Loading branch information
cyrusdaboo committed Apr 27, 2015
1 parent 682a248 commit 2e6fe57
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 18 deletions.
11 changes: 10 additions & 1 deletion scripts/tests-pod/CalDAV/sharing-reports-query.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2984,6 +2984,15 @@
</test>
</test-suite>

<end/>
<end>
<request user="$useradmin:" pswd="$pswdadmin:">
<method>DELETEALL</method>
<ruri>$notificationpath1:/</ruri>
</request>
<request host2="yes" user="$useradmin:" pswd="$pswdadmin:">
<method>DELETEALL</method>
<ruri>$pnotificationpath2:/</ruri>
</request>
</end>

</caldavtest>
49 changes: 32 additions & 17 deletions src/caldavtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,11 @@ def dorequests(self, description, list, doverify=True, forceverify=False, label=
return result


def doget(self, resource, label=""):
def doget(self, original_request, resource, label=""):
req = request(self.manager)
req.method = "GET"
req.host = original_request.host
req.port = original_request.port
req.ruris.append(resource[0])
req.ruri = resource[0]
if len(resource[1]):
Expand All @@ -275,10 +277,12 @@ def doget(self, resource, label=""):
return True, respdata


def dofindall(self, collection, label=""):
def dofindall(self, original_request, collection, label=""):
hrefs = []
req = request(self.manager)
req.method = "PROPFIND"
req.host = original_request.host
req.port = original_request.port
req.ruris.append(collection[0])
req.ruri = collection[0]
req.headers["Depth"] = "1"
Expand Down Expand Up @@ -315,12 +319,14 @@ def dofindall(self, collection, label=""):
return hrefs


def dodeleteall(self, deletes, label=""):
def dodeleteall(self, original_request, deletes, label=""):
if len(deletes) == 0:
return True
for deleter in deletes:
req = request(self.manager)
req.method = "DELETE"
req.host = original_request.host
req.port = original_request.port
req.ruris.append(deleter[0])
req.ruri = deleter[0]
if len(deleter[1]):
Expand All @@ -334,7 +340,7 @@ def dodeleteall(self, deletes, label=""):
return True


def dofindnew(self, collection, label="", other=False):
def dofindnew(self, original_request, collection, label="", other=False):
hresult = ""

uri = collection[0]
Expand All @@ -347,6 +353,8 @@ def dofindnew(self, collection, label="", other=False):
possible_matches = set()
req = request(self.manager)
req.method = "PROPFIND"
req.host = original_request.host
req.port = original_request.port
req.ruris.append(uri)
req.ruri = uri
req.headers["Depth"] = "1"
Expand Down Expand Up @@ -427,12 +435,14 @@ def dofindnew(self, collection, label="", other=False):
return hresult


def dowaitcount(self, collection, count, label=""):
def dowaitcount(self, original_request, collection, count, label=""):

hrefs = []
for _ignore in range(self.manager.server_info.waitcount):
req = request(self.manager)
req.method = "PROPFIND"
req.host = original_request.host
req.port = original_request.port
req.ruris.append(collection[0])
req.ruri = collection[0]
req.headers["Depth"] = "1"
Expand Down Expand Up @@ -470,7 +480,7 @@ def dowaitcount(self, collection, count, label=""):
# Get the content of each resource
rdata = ""
for href in hrefs:
result, respdata = self.doget((href, collection[1], collection[2],), label)
result, respdata = self.doget(req, (href, collection[1], collection[2],), label)
test = "unknown"
if respdata.startswith("BEGIN:VCALENDAR"):
uid = respdata.find("UID:")
Expand All @@ -484,11 +494,13 @@ def dowaitcount(self, collection, count, label=""):
return False, len(hrefs)


def dowaitchanged(self, uri, etag, user, pswd, label=""):
def dowaitchanged(self, original_request, uri, etag, user, pswd, label=""):

for _ignore in range(self.manager.server_info.waitcount):
req = request(self.manager)
req.method = "HEAD"
req.host = original_request.host
req.port = original_request.port
req.ruris.append(uri)
req.ruri = uri
if user:
Expand Down Expand Up @@ -522,6 +534,8 @@ def doenddelete(self, description, label=""):
for deleter in self.end_deletes:
req = request(self.manager)
req.method = "DELETE"
req.host = deleter[3]
req.port = deleter[4]
req.ruris.append(deleter[0])
req.ruri = deleter[0]
if len(deleter[1]):
Expand Down Expand Up @@ -551,8 +565,8 @@ def dorequest(self, req, details=False, doverify=True, forceverify=False, stats=
if req.method == "DELETEALL":
for ruri in req.ruris:
collection = (ruri, req.user, req.pswd)
hrefs = self.dofindall(collection, label="%s | %s" % (label, "DELETEALL"))
if not self.dodeleteall(hrefs, label="%s | %s" % (label, "DELETEALL")):
hrefs = self.dofindall(req, collection, label="%s | %s" % (label, "DELETEALL"))
if not self.dodeleteall(req, hrefs, label="%s | %s" % (label, "DELETEALL")):
return False, "DELETEALL failed for: {r}".format(r=ruri), None, None
return True, "", None, None

Expand All @@ -568,7 +582,7 @@ def dorequest(self, req, details=False, doverify=True, forceverify=False, stats=
# Special for GETNEW
elif req.method == "GETNEW":
collection = (req.ruri, req.user, req.pswd)
self.grabbedlocation = self.dofindnew(collection, label=label)
self.grabbedlocation = self.dofindnew(req, collection, label=label)
if req.graburi:
self.manager.server_info.addextrasubs({req.graburi: self.grabbedlocation})
req.method = "GET"
Expand All @@ -577,15 +591,15 @@ def dorequest(self, req, details=False, doverify=True, forceverify=False, stats=
# Special for FINDNEW
elif req.method == "FINDNEW":
collection = (req.ruri, req.user, req.pswd)
self.grabbedlocation = self.dofindnew(collection, label=label)
self.grabbedlocation = self.dofindnew(req, collection, label=label)
if req.graburi:
self.manager.server_info.addextrasubs({req.graburi: self.grabbedlocation})
return True, "", None, None

# Special for GETOTHER
elif req.method == "GETOTHER":
collection = (req.ruri, req.user, req.pswd)
self.grabbedlocation = self.dofindnew(collection, label=label, other=True)
self.grabbedlocation = self.dofindnew(req, collection, label=label, other=True)
if req.graburi:
self.manager.server_info.addextrasubs({req.graburi: self.grabbedlocation})
req.method = "GET"
Expand All @@ -596,7 +610,7 @@ def dorequest(self, req, details=False, doverify=True, forceverify=False, stats=
count = int(req.method[10:])
for ruri in req.ruris:
collection = (ruri, req.user, req.pswd)
waitresult, waitdetails = self.dowaitcount(collection, count, label=label)
waitresult, waitdetails = self.dowaitcount(req, collection, count, label=label)
if not waitresult:
return False, "Count did not change: {w}".format(w=waitdetails), None, None
else:
Expand All @@ -607,10 +621,10 @@ def dorequest(self, req, details=False, doverify=True, forceverify=False, stats=
count = int(req.method[len("WAITDELETEALL"):])
for ruri in req.ruris:
collection = (ruri, req.user, req.pswd)
waitresult, waitdetails = self.dowaitcount(collection, count, label=label)
waitresult, waitdetails = self.dowaitcount(req, collection, count, label=label)
if waitresult:
hrefs = self.dofindall(collection, label="%s | %s" % (label, "DELETEALL"))
self.dodeleteall(hrefs, label="%s | %s" % (label, "DELETEALL"))
hrefs = self.dofindall(req, collection, label="%s | %s" % (label, "DELETEALL"))
self.dodeleteall(req, hrefs, label="%s | %s" % (label, "DELETEALL"))
else:
return False, "Count did not change: {w}".format(w=waitdetails), None, None
else:
Expand All @@ -630,14 +644,15 @@ def dorequest(self, req, details=False, doverify=True, forceverify=False, stats=

# Cache delayed delete
if req.end_delete:
self.end_deletes.append((uri, req.user, req.pswd))
self.end_deletes.append((uri, req.user, req.pswd, req.host, req.port,))

if details:
resulttxt += " %s: %s\n" % (method, uri)

# Special for GETCHANGED
if req.method == "GETCHANGED":
if not self.dowaitchanged(
req,
uri, etags[uri], req.user, req.pswd,
label=label
):
Expand Down

0 comments on commit 2e6fe57

Please sign in to comment.