Skip to content

Commit c0324f6

Browse files
Enable invalid cert test (#1652)
* Enable invalid cert test * Add docker directory * Update windowsLinuxAndAndroidBuildMatrixConfig.yaml Add ACR login task * Cleanup * Update ProvisioningTests.java Re-enable invalid cert tests * Update iot-e2e-tests/docker/readme.md Co-authored-by: Sophia Ji Who Choi <[email protected]> * Cleanup * Prevent test from running on windows * Add yaml task to Android * Remove cert tests from Android build * Cleanup Co-authored-by: Sophia Ji Who Choi <[email protected]>
1 parent c634fcd commit c0324f6

File tree

17 files changed

+428
-43
lines changed

17 files changed

+428
-43
lines changed

iot-e2e-tests/common/src/test/java/tests/integration/com/microsoft/azure/sdk/iot/helpers/Tools.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,11 @@ public static String getStackTraceFromThrowable(Throwable throwable)
962962
return ExceptionUtils.getStackTrace(throwable);
963963
}
964964

965+
public static boolean isLinux()
966+
{
967+
return System.getProperty("os.name").toLowerCase().contains("linux");
968+
}
969+
965970
public static boolean isAndroid()
966971
{
967972
return IS_ANDROID;

iot-e2e-tests/common/src/test/java/tests/integration/com/microsoft/azure/sdk/iot/iothub/serviceclient/MessagingClientTests.java

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,36 @@
66
package tests.integration.com.microsoft.azure.sdk.iot.iothub.serviceclient;
77

88
import com.azure.core.credential.AzureSasCredential;
9+
import com.microsoft.azure.sdk.iot.device.IotHubClientProtocol;
910
import com.microsoft.azure.sdk.iot.device.auth.IotHubSSLContext;
10-
import com.microsoft.azure.sdk.iot.service.exceptions.IotHubException;
11-
import com.microsoft.azure.sdk.iot.service.exceptions.IotHubMessageTooLargeException;
12-
import com.microsoft.azure.sdk.iot.service.messaging.MessagingClient;
13-
import com.microsoft.azure.sdk.iot.service.registry.Device;
11+
import com.microsoft.azure.sdk.iot.service.ProxyOptions;
12+
import com.microsoft.azure.sdk.iot.service.auth.AuthenticationType;
1413
import com.microsoft.azure.sdk.iot.service.auth.IotHubConnectionString;
1514
import com.microsoft.azure.sdk.iot.service.auth.IotHubConnectionStringBuilder;
15+
import com.microsoft.azure.sdk.iot.service.auth.IotHubServiceSasToken;
16+
import com.microsoft.azure.sdk.iot.service.exceptions.IotHubException;
17+
import com.microsoft.azure.sdk.iot.service.exceptions.IotHubMessageTooLargeException;
18+
import com.microsoft.azure.sdk.iot.service.exceptions.IotHubUnauthorizedException;
1619
import com.microsoft.azure.sdk.iot.service.messaging.IotHubServiceClientProtocol;
1720
import com.microsoft.azure.sdk.iot.service.messaging.Message;
18-
import com.microsoft.azure.sdk.iot.service.ProxyOptions;
21+
import com.microsoft.azure.sdk.iot.service.messaging.MessagingClient;
22+
import com.microsoft.azure.sdk.iot.service.messaging.MessagingClientOptions;
23+
import com.microsoft.azure.sdk.iot.service.registry.Device;
1924
import com.microsoft.azure.sdk.iot.service.registry.RegistryClient;
2025
import com.microsoft.azure.sdk.iot.service.registry.RegistryClientOptions;
21-
import com.microsoft.azure.sdk.iot.service.messaging.MessagingClientOptions;
22-
import com.microsoft.azure.sdk.iot.service.auth.IotHubServiceSasToken;
23-
import com.microsoft.azure.sdk.iot.service.exceptions.IotHubUnauthorizedException;
2426
import lombok.extern.slf4j.Slf4j;
25-
import com.microsoft.azure.sdk.iot.device.IotHubClientProtocol;
26-
import com.microsoft.azure.sdk.iot.service.auth.AuthenticationType;
2727
import org.junit.AfterClass;
28+
import org.junit.Assume;
2829
import org.junit.BeforeClass;
29-
import org.junit.Ignore;
3030
import org.junit.Test;
3131
import org.junit.runner.RunWith;
3232
import org.junit.runners.Parameterized;
33-
import tests.integration.com.microsoft.azure.sdk.iot.helpers.proxy.HttpProxyServer;
34-
import tests.integration.com.microsoft.azure.sdk.iot.helpers.proxy.impl.DefaultHttpProxyServer;
35-
import tests.integration.com.microsoft.azure.sdk.iot.helpers.IntegrationTest;
36-
import tests.integration.com.microsoft.azure.sdk.iot.helpers.SasTokenTools;
37-
import tests.integration.com.microsoft.azure.sdk.iot.helpers.TestConstants;
38-
import tests.integration.com.microsoft.azure.sdk.iot.helpers.TestDeviceIdentity;
39-
import tests.integration.com.microsoft.azure.sdk.iot.helpers.Tools;
33+
import tests.integration.com.microsoft.azure.sdk.iot.helpers.*;
4034
import tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest;
4135
import tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.IotHubTest;
4236
import tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest;
37+
import tests.integration.com.microsoft.azure.sdk.iot.helpers.proxy.HttpProxyServer;
38+
import tests.integration.com.microsoft.azure.sdk.iot.helpers.proxy.impl.DefaultHttpProxyServer;
4339

4440
import javax.net.ssl.SSLContext;
4541
import java.io.IOException;
@@ -336,11 +332,11 @@ public void messagingClientTokenRenewalWithAzureSasCredential() throws Exception
336332
Tools.disposeTestIdentity(testDeviceIdentity, iotHubConnectionString);
337333
}
338334

