public async Task GetSucceedsAccessToLockedDocumentTest() { var response = await Client.LockAsync( "/test1.txt", WebDavTimeoutHeaderValue.CreateInfiniteWebDavTimeout(), WebDavDepthHeaderValue.Zero, new LockInfo() { LockScope = LockScope.CreateExclusiveLockScope(), LockType = LockType.CreateWriteLockType(), }).ConfigureAwait(false); var prop = await WebDavResponseContentParser.ParsePropResponseContentAsync(response.EnsureSuccessStatusCode().Content).ConfigureAwait(false); Assert.NotNull(prop.LockDiscovery); Assert.Collection( prop.LockDiscovery.ActiveLock, activeLock => { Assert.Equal("/test1.txt", activeLock.LockRoot.Href); Assert.Equal(WebDavDepthHeaderValue.Zero.ToString(), activeLock.Depth, StringComparer.OrdinalIgnoreCase); Assert.IsType <Exclusive>(activeLock.LockScope.Item); Assert.Null(activeLock.OwnerRaw); Assert.Equal(WebDavTimeoutHeaderValue.CreateInfiniteWebDavTimeout().ToString(), activeLock.Timeout, StringComparer.OrdinalIgnoreCase); Assert.NotNull(activeLock.LockToken?.Href); Assert.True(Uri.IsWellFormedUriString(activeLock.LockToken.Href, UriKind.RelativeOrAbsolute)); }); var ct = CancellationToken.None; var getResponse = await Client.GetAsync("/test1.txt", ct).ConfigureAwait(false); getResponse.EnsureSuccessStatusCode(); }
public async Task AddLockToRootRecursiveWithPrincipalOwnerTest() { var response = await Client.LockAsync( "/", WebDavTimeoutHeaderValue.CreateInfiniteWebDavTimeout(), WebDavDepthHeaderValue.Infinity, new LockInfo() { LockScope = LockScope.CreateExclusiveLockScope(), LockType = LockType.CreateWriteLockType(), OwnerRaw = new XElement("{DAV:}owner", "principal"), }) ; var prop = await WebDavResponseContentParser.ParsePropResponseContentAsync(response.EnsureSuccessStatusCode().Content); Assert.Collection( prop.LockDiscovery.ActiveLock, activeLock => { Assert.Equal("/", activeLock.LockRoot.Href); Assert.Equal(WebDavDepthHeaderValue.Infinity.ToString(), activeLock.Depth, StringComparer.OrdinalIgnoreCase); Assert.IsType <Exclusive>(activeLock.LockScope.Item); Assert.Equal("<owner xmlns=\"DAV:\">principal</owner>", activeLock.OwnerRaw.ToString(SaveOptions.DisableFormatting)); Assert.Equal(WebDavTimeoutHeaderValue.CreateInfiniteWebDavTimeout().ToString(), activeLock.Timeout, StringComparer.OrdinalIgnoreCase); Assert.NotNull(activeLock.LockToken?.Href); Assert.True(Uri.IsWellFormedUriString(activeLock.LockToken.Href, UriKind.RelativeOrAbsolute)); }); }
public async Task UT_WebDavSession_LockSingleFile() { var testFileToLock = UriHelper.CombineUrl(WebDavRootFolder, TestFile, true); var lockRequestContent = "<?xml version=\"1.0\" encoding=\"utf-8\"?><D:lockinfo xmlns:D=\"DAV:\"><D:lockscope><D:exclusive /></D:lockscope><D:locktype><D:write /></D:locktype></D:lockinfo>"; var lockResponseContent = "<?xml version=\"1.0\" encoding=\"utf-8\"?><D:prop xmlns:D=\"DAV:\"><D:lockdiscovery><D:activelock><D:locktype><D:write/></D:locktype><D:lockscope><D:exclusive/></D:lockscope><D:depth>infinity</D:depth><D:timeout>Infinite</D:timeout><D:locktoken><D:href>opaquelocktoken:d32688a4-478f-46eb-bcc4-cfe6129a207e.96bb01d2b440d8db</D:href></D:locktoken><D:lockroot><D:href>http://127.0.0.1/webdav/TextFile1.txt</D:href></D:lockroot></D:activelock></D:lockdiscovery></D:prop>"; var infiniteTimeout = WebDavTimeoutHeaderValue.CreateInfiniteWebDavTimeout(); var depth = WebDavDepthHeaderValue.Infinity; var mockHandler = new MockHttpMessageHandler(); var requestHeaders = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>(WebDavConstants.Depth, depth.ToString()), new KeyValuePair <string, string>(WebDavRequestHeader.Timeout, infiniteTimeout.ToString()) }; mockHandler.When(WebDavMethod.Lock, testFileToLock).WithHeaders(requestHeaders).WithContent(lockRequestContent).Respond(HttpStatusCode.OK, new StringContent(lockResponseContent)); using (var session = CreateWebDavSession(mockHandler)) { var success = await session.LockAsync(TestFile); Assert.IsTrue(success); } }
public async Task AddLockToRootAndTryRefreshTest() { var lockResponse = await Client.LockAsync( "/", WebDavTimeoutHeaderValue.CreateInfiniteWebDavTimeout(), WebDavDepthHeaderValue.Infinity, new LockInfo() { LockScope = LockScope.CreateExclusiveLockScope(), LockType = LockType.CreateWriteLockType(), }) ; lockResponse.EnsureSuccessStatusCode(); var prop = await WebDavResponseContentParser.ParsePropResponseContentAsync(lockResponse.Content); var lockToken = prop.LockDiscovery.ActiveLock.Single().LockToken; Assert.True(AbsoluteUri.TryParse(lockToken.Href, out var lockTokenUri)); var refreshResponse = await Client.RefreshLockAsync( "/", WebDavTimeoutHeaderValue.CreateInfiniteWebDavTimeout(), new LockToken(lockTokenUri)); refreshResponse.EnsureSuccessStatusCode(); var refreshProp = await WebDavResponseContentParser.ParsePropResponseContentAsync(refreshResponse.Content); Assert.NotNull(refreshProp.LockDiscovery); }
public async Task AddLockToRootRecursiveMinimumTest() { var response = await Client.LockAsync( "/", WebDavTimeoutHeaderValue.CreateInfiniteWebDavTimeout(), WebDavDepthHeaderValue.Infinity, new LockInfo() { LockScope = LockScope.CreateExclusiveLockScope(), LockType = LockType.CreateWriteLockType(), }); var prop = await WebDavResponseContentParser.ParsePropResponseContentAsync(response.EnsureSuccessStatusCode().Content); var lockToken = CodedUrlParser.Parse(response.Headers.GetValues(WebDavRequestHeader.LockToken).Single()); Assert.NotNull(prop.LockDiscovery); Assert.Collection( prop.LockDiscovery.ActiveLock, activeLock => { Assert.Equal("/", activeLock.LockRoot.Href); Assert.Equal(WebDavDepthHeaderValue.Infinity.ToString(), activeLock.Depth, StringComparer.OrdinalIgnoreCase); Assert.IsType <Exclusive>(activeLock.LockScope.Item); Assert.Null(activeLock.OwnerRaw); Assert.Equal(WebDavTimeoutHeaderValue.CreateInfiniteWebDavTimeout().ToString(), activeLock.Timeout, StringComparer.OrdinalIgnoreCase); Assert.NotNull(activeLock.LockToken?.Href); Assert.True(Uri.IsWellFormedUriString(activeLock.LockToken.Href, UriKind.RelativeOrAbsolute)); Assert.Equal(lockToken.OriginalString, activeLock.LockToken.Href); }); }
public async Task AddLockToRootAndQueryLockDiscoveryTest() { var lockResponse = await Client.LockAsync( "/", WebDavTimeoutHeaderValue.CreateInfiniteWebDavTimeout(), WebDavDepthHeaderValue.Infinity, new LockInfo() { LockScope = LockScope.CreateExclusiveLockScope(), LockType = LockType.CreateWriteLockType(), }) ; lockResponse.EnsureSuccessStatusCode(); var propFindResponse = await Client.PropFindAsync( "/", WebDavDepthHeaderValue.Zero, new PropFind() { Item = new Prop() { LockDiscovery = new LockDiscovery(), }, }); Assert.Equal(WebDavStatusCode.MultiStatus, propFindResponse.StatusCode); var multiStatus = await WebDavResponseContentParser.ParseMultistatusResponseContentAsync(propFindResponse.Content); Assert.Collection( multiStatus.Response, response => { Assert.Equal("/", response.Href); Assert.Collection( response.ItemsElementName, n => Assert.Equal(ItemsChoiceType.propstat, n)); Assert.Collection( response.Items, item => { var propStat = Assert.IsType <Propstat>(item); var status = WebDav.Server.Model.Status.Parse(propStat.Status); Assert.Equal(200, status.StatusCode); Assert.NotNull(propStat.Prop?.LockDiscovery?.ActiveLock); Assert.Collection( propStat.Prop.LockDiscovery.ActiveLock, activeLock => { Assert.Equal("/", activeLock.LockRoot.Href); Assert.Equal(WebDavDepthHeaderValue.Infinity.ToString(), activeLock.Depth, StringComparer.OrdinalIgnoreCase); Assert.IsType <Exclusive>(activeLock.LockScope.Item); Assert.Null(activeLock.OwnerRaw); Assert.Equal(WebDavTimeoutHeaderValue.CreateInfiniteWebDavTimeout().ToString(), activeLock.Timeout, StringComparer.OrdinalIgnoreCase); Assert.NotNull(activeLock.LockToken?.Href); Assert.True(Uri.IsWellFormedUriString(activeLock.LockToken.Href, UriKind.RelativeOrAbsolute)); }); }); }); }
public void UT_WebDavClient_RefreshLockAsync_WithoutLockToken() { var client = CreateWebDavClient(); var lockInfo = new LockInfo(); try { client.RefreshLockAsync(FakeUrl, WebDavTimeoutHeaderValue.CreateInfiniteWebDavTimeout(), null).Wait(); } catch (AggregateException ae) { Assert.AreEqual(ae.InnerException.GetType(), typeof(WebDavException)); } }
public void UT_WebDavClient_LockAsync_WithDepthOne() { var client = CreateWebDavClient(); var lockInfo = new LockInfo(); try { client.LockAsync(FakeUrl, WebDavTimeoutHeaderValue.CreateInfiniteWebDavTimeout(), WebDavDepthHeaderValue.One, lockInfo).Wait(); } catch (AggregateException ae) { Assert.AreEqual(ae.InnerException.GetType(), typeof(WebDavException)); } }
public async Task AddLockToRootAndTryRefreshWrongLockTest() { var lockResponse = await Client.LockAsync( "/", WebDavTimeoutHeaderValue.CreateInfiniteWebDavTimeout(), WebDavDepthHeaderValue.Infinity, new LockInfo() { LockScope = LockScope.CreateExclusiveLockScope(), LockType = LockType.CreateWriteLockType(), }) ; lockResponse.EnsureSuccessStatusCode(); Assert.True(AbsoluteUri.TryParse("urn:asasdasd", out var lockTokenUri)); var refreshResult = await Client.RefreshLockAsync( "/", WebDavTimeoutHeaderValue.CreateInfiniteWebDavTimeout(), new LockToken(lockTokenUri)); Assert.Equal(WebDavStatusCode.PreconditionFailed, refreshResult.StatusCode); }
public async Task GetAccessToLockedDocumentTest() { var response = await Client.LockAsync( "/test1.txt", WebDavTimeoutHeaderValue.CreateInfiniteWebDavTimeout(), WebDavDepthHeaderValue.Zero, new LockInfo() { LockScope = LockScope.CreateExclusiveLockScope(), LockType = LockType.CreateWriteLockType(), }).ConfigureAwait(false); response.EnsureSuccessStatusCode(); var lockToken = response.Headers.GetValues(WebDavRequestHeader.LockToken).Single(); var ct = CancellationToken.None; Client.DefaultRequestHeaders.Add("If", $"({lockToken})"); var getResponse = await Client.GetAsync( "/test1.txt", ct).ConfigureAwait(false); getResponse.EnsureSuccessStatusCode(); }
public void UT_WebDavClient_RefreshLockAsync_WithoutLockToken() { using (var client = CreateWebDavClient(new MockHttpMessageHandler())) { var lockInfo = new LockInfo(); Assert.ThrowsExceptionAsync <WebDavException>(() => client.RefreshLockAsync(WebDavRootFolder, WebDavTimeoutHeaderValue.CreateInfiniteWebDavTimeout(), null)); } }
public void UT_WebDavClient_LockAsync_WithDepthOne() { using (var client = CreateWebDavClient(new MockHttpMessageHandler())) { var lockInfo = new LockInfo(); Assert.ThrowsExceptionAsync <WebDavException>(() => client.LockAsync(WebDavRootFolder, WebDavTimeoutHeaderValue.CreateInfiniteWebDavTimeout(), WebDavDepthHeaderValue.One, lockInfo)); } }
public void UT_WebDavTimeoutHeaderValue_ToString_Infinite() { var wdthv = WebDavTimeoutHeaderValue.CreateInfiniteWebDavTimeout(); Assert.AreEqual(wdthv.ToString(), "Infinite"); }