### Question:
HostAllowlistUtils { static boolean isHostAuthorized(final List<String> allowlist, String hostHeader) { Optional<String> optionalHost = getAndValidateHostHeader(hostHeader); if (allowlist.contains("*") || (optionalHost.isPresent() && hostIsInAllowlist(allowlist, optionalHost.get()))) { return true; } else { return false; } }    }### Answer:
@Test public void isHostAuthorized_shouldBeTrueIfInList() { assertThat(isHostAuthorized(List.of("A", "B"), "A")).isTrue(); assertThat(isHostAuthorized(List.of("A", "B"), "B")).isTrue(); }
@Test public void isHostAuthorized_shouldBeFalseIfNotInList() { assertThat(isHostAuthorized(List.of("A", "B"), "C")).isFalse(); assertThat(isHostAuthorized(List.of("A", "B"), "AA")).isFalse(); assertThat(isHostAuthorized(List.of("A.B.C", "B"), "A")).isFalse(); }
@Test public void isHostAuthorized_shouldBeTrueIfStarInList() { assertThat(isHostAuthorized(List.of("*"), "A")).isTrue(); assertThat(isHostAuthorized(List.of("*"), "my.host.name")).isTrue(); assertThat(isHostAuthorized(List.of("*", "B"), "A")).isTrue(); assertThat(isHostAuthorized(List.of("*"), BAD_HOST)).isTrue(); }
@Test public void isHostAuthorized_shouldBeFalseIfHostNotCorrectlyFormatted() { assertThat(isHostAuthorized(List.of("A", "B"), BAD_HOST)).isFalse(); }