-
Notifications
You must be signed in to change notification settings - Fork 674
/
HttpRequestTlsInsecureTestCase.java
83 lines (73 loc) · 2.82 KB
/
HttpRequestTlsInsecureTestCase.java
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
* Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
* The software in this package is published under the terms of the CPAL v1.0
* license, a copy of which has been included with this distribution in the
* LICENSE.txt file.
*/
package org.mule.module.http.functional.requester;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.isA;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import static org.junit.internal.matchers.ThrowableMessageMatcher.hasMessage;
import static org.junit.rules.ExpectedException.none;
import org.mule.api.MessagingException;
import org.mule.api.MuleEvent;
import org.mule.construct.Flow;
import org.mule.tck.junit4.FunctionalTestCase;
import org.mule.tck.junit4.rule.DynamicPort;
import org.mule.tck.junit4.rule.SystemProperty;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
/**
* Sets up two HTTPS clients using a regular trust-store, but one of them insecure.
* Then two HTTPS servers: one will return a certificate present in the trust-store
* but with an invalid SAN extension, the other will return a certificate that's not in the trust-store.
* Verifies that only the insecure client is successful.
*/
@RunWith(Parameterized.class)
public class HttpRequestTlsInsecureTestCase extends FunctionalTestCase
{
@Parameterized.Parameter
public String config;
@Rule
public DynamicPort port1 = new DynamicPort("port1");
@Rule
public SystemProperty insecure = new SystemProperty("insecure", "true");
@Rule
public ExpectedException expectedException = none();
@Override
protected String getConfigFile()
{
return config;
}
@Parameterized.Parameters
public static Collection<Object[]> parameters()
{
return Arrays.asList(new Object[][] {
{"http-request-insecure-hostname-config.xml"},
{"http-request-insecure-certificate-config.xml"}});
}
@Test
public void insecureRequest() throws Exception
{
Flow flow = (Flow) getFlowConstruct("testInsecureRequest");
final MuleEvent res = flow.process(getTestEvent(TEST_PAYLOAD));
assertThat(res.getMessage().getPayloadAsString(), is(TEST_PAYLOAD));
}
@Test
public void secureRequest() throws Exception
{
Flow flow = (Flow) getFlowConstruct("testSecureRequest");
expectedException.expect(MessagingException.class);
expectedException.expectCause(isA(IOException.class));
expectedException.expectCause(hasMessage(containsString("General SSLEngine problem")));
flow.process(getTestEvent(TEST_PAYLOAD));
}
}