Skip to content

Commit b8ce96a

Browse files
committed
Add more OCSP tests
1 parent 8059007 commit b8ce96a

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.tomcat.util.net.ocsp;
18+
19+
import java.util.ArrayList;
20+
import java.util.Collection;
21+
import java.util.List;
22+
23+
import javax.net.ssl.SSLHandshakeException;
24+
25+
import org.junit.AfterClass;
26+
import org.junit.Assert;
27+
import org.junit.Assume;
28+
import org.junit.BeforeClass;
29+
import org.junit.Test;
30+
import org.junit.runner.RunWith;
31+
import org.junit.runners.Parameterized;
32+
import org.junit.runners.Parameterized.Parameter;
33+
import org.junit.runners.Parameterized.Parameters;
34+
35+
import org.apache.tomcat.util.net.ocsp.TesterOcspResponder.OcspResponse;
36+
37+
@RunWith(Parameterized.class)
38+
public class TestOcspSoftFailTryLater extends OcspBaseTest {
39+
40+
private static TesterOcspResponder ocspResponder;
41+
42+
@BeforeClass
43+
public static void startOcspResponder() {
44+
ocspResponder = new TesterOcspResponder();
45+
ocspResponder.setFixedResponse(OcspResponse.TRY_LATER);
46+
try {
47+
ocspResponder.start();
48+
} catch (Exception e) {
49+
e.printStackTrace();
50+
}
51+
}
52+
53+
54+
@AfterClass
55+
public static void stopOcspResponder() {
56+
if (ocspResponder != null) {
57+
ocspResponder.stop();
58+
ocspResponder = null;
59+
}
60+
}
61+
62+
63+
@Parameters(name = "{0} with OpenSSL trust {2}: softFail {4}, clientOk {5}")
64+
public static Collection<Object[]> parameters() {
65+
List<Object[]> parameterSets = new ArrayList<>();
66+
Collection<Object[]> baseData = OcspBaseTest.parameters();
67+
68+
for (Object[] base : baseData) {
69+
for (Boolean softFail : booleans) {
70+
for (Boolean clientCertValid : booleans) {
71+
Boolean handshakeFailureExpected;
72+
73+
if (softFail.booleanValue()) {
74+
handshakeFailureExpected = Boolean.FALSE;
75+
} else {
76+
handshakeFailureExpected = Boolean.TRUE;
77+
}
78+
79+
parameterSets.add(new Object[] { base[0], base[1], base[2], base[3], softFail, clientCertValid,
80+
handshakeFailureExpected});
81+
}
82+
}
83+
}
84+
return parameterSets;
85+
}
86+
87+
@Parameter(4)
88+
public Boolean softFail;
89+
90+
@Parameter(5)
91+
public boolean clientCertValid;
92+
93+
@Parameter(6)
94+
public boolean handshakeFailureExpected;
95+
96+
@Test
97+
public void test() throws Exception {
98+
Assume.assumeNotNull(ocspResponder);
99+
try {
100+
doTest(clientCertValid, true, ClientCertificateVerification.ENABLED, false, softFail);
101+
if (handshakeFailureExpected) {
102+
Assert.fail("Handshake did not fail when expected to do so.");
103+
}
104+
} catch (SSLHandshakeException e) {
105+
if (!handshakeFailureExpected) {
106+
Assert.fail("Handshake failed when not expected to do so.");
107+
}
108+
}
109+
}
110+
}

0 commit comments

Comments
 (0)