|
| 1 | +// SPDX-FileCopyrightText: the secureCodeBox authors |
| 2 | +// |
| 3 | +// SPDX-License-Identifier: Apache-2.0 |
| 4 | + |
| 5 | +package io.securecodebox.persistence.defectdojo.http; |
| 6 | + |
| 7 | +import io.securecodebox.persistence.defectdojo.config.Config; |
| 8 | +import lombok.NonNull; |
| 9 | +import org.junit.jupiter.api.Disabled; |
| 10 | +import org.junit.jupiter.api.Test; |
| 11 | +import org.springframework.http.HttpHeaders; |
| 12 | + |
| 13 | +import static org.junit.jupiter.api.Assertions.*; |
| 14 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 15 | +import static org.hamcrest.Matchers.*; |
| 16 | + |
| 17 | +/** |
| 18 | + * Tests for {@link Foo} |
| 19 | + */ |
| 20 | +class FooTest { |
| 21 | + private final Config config = new Config("url", "apikey"); |
| 22 | + |
| 23 | + @Test |
| 24 | + void generateAuthorizationHeaders_withoutProxyAuth() { |
| 25 | + final var incompleteProxyConfig = ProxyConfig.NULL; |
| 26 | + |
| 27 | + final var sut = new Foo(config, incompleteProxyConfig); |
| 28 | + |
| 29 | + assertAll( |
| 30 | + () -> assertThat( |
| 31 | + sut.generateAuthorizationHeaders().get(HttpHeaders.AUTHORIZATION), |
| 32 | + contains("Token apikey")), |
| 33 | + () -> assertThat( |
| 34 | + sut.generateAuthorizationHeaders().get(HttpHeaders.PROXY_AUTHORIZATION), |
| 35 | + not(contains("Basic dXNlcjpwdw=="))) |
| 36 | + ); |
| 37 | + } |
| 38 | + |
| 39 | + @Test |
| 40 | + void generateAuthorizationHeaders_withProxyAuth() { |
| 41 | + final var completeProxyConfig = ProxyConfig.builder() |
| 42 | + .user("user") |
| 43 | + .password("pw") |
| 44 | + .host("host") |
| 45 | + .port(42) |
| 46 | + .build(); |
| 47 | + |
| 48 | + final var sut = new Foo(config, completeProxyConfig); |
| 49 | + |
| 50 | + assertAll( |
| 51 | + () -> assertThat( |
| 52 | + sut.generateAuthorizationHeaders().get(HttpHeaders.AUTHORIZATION), |
| 53 | + contains("Token apikey")), |
| 54 | + () -> assertThat( |
| 55 | + sut.generateAuthorizationHeaders().get(HttpHeaders.PROXY_AUTHORIZATION), |
| 56 | + contains("Basic dXNlcjpwdw==")) |
| 57 | + ); |
| 58 | + } |
| 59 | + |
| 60 | + @Test |
| 61 | + void encodeProxyCredentials() { |
| 62 | + final var proxyConfig = ProxyConfig.builder() |
| 63 | + .user("bärtram") |
| 64 | + .password("gohze8Ae") |
| 65 | + .build(); |
| 66 | + |
| 67 | + assertThat(Foo.encodeProxyCredentials(proxyConfig), is("YsOkcnRyYW06Z29oemU4QWU=")); |
| 68 | + } |
| 69 | +} |
0 commit comments