drashland/wocket

HTTPS Integration tests not working (app_3001)

d4vsanchez opened this issue · 10 comments

The app_3001 is not working for two reasons:

  • Drash is not exported in the 'tests/deps.ts' file. (Easy to fix)
  • The WebSocket client created in the Drash Server is not changing its readyState from CONNECTING to OPEN. And sending the data to the socket in the CONNECTING state fails with a Sending fatal alert DecodeError exception.

To Reproduce
Steps to reproduce the first behavior:

  1. Run the app_3001 integration tests: deno test --allow-all tests/integration/app_3001/tests.ts.

Steps to reproduce the second behavior:

  1. Export the Drash module in the tests dependencies file: tests/deps.ts.
  2. Run the app_3001 integration tests: deno test --allow-all tests/integration/app_3001/tests.ts.

I'm exporting Drash with the following change in the tests/deps.ts file:

 export { Rhum } from "https://deno.land/x/rhum@v1.1.4/mod.ts";

+export { Drash } from "https://deno.land/x/drash@v1.2.5/mod.ts";
+
export { deferred } from "https://deno.land/std@0.74.0/async/deferred.ts";

Expected behavior
Tests must pass.

Suggested Solution(s)

  • First problem's solution I think is simple, Drash could be imported as above and that'll fix it.

  • Second problem is not that straightforward (at least for me). I tried setting a while loop and an "open" event listener to the clientSocket variable to check if the Socket would change its readyStatus to OPEN, but it never did. Moving the Socket to the test case, instead of having it on the Drash server worked OK (the "open" event listener was called), my two cents is that the return this.response; of the Drash server has any kind of problem with the async nature of the connection of the Socket and that function gets executed without expecting the OPEN connection status.

Screenshots

  • This is the error caused by not exporting Drash in the tests/deps.ts file:

Drash Dependency Error

  • This is the error caused because of the WebSocket client not changing its state to OPEN:

WebSocket error

Environment

  • OS: Debian Testing (Bullseye)
  • Deno Version: 1.4.6
  • V8 Version: 8.7.220.3
  • TypeScript: 4.0.3

Additional context

  • I didn't move the WebSocket Behavior outside the Drash server because I'm not a 100% sure what's the difference between the app_3000 and the app_3001 tests, and maybe that server is the cornerstone of the test.

Hey @d4vsanchez, thanks for the really detailed description! I personally haven't been able to get any integration tests working for apps. using ssl, it always resulted in a bad cert error (i think it is an issue with fetch as it did work with curl), so I reckon the tests don't work because they are severely out of date. Regardless, i'll give it a shot using your description 👍

Tbh i think having a drash server made it a bit convoluted - i'm not saying it's hard or impossible to have a drash server, sockets server and sockets client work together, just 3 being in 1 file with tests is a bit tricky, and the drash server isn't actually needed.

I'm curious how you managed to get it working though, do you still have the code you used?

FYI there's an in progress PR here: https://github.com/drashland/sockets/pull/89

The decode error is coming from when a socket client is trying to connect to the server it seems (new WebSocket(...))

@ebebbington I thought I have git stashed it on the weekend but it seems that erased the changes.

Exactly, what I managed to look is that the DecodeError is after that line. The WebSocket seems to be created successfully (not 100% sure) but its state doesn't change from CONNECTING to OPEN.

If you remove the Line 17 which sends the data, the DecodeError doesn't happen anymore (though the test doesn't work for obvious reasons).

I tested that the WebSocket wasn't changing its status by adding a while loop between the WebSocket instantiation and the send() method. And it never leaves that loop.

  const socketClient = new WebSocket(
    `wss://${socketServer.hostname}:${socketServer.port}`,
  );
+ while (socketClient.readyState === 0) {}
  await socketClient.send(JSON.stringify(data));

I'm going to check the #89 after work to see if I can help in something else.

I believe that loop stops the event loop anyways, i think a better way might be:

import { deferred } from "https://deno.land/std/async/deferred.ts"
const client = ...
const promise = deferred()
client.onopen = function () {
  promise.resolve()
}
await promise

That process has helped me countless times xD

Thanks for the fast response, and yeah feel free to check it out, have a tinker etc etc, it's all very appreciated.

Although, i get the error when just trying to connect to the server, without sending any messages - i wonder if the certs are invalid in some way

I don't think the certs are valid... atm i'm just trying to use wscat but. getting ECONNREFUSED, really stuck on how to fix it :/

i'm going to look into this during the month of june. if i can't figure out, then we're going to have to release v1.0.0 without it; and make a fix to include this in v1.0.1 or 1.1.0, whichever comes first

Hi everyone!

I managed to make it work by issuing a new certificate that's valid until 2120.

image

The thing is that I had to create some files as said here: https://gist.github.com/cecilemuller/9492b848eb8fe46d462abeb26656c4f8 and run the tests using the following flag --cert tests/integration/app_3001/RootCA.pem

Do you think is useful if I create a PR and you help me find out if it's possible to run the tests without the --cert flag?

Hi @d4vsanchez, that’s great news! Yes PR’s are welcome :)

closing as this issue is way too old compared to the current codebase, closing in favour of #128