Fix PROPFIND with Depth 1 if external bind is included

Previously something like this would be logged if debugging is enabled:

davical: LOG: Principal: Query: DBGQ: SELECT * FROM collection WHERE user_no= :user_no
davical: LOG: Principal: Query: DBGQ:  ":user_no" => ""
davical: BUG: :DAViCal Fatal Error: [42883] SQLSTATE[42883]: Undefined function: 7 ERROR:  operator does not exist: integer = boolean\nLINE 1: SELECT * FROM collection WHERE user_no= FALSE\n                                              ^\nHINT:  No operator matches the given name and argument types. You might need to add explicit type casts. at /home/puck/work/Calendar/awl/inc/AwlDatabase.php:94

And this would be returned as a response:

DAViCal Fatal Error

user_no doesn't get set when construction the Collection for the external
bind, so, just handle that instead of sending the empty string to the
database as a user_no.

Modify the tests from ccc7e182ba4cbfba66a4fe96e1c0620e46390b95 to tickle the
bug.

Closes #175.
This commit is contained in:
Andrew Ruthven 2024-02-17 23:57:42 +13:00
parent d7d19b906f
commit e989e1cf97
8 changed files with 516 additions and 14 deletions

View File

@ -50,7 +50,7 @@ test:
- echo "en_NZ.UTF-8 UTF-8" >> /etc/locale.gen
- locale-gen
- echo "LANG=en_NZ.UTF-8" > /etc/default/locale
- apt-get -y install libdbd-pg-perl libyaml-perl php php-cli php-pgsql php-xml postgresql-client postgresql libapache2-mod-php curl xmlstarlet
- apt-get -y install libdbd-pg-perl libyaml-perl php php-cli php-pgsql php-xml php-curl postgresql-client postgresql libapache2-mod-php curl xmlstarlet
- curl 'https://gitlab.com/davical-project/awl/-/archive/master/awl-master.tar.gz' | tar zxf -
- mv awl-master /usr/share/awl/
- chown -R www-data /usr/share/awl/
@ -61,6 +61,8 @@ test:
- sed -i 's/\/path\/to/\/usr\/share/g' /etc/apache2/sites-enabled/davical-regression.conf
- mkdir /usr/share/davical/testing/
- cp testing/*.php /usr/share/davical/testing/
- mkdir /usr/share/davical/htdocs/testfiles
- ln -s /usr/share/davical/htdocs/testfiles htdocs
- rm /etc/davical/config.php
- cat testing/regression-conf.php.example | sed 's.//$c->dbg.$c->dbg.' > /etc/davical/regression-conf.php
- ln -s /etc/davical/regression-conf.php /etc/davical/mycaldav-conf.php
@ -216,6 +218,8 @@ test_bullseye_latestphp:
- sed -i 's/\/path\/to/\/usr\/share/g' /etc/apache2/sites-enabled/davical-regression.conf
- mkdir /usr/share/davical/testing/
- cp testing/*.php /usr/share/davical/testing/
- mkdir /usr/share/davical/htdocs/testfiles
- ln -s /usr/share/davical/htdocs/testfiles htdocs
- rm /etc/davical/config.php
- cat testing/regression-conf.php.example | sed 's.//$c->dbg.$c->dbg.' > /etc/davical/regression-conf.php
- ln -s /etc/davical/regression-conf.php /etc/davical/mycaldav-conf.php
@ -261,7 +265,7 @@ test_memcache:
- echo "en_NZ.UTF-8 UTF-8" >> /etc/locale.gen
- locale-gen
- echo "LANG=en_NZ.UTF-8" > /etc/default/locale
- apt-get -y install libdbd-pg-perl libyaml-perl php php-cli php-pgsql php-xml php-memcached postgresql-client postgresql libapache2-mod-php curl xmlstarlet memcached netcat-openbsd
- apt-get -y install libdbd-pg-perl libyaml-perl php php-cli php-pgsql php-xml php-memcached php-curl postgresql-client postgresql libapache2-mod-php curl xmlstarlet memcached netcat-openbsd
- phpenmod memcached
- curl 'https://gitlab.com/davical-project/awl/-/archive/master/awl-master.tar.gz' | tar zxf -
- mv awl-master /usr/share/awl/
@ -273,6 +277,8 @@ test_memcache:
- sed -i 's/\/path\/to/\/usr\/share/g' /etc/apache2/sites-enabled/davical-regression.conf
- mkdir /usr/share/davical/testing/
- cp testing/*.php /usr/share/davical/testing/
- mkdir /usr/share/davical/htdocs/testfiles
- ln -s /usr/share/davical/htdocs/testfiles htdocs
- rm /etc/davical/config.php
- cat testing/regression-conf.php.example | sed 's.//$c->dbg.$c->dbg.' | sed 's.//memcache ..g' > /etc/davical/regression-conf.php
- ln -s /etc/davical/regression-conf.php /etc/davical/mycaldav-conf.php
@ -320,7 +326,7 @@ test_ldap:
- echo "en_NZ.UTF-8 UTF-8" >> /etc/locale.gen
- locale-gen
- echo "LANG=en_NZ.UTF-8" > /etc/default/locale
- apt-get -y install libdbd-pg-perl libyaml-perl php php-cli php-pgsql php-xml php-ldap postgresql-client postgresql libapache2-mod-php curl xmlstarlet libnet-ldap-server-test-perl netcat-openbsd
- apt-get -y install libdbd-pg-perl libyaml-perl php php-cli php-pgsql php-xml php-ldap php-curl postgresql-client postgresql libapache2-mod-php curl xmlstarlet libnet-ldap-server-test-perl netcat-openbsd
- phpenmod ldap
- curl 'https://gitlab.com/davical-project/awl/-/archive/master/awl-master.tar.gz' | tar zxf -
- mv awl-master /usr/share/awl/
@ -332,6 +338,8 @@ test_ldap:
- sed -i 's/\/path\/to/\/usr\/share/g' /etc/apache2/sites-enabled/davical-regression.conf
- mkdir /usr/share/davical/testing/
- cp testing/*.php /usr/share/davical/testing/
- mkdir /usr/share/davical/htdocs/testfiles
- ln -s /usr/share/davical/htdocs/testfiles htdocs
- rm /etc/davical/config.php
- cat testing/regression-conf.php.example | sed 's.//$c->dbg.$c->dbg.' | sed -E 's.//(memcache|ldap) ..g' > /etc/davical/regression-conf.php
- ln -s /etc/davical/regression-conf.php /etc/davical/mycaldav_ldap-conf.php

View File

@ -414,6 +414,9 @@ class Principal {
protected function FetchCollections() {
if ( isset($this->collections) ) return;
// If this is an external binding, then user_no will most likely be empty.
if ( ! isset($this->user_no) ) return;
$this->collections = array();
$qry = new AwlQuery('SELECT * FROM collection WHERE user_no= :user_no', array(':user_no' => $this->user_no()) );
if ( $qry->Exec('Principal') ) {
@ -448,7 +451,7 @@ class Principal {
if ( isset($this->collections[$dav_name]) && ($this->collections[$dav_name]->is_calendar == 't') ) {
$this->default_calendar = $dav_name;
}
else {
else if ( isset($this->collections) ) {
foreach( $this->collections AS $dav_name => $collection ) {
if ( $collection->is_calendar == 't' ) {
$this->default_calendar = $dav_name;

View File

@ -29,5 +29,6 @@ Listen 127.0.1.1:80
# let caldav.php handle "anything else"
RewriteCond %{REQUEST_URI} !^/$
RewriteCond %{REQUEST_URI} !\.(php|css|png|gif|js|jpg|ico)
RewriteCond %{REQUEST_URI} !/testfiles/.*$
RewriteRule ^(.*)$ /caldav.php$1 [NC,L]
</VirtualHost>

View File

@ -9,7 +9,7 @@ Content-Type: text/plain; charset="utf-8"
bind_id: >1058<
bound_source_id: >1057<
dav_displayname: >Moon<
dav_name: >/user4/Moon/<
external_url: >http://regression.host/testfiles/mooncal.ics?lang=de&phases%5Bfull%5D=true&phases%5Bnew%5D=true&phases%5Bquarter%5D=true&phases%5Bdaily%5D=false&events%5Blunareclipse%5D=true&events%5Bsolareclipse%5D=true&events%5Bmoonlanding%5D=false&before=P6M&after=P2Y&zone=CET<
parent_container: >/user4/<
dav_name: >/teamclient1/Moon/<
external_url: >http://regression/testfiles/mooncal.ics?lang=de&phases%5Bfull%5D=true&phases%5Bnew%5D=true&phases%5Bquarter%5D=true&phases%5Bdaily%5D=false&events%5Blunareclipse%5D=true&events%5Bsolareclipse%5D=true&events%5Bmoonlanding%5D=false&before=P6M&after=P2Y&zone=CET<
parent_container: >/teamclient1/<

View File

@ -3,8 +3,8 @@
#
TYPE=BIND
URL=http://regression.host/caldav.php/user4/
AUTH=user4:user4
URL=http://regression.host/caldav.php/teamclient1/
AUTH=admin:nimda
HEADER=User-Agent: Test external bind
HEADER=Content-Type: text/xml; charset="UTF-8"
@ -16,7 +16,7 @@ BEGINDATA
<?xml version="1.0" encoding="utf-8"?>
<bind xmlns="DAV:">
<segment>Moon</segment>
<href>http://regression.host/testfiles/mooncal.ics?lang=de&amp;phases%5Bfull%5D=true&amp;phases%5Bnew%5D=true&amp;phases%5Bquarter%5D=true&amp;phases%5Bdaily%5D=false&amp;events%5Blunareclipse%5D=true&amp;events%5Bsolareclipse%5D=true&amp;events%5Bmoonlanding%5D=false&amp;before=P6M&amp;after=P2Y&amp;zone=CET</href>
<href>http://regression/testfiles/mooncal.ics?lang=de&amp;phases%5Bfull%5D=true&amp;phases%5Bnew%5D=true&amp;phases%5Bquarter%5D=true&amp;phases%5Bdaily%5D=false&amp;events%5Blunareclipse%5D=true&amp;events%5Bsolareclipse%5D=true&amp;events%5Bmoonlanding%5D=false&amp;before=P6M&amp;after=P2Y&amp;zone=CET</href>
</bind>
ENDDATA

View File

@ -5,8 +5,8 @@
#
TYPE=GET
URL=http://regression.host/caldav.php/user4/Moon
AUTH=user4:user4
URL=http://regression.host/caldav.php/teamclient1/Moon
AUTH=user1:user1
HEADER=User-Agent: DAViCalTester/public
HEAD

View File

@ -0,0 +1,487 @@
HTTP/1.1 207 Multi-Status
Date: Dow, 01 Jan 2000 00:00:00 GMT
Content-Location: /caldav.php/teamclient1/
DAV: 1, 2, 3, access-control, calendar-access, calendar-schedule
DAV: extended-mkcol, bind, addressbook, calendar-auto-schedule, calendar-proxy
ETag: "ac625cb5a5ff728cc50520d0aaae27dd"
Content-Length: 11956
Content-Type: text/xml; charset="utf-8"
<?xml version="1.0" encoding="utf-8" ?>
<multistatus xmlns="DAV:" xmlns:C="http://calendarserver.org/ns/" xmlns:C1="urn:ietf:params:xml:ns:caldav" xmlns:X="http://xmlns.davical.org/davical" xmlns:C2="urn:ietf:params:xml:ns:carddav">
<response>
<href>/caldav.php/teamclient1/</href>
<propstat>
<prop>
<current-user-privilege-set>
<privilege>
<read/>
</privilege>
<privilege>
<read-current-user-privilege-set/>
</privilege>
</current-user-privilege-set>
<displayname>Team for Client1</displayname>
<C:getctag>"002aad3bf49fc30b841eedc6eb9d4206"</C:getctag>
<owner>
<href>/caldav.php/teamclient1/</href>
</owner>
<resource-id>
<href>/caldav.php/.resources/1013</href>
</resource-id>
<resourcetype>
<collection/>
<principal/>
</resourcetype>
<C1:schedule-default-calendar-URL>
<href>/caldav.php/teamclient1/home/</href>
</C1:schedule-default-calendar-URL>
<supported-report-set>
<supported-report>
<report>
<principal-property-search/>
</report>
</supported-report>
<supported-report>
<report>
<principal-search-property-set/>
</report>
</supported-report>
<supported-report>
<report>
<expand-property/>
</report>
</supported-report>
<supported-report>
<report>
<principal-match/>
</report>
</supported-report>
<supported-report>
<report>
<sync-collection/>
</report>
</supported-report>
</supported-report-set>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
<response>
<href>/caldav.php/teamclient1/Moon/</href>
<propstat>
<prop>
<add-member>
<href>/caldav.php/teamclient1/Moon/?add_member</href>
</add-member>
<current-user-privilege-set>
<privilege>
<read/>
</privilege>
<privilege>
<read-acl/>
</privilege>
<privilege>
<read-current-user-privilege-set/>
</privilege>
</current-user-privilege-set>
<displayname>Moon</displayname>
<C:getctag>"4998d2df79f8f730e2f56f4d715bdba8"</C:getctag>
<owner>
<href>/caldav.php/.external/127bf0002abfcecbe9203a3015c9b54f</href>
</owner>
<resource-id>
<href>/caldav.php/.resources/1057</href>
</resource-id>
<resourcetype>
<collection/>
<C1:calendar/>
<X:webdav-binding/>
</resourcetype>
<C1:schedule-default-calendar-URL>
<href>/caldav.php/</href>
</C1:schedule-default-calendar-URL>
<C1:supported-calendar-component-set>
<C1:comp name="VEVENT"/>
<C1:comp name="VTODO"/>
<C1:comp name="VJOURNAL"/>
</C1:supported-calendar-component-set>
<supported-report-set>
<supported-report>
<report>
<principal-property-search/>
</report>
</supported-report>
<supported-report>
<report>
<principal-search-property-set/>
</report>
</supported-report>
<supported-report>
<report>
<expand-property/>
</report>
</supported-report>
<supported-report>
<report>
<principal-match/>
</report>
</supported-report>
<supported-report>
<report>
<sync-collection/>
</report>
</supported-report>
<supported-report>
<report>
<C1:calendar-query/>
</report>
</supported-report>
<supported-report>
<report>
<C1:calendar-multiget/>
</report>
</supported-report>
<supported-report>
<report>
<C1:free-busy-query/>
</report>
</supported-report>
</supported-report-set>
<sync-token>data:,7</sync-token>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
<response>
<href>/caldav.php/teamclient1/home/</href>
<propstat>
<prop>
<add-member>
<href>/caldav.php/teamclient1/home/?add_member</href>
</add-member>
<current-user-privilege-set>
<privilege>
<read/>
</privilege>
<privilege>
<read-current-user-privilege-set/>
</privilege>
<privilege>
<C1:read-free-busy/>
</privilege>
</current-user-privilege-set>
<displayname>teamclient1 home</displayname>
<C:getctag>"edc1a74f98499d4a547a7c23125cabf2"</C:getctag>
<owner>
<href>/caldav.php/teamclient1/</href>
</owner>
<resource-id>
<href>/caldav.php/.resources/450</href>
</resource-id>
<resourcetype>
<collection/>
<C1:calendar/>
</resourcetype>
<C1:schedule-default-calendar-URL>
<href>/caldav.php/teamclient1/home/</href>
</C1:schedule-default-calendar-URL>
<C1:supported-calendar-component-set>
<C1:comp name="VEVENT"/>
<C1:comp name="VTODO"/>
<C1:comp name="VJOURNAL"/>
</C1:supported-calendar-component-set>
<supported-report-set>
<supported-report>
<report>
<principal-property-search/>
</report>
</supported-report>
<supported-report>
<report>
<principal-search-property-set/>
</report>
</supported-report>
<supported-report>
<report>
<expand-property/>
</report>
</supported-report>
<supported-report>
<report>
<principal-match/>
</report>
</supported-report>
<supported-report>
<report>
<sync-collection/>
</report>
</supported-report>
<supported-report>
<report>
<C1:calendar-query/>
</report>
</supported-report>
<supported-report>
<report>
<C1:calendar-multiget/>
</report>
</supported-report>
<supported-report>
<report>
<C1:free-busy-query/>
</report>
</supported-report>
</supported-report-set>
<sync-token>data:,8</sync-token>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
<response>
<href>/caldav.php/teamclient1/addresses/</href>
<propstat>
<prop>
<add-member>
<href>/caldav.php/teamclient1/addresses/?add_member</href>
</add-member>
<current-user-privilege-set>
<privilege>
<read/>
</privilege>
<privilege>
<read-current-user-privilege-set/>
</privilege>
</current-user-privilege-set>
<displayname>teamclient1 addresses</displayname>
<C:getctag>"edc1a74f98499d4a547a7c23125cabf2"</C:getctag>
<owner>
<href>/caldav.php/teamclient1/</href>
</owner>
<resource-id>
<href>/caldav.php/.resources/750</href>
</resource-id>
<resourcetype>
<collection/>
<C2:addressbook/>
</resourcetype>
<C1:schedule-default-calendar-URL>
<href>/caldav.php/teamclient1/home/</href>
</C1:schedule-default-calendar-URL>
<supported-report-set>
<supported-report>
<report>
<principal-property-search/>
</report>
</supported-report>
<supported-report>
<report>
<principal-search-property-set/>
</report>
</supported-report>
<supported-report>
<report>
<expand-property/>
</report>
</supported-report>
<supported-report>
<report>
<principal-match/>
</report>
</supported-report>
<supported-report>
<report>
<sync-collection/>
</report>
</supported-report>
<supported-report>
<report>
<C2:addressbook-query/>
</report>
</supported-report>
<supported-report>
<report>
<C2:addressbook-multiget/>
</report>
</supported-report>
</supported-report-set>
<sync-token>data:,9</sync-token>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
<response>
<href>/caldav.php/teamclient1/calendar-proxy-read/</href>
<propstat>
<prop>
<add-member>
<href>/caldav.php/teamclient1/calendar-proxy-read/?add_member</href>
</add-member>
<current-user-privilege-set>
<privilege>
<read/>
</privilege>
<privilege>
<read-current-user-privilege-set/>
</privilege>
<privilege>
<C1:read-free-busy/>
</privilege>
</current-user-privilege-set>
<displayname>/teamclient1/calendar-proxy-read/</displayname>
<C:getctag>"bfc43198a490f445e8676ca22863d1f1"</C:getctag>
<owner>
<href>/caldav.php/teamclient1/</href>
</owner>
<resourcetype>
<principal/>
<collection/>
<C:calendar-proxy-read/>
</resourcetype>
<C1:schedule-default-calendar-URL>
<href>/caldav.php/teamclient1/home/</href>
</C1:schedule-default-calendar-URL>
<supported-report-set>
<supported-report>
<report>
<principal-property-search/>
</report>
</supported-report>
<supported-report>
<report>
<principal-search-property-set/>
</report>
</supported-report>
<supported-report>
<report>
<expand-property/>
</report>
</supported-report>
<supported-report>
<report>
<principal-match/>
</report>
</supported-report>
<supported-report>
<report>
<sync-collection/>
</report>
</supported-report>
<supported-report>
<report>
<C1:calendar-query/>
</report>
</supported-report>
<supported-report>
<report>
<C1:calendar-multiget/>
</report>
</supported-report>
<supported-report>
<report>
<C1:free-busy-query/>
</report>
</supported-report>
<supported-report>
<report>
<C2:addressbook-query/>
</report>
</supported-report>
<supported-report>
<report>
<C2:addressbook-multiget/>
</report>
</supported-report>
</supported-report-set>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
<response>
<href>/caldav.php/teamclient1/calendar-proxy-write/</href>
<propstat>
<prop>
<add-member>
<href>/caldav.php/teamclient1/calendar-proxy-write/?add_member</href>
</add-member>
<current-user-privilege-set>
<privilege>
<read/>
</privilege>
<privilege>
<read-current-user-privilege-set/>
</privilege>
<privilege>
<C1:read-free-busy/>
</privilege>
</current-user-privilege-set>
<displayname>/teamclient1/calendar-proxy-write/</displayname>
<C:getctag>"f869e3b42c47170cd27adae8494859f3"</C:getctag>
<owner>
<href>/caldav.php/teamclient1/</href>
</owner>
<resourcetype>
<principal/>
<collection/>
<C:calendar-proxy-write/>
</resourcetype>
<C1:schedule-default-calendar-URL>
<href>/caldav.php/teamclient1/home/</href>
</C1:schedule-default-calendar-URL>
<supported-report-set>
<supported-report>
<report>
<principal-property-search/>
</report>
</supported-report>
<supported-report>
<report>
<principal-search-property-set/>
</report>
</supported-report>
<supported-report>
<report>
<expand-property/>
</report>
</supported-report>
<supported-report>
<report>
<principal-match/>
</report>
</supported-report>
<supported-report>
<report>
<sync-collection/>
</report>
</supported-report>
<supported-report>
<report>
<C1:calendar-query/>
</report>
</supported-report>
<supported-report>
<report>
<C1:calendar-multiget/>
</report>
</supported-report>
<supported-report>
<report>
<C1:free-busy-query/>
</report>
</supported-report>
<supported-report>
<report>
<C2:addressbook-query/>
</report>
</supported-report>
<supported-report>
<report>
<C2:addressbook-multiget/>
</report>
</supported-report>
</supported-report-set>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
</multistatus>

View File

@ -6,10 +6,13 @@
#
TYPE=PROPFIND
URL=http://regression.host/caldav.php/user4
AUTH=user4:user4
URL=http://regression.host/caldav.php/teamclient1
AUTH=user1:user1
HEADER=User-Agent: DAViCalTester/public
HEADER=Brief: t
HEADER=Depth: 1
HEADER=Prefer: return=minimal
HEAD
BEGINDATA