<?xml version="1.0" standalone="no"?>

<!DOCTYPE caldavtest SYSTEM "caldavtest.dtd">

<!--
 Copyright (c) 2006-2015 Apple Inc. All rights reserved.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 -->

<caldavtest>
	<description>Test DAV:current-user-principal support</description>

	<require-feature>
		<feature>carddav</feature>
	</require-feature>

	<start/>
	
	<test-suite name='Check for the property on /'>
		<require-feature>
			<feature>own-root</feature>
		</require-feature>
		<test name='1'>
			<description>Check for authenticated property on /</description>
			<request>
				<method>PROPFIND</method>
				<ruri>$root:</ruri>
				<header>
					<name>Depth</name>
					<value>0</value>
				</header>
				<data>
					<content-type>text/xml; charset=utf-8</content-type>
					<filepath>Resource/CardDAV/vcurrent-user-principal/1.xml</filepath>
				</data>
				<verify>
					<callback>propfindItems</callback>
					<arg>
						<name>okprops</name>
						<value><![CDATA[{DAV:}current-user-principal$<D:href xmlns:D="DAV:">$principaluri1:</D:href>]]></value>
					</arg>
				</verify>
			</request>
		</test>
		<test name='3'>
			<description>Check for authenticated property on / (user02)</description>
			<request user="$userid2:" pswd="$pswd2:">
				<method>PROPFIND</method>
				<ruri>$root:</ruri>
				<header>
					<name>Depth</name>
					<value>0</value>
				</header>
				<data>
					<content-type>text/xml; charset=utf-8</content-type>
					<filepath>Resource/CardDAV/vcurrent-user-principal/1.xml</filepath>
				</data>
				<verify>
					<callback>propfindItems</callback>
					<arg>
						<name>okprops</name>
						<value><![CDATA[{DAV:}current-user-principal$<D:href xmlns:D="DAV:">$principaluri2:</D:href>]]></value>
					</arg>
				</verify>
			</request>
		</test>
	</test-suite>

	<test-suite name='Check for the property on /principals/'>
		<test name='1'>
			<description>Check for authenticated property on /</description>
			<request>
				<method>PROPFIND</method>
				<ruri>$principalcollection:</ruri>
				<header>
					<name>Depth</name>
					<value>0</value>
				</header>
				<data>
					<content-type>text/xml; charset=utf-8</content-type>
					<filepath>Resource/CardDAV/vcurrent-user-principal/1.xml</filepath>
				</data>
				<verify>
					<callback>propfindItems</callback>
					<arg>
						<name>okprops</name>
						<value><![CDATA[{DAV:}current-user-principal$<D:href xmlns:D="DAV:">$principaluri1:</D:href>]]></value>
					</arg>
				</verify>
			</request>
		</test>
		<test name='2'>
			<description>Check for unauthenticated property on /</description>
			<request auth="no">
				<method>PROPFIND</method>
				<ruri>$principalcollection:</ruri>
				<header>
					<name>Depth</name>
					<value>0</value>
				</header>
				<data>
					<content-type>text/xml; charset=utf-8</content-type>
					<filepath>Resource/CardDAV/vcurrent-user-principal/1.xml</filepath>
				</data>
				<verify>
					<callback>statusCode</callback>
					<arg>
						<name>status</name>
						<value>401</value>
					</arg>
				</verify>
			</request>
		</test>
		<test name='3'>
			<description>Check for authenticated property on / (user02)</description>
			<request user="$userid2:" pswd="$pswd2:">
				<method>PROPFIND</method>
				<ruri>$principalcollection:</ruri>
				<header>
					<name>Depth</name>
					<value>0</value>
				</header>
				<data>
					<content-type>text/xml; charset=utf-8</content-type>
					<filepath>Resource/CardDAV/vcurrent-user-principal/1.xml</filepath>
				</data>
				<verify>
					<callback>propfindItems</callback>
					<arg>
						<name>okprops</name>
						<value><![CDATA[{DAV:}current-user-principal$<D:href xmlns:D="DAV:">$principaluri2:</D:href>]]></value>
					</arg>
				</verify>
			</request>
		</test>
	</test-suite>

	<end/>	
</caldavtest>