339-
@Ignore // The IoT Hub instance we use for this test is currently offline, so this test cannot be run
340335
@Test
341336
@ContinuousIntegrationTest
342337
public void messagingClientValidatesRemoteCertificateWhenSendingTelemetry() throws InterruptedException
343338
{
339+
Assume.assumeTrue(Tools.isLinux());
344340
boolean expectedExceptionWasCaught = false;
345341

346342
MessagingClient messagingClient = new MessagingClient(invalidCertificateServerConnectionString, testInstance.protocol);

iot-e2e-tests/common/src/test/java/tests/integration/com/microsoft/azure/sdk/iot/provisioning/ProvisioningTests.java

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,45 +5,24 @@
55

66
package tests.integration.com.microsoft.azure.sdk.iot.provisioning;
77

8-
9-
import com.microsoft.azure.sdk.iot.device.exceptions.IotHubClientException;
10-
import com.microsoft.azure.sdk.iot.device.twin.TwinCollection;
11-
import com.microsoft.azure.sdk.iot.provisioning.service.configs.DeviceCapabilities;
12-
import com.microsoft.azure.sdk.iot.device.DeviceClient;
13-
import com.microsoft.azure.sdk.iot.device.IotHubClientProtocol;
148
import com.microsoft.azure.sdk.iot.provisioning.device.ProvisioningDeviceClientTransportProtocol;
159
import com.microsoft.azure.sdk.iot.provisioning.security.SecurityProvider;
1610
import com.microsoft.azure.sdk.iot.provisioning.security.SecurityProviderTpm;
1711
import com.microsoft.azure.sdk.iot.provisioning.security.exceptions.SecurityProviderException;
1812
import com.microsoft.azure.sdk.iot.provisioning.security.hsm.SecurityProviderTPMEmulator;
1913
import com.microsoft.azure.sdk.iot.provisioning.service.configs.*;
2014
import com.microsoft.azure.sdk.iot.provisioning.service.exceptions.ProvisioningServiceClientException;
21-
import com.microsoft.azure.sdk.iot.service.auth.IotHubConnectionString;
22-
import com.microsoft.azure.sdk.iot.service.twin.Twin;
23-
import com.microsoft.azure.sdk.iot.service.twin.TwinClient;
24-
import com.microsoft.azure.sdk.iot.service.twin.TwinClientOptions;
25-
import com.microsoft.azure.sdk.iot.service.exceptions.IotHubException;
26-
import org.junit.Assert;
27-
import org.junit.Ignore;
15+
import org.junit.Assume;
2816
import org.junit.Test;
2917
import org.junit.runner.RunWith;
3018
import org.junit.runners.Parameterized;
31-
import tests.integration.com.microsoft.azure.sdk.iot.helpers.CorrelationDetailsLoggingAssert;
3219
import tests.integration.com.microsoft.azure.sdk.iot.helpers.Tools;
3320
import tests.integration.com.microsoft.azure.sdk.iot.helpers.X509CertificateGenerator;
3421
import tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest;
3522
import tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.DeviceProvisioningServiceTest;
36-
import tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest;
3723
import tests.integration.com.microsoft.azure.sdk.iot.provisioning.setup.ProvisioningCommon;
3824

3925
import javax.net.ssl.SSLHandshakeException;
40-
import java.io.IOException;
41-
import java.net.URISyntaxException;
42-
import java.util.ArrayList;
43-
import java.util.List;
44-
import java.util.concurrent.CountDownLatch;
45-
import java.util.concurrent.TimeUnit;
46-
import java.util.concurrent.TimeoutException;
4726

4827
import static com.microsoft.azure.sdk.iot.provisioning.device.ProvisioningDeviceClientTransportProtocol.*;
4928
import static junit.framework.TestCase.assertNotNull;
@@ -81,19 +60,19 @@ public void enrollmentGroupRegistration() throws Exception
8160
basicRegistrationFlow(EnrollmentType.GROUP);
8261
}
8362

