Permalink
Browse files

Made HttpAcceptanceTest.rejectWithoutClientCertificate accept SocketE…

…xception or SSLHandshakeException as these are both thrown depending on platform.
  • Loading branch information...
1 parent 1b6dc57 commit c1e40d51d7e5bd131dd4f8974cbb5a97fba2f5f4 @tomakehurst committed Feb 24, 2015
Showing with 53 additions and 3 deletions.
  1. +1 −0 .gitignore
  2. +1 −0 .travis.yml
  3. +40 −0 Vagrantfile
  4. +11 −3 src/test/java/com/github/tomakehurst/wiremock/HttpsAcceptanceTest.java
View
@@ -47,3 +47,4 @@ copy-admin.sh
.DS_Store
**/.DS_Store
+.vagrant
View
@@ -1,5 +1,6 @@
language: java
jdk:
+ - openjdk6
- openjdk7
- oraclejdk7
- oraclejdk8
View
@@ -0,0 +1,40 @@
+# -*- mode: ruby -*-
+# vi: set ft=ruby :
+
+Vagrant.configure(2) do |config|
+ config.vm.box = "https://cloud-images.ubuntu.com/vagrant/utopic/current/utopic-server-cloudimg-i386-vagrant-disk1.box"
+ config.vm.box_check_update = false
+
+ # Create a private network, which allows host-only access to the machine
+ # using a specific IP.
+ # config.vm.network "private_network", ip: "192.168.33.10"
+
+ # Create a public network, which generally matched to bridged network.
+ # Bridged networks make the machine appear as another physical device on
+ # your network.
+ # config.vm.network "public_network"
+
+ config.vm.synced_folder ".", "/wiremock"
+
+ config.vm.provider "virtualbox" do |vb|
+ vb.memory = "2048"
+ end
+ #
+ # View the documentation for the provider you are using for more
+ # information on available options.
+
+ # Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
+ # such as FTP and Heroku are also available. See the documentation at
+ # https://docs.vagrantup.com/v2/push/atlas.html for more information.
+ # config.push.define "atlas" do |push|
+ # push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
+ # end
+
+ # Enable provisioning with a shell script. Additional provisioners such as
+ # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
+ # documentation for more information about their specific syntax and use.
+ config.vm.provision "shell", inline: <<-SHELL
+ sudo apt-get update
+ sudo apt-get install -y openjdk-7-jdk
+ SHELL
+end
@@ -33,10 +33,12 @@
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
+import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Test;
import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLHandshakeException;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@@ -53,6 +55,7 @@
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
public class HttpsAcceptanceTest {
@@ -135,12 +138,17 @@ public void acceptsAlternativeKeystoreWithNonDefaultPassword() throws Exception
assertThat(contentFor(url("/alt-password-https")), is("HTTPS content"));
}
- @Test(expected = SocketException.class)
- public void rejectsWithoutClientCertificate() throws Exception {
+ @Test
+ public void rejectsWithoutClientCertificate() {
startServerEnforcingClientCert(KEY_STORE_PATH, TRUST_STORE_PATH, TRUST_STORE_PASSWORD);
stubFor(get(urlEqualTo("/https-test")).willReturn(aResponse().withStatus(200).withBody("HTTPS content")));
- contentFor(url("/https-test")); // this lacks the required client certificate
+ try {
+ contentFor(url("/https-test")); // this lacks the required client certificate
+ fail("Expected a SocketException or SSLHandshakeException to be thrown");
+ } catch (Exception e) {
+ assertThat(e.getClass().getName(), Matchers.anyOf(is(SocketException.class.getName()), is(SSLHandshakeException.class.getName())));
+ }
}
@Test

0 comments on commit c1e40d5

Please sign in to comment.