|
18 | 18 |
|
19 | 19 | import static org.junit.jupiter.api.Assertions.assertEquals; |
20 | 20 | import static org.junit.jupiter.api.Assertions.assertFalse; |
| 21 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
21 | 22 | import static org.junit.jupiter.api.Assertions.assertTrue; |
22 | 23 |
|
23 | 24 | import java.nio.file.Path; |
|
32 | 33 | import org.junit.jupiter.api.Test; |
33 | 34 |
|
34 | 35 | import org.apache.tika.TikaTest; |
| 36 | +import org.apache.tika.exception.TikaConfigException; |
35 | 37 | import org.apache.tika.utils.ProcessUtils; |
36 | 38 |
|
37 | 39 | public class TikaServerConfigTest extends TikaTest { |
@@ -76,6 +78,44 @@ public void testPorts() throws Exception { |
76 | 78 | TikaServerConfig config = TikaServerConfig.load(commandLine); |
77 | 79 | } |
78 | 80 |
|
| 81 | + @Test |
| 82 | + public void testUnsecureEndpointRequiresEnableUnsecureFeatures() throws Exception { |
| 83 | + // Selecting /pipes (or /async, /status) without enableUnsecureFeatures must fail |
| 84 | + // at config load, forcing an explicit opt-in. |
| 85 | + CommandLineParser parser = new DefaultParser(); |
| 86 | + Path path = getConfigPath(getClass(), "tika-config-server-pipes-no-unsecure.json"); |
| 87 | + CommandLine commandLine = parser.parse(new Options() |
| 88 | + .addOption(Option |
| 89 | + .builder("c") |
| 90 | + .longOpt("config") |
| 91 | + .hasArg() |
| 92 | + .get()), new String[]{"-c", ProcessUtils.escapeCommandLine(path |
| 93 | + .toAbsolutePath() |
| 94 | + .toString())}); |
| 95 | + TikaConfigException ex = assertThrows(TikaConfigException.class, |
| 96 | + () -> TikaServerConfig.load(commandLine)); |
| 97 | + assertContains("enableUnsecureFeatures", ex.getMessage()); |
| 98 | + assertContains("pipes", ex.getMessage()); |
| 99 | + } |
| 100 | + |
| 101 | + @Test |
| 102 | + public void testUnsecureEndpointAllowedWithEnableUnsecureFeatures() throws Exception { |
| 103 | + // tika-config-server-basic.json selects the 'status' endpoint together with |
| 104 | + // enableUnsecureFeatures=true, so it must load without error. |
| 105 | + CommandLineParser parser = new DefaultParser(); |
| 106 | + Path path = getConfigPath(getClass(), "tika-config-server-basic.json"); |
| 107 | + CommandLine commandLine = parser.parse(new Options() |
| 108 | + .addOption(Option |
| 109 | + .builder("c") |
| 110 | + .longOpt("config") |
| 111 | + .hasArg() |
| 112 | + .get()), new String[]{"-c", ProcessUtils.escapeCommandLine(path |
| 113 | + .toAbsolutePath() |
| 114 | + .toString())}); |
| 115 | + TikaServerConfig config = TikaServerConfig.load(commandLine); |
| 116 | + assertTrue(config.isEnableUnsecureFeatures()); |
| 117 | + } |
| 118 | + |
79 | 119 | @Test |
80 | 120 | public void testTlsConfig() throws Exception { |
81 | 121 | Set<String> settings = new HashSet<>(); |
|
0 commit comments