laracoft's avatar

HTTP test for SSL

I have a middleware that redirects to HTTPS if loaded via HTTP.

Is there a way to write a test to check if my website is indeed performing this redirection? I found in the Laravel docs:

$response = $this->get("/"); // but how do I specify that this must be http (not https)
0 likes
3 replies
laracoft's avatar

This was what I did, but feels there can be a better way

        $response = $this->get("/");
        $response->assertStatus(302);
        $this->assertTrue(Str::of(url(""))->startsWith("http://"));
        $this->assertTrue(Str::of($response->getTargetUrl())->startsWith("https://"));
laracoft's avatar

@martinbean

I agree, but this is a piece of legacy code that requires certain URLs to be on http and others on https... I need a test to ensure it remains that way so that we can deploy with confidence...

As you can imagine, something unpleasant happened yesterday. :)

Please or to participate in this conversation.