package org.apereo.cas.util;

import lombok.val;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
import org.springframework.http.HttpMethod;

import java.util.UUID;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

/**
 * This is {@link HttpUtilsTests}.
 *
 * @author Misagh Moayyed
 * @since 6.3.0
 */
@Tag("Utility")
public class HttpUtilsTests {

    @Test
    public void verifyExec() {
        val exec = HttpUtils.HttpExecutionRequest.builder()
            .basicAuthPassword("password")
            .basicAuthUsername("user")
            .method(HttpMethod.GET)
            .entity("entity")
            .url("http://localhost:8081")
            .proxyUrl("http://localhost:8080")
            .build();

        assertNull(HttpUtils.execute(exec));
    }

    @Test
    public void verifyBearerToken() {
        val exec = HttpUtils.HttpExecutionRequest.builder()
            .bearerToken(UUID.randomUUID().toString())
            .method(HttpMethod.GET)
            .entity("entity")
            .url("http://localhost:8081")
            .proxyUrl("http://localhost:8080")
            .build();

        assertNull(HttpUtils.execute(exec));
    }

    @Test
    public void verifyClose() {
        assertDoesNotThrow(new Executable() {
            @Override
            public void execute() throws Exception {
                HttpUtils.close(null);
                val response = mock(CloseableHttpResponse.class);
                doThrow(new RuntimeException()).when(response).close();
                HttpUtils.close(response);
            }
        });
    }

}

@@ -205,27 +205,206 @@
 api.
-function.Executable
+extension.ExtendWith;%0Aimport org.junit.jupiter.api.function.Executable;%0Aimport org.springframework.boot.test.system.CapturedOutput;%0Aimport org.springframework.boot.test.system.OutputCaptureExtension
 ;%0Aim
@@ -662,16 +662,58 @@
 ility%22)%0A
+@ExtendWith(OutputCaptureExtension.class)%0A
 public c
@@ -1957,10 +1957,544 @@
 %0A    %7D%0A%0A
+    @Test%0A    public void verifyBadSSLLogging(final CapturedOutput capturedOutput) %7B%0A        val exec = HttpUtils.HttpExecutionRequest.builder()%0A                .method(HttpMethod.GET)%0A                .url(%22https://untrusted-root.badssl.com/endpoint?secret=sensitiveinfo%22)%0A                .build();%0A        assertNull(HttpUtils.execute(exec));%0A        val output = capturedOutput.getAll();%0A        assertTrue(output.contains(%22https://untrusted-root.badssl.com/endpoint%22));%0A        assertFalse(output.contains(%22sensitiveinfo%22));%0A    %7D%0A
 %7D%0A

address feedback