public void MSWOPI_S19_TC05_PutFile_Fail409() { // Get the file URL. string fileUrl = this.AddFileToSUT(); // Get the WOPI URL. string wopiTargetFileUrl = WopiSutManageCodeControlAdapter.GetWOPIRootResourceUrl(fileUrl, WOPIRootResourceUrlType.FileLevel, TokenAndRequestUrlHelper.DefaultUserName, TokenAndRequestUrlHelper.DefaultPassword, TokenAndRequestUrlHelper.DefaultDomain); // Get the common header. WebHeaderCollection commonHeaders = HeadersHelper.GetCommonHeaders(wopiTargetFileUrl); string identifierForLock = Guid.NewGuid().ToString("N"); // Lock this file. WopiAdapter.Lock(wopiTargetFileUrl, commonHeaders, identifierForLock); try { // Get file content URL. string wopiFileContentsLevelUrl = TokenAndRequestUrlHelper.GetSubResourceUrl(wopiTargetFileUrl, WOPISubResourceUrlType.FileContentsLevel); // Get the common header. commonHeaders = HeadersHelper.GetCommonHeaders(wopiFileContentsLevelUrl); string exceptedUpdateContent = "WOPI PUT file test"; byte[] bodycontents = Encoding.UTF8.GetBytes(exceptedUpdateContent); string identifier = Guid.NewGuid().ToString("N"); int statusCode = 0; try { // Update a file on the WOPI server. WOPIHttpResponse httpWebResponseOfPutFile = WopiAdapter.PutFile(wopiFileContentsLevelUrl, commonHeaders, null, bodycontents, identifier); statusCode = httpWebResponseOfPutFile.StatusCode; } catch (WebException webEx) { HttpWebResponse errorResponse = this.GetErrorResponseFromWebException(webEx); statusCode = this.GetStatusCodeFromHTTPResponse(errorResponse); } // Verify MS-WOPI requirement: MS-WOPI_R690 this.Site.CaptureRequirementIfAreEqual( 409, statusCode, 690, @"[In PutFile] Status code ""409"" means ""Lock mismatch""."); } finally { // Release a lock for editing a file. commonHeaders = HeadersHelper.GetCommonHeaders(wopiTargetFileUrl); WopiAdapter.UnLock(wopiTargetFileUrl, commonHeaders, identifierForLock); } }
public void MSWOPI_S19_TC06_PutFile_Lock() { // Get the file URL. string fileUrl = this.AddFileToSUT(); // Get the WOPI URL. string wopiTargetFileUrl = WopiSutManageCodeControlAdapter.GetWOPIRootResourceUrl(fileUrl, WOPIRootResourceUrlType.FileLevel, TokenAndRequestUrlHelper.DefaultUserName, TokenAndRequestUrlHelper.DefaultPassword, TokenAndRequestUrlHelper.DefaultDomain); // Get file content URL. string wopiFileContentsLevelUrl = TokenAndRequestUrlHelper.GetSubResourceUrl(wopiTargetFileUrl, WOPISubResourceUrlType.FileContentsLevel); // Get the common header. WebHeaderCollection commonHeaders = HeadersHelper.GetCommonHeaders(wopiTargetFileUrl); string identifierForLock = Guid.NewGuid().ToString("N"); // Lock this file. WopiAdapter.Lock(wopiTargetFileUrl, commonHeaders, identifierForLock); try { // Get the common header. commonHeaders = HeadersHelper.GetCommonHeaders(wopiFileContentsLevelUrl); string exceptedUpdateContent = "WOPI PUT file test"; byte[] bodycontents = Encoding.UTF8.GetBytes(exceptedUpdateContent); // Update a file on the WOPI server with the identifier of Lock. WopiAdapter.PutFile(wopiFileContentsLevelUrl, commonHeaders, null, bodycontents, identifierForLock); // Get the common header. commonHeaders = HeadersHelper.GetCommonHeaders(wopiFileContentsLevelUrl); // Get a file. WOPIHttpResponse responseOfGetFile = WopiAdapter.GetFile(wopiFileContentsLevelUrl, commonHeaders, null); // Read message from response of GetFile. string actualUpdateContent = WOPIResponseHelper.ReadHTTPResponseBodyToString(responseOfGetFile); // Verify MS-WOPI requirement: MS-WOPI_R697 this.Site.CaptureRequirementIfAreEqual( exceptedUpdateContent, actualUpdateContent, 697, @"[In Processing Details] If the file is currently associated with a lock established by the Lock operation (see section 3.3.5.1.3) [or the UnlockAndRelock operation (see section 3.3.5.1.6)] the WOPI server MUST provide the matching lock value in order for this operation to succeed."); } finally { // Release a lock for editing a file. commonHeaders = HeadersHelper.GetCommonHeaders(wopiTargetFileUrl); WopiAdapter.UnLock(wopiTargetFileUrl, commonHeaders, identifierForLock); } }
public void MSWOPI_S19_TC05_PutFile_Fail409() { // Get the file URL. string fileUrl = this.AddFileToSUT(); // Get the WOPI URL. string wopiTargetFileUrl = WopiSutManageCodeControlAdapter.GetWOPIRootResourceUrl(fileUrl, WOPIRootResourceUrlType.FileLevel, TokenAndRequestUrlHelper.DefaultUserName, TokenAndRequestUrlHelper.DefaultPassword, TokenAndRequestUrlHelper.DefaultDomain); // Get the common header. WebHeaderCollection commonHeaders = HeadersHelper.GetCommonHeaders(wopiTargetFileUrl); string identifierForLock = Guid.NewGuid().ToString("N"); // Lock this file. WopiAdapter.Lock(wopiTargetFileUrl, commonHeaders, identifierForLock); try { // Get file content URL. string wopiFileContentsLevelUrl = TokenAndRequestUrlHelper.GetSubResourceUrl(wopiTargetFileUrl, WOPISubResourceUrlType.FileContentsLevel); // Get the common header. commonHeaders = HeadersHelper.GetCommonHeaders(wopiFileContentsLevelUrl); string exceptedUpdateContent = "WOPI PUT file test"; byte[] bodycontents = Encoding.UTF8.GetBytes(exceptedUpdateContent); string identifier = Guid.NewGuid().ToString("N"); int statusCode = 0; HttpWebResponse errorResponse = null; try { // Update a file on the WOPI server. WOPIHttpResponse httpWebResponseOfPutFile = WopiAdapter.PutFile(wopiFileContentsLevelUrl, commonHeaders, null, bodycontents, identifier); statusCode = httpWebResponseOfPutFile.StatusCode; } catch (WebException webEx) { errorResponse = this.GetErrorResponseFromWebException(webEx); statusCode = this.GetStatusCodeFromHTTPResponse(errorResponse); } // Verify MS-WOPI requirement: MS-WOPI_R690 this.Site.CaptureRequirementIfAreEqual( 409, statusCode, 690, @"[In PutFile] Status code ""409"" means ""Lock mismatch""."); if (Common.IsRequirementEnabled("MS-WOPI", 685003, this.Site)) { // Verify MS-WOPI requirement: MS-WOPI_R685003 this.Site.CaptureRequirementIfIsTrue( errorResponse.Headers.Get("X-WOPI-Lock") != null, 685003, @"[In PutFile] This header [X-WOPI-Lock] MUST be included when responding with the 409 status code. "); // Verify MS-WOPI requirement: MS-WOPI_R980001 this.Site.CaptureRequirementIfIsTrue( errorResponse.Headers.Get("X-WOPI-Lock") != null, 980001, @"[In PutFile] an X-WOPI-Lock response header containing the value of the current lock on the file MUST be included when using this response code [409]."); Boolean VerifyR685005 = false; for (int i = 0; i < errorResponse.Headers.Count; i++) { if (errorResponse.Headers.AllKeys[i] == "X-WOPI-Lock") { VerifyR685005 = true; break; } } // Verify MS-WOPI requirement: MS-WOPI_R685005 this.Site.CaptureRequirementIfIsTrue( VerifyR685005, 685005, @"[In PutFile] X-WOPI-Lock is a string."); } if (Common.IsRequirementEnabled("MS-WOPI", 685009001, this.Site)) { // Verify MS-WOPI requirement: MS-WOPI_R685009001 this.Site.CaptureRequirementIfIsTrue( string.IsNullOrEmpty(errorResponse.Headers.Get("X-WOPI-LockFailureReason")), 685009001, @"[In PutFile] Implementation does not include the header X-WOPI-LockFailureReason when responding with the 409 status code. (SharePoint Foundation 2010 and above follows this behavior)."); } if (Common.IsRequirementEnabled("MS-WOPI", 685012001, this.Site)) { // Verify MS-WOPI requirement: MS-WOPI_R685012001 this.Site.CaptureRequirementIfIsTrue( string.IsNullOrEmpty(errorResponse.Headers.Get("X-WOPI-LockedByOtherInterface")), 685012001, @"[In PutFile] Implementation does not include the header X-WOPI-LockedByOtherInterface when responding with the 409 status code. (SharePoint Foundation 2010 and above follows this behavior)."); } } finally { // Release a lock for editing a file. commonHeaders = HeadersHelper.GetCommonHeaders(wopiTargetFileUrl); WopiAdapter.UnLock(wopiTargetFileUrl, commonHeaders, identifierForLock); } }