web icon indicating copy to clipboard operation
web copied to clipboard

Support for HTTPS

Open robertsLando opened this issue 1 year ago • 14 comments

I would like to be able to run tests in an HTTPS environment but I cannot find options to do this.

Related issue: https://github.com/modernweb-dev/web/issues/2517

robertsLando avatar Nov 06 '23 15:11 robertsLando

I found that we do support HTTPS by using http2 flag.

Can you try adding http2: true to your config, and sslKey and sslCert if needed.

// @web/test-runner-core/src/config/TestRunnerCoreConfig.ts
export interface TestRunnerCoreConfig {
  // ...
  http2?: boolean;
  sslKey?: string;
  sslCert?: string;
  // ...
}

This is documented only in WDS though: https://modern-web.dev/docs/dev-server/cli-and-configuration/

And not in WTR: https://modern-web.dev/docs/test-runner/cli-and-configuration/

bashmish avatar Nov 06 '23 15:11 bashmish

Ok I confirm this is working, I only report that the addresses printed on console are still using http and if you set the open to true it opens the http url resulting to a 404. If I manually fix http --> https it works BTW. I think may be worth adding this to docs too

robertsLando avatar Nov 06 '23 15:11 robertsLando

Ok I think part of #2540 is also related to this, when http2 is enabled and playwright browsers are lunched the url is wrong there too:

test/browser/test.js:

 ❌ page.goto: net::ERR_EMPTY_RESPONSE at http://localhost:8001/?wtr-session-id=uqh67wN1nTY5Ieug0bLwQ
=========================== logs ===========================
navigating to "http://localhost:8001/?wtr-session-id=uqh67wN1nTY5Ieug0bLwQ", waiting until "load"
============================================================  (failed on Chromium)
    page.goto: net::ERR_EMPTY_RESPONSE at http://localhost:8001/?wtr-session-id=uqh67wN1nTY5Ieug0bLwQ
    =========================== logs ===========================
    navigating to "http://localhost:8001/?wtr-session-id=uqh67wN1nTY5Ieug0bLwQ", waiting until "load"
    ============================================================
        at PlaywrightLauncherPage.runSession (/home/daniel/GitProjects/MQTT.js/node_modules/@web/test-runner-playwright/dist/PlaywrightLauncherPage.js:26:35)
        at async PlaywrightLauncher.startSession (/home/daniel/GitProjects/MQTT.js/node_modules/@web/test-runner-playwright/dist/PlaywrightLauncher.js:45:9)

If I disalble http2 error goes away but still not working because of https errors

robertsLando avatar Nov 06 '23 16:11 robertsLando

Can you please make a smallest possible reproduction of this issue?

bashmish avatar Nov 06 '23 16:11 bashmish

Just checkout this: https://github.com/mqttjs/MQTT.js/pull/1722

uncomment this lines: https://github.com/mqttjs/MQTT.js/pull/1722/files#diff-7bfdd444e5650854e7536869ef3973956e89fbfc8562197c7c13f99cfb3047bfR41-R43

Then run:

npm install
npx wtr

robertsLando avatar Nov 06 '23 16:11 robertsLando

By smallest possible reproduction I mean smth that contains minimum code that is required to show the error, e.g. minimal config and 1 test file with 1 test, not the whole project.

bashmish avatar Nov 06 '23 16:11 bashmish

Btw, auto-open which doesn't respect http2 flag should definitely be fixed. I'm wondering more about the other error you are running into.

bashmish avatar Nov 06 '23 16:11 bashmish

I will create a small repo to reproduce this, in the meanwhile if you want you can try doing what i described in my comment (would save me effort in creating a repro of the issue).

In general seems like http2 flah is completely ignored code wise when building the url, so you see the url wrong everywhere: in console, open, playwright goTo page and so on....

robertsLando avatar Nov 06 '23 16:11 robertsLando

Here is the smallest possible repro: https://github.com/robertsLando/wtr-bug-test

robertsLando avatar Nov 06 '23 17:11 robertsLando

Makes sense indeed, thanks for your time analysing this and providing this repro. I saw code that is handling the flag http2 for the URL construction, so I assumed it was working fine, but apparently not in all contexts and not for all features. So looks like it needs more work for WTR. I'd say you probably know enough now to make a fix PR, so give it a shot if you have time.

bashmish avatar Nov 06 '23 17:11 bashmish

Ok so seems the missing piece was this setting:

protocol: 'https:',

When this is set everything else is ok. Not sure if this is expected BTW...

robertsLando avatar Nov 07 '23 08:11 robertsLando

@robertsLando is http2 still needed then?

I feel like some docs is missing to explain all this. Would be good to work on this improvement, so I'll keep this issue open.

bashmish avatar Nov 07 '23 09:11 bashmish

still needed then

Yeah seems without that something else is broken, I see in some places it uses http2 to build the url and others use protocol

robertsLando avatar Nov 07 '23 09:11 robertsLando

I'm missing some of the built-in certificate options, specifically .pfx and .passphrase as I'm using pfx certificate instead of pem.

It would be nice if you could expose these as well.

More details: https://nodejs.org/docs/v8.6.0/api/http2.html#http2_http2_createsecureserver_options_onrequesthandler https://nodejs.org/docs/v8.6.0/api/tls.html#tls_tls_createsecurecontext_options

klasjersevi avatar Dec 15 '23 10:12 klasjersevi