public void PROPFIND_should_handle_empty_url_when_rewriting_response_href()
        {
            context.Setup(c => c.Request).Returns(request.Object);
            request.Setup(r => r.Url).Returns(new Uri("http://localhost/web/files/litmus"));

            var propFind = new PropfindRequest { PathInfo = "/" };
            provider.Setup(p => p.CheckExists(It.IsAny<string>())).Returns(true);

            var multiStatusResult = new MultiStatusResult();
            multiStatusResult.Responses.AddRange(new[] { new Response { Href = "/" }, new Response { Href = "/newFile" }});
            provider.Setup(p => p.Process(propFind)).Returns(multiStatusResult);

            var result = controller.Propfind(propFind) as MultiStatusResult;

            Assert.That(result, Is.SameAs(multiStatusResult));
            Assert.That(result.Responses.Count, Is.EqualTo(2));

            Assert.That(result.Responses[0].Href, Is.EqualTo("/web/files/litmus"));
            Assert.That(result.Responses[1].Href, Is.EqualTo("/web/files/litmus/newFile"));
        }
Ejemplo n.º 2
0
        public void adding_not_found_property_should_be_returned_in_xml()
        {
            var response = new Response { Href = "/public/litmus" };
            response.NotFound.Status = "HTTP/1.1 404 Not Found";
            response.NotFound.AddProperty("getlastmodified", null);
            var multiStatus = new MultiStatusResult();
            multiStatus.Responses.Add(response);
            var result = multiStatus.ToString();

            Assert.That(result, Is.EqualTo(@"<d:multistatus xmlns:d=""DAV:"">
              <d:response>
            <d:href>/public/litmus</d:href>
            <d:propstat>
              <d:prop>
            <d:getlastmodified />
              </d:prop>
              <d:status>HTTP/1.1 404 Not Found</d:status>
            </d:propstat>
              </d:response>
            </d:multistatus>"));
        }
Ejemplo n.º 3
0
        public void adding_last_modified_property_should_be_returned_in_xml()
        {
            var response = new Response { Href = "/public/litmus" };
            response.Found.Status = "HTTP/1.1 200 OK";
            var dateTime = new DateTime(2012, 4, 23, 23, 09, 47);
            response.Found.AddLastModified(dateTime);
            var multiStatus = new MultiStatusResult();
            multiStatus.Responses.Add(response);
            var result = multiStatus.ToString();

            Assert.That(result, Is.EqualTo(@"<d:multistatus xmlns:d=""DAV:"">
              <d:response>
            <d:href>/public/litmus</d:href>
            <d:propstat>
              <d:prop>
            <d:getlastmodified>Mon, 23 Apr 2012 23:09:47 GMT</d:getlastmodified>
              </d:prop>
              <d:status>HTTP/1.1 200 OK</d:status>
            </d:propstat>
              </d:response>
            </d:multistatus>"));
            Assert.That(response.Found.LastModified, Is.EqualTo(dateTime));
        }
Ejemplo n.º 4
0
        public void adding_found_property_should_be_returned_in_xml()
        {
            var response = new Response { Href = "/public/litmus" };
            response.Found.Status = "HTTP/1.1 200 OK";
            XNamespace dateNs = "urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882";
            response.Found.AddProperty("getlastmodified", "Mon, 23 Apr 2012 23:09:47 GMT")
                          .SetAttributeValue(dateNs + "dt", "dateTime.rfc1123");
            var multiStatus = new MultiStatusResult();
            multiStatus.Responses.Add(response);
            var result = multiStatus.ToString();

            Assert.That(result, Is.EqualTo(@"<d:multistatus xmlns:d=""DAV:"">
              <d:response>
            <d:href>/public/litmus</d:href>
            <d:propstat>
              <d:prop>
            <d:getlastmodified p5:dt=""dateTime.rfc1123"" xmlns:p5=""urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882"">Mon, 23 Apr 2012 23:09:47 GMT</d:getlastmodified>
              </d:prop>
              <d:status>HTTP/1.1 200 OK</d:status>
            </d:propstat>
              </d:response>
            </d:multistatus>"));
        }
Ejemplo n.º 5
0
        public void mark_response_as_a_collection_should_be_returned_in_xml()
        {
            var response = new Response { Href = "/public/litmus" };
            response.Found.Status = "HTTP/1.1 200 Found";
            response.Found.AddResourceType(true);
            var multiStatus = new MultiStatusResult();
            multiStatus.Responses.Add(response);
            var result = multiStatus.ToString();

            Assert.That(result, Is.EqualTo(@"<d:multistatus xmlns:d=""DAV:"">
              <d:response>
            <d:href>/public/litmus</d:href>
            <d:propstat>
              <d:prop>
            <d:resourcetype>
              <d:collection />
            </d:resourcetype>
              </d:prop>
              <d:status>HTTP/1.1 200 Found</d:status>
            </d:propstat>
              </d:response>
            </d:multistatus>"));
            Assert.That(response.Found.IsCollection, Is.True);
        }
Ejemplo n.º 6
0
        public void set_content_length_property()
        {
            var response = new Response { Href = "/public/litmus" };
            response.Found.Status = "HTTP/1.1 200 Found";
            response.Found.AddContentLength(4096);
            var multiStatus = new MultiStatusResult();
            multiStatus.Responses.Add(response);
            var result = multiStatus.ToString();

            Assert.That(result, Is.EqualTo(@"<d:multistatus xmlns:d=""DAV:"">
              <d:response>
            <d:href>/public/litmus</d:href>
            <d:propstat>
              <d:prop>
            <d:getcontentlength>4096</d:getcontentlength>
              </d:prop>
              <d:status>HTTP/1.1 200 Found</d:status>
            </d:propstat>
              </d:response>
            </d:multistatus>"));
            Assert.That(response.Found.ContentLength, Is.EqualTo(4096));
        }
Ejemplo n.º 7
0
        public void print_empty_status_result()
        {
            var multiStatus = new MultiStatusResult();
            var result = multiStatus.ToString();

            Assert.That(result, Is.EqualTo(@"<d:multistatus xmlns:d=""DAV:"" />"));
        }
Ejemplo n.º 8
0
        public void namespaced_properties_should_be_returned_in_xml()
        {
            var response = new Response { Href = "/public/litmus" };
            response.Found.Status = "HTTP/1.1 200 Found";
            response.Found.AddProperty("http://example.com/neon/litmus/", "foo", null);
            var multiStatus = new MultiStatusResult();
            multiStatus.Responses.Add(response);
            var result = multiStatus.ToString();

            Assert.That(result, Is.EqualTo(@"<d:multistatus xmlns:d=""DAV:"">
              <d:response>
            <d:href>/public/litmus</d:href>
            <d:propstat>
              <d:prop>
            <foo xmlns=""http://example.com/neon/litmus/"" />
              </d:prop>
              <d:status>HTTP/1.1 200 Found</d:status>
            </d:propstat>
              </d:response>
            </d:multistatus>"));
        }
        public void PROPFIND_should_not_fail_on_empty_input_stream()
        {
            request.Setup(r => r.ContentLength).Returns(0);
            request.Setup(r => r.Headers).Returns(new NameValueCollection());
            context.Setup(c => c.Request).Returns(request.Object);

            provider.Setup(p => p.CheckExists(It.IsAny<string>())).Returns(true);
            var multiStatusResult = new MultiStatusResult();

            //empty propfind should return all dav properties
            provider.Setup(p => p.Process(It.IsAny<PropfindRequest>())).Callback<PropfindRequest>(r =>
            {
                Assert.That(r.HasGetContentLength, Is.True);
                Assert.That(r.HasGetLastModified, Is.True);
                Assert.That(r.HasResourceType, Is.True);
                Assert.That(r.NonDavProperties.Any(), Is.False);
                Assert.That(r.DavProperties.Any(), Is.False);
            }).Returns(multiStatusResult);

            var result = controller.Propfind("litmus/");

            Assert.That(result, Is.Not.Null);
            Assert.That(result, Is.SameAs(multiStatusResult));
        }
        public void PROPFIND_should_rewrite_urls_relative_to_web_host()
        {
            context.Setup(c => c.Request).Returns(request.Object);
            request.Setup(r => r.Url).Returns(new Uri("http://localhost/web/files/litmus/"));

            var propFind = new PropfindRequest("/litmus/", null);
            provider.Setup(p => p.CheckExists("/litmus/")).Returns(true);

            var multiStatusResult = new MultiStatusResult();
            multiStatusResult.Responses.AddRange(new [] { new Response { Href = "litmus/test" }, new Response { Href = "litmus/test2" }});
            provider.Setup(p => p.Process(propFind)).Returns(multiStatusResult);

            var result = controller.Propfind(propFind) as MultiStatusResult;

            Assert.That(result, Is.SameAs(multiStatusResult));
            Assert.That(result.Responses.Count, Is.EqualTo(2));

            Assert.That(result.Responses[0].Href, Is.EqualTo("/web/files/litmus/test"));
            Assert.That(result.Responses[1].Href, Is.EqualTo("/web/files/litmus/test2"));
        }
        public void PROPFIND_should_return_status_for_directory()
        {
            var request = new PropfindRequest { PathInfo = "/litmus/" };
            request.DavProperties.AddRange(new[] { "getcontentlength" });
            XNamespace ns = "urn:someNamespace";
            request.NonDavProperties.Add(new XElement(ns + "test"));

            provider.Setup(p => p.CheckExists("/litmus/")).Returns(true);
            var multiStatusResult = new MultiStatusResult();
            provider.Setup(p => p.Process(request)).Returns(multiStatusResult);

            var result = controller.Propfind(request) as MultiStatusResult;

            Assert.That(result, Is.Not.Null);
            Assert.That(result, Is.SameAs(multiStatusResult));
        }
Ejemplo n.º 12
0
        void Process(PropfindRequest request, string relativePath, int currentDepth, MultiStatusResult multiStatus)
        {
            var fullPath = GetFullPath(relativePath);

            var response = new Response { Href = relativePath };
            multiStatus.Responses.Add(response);
            var isACollection = IsACollection(fullPath);

            if (request.HasGetContentLength)
            {
                if (isACollection)
                    response.NotFound.AddProperty("getcontentlength", null);
                else
                    response.Found.AddContentLength(new FileInfo(fullPath).Length);
            }

            if (request.HasGetLastModified) {
                if (isACollection)
                    response.Found.AddLastModified(Directory.GetLastWriteTimeUtc(fullPath));
                else
                    response.Found.AddLastModified(File.GetLastWriteTimeUtc(fullPath));
            }

            if (request.HasResourceType)
                response.Found.AddResourceType(isACollection);

            if (response.Found.Properties.Any())
                response.Found.Status = "HTTP/1.1 200 OK";

            var supportedProperties = new[] { "getcontentlength", "getlastmodified", "resourcetype" };
            foreach (var prop in request.DavProperties.Where(p => !supportedProperties.Contains(p)))
                response.NotFound.AddProperty(prop, null);

            response.NotFound.Properties.AddRange(request.NonDavProperties);

            if (response.NotFound.Properties.Any())
                response.NotFound.Status = "HTTP/1.1 404 Not Found";

            if (currentDepth == 0)
                return;

            if (isACollection)
            {
                //process files
                var files = Directory.GetFiles(fullPath);
                foreach (var file in files)
                    Process(request, JoinRelativePath(relativePath, Path.GetFileName(file)), 0, multiStatus);

                //process directories
                var dirs = Directory.GetDirectories(fullPath);
                foreach (var dir in dirs)
                    Process(request, JoinRelativePath(relativePath, Path.GetFileName(dir)) + "/", currentDepth - 1, multiStatus);
            }
        }
Ejemplo n.º 13
0
        public MultiStatusResult Process(PropfindRequest request)
        {
            var multiStatus = new MultiStatusResult();

            var relativePath = request.PathInfo.StartsWith("/") ? request.PathInfo : "/" + request.PathInfo;

            Process(request, relativePath, request.Depth, multiStatus);

            return multiStatus;
        }