Giter Club home page Giter Club logo

wopi-validator-core's Introduction

WOPI Validator

AppVeyor

Travis

This project contains the core logic of the WOPI validator as well as a command-line interface to it.

Building the project

The project can be built in Visual Studio 2017, Visual Studio Code, or using dotnet build:

dotnet build -c Release

The resulting build will be output to src\WopiValidator\bin\Release\net6.0\. Omit the -c Release portion if you want to build the debug version instead.

Building a self-contained package

To build a self-contained package for Linux or macOS, use the dotnet publish command:

dotnet publish -c Release -f net6.0 -r linux-x64
dotnet publish -c Release -f net6.0 -r osx-x64
dotnet publish -c Release -f net6.0 -r win-x64

Note: you may see an error on build like this:

error MSB3030: Could not copy the file "obj\Release\net6.0\win-x64\Microsoft.Office.WopiValidator.dll"
because it was not found.

If you see this error, you should re-build the app using the same -r option used in the publish command. For example, if you were trying to package the Linux self-contained package, first build the app using dotnet build -c Release -r linux-x64, then publish it using dotnet publish -c Release -r linux-x64.

The output will be placed in src/WopiValidator/bin/Release/net6.0/linux-x64/publish (replace linux-x64 with other platforms as needed).

Running tests

Basic unit tests can be run using the dotnet test command:

dotnet test ./test/WopiValidator.Core.Tests/WopiValidator.Core.Tests.csproj -c Release

Packing the NuGet package

From the root of the project, use the following command:

dotnet pack -c Release

The package will be output to src\WopiValidator\bin\Release\WopiValidator.1.0.0-local.nupkg

Note: if you see any errors, you may need to build the project first, as described above.

Usage

There are several ways to run the validator.

Option 1: dotnet

After building the projects as described above, you can run the resulting Microsoft.Office.WopiValidator.dll using the dotnet command. For example:

dotnet Microsoft.Office.WopiValidator.dll --token MyAccessToken --token_ttl 0 --wopisrc http://localhost:5000/wopi/files/<id> --testcategory OfficeOnline --ignore-skipped

Note: the Microsoft.Office.WopiValidator.dll file can be found in src\WopiValidator\bin\Release\netcoreapp2.0\.

Option 2: dotnet run --project

You can also use the dotnet run command, passing the path to the WopiValidator.csproj file using the --project option. Arguments to the validator itself can be passed in by separating them from the dotnet run arguments with a --. For example:

dotnet run --project ./src/WopiValidator/WopiValidator.csproj --framework net6.0 -- -t MyAccessToken -l 0 -w http://localhost:5000/wopi/files/<id> -e OfficeOnline -s

Option 3: self-contained package

Another option is to build a self-contained package for your OS (see above) and execute the resulting executable file, which be called Microsoft.Office.Validator.exe on Windows and Microsoft.Office.Validator on Linux and macOS. Arguments to the validator can be passed in directly. For example:

Microsoft.Office.Validator.exe -t MyAccessToken -l 0 -w http://localhost:5000/wopi/files/<id> -e OfficeOnline -s

Full usage options

Microsoft.Office.WopiValidator 1.0.0
Copyright (C) 2018 Microsoft

  -w, --wopisrc           Required. WopiSrc URL for a wopitest file

  -t, --token             Required. WOPI access token

  -l, --token_ttl         Required. WOPI access token ttl

  -c, --config            (Default: runConfig.xml) Path to XML file with test definitions

  -g, --testgroup         Run only the tests in the specified group (cannot be used with testname)

  -n, --testname          Run only the test specified (cannot be used with testgroup)

  -e, --testcategory      (Default: All) Run only the tests in the specified category

  -s, --ignore-skipped    Don't output any info about skipped tests

  -d, --include-delaytests    Run test cases with delay

  --help                  Display this help screen.

  --version               Display version information.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

wopi-validator-core's People

Contributors

ataillefer avatar borisf-msft avatar deepdiver1975 avatar marcinjuraszek avatar microsoft-github-policy-service[bot] avatar msftgits avatar nisha-singh avatar niulongjia avatar petmat avatar shaharso avatar thomaslevesque avatar tylerbutler avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wopi-validator-core's Issues

X-WOPI-Proof and X-WOPI-ProofOld not sended into http request

ProofKeys section of tests fail because my server not receive the X-WOPI-Proof and X-WOPI-ProofOld HTTP headers.

Step for reproduce

  1. clone this repo and compiled into exe with Visual Studio 2015.

  2. run this command

Microsoft.Office.WopiValidator.exe -t MYTOKEN -l 0 -w http://localhost:3000/api/wopi/files/5d8488e930a07d2218d89d35  -e OfficeOnline -s -g ProofKeys

Test ProofKeys fails.

These are the received headers (only 2):

Authorization: Bearer eyJvIjoiQUU5RENGMTQ0MkNDMkUyM0ZBRUE2Mjk1MTg4NzI3QzgiLCJlIjoiRHROT2NHQ2o4NFM1TVhMVkU4VVlqeVNoWmp1cHFtbGMiLCJpIjoiNWQ4NDg4ZTkzMGEwN2QyMjE4ZDg5ZDM1In0=
Host: localhost:3000

