2009-12-08 22:15:56 +01:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
2010-04-24 00:23:47 +02:00
|
|
|
from config import hostname, port, username, password, subscriber_username
|
2009-12-08 22:15:56 +01:00
|
|
|
|
2010-07-13 18:02:56 +02:00
|
|
|
import sogotests
|
2009-12-08 22:15:56 +01:00
|
|
|
import unittest
|
2010-01-18 12:27:11 +01:00
|
|
|
import utilities
|
2009-12-08 22:15:56 +01:00
|
|
|
import webdavlib
|
|
|
|
|
|
|
|
class WebDAVTest(unittest.TestCase):
|
2010-01-18 12:27:11 +01:00
|
|
|
def __init__(self, arg):
|
|
|
|
unittest.TestCase.__init__(self, arg)
|
|
|
|
self.client = webdavlib.WebDAVClient(hostname, port,
|
|
|
|
username, password)
|
2010-06-01 20:14:17 +02:00
|
|
|
self.dav_utility = utilities.TestUtility(self, self.client)
|
2010-01-18 12:27:11 +01:00
|
|
|
|
2009-12-08 22:15:56 +01:00
|
|
|
def testPrincipalCollectionSet(self):
|
2009-12-22 21:35:19 +01:00
|
|
|
"""property: 'principal-collection-set' on collection object"""
|
2009-12-08 22:15:56 +01:00
|
|
|
resource = '/SOGo/dav/%s/' % username
|
|
|
|
propfind = webdavlib.WebDAVPROPFIND(resource,
|
|
|
|
["{DAV:}principal-collection-set"],
|
|
|
|
0)
|
2010-01-18 12:27:11 +01:00
|
|
|
self.client.execute(propfind)
|
2010-01-15 00:19:19 +01:00
|
|
|
self.assertEquals(propfind.response["status"], 207)
|
2010-06-01 20:14:17 +02:00
|
|
|
nodes = propfind.response["document"] \
|
|
|
|
.findall('{DAV:}response/{DAV:}propstat/{DAV:}prop/{DAV:}principal-collection-set/{DAV:}href')
|
|
|
|
responseHref = nodes[0].text
|
2009-12-08 22:15:56 +01:00
|
|
|
if responseHref[0:4] == "http":
|
2010-01-15 00:19:19 +01:00
|
|
|
self.assertEquals("http://%s/SOGo/dav/" % hostname, responseHref,
|
|
|
|
"{DAV:}principal-collection-set returned %s instead of 'http../SOGo/dav/'"
|
2009-12-08 22:15:56 +01:00
|
|
|
% ( responseHref, resource ))
|
|
|
|
else:
|
2010-01-15 00:19:19 +01:00
|
|
|
self.assertEquals("/SOGo/dav/", responseHref,
|
|
|
|
"{DAV:}principal-collection-set returned %s instead of '/SOGo/dav/'"
|
|
|
|
% responseHref)
|
2009-12-08 22:15:56 +01:00
|
|
|
|
|
|
|
def testPrincipalCollectionSet2(self):
|
2009-12-22 21:35:19 +01:00
|
|
|
"""property: 'principal-collection-set' on non-collection object"""
|
2009-12-08 22:15:56 +01:00
|
|
|
resource = '/SOGo/dav/%s/freebusy.ifb' % username
|
|
|
|
propfind = webdavlib.WebDAVPROPFIND(resource,
|
|
|
|
["{DAV:}principal-collection-set"],
|
|
|
|
0)
|
2010-01-18 12:27:11 +01:00
|
|
|
self.client.execute(propfind)
|
2010-01-15 00:19:19 +01:00
|
|
|
self.assertEquals(propfind.response["status"], 207)
|
2010-06-01 20:14:17 +02:00
|
|
|
node = propfind.response["document"] \
|
|
|
|
.find('{DAV:}response/{DAV:}propstat/{DAV:}prop/{DAV:}principal-collection-set/{DAV:}href')
|
|
|
|
responseHref = node.text
|
2010-01-15 00:19:19 +01:00
|
|
|
expectedHref = '/SOGo/dav/'
|
2009-12-08 22:15:56 +01:00
|
|
|
if responseHref[0:4] == "http":
|
2009-12-22 21:35:19 +01:00
|
|
|
self.assertEquals("http://%s%s" % (hostname, expectedHref), responseHref,
|
2009-12-08 22:15:56 +01:00
|
|
|
"{DAV:}principal-collection-set returned %s instead of '%s'"
|
2009-12-22 21:35:19 +01:00
|
|
|
% ( responseHref, expectedHref ))
|
2009-12-08 22:15:56 +01:00
|
|
|
else:
|
2009-12-22 21:35:19 +01:00
|
|
|
self.assertEquals(expectedHref, responseHref,
|
2009-12-08 22:15:56 +01:00
|
|
|
"{DAV:}principal-collection-set returned %s instead of '%s'"
|
2009-12-22 21:35:19 +01:00
|
|
|
% ( responseHref, expectedHref ))
|
2009-12-08 22:15:56 +01:00
|
|
|
|
2010-01-15 00:19:19 +01:00
|
|
|
def _testPropfindURL(self, resource):
|
|
|
|
resourceWithSlash = resource[-1] == '/'
|
|
|
|
propfind = webdavlib.WebDAVPROPFIND(resource,
|
|
|
|
["{DAV:}displayname", "{DAV:}resourcetype"],
|
|
|
|
1)
|
2010-01-18 12:27:11 +01:00
|
|
|
self.client.execute(propfind)
|
2010-01-15 00:19:19 +01:00
|
|
|
self.assertEquals(propfind.response["status"], 207)
|
|
|
|
|
2010-06-01 20:14:17 +02:00
|
|
|
nodes = propfind.response["document"].findall('{DAV:}response')
|
2010-01-15 00:19:19 +01:00
|
|
|
for node in nodes:
|
2010-06-01 20:14:17 +02:00
|
|
|
responseHref = node.find('{DAV:}href').text
|
2010-01-15 00:19:19 +01:00
|
|
|
hasSlash = responseHref[-1] == '/'
|
2010-06-01 20:14:17 +02:00
|
|
|
resourcetype = node.find('{DAV:}propstat/{DAV:}prop/{DAV:}resourcetype')
|
|
|
|
isCollection = len(resourcetype.getchildren()) > 0
|
2010-01-15 00:19:19 +01:00
|
|
|
if isCollection:
|
|
|
|
self.assertEquals(hasSlash, resourceWithSlash,
|
|
|
|
"failure with href '%s' while querying '%s'"
|
|
|
|
% (responseHref, resource))
|
|
|
|
else:
|
|
|
|
self.assertEquals(hasSlash, False,
|
|
|
|
"failure with href '%s' while querying '%s'"
|
|
|
|
% (responseHref, resource))
|
|
|
|
|
|
|
|
def testPropfindURL(self):
|
|
|
|
"""propfind: ensure various NSURL work-arounds"""
|
|
|
|
# a collection without /
|
|
|
|
self._testPropfindURL('/SOGo/dav/%s' % username)
|
|
|
|
# a collection with /
|
|
|
|
self._testPropfindURL('/SOGo/dav/%s/' % username)
|
|
|
|
# a non-collection
|
|
|
|
self._testPropfindURL('/SOGo/dav/%s/freebusy.ifb' % username)
|
|
|
|
|
|
|
|
## REPORT
|
2010-04-24 00:23:47 +02:00
|
|
|
def testPrincipalPropertySearch(self):
|
|
|
|
"""principal-property-search"""
|
|
|
|
resource = '/SOGo/dav'
|
|
|
|
userInfo = self.dav_utility.fetchUserInfo(username)
|
|
|
|
# subscriber_userInfo = self.dav_utility.fetchUserInfo(subscriber_username)
|
|
|
|
matches = [["{urn:ietf:params:xml:ns:caldav}calendar-home-set",
|
|
|
|
"/SOGo/dav/%s/Calendar" % username]]
|
|
|
|
## the SOGo implementation does not support more than one
|
|
|
|
## property-search at a time:
|
|
|
|
# ["{urn:ietf:params:xml:ns:caldav}calendar-home-set",
|
|
|
|
# "/SOGo/dav/%s/Calendar" % subscriber_username]]
|
2010-04-26 17:15:42 +02:00
|
|
|
query = webdavlib.WebDAVPrincipalPropertySearch(resource,
|
|
|
|
["displayname"], matches)
|
2010-04-24 00:23:47 +02:00
|
|
|
self.client.execute(query)
|
|
|
|
self.assertEquals(query.response["status"], 207)
|
2010-06-01 20:14:17 +02:00
|
|
|
response = query.response["document"].findall('{DAV:}response')[0]
|
|
|
|
href = response.find('{DAV:}href').text
|
|
|
|
self.assertEquals("/SOGo/dav/%s/" % username, href)
|
|
|
|
displayname = response.find('{DAV:}propstat/{DAV:}prop/{DAV:}displayname')
|
|
|
|
value = displayname.text
|
2010-04-24 00:23:47 +02:00
|
|
|
if value is None:
|
|
|
|
value = ""
|
|
|
|
self.assertEquals(userInfo[0], value)
|
|
|
|
|
2010-01-15 00:19:19 +01:00
|
|
|
# http://tools.ietf.org/html/rfc3253.html#section-3.8
|
|
|
|
def testExpandProperty(self):
|
|
|
|
"""expand-property"""
|
|
|
|
resource = '/SOGo/dav/%s/' % username
|
2010-01-18 12:27:11 +01:00
|
|
|
userInfo = self.dav_utility.fetchUserInfo(username)
|
2010-01-15 00:19:19 +01:00
|
|
|
|
2010-06-01 20:14:17 +02:00
|
|
|
query_props = {"{DAV:}owner": { "{DAV:}href": resource,
|
|
|
|
"{DAV:}displayname": userInfo[0]},
|
|
|
|
"{DAV:}principal-collection-set": { "{DAV:}href": "/SOGo/dav/",
|
|
|
|
"{DAV:}displayname": "SOGo"}}
|
2010-01-15 00:19:19 +01:00
|
|
|
query = webdavlib.WebDAVExpandProperty(resource, query_props.keys(),
|
|
|
|
["displayname"])
|
2010-01-18 12:27:11 +01:00
|
|
|
self.client.execute(query)
|
2010-01-15 00:19:19 +01:00
|
|
|
self.assertEquals(query.response["status"], 207)
|
|
|
|
|
2010-06-01 20:14:17 +02:00
|
|
|
topResponse = query.response["document"].find('{DAV:}response')
|
|
|
|
topHref = topResponse.find('{DAV:}href')
|
|
|
|
self.assertEquals(resource, topHref.text)
|
2010-01-15 00:19:19 +01:00
|
|
|
for query_prop in query_props.keys():
|
2010-06-01 20:14:17 +02:00
|
|
|
propResponse = topResponse.find('{DAV:}propstat/{DAV:}prop/%s'
|
|
|
|
% query_prop)
|
|
|
|
propHref = propResponse.find('{DAV:}response/{DAV:}href')
|
|
|
|
self.assertEquals(query_props[query_prop]["{DAV:}href"],
|
|
|
|
propHref.text,
|
2010-01-15 00:19:19 +01:00
|
|
|
"'%s', href mismatch: exp. '%s', got '%s'"
|
|
|
|
% (query_prop,
|
2010-06-01 20:14:17 +02:00
|
|
|
query_props[query_prop]["{DAV:}href"],
|
|
|
|
propHref.text))
|
|
|
|
propDisplayname = propResponse.find('{DAV:}response/{DAV:}propstat/{DAV:}prop/{DAV:}displayname')
|
|
|
|
displayName = propDisplayname.text
|
|
|
|
if displayName is None:
|
2010-04-09 20:31:17 +02:00
|
|
|
displayName = ""
|
2010-06-01 20:14:17 +02:00
|
|
|
self.assertEquals(query_props[query_prop]["{DAV:}displayname"],
|
2010-04-09 20:31:17 +02:00
|
|
|
displayName,
|
2010-01-15 00:19:19 +01:00
|
|
|
"'%s', displayname mismatch: exp. '%s', got '%s'"
|
|
|
|
% (query_prop,
|
2010-06-01 20:14:17 +02:00
|
|
|
query_props[query_prop]["{DAV:}displayname"],
|
|
|
|
propDisplayname))
|
2010-01-15 00:19:19 +01:00
|
|
|
|
2009-12-08 22:15:56 +01:00
|
|
|
if __name__ == "__main__":
|
2010-07-13 18:02:56 +02:00
|
|
|
sogotests.runTests()
|