microsoft / wopi-validator-core

A tool to test and validate server-side WOPI implementations
MIT License
42 stars 34 forks source link

PutUnlockedFile Fails because it doesn't send empty file #94

Closed Prototipo-Erick-Santander closed 1 year ago

Prototipo-Erick-Santander commented 4 years ago

The PutUnlockedFile test is failing because the resource "WordBlankDocument", doesn't return a 0 length stream nor does it lock a file first, and, since the docs say

"When a host receives a PutFile request on a file that is not locked, the host must check the current size of the file. If it is 0 bytes, the PutFile request should be considered valid and should proceed. If it is any value other than 0 bytes, or is missing altogether, the host should respond with a 409 Conflict. "

I deal with that situation as per the docs and send a 409 Conflict response when the stream.Length > 0 && lockValue.IsNullOrEmpty() but then the test fails.

From what I saw, the only resource that return a 0 length stream is the "ZeroByteFile.wopitest" but the resource being used for this test is "WordBlankDocument", as defined in the TestCases.xml

<TestCase Name="PutUnlockedFile" Category="WopiCore">
  <Description>
    Simulates creating a new file on the host, which requires PutFile requests to an unlocked 0-byte file to succeed.
  </Description>
  <Requests>
    <!-- Set up the test -->
    <Lock Lock="LockString" />
    <PutFile Lock="LockString" ResourceId="ZeroByteFile" />
    <Unlock Lock="LockString" />

    <!-- Execute the actual test -->
    <PutFile ResourceId="WordBlankDocument" />
    <GetFile>
      <Validators>
        <ResponseContentValidator ExpectedResourceId="WordBlankDocument" />
      </Validators>
    </GetFile>
  </Requests>
  <CleanupRequests>
    <!-- If any of the setup steps fail, subsequent requests won't be issued, leaving the file potentially locked, so unlock it here in a cleanup request. -->
    <Unlock Lock="LockString" />
  </CleanupRequests>
</TestCase>

The code of the Resource.cs Class

internal MemoryStream GetContentStream(ILogger logger)
{
    try
    {
        // Use the filename as the actual content of the stream, unless the FileName is
        // "ZeroByteFile.wopitest". This way we can still write out zero-byte files.
        MemoryStream result = new MemoryStream();
        StreamWriter sw = new StreamWriter(result);
        string fileContent = FileName == "ZeroByteFile.wopitest" ? string.Empty : ResourceId + FilePath + FileName;
        sw.Write(fileContent);
        sw.Flush();
        result.Seek(0, SeekOrigin.Begin);
        return result;
    }
    catch (IOException ex)
    {

        logger.Log("IO Exception when trying to get resource content.");
        logger.Log(ex.Message);
        return null;
    }
}

Is this a bug of the validator, are the docs wrong? What sould be my course of action here?

Thanks in advance.

hafeezsaleh commented 2 years ago

We are facing same issue with PutUnlockedFile test. "WordBlankDocument" doesn't return a 0 length stream.

Any updates regarding this ?

Prototipo-Erick-Santander commented 2 years ago

Unfortunately, due to the lack of response from the team I simply bypassed this test, and moved on from there, this said, if I'm not mistaken, they do say in the docs that the preferred way of testing is with online with a .wopitest file.

As such, I would advise using the executable for quick tests in the beginning and then moving on to online testing.

hafeezsaleh commented 2 years ago

Thanks for sharing. So you can confirm online testing don't have this issue for PutUnlockedFile scenario.

Prototipo-Erick-Santander commented 2 years ago

I can't say for sure, since I don't remember it that clearly, but I think it doesn't have the issue there.

jeyasithar commented 1 year ago

I got the same issue and resolved it. In my case the following was the scenario:

  1. WOPI send empty file (basically null body). (My system was originally throwing an exception in this place)
  2. I made empty strings write to the file if body is null
  3. Compare the existing file to be 0 to validate the test instead of the file being sent as 0 bytes.
  4. Issue resolved.
v-stefansi commented 1 year ago

We are in the process of closing WOPI Validator GitHub. If you still need help with this issue, please reach out to the CSPP partner Yammer channel or contact csppteam@microsoft.com.