From 3b22e92a8e9520f22bd4b1d4bfb895c3ad80f143 Mon Sep 17 00:00:00 2001 From: Pete Cornish Date: Sat, 22 Feb 2025 20:32:40 +0000 Subject: [PATCH 1/2] test: splits HTTPS test into separate suite. --- .../io/gatehill/imposter/server/HttpsTest.kt | 129 ++++++++++++++++++ .../imposter/server/ImposterVerticleTest.kt | 21 +-- 2 files changed, 131 insertions(+), 19 deletions(-) create mode 100644 server/src/test/java/io/gatehill/imposter/server/HttpsTest.kt diff --git a/server/src/test/java/io/gatehill/imposter/server/HttpsTest.kt b/server/src/test/java/io/gatehill/imposter/server/HttpsTest.kt new file mode 100644 index 000000000..5b0667ad8 --- /dev/null +++ b/server/src/test/java/io/gatehill/imposter/server/HttpsTest.kt @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2016-2021. + * + * This file is part of Imposter. + * + * "Commons Clause" License Condition v1.0 + * + * The Software is provided to you by the Licensor under the License, as + * defined below, subject to the following condition. + * + * Without limiting other conditions in the License, the grant of rights + * under the License will not include, and the License does not grant to + * you, the right to Sell the Software. + * + * For purposes of the foregoing, "Sell" means practicing any or all of + * the rights granted to you under the License to provide to third parties, + * for a fee or other consideration (including without limitation fees for + * hosting or consulting/support services related to the Software), a + * product or service whose value derives, entirely or substantially, from + * the functionality of the Software. Any license notice or attribution + * required by the License must also include this Commons Clause License + * Condition notice. + * + * Software: Imposter + * + * License: GNU Lesser General Public License version 3 + * + * Licensor: Peter Cornish + * + * Imposter is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Imposter is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Imposter. If not, see . + */ +package io.gatehill.imposter.server + +import io.gatehill.imposter.ImposterConfig +import io.gatehill.imposter.plugin.PluginManager +import io.gatehill.imposter.plugin.test.TestPluginImpl +import io.gatehill.imposter.util.CryptoUtil.DEFAULT_KEYSTORE_PASSWORD +import io.gatehill.imposter.util.CryptoUtil.DEFAULT_KEYSTORE_PATH +import io.gatehill.imposter.util.CryptoUtil.getDefaultKeystore +import io.gatehill.imposter.util.FileUtil.CLASSPATH_PREFIX +import io.gatehill.imposter.util.HttpUtil +import io.gatehill.imposter.util.InjectorUtil +import io.restassured.RestAssured +import io.vertx.core.Vertx +import io.vertx.junit5.VertxTestContext +import org.hamcrest.Matchers +import org.junit.jupiter.api.Assertions +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test + +/** + * Tests HTTPS support. + */ +class HttpsTest : BaseVerticleTest() { + override val pluginClass = TestPluginImpl::class.java + + @BeforeEach + @Throws(Exception::class) + override fun setUp(vertx: Vertx, testContext: VertxTestContext) { + super.setUp(vertx, testContext) + + // set up trust store for TLS + RestAssured.trustStore(getDefaultKeystore(HttpsTest::class.java).toFile(), DEFAULT_KEYSTORE_PASSWORD) + RestAssured.baseURI = "https://$host:$listenPort" + } + + override val testConfigDirs = listOf( + "/simple-config" + ) + + @Throws(Exception::class) + override fun configure(imposterConfig: ImposterConfig) { + super.configure(imposterConfig) + + // enable TLS + imposterConfig.isTlsEnabled = true + imposterConfig.keystorePath = CLASSPATH_PREFIX + DEFAULT_KEYSTORE_PATH + imposterConfig.keystorePassword = DEFAULT_KEYSTORE_PASSWORD + } + + @Test + fun testPluginLoadAndConfig() { + val pluginManager = InjectorUtil.getInstance() + val plugin = pluginManager.getPlugin(TestPluginImpl::class.java.canonicalName) + Assertions.assertNotNull(plugin) + Assertions.assertNotNull(plugin!!.configs) + Assertions.assertEquals(1, plugin.configs.size) + + val pluginConfig = plugin.configs[0] + Assertions.assertEquals("/example", pluginConfig.path) + Assertions.assertEquals("test-plugin-data.json", pluginConfig.responseConfig.file) + Assertions.assertEquals("testValue", pluginConfig.customProperty) + } + + @Test + fun testRequestSuccess() { + RestAssured.given().`when`() + .get("/example") + .then() + .statusCode(Matchers.equalTo(HttpUtil.HTTP_OK)) + } + + @Test + fun testRequestNotFound() { + RestAssured.given().`when`() + .get("/does_not_match") + .then() + .statusCode(Matchers.equalTo(HttpUtil.HTTP_NOT_FOUND)) + } + + @Test + fun testResponseFileNotFound() { + RestAssured.given().`when`() + .get("/static-file-example") + .then() + .statusCode(Matchers.equalTo(HttpUtil.HTTP_NOT_FOUND)) + } +} diff --git a/server/src/test/java/io/gatehill/imposter/server/ImposterVerticleTest.kt b/server/src/test/java/io/gatehill/imposter/server/ImposterVerticleTest.kt index 6d7497b5b..62a4f8077 100644 --- a/server/src/test/java/io/gatehill/imposter/server/ImposterVerticleTest.kt +++ b/server/src/test/java/io/gatehill/imposter/server/ImposterVerticleTest.kt @@ -42,13 +42,8 @@ */ package io.gatehill.imposter.server -import io.gatehill.imposter.ImposterConfig import io.gatehill.imposter.plugin.PluginManager import io.gatehill.imposter.plugin.test.TestPluginImpl -import io.gatehill.imposter.util.CryptoUtil.DEFAULT_KEYSTORE_PASSWORD -import io.gatehill.imposter.util.CryptoUtil.DEFAULT_KEYSTORE_PATH -import io.gatehill.imposter.util.CryptoUtil.getDefaultKeystore -import io.gatehill.imposter.util.FileUtil.CLASSPATH_PREFIX import io.gatehill.imposter.util.HttpUtil import io.gatehill.imposter.util.InjectorUtil import io.restassured.RestAssured @@ -69,26 +64,14 @@ class ImposterVerticleTest : BaseVerticleTest() { @Throws(Exception::class) override fun setUp(vertx: Vertx, testContext: VertxTestContext) { super.setUp(vertx, testContext) - - // set up trust store for TLS - RestAssured.trustStore(getDefaultKeystore(ImposterVerticleTest::class.java).toFile(), DEFAULT_KEYSTORE_PASSWORD) - RestAssured.baseURI = "https://$host:$listenPort" + RestAssured.baseURI = "http://$host:$listenPort" + RestAssured.enableLoggingOfRequestAndResponseIfValidationFails() } override val testConfigDirs = listOf( "/simple-config" ) - @Throws(Exception::class) - override fun configure(imposterConfig: ImposterConfig) { - super.configure(imposterConfig) - - // enable TLS - imposterConfig.isTlsEnabled = true - imposterConfig.keystorePath = CLASSPATH_PREFIX + DEFAULT_KEYSTORE_PATH - imposterConfig.keystorePassword = DEFAULT_KEYSTORE_PASSWORD - } - @Test fun testPluginLoadAndConfig() { val pluginManager = InjectorUtil.getInstance() From 7db775667b473c5ec154faa5c9cafdad8fe05b32 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 24 Feb 2025 13:29:14 +0000 Subject: [PATCH 2/2] chore(deps-dev): bump org.junit.jupiter:junit-jupiter-api Bumps [org.junit.jupiter:junit-jupiter-api](https://github.com/junit-team/junit5) from 5.10.0 to 5.12.0. - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](https://github.com/junit-team/junit5/compare/r5.10.0...r5.12.0) --- updated-dependencies: - dependency-name: org.junit.jupiter:junit-jupiter-api dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- examples/junit-sample/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/junit-sample/pom.xml b/examples/junit-sample/pom.xml index aa3f75496..949f38504 100644 --- a/examples/junit-sample/pom.xml +++ b/examples/junit-sample/pom.xml @@ -99,7 +99,7 @@ org.junit.jupiter junit-jupiter-api - 5.10.0 + 5.12.0 test