Skip to content

Commit 1de2c0b

Browse files
committed
Test that certain constructs are fully banned
1 parent bea4261 commit 1de2c0b

1 file changed

Lines changed: 30 additions & 42 deletions

File tree

src/test/java/com/hubspot/jinjava/el/ext/ValidatorConfigBannedConstructsTest.java

Lines changed: 30 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ public class ValidatorConfigBannedConstructsTest {
1414
@Test
1515
public void itRejectsObjectMethodInAllowedMethods() throws NoSuchMethodException {
1616
Method toStringMethod = Object.class.getMethod("toString");
17-
assertThatThrownBy(
18-
() -> MethodValidatorConfig.builder().addAllowedMethods(toStringMethod).build()
19-
)
17+
assertThatThrownBy(() ->
18+
MethodValidatorConfig.builder().addAllowedMethods(toStringMethod).build()
19+
)
2020
.isInstanceOf(IllegalStateException.class)
2121
.hasMessageContaining("Banned classes or prefixes");
2222
}
2323

2424
@Test
2525
public void itRejectsClassMethodInAllowedMethods() throws NoSuchMethodException {
2626
Method getNameMethod = Class.class.getMethod("getName");
27-
assertThatThrownBy(
28-
() -> MethodValidatorConfig.builder().addAllowedMethods(getNameMethod).build()
29-
)
27+
assertThatThrownBy(() ->
28+
MethodValidatorConfig.builder().addAllowedMethods(getNameMethod).build()
29+
)
3030
.isInstanceOf(IllegalStateException.class)
3131
.hasMessageContaining("Banned classes or prefixes");
3232
}
@@ -35,60 +35,56 @@ public void itRejectsClassMethodInAllowedMethods() throws NoSuchMethodException
3535

3636
@Test
3737
public void itRejectsObjectClassInAllowedDeclaredMethodClassNames() {
38-
assertThatThrownBy(
39-
() ->
38+
assertThatThrownBy(() ->
4039
MethodValidatorConfig
4140
.builder()
4241
.addAllowedDeclaredMethodsFromCanonicalClassNames(
4342
Object.class.getCanonicalName()
4443
)
4544
.build()
46-
)
45+
)
4746
.isInstanceOf(IllegalStateException.class)
4847
.hasMessageContaining("Banned classes or prefixes");
4948
}
5049

5150
@Test
5251
public void itRejectsClassClassInAllowedDeclaredMethodClassNames() {
53-
assertThatThrownBy(
54-
() ->
52+
assertThatThrownBy(() ->
5553
MethodValidatorConfig
5654
.builder()
5755
.addAllowedDeclaredMethodsFromCanonicalClassNames(
5856
Class.class.getCanonicalName()
5957
)
6058
.build()
61-
)
59+
)
6260
.isInstanceOf(IllegalStateException.class)
6361
.hasMessageContaining("Banned classes or prefixes");
6462
}
6563

6664
@Test
6765
public void itRejectsObjectMapperInAllowedDeclaredMethodClassNames() {
68-
assertThatThrownBy(
69-
() ->
66+
assertThatThrownBy(() ->
7067
MethodValidatorConfig
7168
.builder()
7269
.addAllowedDeclaredMethodsFromCanonicalClassNames(
7370
ObjectMapper.class.getCanonicalName()
7471
)
7572
.build()
76-
)
73+
)
7774
.isInstanceOf(IllegalStateException.class)
7875
.hasMessageContaining("Banned classes or prefixes");
7976
}
8077

8178
@Test
8279
public void itRejectsJinjavaInterpreterInAllowedDeclaredMethodClassNames() {
83-
assertThatThrownBy(
84-
() ->
80+
assertThatThrownBy(() ->
8581
MethodValidatorConfig
8682
.builder()
8783
.addAllowedDeclaredMethodsFromCanonicalClassNames(
8884
JinjavaInterpreter.class.getCanonicalName()
8985
)
9086
.build()
91-
)
87+
)
9288
.isInstanceOf(IllegalStateException.class)
9389
.hasMessageContaining("Banned classes or prefixes");
9490
}
@@ -97,30 +93,28 @@ public void itRejectsJinjavaInterpreterInAllowedDeclaredMethodClassNames() {
9793

9894
@Test
9995
public void itRejectsReflectPackageInAllowedDeclaredMethodPrefixes() {
100-
assertThatThrownBy(
101-
() ->
96+
assertThatThrownBy(() ->
10297
MethodValidatorConfig
10398
.builder()
10499
.addAllowedDeclaredMethodsFromCanonicalClassPrefixes(
105100
Method.class.getPackageName()
106101
)
107102
.build()
108-
)
103+
)
109104
.isInstanceOf(IllegalStateException.class)
110105
.hasMessageContaining("Banned classes or prefixes");
111106
}
112107

113108
@Test
114109
public void itRejectsJacksonDatabindPackageInAllowedDeclaredMethodPrefixes() {
115-
assertThatThrownBy(
116-
() ->
110+
assertThatThrownBy(() ->
117111
MethodValidatorConfig
118112
.builder()
119113
.addAllowedDeclaredMethodsFromCanonicalClassPrefixes(
120114
ObjectMapper.class.getPackageName()
121115
)
122116
.build()
123-
)
117+
)
124118
.isInstanceOf(IllegalStateException.class)
125119
.hasMessageContaining("Banned classes or prefixes");
126120
}
@@ -129,52 +123,48 @@ public void itRejectsJacksonDatabindPackageInAllowedDeclaredMethodPrefixes() {
129123

130124
@Test
131125
public void itRejectsObjectClassInAllowedReturnTypeClassNames() {
132-
assertThatThrownBy(
133-
() ->
126+
assertThatThrownBy(() ->
134127
ReturnTypeValidatorConfig
135128
.builder()
136129
.addAllowedCanonicalClassNames(Object.class.getCanonicalName())
137130
.build()
138-
)
131+
)
139132
.isInstanceOf(IllegalStateException.class)
140133
.hasMessageContaining("Banned classes or prefixes");
141134
}
142135

143136
@Test
144137
public void itRejectsClassClassInAllowedReturnTypeClassNames() {
145-
assertThatThrownBy(
146-
() ->
138+
assertThatThrownBy(() ->
147139
ReturnTypeValidatorConfig
148140
.builder()
149141
.addAllowedCanonicalClassNames(Class.class.getCanonicalName())
150142
.build()
151-
)
143+
)
152144
.isInstanceOf(IllegalStateException.class)
153145
.hasMessageContaining("Banned classes or prefixes");
154146
}
155147

156148
@Test
157149
public void itRejectsObjectMapperInAllowedReturnTypeClassNames() {
158-
assertThatThrownBy(
159-
() ->
150+
assertThatThrownBy(() ->
160151
ReturnTypeValidatorConfig
161152
.builder()
162153
.addAllowedCanonicalClassNames(ObjectMapper.class.getCanonicalName())
163154
.build()
164-
)
155+
)
165156
.isInstanceOf(IllegalStateException.class)
166157
.hasMessageContaining("Banned classes or prefixes");
167158
}
168159

169160
@Test
170161
public void itRejectsJinjavaInterpreterInAllowedReturnTypeClassNames() {
171-
assertThatThrownBy(
172-
() ->
162+
assertThatThrownBy(() ->
173163
ReturnTypeValidatorConfig
174164
.builder()
175165
.addAllowedCanonicalClassNames(JinjavaInterpreter.class.getCanonicalName())
176166
.build()
177-
)
167+
)
178168
.isInstanceOf(IllegalStateException.class)
179169
.hasMessageContaining("Banned classes or prefixes");
180170
}
@@ -183,26 +173,24 @@ public void itRejectsJinjavaInterpreterInAllowedReturnTypeClassNames() {
183173

184174
@Test
185175
public void itRejectsReflectPackageInAllowedReturnTypePrefixes() {
186-
assertThatThrownBy(
187-
() ->
176+
assertThatThrownBy(() ->
188177
ReturnTypeValidatorConfig
189178
.builder()
190179
.addAllowedCanonicalClassPrefixes(Method.class.getPackageName())
191180
.build()
192-
)
181+
)
193182
.isInstanceOf(IllegalStateException.class)
194183
.hasMessageContaining("Banned classes or prefixes");
195184
}
196185

197186
@Test
198187
public void itRejectsJacksonDatabindPackageInAllowedReturnTypePrefixes() {
199-
assertThatThrownBy(
200-
() ->
188+
assertThatThrownBy(() ->
201189
ReturnTypeValidatorConfig
202190
.builder()
203191
.addAllowedCanonicalClassPrefixes(ObjectMapper.class.getPackageName())
204192
.build()
205-
)
193+
)
206194
.isInstanceOf(IllegalStateException.class)
207195
.hasMessageContaining("Banned classes or prefixes");
208196
}

0 commit comments

Comments
 (0)