|
26 | 26 | import java.security.cert.CertificateException; |
27 | 27 | import java.security.cert.X509Certificate; |
28 | 28 | import java.util.Date; |
| 29 | +import static java.util.logging.Level.INFO; |
29 | 30 | import java.util.logging.Logger; |
30 | 31 |
|
31 | 32 | import org.apache.commons.logging.Log; |
|
51 | 52 | import org.junit.runner.RunWith; |
52 | 53 | import org.omnifaces.utils.security.Certificates; |
53 | 54 |
|
| 55 | +import com.gargoylesoftware.htmlunit.HttpMethod; |
54 | 56 | import com.gargoylesoftware.htmlunit.TextPage; |
55 | 57 | import com.gargoylesoftware.htmlunit.WebClient; |
| 58 | +import com.gargoylesoftware.htmlunit.WebRequest; |
56 | 59 |
|
57 | 60 | /** |
58 | 61 | * @author Arjan Tijms |
@@ -172,29 +175,32 @@ public void setup() throws FileNotFoundException, IOException { |
172 | 175 | // and sent a reply to the server |
173 | 176 | webClient.getOptions().setSSLClientCertificate(new File(clientKeyStorePath).toURI().toURL(), "changeit", "jks"); |
174 | 177 |
|
| 178 | + // First do a request to install Bouncy Castle as provider |
| 179 | + // This is a normal HTTP request and doesn't use certificate authentication |
| 180 | + TextPage pageb = webClient.getPage(base + "BouncyServlet"); |
| 181 | + log.log(INFO, "Bouncy Castle provider inserted at position: {0}", pageb.getContent()); |
| 182 | + |
175 | 183 | System.out.println("*********** SETUP DONE ***************************\n"); |
176 | 184 | } |
177 | 185 |
|
178 | 186 | @After |
179 | | - public void tearDown() { |
| 187 | + public void tearDown() throws IOException { |
| 188 | + // Remove Bouncy Castle as provider |
| 189 | + TextPage pageb = webClient.getPage(new WebRequest(new URL(base + "BouncyServlet"), HttpMethod.DELETE)); |
| 190 | + log.log(INFO, "Bouncy Castle provider removed: {0}", pageb.getContent()); |
| 191 | + |
180 | 192 | webClient.getCookieManager().clearCookies(); |
181 | 193 | webClient.close(); |
182 | 194 | System.out.println("\n*********** TEST END ***************************\n"); |
183 | 195 | } |
184 | 196 |
|
185 | 197 | @Test |
186 | 198 | public void testGetWithCorrectCredentials() throws Exception { |
187 | | - |
| 199 | + |
188 | 200 | System.out.println("\n*********** TEST START ***************************\n"); |
189 | | - |
| 201 | + |
190 | 202 | try { |
191 | | - |
192 | | - // First do a request to install Bouncy Castle as provider |
193 | | - // This is a normal HTTP request and doesn't use certificate authentication |
194 | | - TextPage pageb = webClient.getPage(base + "BouncyServlet"); |
195 | 203 |
|
196 | | - log.info("Bouncy Castle provider inserted at position: " + pageb.getContent()); |
197 | | - |
198 | 204 | // With Bouncy Castle installed, do the request via HTTPS to the secured |
199 | 205 | // Servlet |
200 | 206 | TextPage page = webClient.getPage(baseHttps + "SecureServlet"); |
|
0 commit comments