webhintio / hint

💡 A hinting engine for the web
https://webhint.io/
Apache License 2.0
3.62k stars 671 forks source link

Support `https` and `http` requests simultaneously in the test-server #384

Open qzhou1607-zz opened 7 years ago

qzhou1607-zz commented 7 years ago

The current test-server after https://github.com/sonarwhal/sonar/pull/370 is merged supports creating a server that serves EITHER http or https pages ONLY, but doesn't have support for listening to http and https requests simultaneously in the same rule test, which is needed to add tests for rule strict transport security (https://github.com/sonarwhal/sonar/pull/370) if we want to support testing http site first, and then test the same site with https protocol if it doesn't redirect itself, as suggested by @alrra .

alrra commented 7 years ago

@qzhou1607 Can you also post some short code examples on how this would look like? Thanks!

qzhou1607-zz commented 7 years ago

So when creating a test server, we need to have two port numbers instead of one. Creating both http and https servers simultaneously is shown as below. We just need to make sure that both the http and https port numbers increment by 2 each time a new test server is created.

const startServer = async () => {
    options = {
        cert: await promisify(fs.readFile)(path.join(__dirname, 'fixture/server.crt'), 'utf8'),
        key: await promisify(fs.readFile)(path.join(__dirname, 'fixture/server.key'), 'utf8')
    };

    http.createServer(app).listen(HTTP_PORT_NUMBER);
    https.createServer(options, app).listen(HTTPS_PORT_NUMBER);
};

startServer();
alrra commented 7 years ago

@qzhou1607 I was referring to the tests.

molant commented 7 years ago

Also I think the http and https option should be optional (http, https, or both).

alrra commented 7 years ago

This was done in: https://github.com/sonarwhal/sonar/commit/173c5fc598914c4d6b08451d8fc24355b3371ffc.

qzhou1607-zz commented 7 years ago

@alrra If I remember right, this issue is for supporting http and https both when running a ruleTest. With https://github.com/sonarwhal/sonar/commit/173c5fc598914c4d6b08451d8fc24355b3371ffc we only have the option of http OR https, but not both. Do we still want that option?

alrra commented 7 years ago

Ahh, ok.

molant commented 7 years ago

In order to do this, the server needs to use 2 ports, 1 for http, and another 1 for https. We could add another property httpsPort and try to use that one. The problem would be how to handle the redirects from one to another

molant commented 6 years ago

Another problem we currently have with http vs https is that we cannot have http and https tests in the same file even if they are in different arrays. I have no clue why is that.