src/server/plugins/postgresql/pgtest.c

branch
webdav
changeset 316
4090fc1b1c52
parent 315
b608b7aa43a6
child 317
09676b559091
equal deleted inserted replaced
315:b608b7aa43a6 316:4090fc1b1c52
91 ucx_test_register(suite, test_pg_vfs_rmdir); 91 ucx_test_register(suite, test_pg_vfs_rmdir);
92 92
93 ucx_test_register(suite, test_pg_webdav_create_from_resdata); 93 ucx_test_register(suite, test_pg_webdav_create_from_resdata);
94 ucx_test_register(suite, test_pg_prepare_tests); 94 ucx_test_register(suite, test_pg_prepare_tests);
95 ucx_test_register(suite, test_pg_webdav_propfind); 95 ucx_test_register(suite, test_pg_webdav_propfind);
96 ucx_test_register(suite, test_pg_webdav_propfind_allprop);
96 97
97 PGresult *result = PQexec(test_connection, "BEGIN"); 98 PGresult *result = PQexec(test_connection, "BEGIN");
98 PQclear(result); 99 PQclear(result);
99 } 100 }
100 } 101 }
154 property->status = status_code; 155 property->status = status_code;
155 xmlNode *value = n->children; 156 xmlNode *value = n->children;
156 if(value && value->type == XML_TEXT_NODE) { 157 if(value && value->type == XML_TEXT_NODE) {
157 property->value = sstrdup_a(a, scstr((const char*)value->content)).ptr; 158 property->value = sstrdup_a(a, scstr((const char*)value->content)).ptr;
158 } 159 }
159 sstr_t pname = sstrcat(3, sstr(property->prefix), S(":"), sstr(property->name)); 160 sstr_t pname = sstrcat(2, sstr(property->namespace), sstr(property->name));
160 ucx_map_sstr_put(properties, pname, property); 161 ucx_map_sstr_put(properties, pname, property);
161 free(pname.ptr); 162 free(pname.ptr);
162 } 163 }
163 n = n->next; 164 n = n->next;
164 } 165 }
564 UCX_TEST_BEGIN; 565 UCX_TEST_BEGIN;
565 566
566 // test data: 567 // test data:
567 // 568 //
568 // /propfind/ 569 // /propfind/
569 // /propfind/res1 (2 properties) 570 // /propfind/res1 (2 properties: test, prop2)
570 // /propfind/res2 (1 property) 571 // /propfind/res2 (1 property: test)
571 // /propfind/res3 572 // /propfind/res3
573 // /propfind/sub
574 // /propfind/sub/res4
572 575
573 int ret; 576 int ret;
574 // Test 1 577 // Test 1
575 init_test_webdav_method(&sn, &rq, &st, &pb, "PROPFIND", "/propfind/", PG_TEST_PROPFIND1); 578 init_test_webdav_method(&sn, &rq, &st, &pb, "PROPFIND", "/propfind/", PG_TEST_PROPFIND1);
576 rq->davCollection = create_test_pgdav(sn, rq); 579 rq->davCollection = create_test_pgdav(sn, rq);
586 TestResponse *r1 = ucx_map_cstr_get(ms->responses, "/propfind/"); 589 TestResponse *r1 = ucx_map_cstr_get(ms->responses, "/propfind/");
587 UCX_TEST_ASSERT(r1, "propfind1: missing /propfind/ response"); 590 UCX_TEST_ASSERT(r1, "propfind1: missing /propfind/ response");
588 591
589 UCX_TEST_ASSERT(ms->responses->count == 1, "propfind1: wrong response count"); 592 UCX_TEST_ASSERT(ms->responses->count == 1, "propfind1: wrong response count");
590 593
591 TestProperty *p = ucx_map_cstr_get(r1->properties, "D:resourcetype"); 594 TestProperty *p = ucx_map_cstr_get(r1->properties, "DAV:resourcetype");
592 UCX_TEST_ASSERT(p, "propfind1: missing property 'resourcetype'"); 595 UCX_TEST_ASSERT(p, "propfind1: missing property 'resourcetype'");
593 UCX_TEST_ASSERT(p->status == 200, "propfind1: wrong status code for property 'resourcetype'"); 596 UCX_TEST_ASSERT(p->status == 200, "propfind1: wrong status code for property 'resourcetype'");
594 597
595 p = ucx_map_cstr_get(r1->properties, "D:getlastmodified"); 598 p = ucx_map_cstr_get(r1->properties, "DAV:getlastmodified");
596 UCX_TEST_ASSERT(p, "propfind1: missing property 'getlastmodified'"); 599 UCX_TEST_ASSERT(p, "propfind1: missing property 'getlastmodified'");
597 UCX_TEST_ASSERT(p->status == 200, "propfind1: wrong status code for property 'getlastmodified'"); 600 UCX_TEST_ASSERT(p->status == 200, "propfind1: wrong status code for property 'getlastmodified'");
598 601
599 testutil_destroy_session(sn); 602 testutil_destroy_session(sn);
600 test_multistatus_destroy(ms); 603 test_multistatus_destroy(ms);
601 testutil_iostream_destroy(st); 604 testutil_iostream_destroy(st);
602 605
621 UCX_TEST_ASSERT(ms->responses->count == 5, "propfind2: wrong response count"); 624 UCX_TEST_ASSERT(ms->responses->count == 5, "propfind2: wrong response count");
622 625
623 r1 = ucx_map_cstr_get(ms->responses, "/propfind/res2"); 626 r1 = ucx_map_cstr_get(ms->responses, "/propfind/res2");
624 UCX_TEST_ASSERT(r1, "propfind2: missing /propfind/res2 response"); 627 UCX_TEST_ASSERT(r1, "propfind2: missing /propfind/res2 response");
625 628
629 p = ucx_map_cstr_get(r1->properties, "http://example.com/test");
630 UCX_TEST_ASSERT(p, "propfind2: missing property 'test'");
631 UCX_TEST_ASSERT(p->status == 200, "propfind2: wrong status code for property 'test'");
632 UCX_TEST_ASSERT(!strcmp(p->value, "res2test"), "propfind2: wrong property value");
633
634
626 testutil_destroy_session(sn); 635 testutil_destroy_session(sn);
627 test_multistatus_destroy(ms); 636 test_multistatus_destroy(ms);
628 testutil_iostream_destroy(st); 637 testutil_iostream_destroy(st);
629 638
630 639
634 rq->davCollection = create_test_pgdav(sn, rq); 643 rq->davCollection = create_test_pgdav(sn, rq);
635 pblock_nvinsert("depth", "infinity", rq->headers); 644 pblock_nvinsert("depth", "infinity", rq->headers);
636 645
637 ret = webdav_propfind(pb, sn, rq); 646 ret = webdav_propfind(pb, sn, rq);
638 647
639 printf("\n\n%.*s\n", (int)st->buf->size, st->buf->space); 648 //printf("\n\n%.*s\n", (int)st->buf->size, st->buf->space);
640 649
641 UCX_TEST_ASSERT(ret == REQ_PROCEED, "webdav_propfind (3) failed"); 650 UCX_TEST_ASSERT(ret == REQ_PROCEED, "webdav_propfind (3) failed");
642 651
643 ms = test_parse_multistatus(st->buf->space, st->buf->size); 652 ms = test_parse_multistatus(st->buf->space, st->buf->size);
644 UCX_TEST_ASSERT(ms, "propfind3: response is not valid xml"); 653 UCX_TEST_ASSERT(ms, "propfind3: response is not valid xml");
646 r1 = ucx_map_cstr_get(ms->responses, "/propfind/"); 655 r1 = ucx_map_cstr_get(ms->responses, "/propfind/");
647 UCX_TEST_ASSERT(r1, "propfind3: missing /propfind/ response"); 656 UCX_TEST_ASSERT(r1, "propfind3: missing /propfind/ response");
648 657
649 UCX_TEST_ASSERT(ms->responses->count == 6, "propfind3: wrong response count"); 658 UCX_TEST_ASSERT(ms->responses->count == 6, "propfind3: wrong response count");
650 659
660
661 r1 = ucx_map_cstr_get(ms->responses, "/propfind/res1");
662 UCX_TEST_ASSERT(r1, "propfind3: missing /propfind/sub/res1 response");
663
664 p = ucx_map_cstr_get(r1->properties, "http://example.com/test");
665 UCX_TEST_ASSERT(p, "propfind3: missing property 'test'");
666 UCX_TEST_ASSERT(p->status == 200, "propfind3: wrong status code for property 'test'");
667 UCX_TEST_ASSERT(!strcmp(p->value, "testvalue"), "propfind3: wrong property value");
668
669 p = ucx_map_cstr_get(r1->properties, "http://example.com/prop2");
670 UCX_TEST_ASSERT(p, "propfind3: missing property 'prop2'");
671 UCX_TEST_ASSERT(p->status == 200, "propfind3: wrong status code for property 'prop2'");
672 UCX_TEST_ASSERT(!strcmp(p->value, "value2"), "propfind3: wrong property value");
673
674
651 r1 = ucx_map_cstr_get(ms->responses, "/propfind/sub/res4"); 675 r1 = ucx_map_cstr_get(ms->responses, "/propfind/sub/res4");
652 UCX_TEST_ASSERT(r1, "propfind3: missing /propfind/sub/res4 response"); 676 UCX_TEST_ASSERT(r1, "propfind3: missing /propfind/sub/res4 response");
653 677
654 testutil_destroy_session(sn); 678 testutil_destroy_session(sn);
655 test_multistatus_destroy(ms); 679 test_multistatus_destroy(ms);
656 testutil_iostream_destroy(st); 680 testutil_iostream_destroy(st);
657 681
658 UCX_TEST_END; 682 UCX_TEST_END;
659 } 683 }
684
685
686 UCX_TEST(test_pg_webdav_propfind_allprop) {
687 Session *sn;
688 Request *rq;
689 TestIOStream *st;
690 pblock *pb;
691
692 UCX_TEST_BEGIN;
693
694 // test data:
695 //
696 // /propfind/
697 // /propfind/res1 (2 properties: test, prop2)
698 // /propfind/res2 (1 property: test)
699 // /propfind/res3
700 // /propfind/sub
701 // /propfind/sub/res4
702
703 int ret;
704 TestResponse *r1;
705 TestProperty *p;
706 // Test 1
707 init_test_webdav_method(&sn, &rq, &st, &pb, "PROPFIND", "/propfind/", PG_TEST_ALLPROP);
708 rq->davCollection = create_test_pgdav(sn, rq);
709 pblock_nvinsert("depth", "0", rq->headers);
710
711 ret = webdav_propfind(pb, sn, rq);
712
713 UCX_TEST_ASSERT(ret == REQ_PROCEED, "webdav_propfind (1) failed");
714
715 TestMultistatus *ms = test_parse_multistatus(st->buf->space, st->buf->size);
716 UCX_TEST_ASSERT(ms, "propfind1: response is not valid xml");
717
718 r1 = ucx_map_cstr_get(ms->responses, "/propfind/");
719 UCX_TEST_ASSERT(r1, "propfind1: missing /propfind/ response");
720 UCX_TEST_ASSERT(ms->responses->count == 1, "propfind1: wrong response count");
721
722 p = ucx_map_cstr_get(r1->properties, "DAV:resourcetype");
723 UCX_TEST_ASSERT(r1, "propfind1: missing resourcetype property");
724
725 testutil_destroy_session(sn);
726 test_multistatus_destroy(ms);
727 testutil_iostream_destroy(st);
728
729 // Test 2
730 init_test_webdav_method(&sn, &rq, &st, &pb, "PROPFIND", "/propfind/", PG_TEST_ALLPROP);
731 rq->davCollection = create_test_pgdav(sn, rq);
732 pblock_nvinsert("depth", "1", rq->headers);
733
734 ret = webdav_propfind(pb, sn, rq);
735
736 //printf("\n\n%.*s\n", (int)st->buf->size, st->buf->space);
737
738 UCX_TEST_ASSERT(ret == REQ_PROCEED, "webdav_propfind (2) failed");
739
740 ms = test_parse_multistatus(st->buf->space, st->buf->size);
741 UCX_TEST_ASSERT(ms, "propfind2: response is not valid xml");
742
743 r1 = ucx_map_cstr_get(ms->responses, "/propfind/");
744 UCX_TEST_ASSERT(r1, "propfind2: missing /propfind/ response");
745 UCX_TEST_ASSERT(ms->responses->count == 5, "propfind2: wrong response count");
746
747 r1 = ucx_map_cstr_get(ms->responses, "/propfind/res1");
748 UCX_TEST_ASSERT(r1, "propfind2: missing /propfind/res1 response");
749
750 p = ucx_map_cstr_get(r1->properties, "DAV:resourcetype");
751 UCX_TEST_ASSERT(r1, "propfind2: missing resourcetype property");
752 p = ucx_map_cstr_get(r1->properties, "http://example.com/test");
753 UCX_TEST_ASSERT(r1, "propfind2: missing test property");
754 p = ucx_map_cstr_get(r1->properties, "http://example.com/prop2");
755 UCX_TEST_ASSERT(r1, "propfind2: missing prop2 property");
756
757 UCX_TEST_ASSERT(ucx_map_cstr_get(ms->responses, "/propfind/res2"), "propfind2: missing /propfind/res2 response");
758 UCX_TEST_ASSERT(ucx_map_cstr_get(ms->responses, "/propfind/res3"), "propfind2: missing /propfind/res3 response");
759 UCX_TEST_ASSERT(ucx_map_cstr_get(ms->responses, "/propfind/sub/"), "propfind2: missing /propfind/sub response");
760
761 testutil_destroy_session(sn);
762 test_multistatus_destroy(ms);
763 testutil_iostream_destroy(st);
764
765 // Test 3
766 init_test_webdav_method(&sn, &rq, &st, &pb, "PROPFIND", "/propfind/", PG_TEST_ALLPROP);
767 rq->davCollection = create_test_pgdav(sn, rq);
768 pblock_nvinsert("depth", "infinity", rq->headers);
769
770 ret = webdav_propfind(pb, sn, rq);
771
772 UCX_TEST_ASSERT(ret == REQ_PROCEED, "webdav_propfind (2) failed");
773
774 ms = test_parse_multistatus(st->buf->space, st->buf->size);
775 UCX_TEST_ASSERT(ms, "propfind3: response is not valid xml");
776
777 r1 = ucx_map_cstr_get(ms->responses, "/propfind/");
778 UCX_TEST_ASSERT(r1, "propfind3: missing /propfind/ response");
779 UCX_TEST_ASSERT(ms->responses->count == 6, "propfind3: wrong response count");
780
781 r1 = ucx_map_cstr_get(ms->responses, "/propfind/res1");
782 UCX_TEST_ASSERT(r1, "propfind3: missing /propfind/res1 response");
783
784 p = ucx_map_cstr_get(r1->properties, "DAV:resourcetype");
785 UCX_TEST_ASSERT(r1, "propfind3: missing resourcetype property");
786 p = ucx_map_cstr_get(r1->properties, "http://example.com/test");
787 UCX_TEST_ASSERT(r1, "propfind3: missing test property");
788 p = ucx_map_cstr_get(r1->properties, "http://example.com/prop2");
789 UCX_TEST_ASSERT(r1, "propfind3: missing prop2 property");
790
791 UCX_TEST_ASSERT(ucx_map_cstr_get(ms->responses, "/propfind/res2"), "propfind3: missing /propfind/res2 response");
792 UCX_TEST_ASSERT(ucx_map_cstr_get(ms->responses, "/propfind/res3"), "propfind3: missing /propfind/res3 response");
793 UCX_TEST_ASSERT(ucx_map_cstr_get(ms->responses, "/propfind/sub/"), "propfind3: missing /propfind/sub response");
794 UCX_TEST_ASSERT(ucx_map_cstr_get(ms->responses, "/propfind/sub/res4"), "propfind3: missing /propfind/sub/res4 response");
795
796 testutil_destroy_session(sn);
797 test_multistatus_destroy(ms);
798 testutil_iostream_destroy(st);
799
800
801 UCX_TEST_END;
802 }
803

mercurial