84-
@Ignore // The DPS instance we use for this test is currently offline, so this test cannot be run
8563
@Test
8664
@ContinuousIntegrationTest
8765
public void individualEnrollmentWithInvalidRemoteServerCertificateFails() throws Exception
8866
{
67+
Assume.assumeTrue(Tools.isLinux());
8968
enrollmentWithInvalidRemoteServerCertificateFails(EnrollmentType.INDIVIDUAL);
9069
}
9170

92-
@Ignore // The DPS instance we use for this test is currently offline, so this test cannot be run
9371
@Test
9472
@ContinuousIntegrationTest
9573
public void groupEnrollmentWithInvalidRemoteServerCertificateFails() throws Exception
9674
{
75+
Assume.assumeTrue(Tools.isLinux());
9776
enrollmentWithInvalidRemoteServerCertificateFails(EnrollmentType.GROUP);
9877
}
9978

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/bin/bash
2+
LOG_INFO="\x1b[33;42;1m[INFO]:\x1b[0m"
3+
LOG_TODO="\x1b[37;43;1m[TODO]:\x1b[0m"
4+
LOG_ERR="\x1b[33;41;1m[ERROR]:\x1b[0m"
5+
6+
echo "============"
7+
echo "Start Docker"
8+
echo "============"
9+
echo "running from $(pwd)"
10+
sudo service docker start
11+
12+
echo "========================"
13+
echo "Extract self-signed cert"
14+
echo "========================"
15+
PROXY_CERT_ZFILE="./haproxy/haproxy.bin"
16+
PROXY_CERT_FILE="./haproxy/haproxy.pem"
17+
if [ -f "$PROXY_CERT_FILE" ];
18+
then
19+
echo -e "$LOG_INFO Use existing Proxy Service Cert found."
20+
elif [ -f "$PROXY_CERT_ZFILE" ];
21+
then
22+
gzip -d -N -k -q -S ".bin" ./haproxy/haproxy.bin
23+
echo -e "$LOG_INFO Proxy Service Cert extracted."
24+
else
25+
echo -e "$LOG_ERR Missing Proxy Service Cert! Check your repo."
26+
exit
27+
fi
28+
29+
echo "==============="
30+
echo "Inspect network"
31+
echo "==============="
32+
ip -4 addr
33+
CVTEST_HOST_IP=$(ip -4 addr show eth0 | grep -Po 'inet \K[\d.]+')
34+
CVTEST_HOST_NETWORK=$(ip -4 addr show eth0 | grep -Po 'inet \K[\d.]+/*\d.')
35+
CVTEST_HOST_SUBNET=$(ip -4 addr show eth0 | grep -Po 'inet \K[\d.]+' | grep -Po '[\d]{1,3}.[\d]{1,3}.[\d]{1,3}')
36+
CVTEST_HOST_SUBNET_MASK=$(ip -4 addr show eth0 | grep -Po 'inet \K[\d.]+/*\d.' | grep -Po '/[\d]{1,2}')
37+
CVTEST_CONTAINER_GW=$(ip -4 addr show docker0 | grep -Po 'inet \K[\d.]+')
38+
CVTEST_HOST_WSL_IP=$(ip -4 addr show eth0 | grep -Po 'inet \K[\d.]+')
39+
CVTEST_ROUTE_NET=$(route -n | grep 'eth0' | grep -v 'UG' | awk -F" " '{print $1}' | awk -F"." '{print $1"."$2"."$3"."$4"/29"}')
40+
CVTEST_TST_NET=$CVTEST_HOST_NETWORK
41+
CVTEST_GDE_IP=$(ip -4 addr show eth0 | grep -Po 'inet \K[\d.]+' | awk -F"." '{print $1"."$2"."$3"."$4+3}')
42+
CVTEST_DPS_IP=$(ip -4 addr show eth0 | grep -Po 'inet \K[\d.]+' | awk -F"." '{print $1"."$2"."$3"."$4+4}')
43+
CVTEST_HUB_IP=$(ip -4 addr show eth0 | grep -Po 'inet \K[\d.]+' | awk -F"." '{print $1"."$2"."$3"."$4+5}')
44+
echo "HOST=$CVTEST_HOST_IP"
45+
echo "HOST NETWORK=$CVTEST_HOST_NETWORK"
46+
echo "HOST SUBNET=$CVTEST_HOST_SUBNET"
47+
echo "HOST SUBNET MASK=$CVTEST_HOST_SUBNET_MASK"
48+
echo "Container GW=$CVTEST_CONTAINER_GW"
49+
echo "WSL=$CVTEST_HOST_WSL_IP"
50+
echo "Container NET=$CVTEST_TST_NET"
51+
echo "Container GDE=$CVTEST_GDE_IP"
52+
echo "Container DPS=$CVTEST_DPS_IP"
53+
echo "Container HUB=$CVTEST_HUB_IP"
54+
ping -c 2 $CVTEST_HOST_IP
55+
56+
echo "===================="
57+
echo "Setup docker network"
58+
echo "===================="
59+
docker images
60+
docker ps -a
61+
docker stop invalid-gde invalid-dps invalid-hub e2etest-tpm e2etest-pxy
62+
docker rm invalid-gde invalid-dps invalid-hub e2etest-tpm e2etest-pxy
63+
docker network rm testnet
64+
docker network create -d ipvlan --subnet=$CVTEST_TST_NET -o ipvlan_mode=l2 -o parent=eth0 testnet
65+
docker network ls
66+
67+
echo "======================"
68+
echo "Setup docker instances"
69+
echo "======================"
70+
AZURE_ACR_TOKEN=$(az acr login -n aziotacr -t --output tsv --query accessToken)
71+
echo $AZURE_ACR_TOKEN | docker login aziotacr.azurecr.io --username 00000000-0000-0000-0000-000000000000 --password-stdin
72+
docker run -h invalidcertgde1.westus.cloudapp.azure.com --name invalid-gde --expose=443 --expose=5671 --expose=8883 --network=testnet --ip=$CVTEST_GDE_IP -v $(pwd)/haproxy:/usr/local/etc/haproxy:ro -d aziotacr.azurecr.io/haproxy haproxy -f /usr/local/etc/haproxy/haproxygde.cfg
73+
docker run -h invalidcertdps1.westus.cloudapp.azure.com --name invalid-dps --expose=443 --expose=5671 --expose=8883 --network=testnet --ip=$CVTEST_DPS_IP -v $(pwd)/haproxy:/usr/local/etc/haproxy:ro -d aziotacr.azurecr.io/haproxy haproxy -f /usr/local/etc/haproxy/haproxydps.cfg
74+
docker run -h invalidcertiothub1.westus.cloudapp.azure.com --name invalid-hub --expose=443 --expose=5671 --expose=8883 --network=testnet --ip=$CVTEST_HUB_IP -v $(pwd)/haproxy:/usr/local/etc/haproxy:ro -d aziotacr.azurecr.io/haproxy haproxy -f /usr/local/etc/haproxy/haproxyhub.cfg
75+
docker run --name e2etest-tpm -p 127.0.0.1:2321:2321 -p 127.0.0.1:2322:2322 -d aziotacr.azurecr.io/aziotbld/testtpm
76+
docker run --name e2etest-pxy -p 127.0.0.1:8888:8888 -d aziotacr.azurecr.io/aziotbld/testproxy
77+
78+
echo "================="
79+
echo "Inspect instances"
80+
echo "================="
81+
docker ps -a
82+
83+
echo "========================================================"
84+
echo -e "$LOG_TODO update host file for local E2E Tests"
85+
echo " (on your host Windows OS)"
86+
echo " add/update hosts file with the following entries"
87+
echo " (at C:\Windows\System32\drivers\etc\hosts)"
88+
echo "========================================================"
89+
echo "$(docker inspect invalid-gde | grep -Po -m 1 '"IPAddress": "\K[\d.]+') invalidcertgde1.westus.cloudapp.azure.com"
90+
echo "$(docker inspect invalid-dps | grep -Po -m 1 '"IPAddress": "\K[\d.]+') invalidcertdps1.westus.cloudapp.azure.com"
91+
echo "$(docker inspect invalid-hub | grep -Po -m 1 '"IPAddress": "\K[\d.]+') invalidcertiothub1.westus.cloudapp.azure.com"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
HTTP/1.0 400 Bad request
2+
Cache-Control: no-cache
3+
Connection: close
4+
Content-Type: text/html
5+
6+
<html><body><h1>400 Bad request</h1>
7+
Your browser sent an invalid request.
8+
</body></html>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
HTTP/1.0 403 Forbidden
2+
Cache-Control: no-cache
3+
Connection: close
4+
Content-Type: text/html
5+
6+
<html><body><h1>403 Forbidden</h1>
7+
Request forbidden by administrative rules.
8+
</body></html>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
HTTP/1.0 408 Request Time-out
2+
Cache-Control: no-cache
3+
Connection: close
4+
Content-Type: text/html
5+
6+
<html><body><h1>408 Request Time-out</h1>
7+
Your browser didn't send a complete request in time.
8+
</body></html>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
HTTP/1.0 500 Internal Server Error
2+
Cache-Control: no-cache
3+
Connection: close
4+
Content-Type: text/html
5+
6+
<html><body><h1>500 Internal Server Error</h1>
7+
An internal server error occurred.
8+
</body></html>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
HTTP/1.0 502 Bad Gateway
2+
Cache-Control: no-cache
3+
Connection: close
4+
Content-Type: text/html
5+
6+
<html><body><h1>502 Bad Gateway</h1>
7+
The server returned an invalid or incomplete response.
8+
</body></html>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
HTTP/1.0 503 Service Unavailable
2+
Cache-Control: no-cache
3+
Connection: close
4+
Content-Type: text/html
5+
6+
<html><body><h1>503 Service Unavailable</h1>
7+
No server is available to handle this request.
8+
</body></html>

0 commit comments

Comments
 (0)