-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: AT-TLS context configuration tests (#3236)
--------- Signed-off-by: Pablo Hernán Carle <[email protected]> Co-authored-by: Pablo Hernán Carle <[email protected]>
- Loading branch information
1 parent
2aac3b6
commit ce012ca
Showing
14 changed files
with
413 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
api-catalog-services/src/test/java/org/zowe/apiml/apicatalog/functional/AttlsConfigTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* This program and the accompanying materials are made available under the terms of the | ||
* Eclipse Public License v2.0 which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Copyright Contributors to the Zowe Project. | ||
*/ | ||
|
||
package org.zowe.apiml.apicatalog.functional; | ||
|
||
import org.apache.http.HttpStatus; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.test.context.TestPropertySource; | ||
|
||
import javax.net.ssl.SSLException; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.hamcrest.core.StringContains.containsString; | ||
import static org.junit.jupiter.api.Assertions.assertInstanceOf; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
@TestPropertySource( | ||
properties = { | ||
"server.attls.enabled=true", | ||
"server.ssl.enabled=false" | ||
} | ||
) | ||
public class AttlsConfigTest extends ApiCatalogFunctionalTest { | ||
|
||
@Nested | ||
class GivenAttlsModeEnabled { | ||
|
||
@Nested | ||
class WhenContextLoads { | ||
|
||
@Test | ||
void requestFailsWithHttps() { | ||
try { | ||
given() | ||
.log().all() | ||
.when() | ||
.get(getCatalogUriWithPath("containers")) | ||
.then() | ||
.log().all() | ||
.statusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR); | ||
fail("Expected an SSL failure"); | ||
} catch (Exception e) { | ||
assertInstanceOf(SSLException.class, e); | ||
} | ||
} | ||
|
||
@Test | ||
void requestFailsWithAttlsContextReasonWithHttp() { | ||
given() | ||
.log().all() | ||
.when() | ||
.get(getCatalogUriWithPath("http", "apicatalog/api/v1/containers")) | ||
.then() | ||
.log().all() | ||
.statusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR) | ||
.body(containsString("Connection is not secure.")) | ||
.body(containsString("AttlsContext.getStatConn")); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
caching-service/src/test/java/org/zowe/apiml/caching/config/AttlsConfigTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* This program and the accompanying materials are made available under the terms of the | ||
* Eclipse Public License v2.0 which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Copyright Contributors to the Zowe Project. | ||
*/ | ||
|
||
package org.zowe.apiml.caching.config; | ||
|
||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestInstance; | ||
import org.junit.jupiter.api.TestInstance.Lifecycle; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.web.server.LocalServerPort; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.context.TestPropertySource; | ||
import org.zowe.apiml.caching.CachingService; | ||
import org.zowe.apiml.util.config.SslContext; | ||
|
||
import javax.net.ssl.SSLException; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.hamcrest.core.StringContains.containsString; | ||
import static org.junit.jupiter.api.Assertions.assertInstanceOf; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
@SpringBootTest( | ||
classes = CachingService.class, | ||
webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT | ||
) | ||
@ActiveProfiles("AttlsConfigTestCachingService") | ||
@TestPropertySource( | ||
properties = { | ||
"server.attls.enabled=true", | ||
"server.ssl.enabled=false" | ||
} | ||
) | ||
@TestInstance(Lifecycle.PER_CLASS) | ||
public class AttlsConfigTest { | ||
|
||
@Value("${apiml.service.hostname:localhost}") | ||
String hostname; | ||
@LocalServerPort | ||
int port; | ||
|
||
|
||
@Nested | ||
class GivenAttlsModeEnabled { | ||
|
||
private String getUri(String scheme, String endpoint) { | ||
return String.format("%s://%s:%d/%s/%s", scheme, hostname, port, "api/v1", endpoint); | ||
} | ||
|
||
@Nested | ||
class WhenContextLoads { | ||
|
||
@Test | ||
void requestFailsWithHttps() { | ||
try { | ||
given() | ||
.config(SslContext.clientCertUnknownUser) | ||
.header("Content-type", "application/json") | ||
.get(getUri("https", "cache")) | ||
.then() | ||
.statusCode(HttpStatus.FORBIDDEN.value()); | ||
fail(""); | ||
} catch (Exception e) { | ||
assertInstanceOf(SSLException.class, e); | ||
} | ||
} | ||
|
||
@Test | ||
void requestFailsWithAttlsReasonWithHttp() { | ||
given() | ||
.config(SslContext.clientCertUnknownUser) | ||
.header("Content-type", "application/json") | ||
.get(getUri("http", "cache")) | ||
.then() | ||
.statusCode(HttpStatus.INTERNAL_SERVER_ERROR.value()) | ||
.body(containsString("Connection is not secure.")) | ||
.body(containsString("AttlsContext.getStatConn")); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
discovery-service/src/test/java/org/zowe/apiml/discovery/config/AttlsConfigTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* This program and the accompanying materials are made available under the terms of the | ||
* Eclipse Public License v2.0 which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Copyright Contributors to the Zowe Project. | ||
*/ | ||
|
||
package org.zowe.apiml.discovery.config; | ||
|
||
import org.apache.http.HttpStatus; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestInstance; | ||
import org.junit.jupiter.api.TestInstance.Lifecycle; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.context.TestPropertySource; | ||
import org.zowe.apiml.discovery.functional.DiscoveryFunctionalTest; | ||
|
||
import java.net.ConnectException; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.hamcrest.core.Is.is; | ||
import static org.hamcrest.core.StringContains.containsString; | ||
import static org.junit.jupiter.api.Assertions.assertInstanceOf; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
@TestPropertySource( | ||
properties = { | ||
"server.attls.enabled=true", | ||
"server.ssl.enabled=false" | ||
} | ||
) | ||
@TestInstance(Lifecycle.PER_CLASS) | ||
@ActiveProfiles("attls") | ||
class AttlsConfigTest extends DiscoveryFunctionalTest { | ||
|
||
private String protocol = "http"; | ||
|
||
@Override | ||
protected String getProtocol() { | ||
return protocol; | ||
} | ||
|
||
@Nested | ||
class GivenAttlsModeEnabledAndHttps { | ||
|
||
@BeforeEach | ||
void setUp() { | ||
protocol = "https"; | ||
} | ||
|
||
@Test | ||
void whenContextLoads_RequestFailsWithHttps() { | ||
try { | ||
given() | ||
.log().all() | ||
.when() | ||
.get(getDiscoveryUriWithPath("/application/info")) | ||
.then() | ||
.log().all() | ||
.statusCode(is(HttpStatus.SC_INTERNAL_SERVER_ERROR)); | ||
fail("Expected SSL failure"); | ||
} catch (Exception e) { | ||
assertInstanceOf(ConnectException.class, e); | ||
} | ||
} | ||
} | ||
|
||
@Nested | ||
class GivenAttlsModeEnabledAndHttp { | ||
|
||
@BeforeEach | ||
void setUp() { | ||
protocol = "http"; | ||
} | ||
|
||
@Test | ||
void whenContextLoads_RequestFailsWithAttlsContextReason() { | ||
given() | ||
.log().all() | ||
.when() | ||
.get(getDiscoveryUriWithPath("/eureka/apps")) | ||
.then() | ||
.log().all() | ||
.statusCode(is(HttpStatus.SC_INTERNAL_SERVER_ERROR)) | ||
.body(containsString("Connection is not secure.")) | ||
.body(containsString("AttlsContext.getStatConn")); | ||
} | ||
} | ||
} |
Oops, something went wrong.