no X-WOPI-Proof and X-WOPI-ProofOld headers.

What i'm doing wrong?

Support exit code

When integrating this tool into a CI system it would be great if this tool would return different exit codes depending on the state of the test cases which have been executed.

Would that be possible? THX

Add better logging support

There is minimal logging support in the validator, but it is a custom interface (though it's simple). Integration with Extensions.Logging would enable package consumers to wire up their own log system, too.

FileUrlUsagePrereq should include a validator for SupportsUpdate and SupportsLocks

I have a read-only WOPI host implementation. The CheckFileInfo endpoint returns a FileUrl, because it's possible to access the file without calling the GetFile endpoint. Because this property is present, the FileUrlUsage test group is executed, and it fails because it attempts to use Lock and PutFile, which my host doesn't implement.

The pre-requisites for FileUrlUsage should include SupportsUpdate and SupportsLock if it's going to use them.

Also, I think the test suite should include a read-only scenario for FileUrl.

WopiTimestampOlderThan20Min test can have false positives

The problem is that we sign the requests in the validator using the wall-clock time, not the X-WOPI-Timestamp header we actually send in the request.

This means that when a host gets the request, it is not signed properly, because it was signed with a different Timestamp than the value on the request. So the host correctly returns a 500, but for the wrong reason. They should be returning a 500 because the X-WOPI-Timestamp value is older than 20 minutes, but they might also return a 500 simply because the proofs don't match due to the timestamp discrepancy.

The fix would be to ensure we're using the timestamp value that we use on the request when actually signing the request. That will ensure that when hosts check the proof, the signature will be correct, and if they still pass the test, it implies they're not checking the timestamp per the spec.

Support using truly random file content in PutFile requests that can later be verified

As of now I'm using the file's modification time and the file's content hash as version.

I think this is a quite reasonable implementation ...

But the tests are sometimes failing because the test tool puts identical content in consecutive calls.
https://github.com/Microsoft/wopi-validator-core/blob/e0ede96728f92b011c6c622c6945a265d3403b04/src/WopiValidator.Core/ResourceManagement/Resource.cs#L30

I'd propose to transmit some random generated file content.

Any objections? THX

Test Against Office Online Server

Hi
How do I test against OOS.
What do i put into the Discovery
Does the wopitest doc have to include anything in particular.

Thanks

EnumerateChildren tests don't verify that filtering is actually done

The containers.EnumerateChildrenWithOneFilter and containers.EnumerateChildrenWithMultipleFilters tests don't actually verify that the filtering is done by the server. If that can't be done in the validator, it doesn't make much sense to have the tests, since a host who's not implemented filtering at all will still pass those tests.

Determine the fate of the proof key tests

The proof key tests can’t work as-is because there’s no signing key. We can disable the tests, but I think a better fix would be to provide a dummy WOPI discovery XML file in this repo and expose a key there. It could be a fixed key since it’s only used for testing.

GetProofData throws ArgumentNullException if accesstoken is missing on the WopiRequest

System.ArgumentNullException: String reference not set to an instance of a String.
Parameter name: s
   at System.Text.Encoding.GetBytes(String s)
   at WopiValidator.Core.ProofKeysHelper.GetProofData(ProofKeyInput proofData)
   at WopiValidator.Core.ProofKeysHelper.GetSignedProofData(ProofKeyInput proofData, RSACryptoServiceProvider rsaAlg)
   at WopiValidator.Core.Requests.WopiRequest.GetProofKeyHeaders(String accessToken, Uri endpointUri, RSACryptoServiceProvider proofKeyProviderNew, RSACryptoServiceProvider proofKeyProviderOld)
   at WopiValidator.Core.Requests.WopiRequest.Execute(String endpointAddress, String accessToken, Int64 accessTokenTtl, ITestCase testCase, Dictionary`2 savedState, IResourceManager resourceManager, String userAgent, RSACryptoServiceProvider proofKeyProviderNew, RSACryptoServiceProvider proofKeyProviderOld)
   at WopiValidator.Core.TestCaseExecutor.ExecuteTestCase(ITestCase testCase)
   at Microsoft.Office.Web.WopiTestService.ExecuteTestMethod.ProcessRequest(HttpContext context)

Notes from chrisbro-MSFT:

I bet the Url property of the ContainerInfo objects returned by /files/EnumerateAncestors does not include an AccessToken. There are only two calls to GetBytes in ProofKeyHelper.GetProofData() and one of them is on a field that couldn’t be null or we would have crashed already. So it has to be access token. And that test is defined like so:

<Requests>
       <EnumerateAncestors>
              <SaveState>
                     <State Name="ParentContainerUrl" Source="AncestorsWithRootFirst[-1:].Url" />
              </SaveState>
       </EnumerateAncestors>
       <CheckContainer OverrideUrl="$State:ParentContainerUrl">

Have seen this a couple of times. Perhaps we should add a try..catch around WopiRequest.Execute() and have it return an IResponseData object that indicates the error. Test would still fail but it will fail properly and the request info can be seen in the inspector tabs.

Use different file extensions for PutRelativeFile tests

Some tests use the foox or wopitestfoox file extension when creating new files. These should be changed to use file extensions like docx or pptx. The files created are cleaned up so it's not a big deal that the files' extensions won't match their type.

Add tests for PutUserInfo operation

These tests should at least check the following:

  • PutUserInfo shouldn't return a 409 (rather, it should only return the status codes outlined in the docs)
  • PutUserInfo value is returned in subsequent Check calls

Test case: RenameFile should not replace the file extension

The RenameFile test cases do not currently check that the renamed file has the correct file extension. This is because the RenameFile request takes the filename without the extension, and the response also returns the filename without the extension.

To address this, we need to add a new test that also calls CheckFileInfo and verifies that the BaseFileName returned matches what we expect.

PutRelativeFile.IncludeHostUrls failes while no values provided

The test PutRelativeFile.IncludeHostUrls fails while no values are provided for HostEditUrl or HostViewUrl.

Those values are supposed to be optional therefore this test should not fail if no values are provided.
See: https://wopi.readthedocs.io/projects/wopirest/en/latest/files/PutRelativeFile.html#optional-response-properties
Either the specs are wrong or the test.

  Fail: PutRelativeFile.IncludeHostUrls
    PutRelativeFile, response code: 200 OK
      Incorrect value for 'HostEditUrl' property. Value is required but not provided.
      Incorrect value for 'HostViewUrl' property. Value is required but not provided.
    DeleteFile, response code: 0 0

Add RenameFile tests that don't require creating new files

The RenameFile tests currently require that the host implements either PutRelativeFile or CreateChildFile, because the test creates new files to rename, then deletes them.

We should consider changing the tests or adding new tests so that they don't rely on creating new files. This may have some unwanted side effects, so we should explore more.

PathOverride should be inserted before '?' if it exists

We have additional logic at backend checking licence by additional parameters in URL. This definitely working Ok with Office Server before. But to implement Office online integration we should validate our's endpoint with wopi-core-validator. And it failing on some tests.
Actual problem:
Url parsing in methods BuildWopiUri and GetEndpointAddressOverride not always working correctly. If Url will already contain ? with parameters Validator will add /contents in the end of URI string and will break it.
Example:
Executing command: Microsoft.Office.Validator.exe ... -w http://localhost:5000/wopi/files/1111?customerId=123
Will create a request to next url: http://localhost:5000/wopi/files/1111?customerId=123/contents
Solution:
Check in both methods if URL already contains ? than insert PathOverride before ? else add to the end.

UserPrincipalName is reported as an unknown property

The docs mention UserPrincipalName in the properties of the CheckFileInfo response, but the validator rejects it as an unknown property:

Fail: FullCheckFileInfoSchema
CheckFileInfo, response code: 200 OK
Unknown Properties: UserPrincipalName
Re-run command: .\wopivalidator.exe -n FullCheckFileInfoSchema -w http://localhost:13958/api/tenant/foobar/wopi/files/d3301821-fddc-4751-b49f-5396cd6c6d6e -t eyJhbGciOiJSUzI1NiIsImtpZCI6IjA1NTU0MDM1QTk2MjA4NjMzMjczNEEyM0VDNTUzQzExRjFENDlGRTMiLCJ4NXQiOiJCVlZBTmFsaUNHTXljMG9qN0ZVOEVmSFVuLU0iLCJ0eXAiOiJKV1QifQ.eyJzdWIiOiI3OGIzMjc2ZS1iNWZlLTQzMjctYTE2Ni0wYjViNjUxNjU0ZTQiLCJmaWxlSWQiOiJkMzMwMTgyMS1mZGRjLTQ3NTEtYjQ5Zi01Mzk2Y2Q2YzZkNmUiLCJwZXJtaXNzaW9uIjoiUmVhZCIsIm5iZiI6MTU3MjQ1MzU3MywiZXhwIjoxNTcyNDU3MTczLCJpYXQiOjE1NzI0NTM1NzN9.B_8njZ8s9e3H_UYfJTmK97HSU_JiyUB0A3R-4QAxhjqhMy-r10LtoFE8Ao3LB3KnqXW8x0StAzIX_PEHFmcEMaxKMYVf9t_32F1Ho4gdz_AMfSB65DxxHiOGKWz-WCR1g3cyqiIc88aln9bgFTIsB5mW9suB9W-aTaiEuSAl6TeyBmkZ5dysVrFIvSblHYa-iZ8bUN7HRTnBS3-ky0FdtuZA4sCxbWNrO_K10kc6aSQU9ROL7MQlfLMpJMkBgJ7yqrBv3DcxzlMqRN--DAPNbRybVpBZfkI5-zdAgeT4mHAlsNRlZ_0HMiXC-vThPFMM-qwS9BUIX30WWVW1azdncw -l 1572457173870

Which is correct, the docs or the validator?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.