Add -local-host and -local-proto flags for nginx virtual hosts proxy#27
Add -local-host and -local-proto flags for nginx virtual hosts proxy#27AndreiTelteu wants to merge 1 commit into
Conversation
replace original module name change log message to reflect new parameters localProto and localHost overwrite host
yusuf-musleh
left a comment
There was a problem hiding this comment.
Hi @AndreiTelteu ! Thanks a lot for the contribution, and apologies for the late response, been a way for some time.
This is a good use case I haven't thought of, and would like to get it merged. Regarding your questions about tests:
Or is this a normal test case scenario since the request was GET /crash ?
Yes, that panic is expected as I am making sure mmar handles it gracefully if the devserver crashes.
I am new to golang testing. How would I write a test for this new flags ?
To test the hostname change should I edit the /etc/hosts ? I think no.
Should I test using an external dns that resolves to localhost ? https://nip.io/ or https://sslip.io/
That's a good question, in general I wanted to avoid any dependancies and making changes to local files/envs when working with mmar including when writing tests. In fact, I built a basic DNS server that runs with the simulation tests in order to avoid depending on external tools like the ones you mentioned, it resolves every address to the loopback address. (I also wrote a blog post about it incase you are interested in reading more). So we can make use of that basic DNS server (through the new flags added to mmar client, see below) in the tests.
Now in order to test these new flags, I made some changes to the tests:
-
It now runs a dev server with TLS with the address of
example.com(by default golang's testhttp TLS server only generates certificates for *.example.com), the generated certificate is written to a temp file that the mmar client can later make use of through the new--custom-certflag. Currently this server is not being used, but you can use it in the tests for this PR. -
The tests also allows running multiple mmar clients, and they now accepts extra flags. For your tests, you can create a new mmar and pass in the appropriate parameters. It would looks something like this:
httpsClientUrlCh := make(chan string)
go StartMmarClient(simulationCtx, httpsClientUrlCh, localDevServer.Port(), "example.com", "https", "127.0.0.1:3535", "./temp-cert")This passes in the basic DNS we have running to the --custom-dns flag and the temp cert file to the --custom-cert flag in the mmar client. Then you'd need to update the mmar client below it to make sure all the tests run.
Let me know if you have any questions or pointers, I'd be happy to help, and would love to help you get this merged!
|
|
||
| The fastest way to create a tunnel what is running on your `localhost:8080` using [Docker](https://www.docker.com/) is by running this command: | ||
| The fastest way to create a tunnel what is running on your `https://project.test:443` using [Docker](https://www.docker.com/) is by running this command: | ||
|
|
||
| ``` | ||
| docker run --rm --network host ghcr.io/yusuf-musleh/mmar:v0.2.6 client --local-port 8080 | ||
| docker run --rm --network host ghcr.io/yusuf-musleh/mmar:v0.2.6 client --local-proto https --local-host project.test --local-port 443 | ||
| ``` |
There was a problem hiding this comment.
We can probably add it as an additional instruction/command rather than replacing this one, as this example is likely more common for users.
I use Laravel Herd as my local webserver because you get local valid ssl and it's easy do use and update, and since it uses nginx virtual hosts to switch between the websites I was not able to proxy to the correct website:
Problem 1: I need to replace localhost with sitename.test
Problem 2: I need to replace http with https, it can work with http as well but it's nicer to use https
In this PR I added 2 new flags:
-local-protothat should get http or https-local-hostto enter the hostname, or virtual host you want to accessI ran the tests and it passes, but with a panic:
Or is this a normal test case scenario since the request was
GET /crash?I am new to golang testing. How would I write a test for this new flags ?
To test the hostname change should I edit the /etc/hosts ? I think no.
Should I test using an external dns that resolves to localhost ? https://nip.io/ or https://sslip.io/