|
| 1 | +/* |
| 2 | + * Copyright (c) 2016-2024. |
| 3 | + * |
| 4 | + * This file is part of Imposter. |
| 5 | + * |
| 6 | + * "Commons Clause" License Condition v1.0 |
| 7 | + * |
| 8 | + * The Software is provided to you by the Licensor under the License, as |
| 9 | + * defined below, subject to the following condition. |
| 10 | + * |
| 11 | + * Without limiting other conditions in the License, the grant of rights |
| 12 | + * under the License will not include, and the License does not grant to |
| 13 | + * you, the right to Sell the Software. |
| 14 | + * |
| 15 | + * For purposes of the foregoing, "Sell" means practicing any or all of |
| 16 | + * the rights granted to you under the License to provide to third parties, |
| 17 | + * for a fee or other consideration (including without limitation fees for |
| 18 | + * hosting or consulting/support services related to the Software), a |
| 19 | + * product or service whose value derives, entirely or substantially, from |
| 20 | + * the functionality of the Software. Any license notice or attribution |
| 21 | + * required by the License must also include this Commons Clause License |
| 22 | + * Condition notice. |
| 23 | + * |
| 24 | + * Software: Imposter |
| 25 | + * |
| 26 | + * License: GNU Lesser General Public License version 3 |
| 27 | + * |
| 28 | + * Licensor: Peter Cornish |
| 29 | + * |
| 30 | + * Imposter is free software: you can redistribute it and/or modify |
| 31 | + * it under the terms of the GNU Lesser General Public License as published by |
| 32 | + * the Free Software Foundation, either version 3 of the License, or |
| 33 | + * (at your option) any later version. |
| 34 | + * |
| 35 | + * Imposter is distributed in the hope that it will be useful, |
| 36 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 37 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 38 | + * GNU Lesser General Public License for more details. |
| 39 | + * |
| 40 | + * You should have received a copy of the GNU Lesser General Public License |
| 41 | + * along with Imposter. If not, see <https://www.gnu.org/licenses/>. |
| 42 | + */ |
| 43 | +package io.gatehill.imposter.server |
| 44 | + |
| 45 | +import io.gatehill.imposter.config.util.EnvVars |
| 46 | +import io.gatehill.imposter.plugin.test.TestPluginImpl |
| 47 | +import io.restassured.RestAssured |
| 48 | +import io.vertx.ext.unit.TestContext |
| 49 | +import io.vertx.ext.unit.junit.VertxUnitRunner |
| 50 | +import org.hamcrest.Matchers.equalTo |
| 51 | +import org.junit.Before |
| 52 | +import org.junit.Test |
| 53 | +import org.junit.runner.RunWith |
| 54 | + |
| 55 | +/** |
| 56 | + * Tests for paths with parameters adjacent to reserved characters. |
| 57 | + * |
| 58 | + * @author Pete Cornish |
| 59 | + */ |
| 60 | +@RunWith(VertxUnitRunner::class) |
| 61 | +class ReservedCharsInPathTest : BaseVerticleTest() { |
| 62 | + override val pluginClass = TestPluginImpl::class.java |
| 63 | + |
| 64 | + @Before |
| 65 | + @Throws(Exception::class) |
| 66 | + override fun setUp(testContext: TestContext) { |
| 67 | + super.setUp(testContext) |
| 68 | + RestAssured.baseURI = "http://$host:$listenPort" |
| 69 | + RestAssured.enableLoggingOfRequestAndResponseIfValidationFails() |
| 70 | + |
| 71 | + // enable work-around for non-parameter colons in paths |
| 72 | + EnvVars.populate("IMPOSTER_ESCAPE_COLONS_IN_PATH" to "true") |
| 73 | + } |
| 74 | + |
| 75 | + override val testConfigDirs = listOf( |
| 76 | + "/reserved-chars-in-path" |
| 77 | + ) |
| 78 | + |
| 79 | + /** |
| 80 | + * Match against a path with an exact match over that with a placeholder. |
| 81 | + */ |
| 82 | + @Test |
| 83 | + fun `should serve response for path containing reserved character`() { |
| 84 | + RestAssured.given().`when`() |
| 85 | + .get("/example/foo:qux") |
| 86 | + .then() |
| 87 | + .body(equalTo("baz")) |
| 88 | + } |
| 89 | +} |
0 commit comments