blob: 62a8b1131fa080a89ec074ace27b4408ea309e75 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.application.validation;
import com.yahoo.config.application.api.ApplicationPackage;
import com.yahoo.config.model.NullConfigModelRegistry;
import com.yahoo.config.model.deploy.DeployState;
import com.yahoo.config.model.deploy.TestProperties;
import com.yahoo.config.model.test.MockApplicationPackage;
import com.yahoo.vespa.model.VespaModel;
import org.junit.jupiter.api.Test;
import org.xml.sax.SAXException;
import java.io.IOException;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* @author bjorncs
*/
class CloudUserFilterValidatorTest {
@Test
void fails_on_user_configured_filter_chain() {
var exception = assertThrows(IllegalArgumentException.class, () -> runValidatorOnApp(true, ""));
var expected = "HTTP filter chains are currently not supported in Vespa Cloud ([chain 'myChain' in cluster 'container'])";
assertEquals(expected, exception.getMessage());
}
@Test
void allows_user_configured_filter_chain_for_infrastructure_app() {
assertDoesNotThrow(() -> runValidatorOnApp(true, " application-type='hosted-infrastructure'"));
}
@Test
void allows_user_configured_filter_chain_for_self_hosted() {
assertDoesNotThrow(() -> runValidatorOnApp(false, ""));
}
private static void runValidatorOnApp(boolean isHosted, String applicationTypeAttribute) throws IOException, SAXException {
String servicesXml = """
<services version='1.0'%s>
<container version='1.0'>
<http>
<filtering>
<request-chain id='myChain'>
<filter id='myFilter'/>
<binding>http://*/search/</binding>
</request-chain>
</filtering>
</http>
</container>
</services>
""".formatted(applicationTypeAttribute);
ApplicationPackage app = new MockApplicationPackage.Builder()
.withServices(servicesXml)
.build();
DeployState deployState = new DeployState.Builder()
.applicationPackage(app)
.properties(new TestProperties().setHostedVespa(isHosted).setAllowUserFilters(false))
.build();
VespaModel model = new VespaModel(new NullConfigModelRegistry(), deployState);
new CloudUserFilterValidator().validate(model, deployState);
}
}
|