예제 #1
0
        public async Task TestCreate_FromEnvironment_UnsupportedAuth_ShouldThrow()
        {
            try
            {
                Environment.SetEnvironmentVariable(IotEdgedUriVariableName, ServerUrl);
                Environment.SetEnvironmentVariable(IotHubHostnameVariableName, "iothub.test");
                Environment.SetEnvironmentVariable(GatewayHostnameVariableName, "localhost");
                Environment.SetEnvironmentVariable(DeviceIdVariableName, "device1");
                Environment.SetEnvironmentVariable(ModuleIdVariableName, "module1");

                Environment.SetEnvironmentVariable(AuthSchemeVariableName, "x509Cert");
                var settings    = new ITransportSettings[] { new MqttTransportSettings(TransportType.Mqtt_Tcp_Only) };
                var trustBundle = Substitute.For <ITrustBundleProvider>();
                await TestAssert
                .ThrowsAsync <InvalidOperationException>(async() => await new EdgeModuleClientFactory(settings, trustBundle).CreateAsync().ConfigureAwait(false))
                .ConfigureAwait(false);
            }
            finally
            {
                Environment.SetEnvironmentVariable(IotEdgedUriVariableName, null);
                Environment.SetEnvironmentVariable(IotHubHostnameVariableName, null);
                Environment.SetEnvironmentVariable(GatewayHostnameVariableName, null);
                Environment.SetEnvironmentVariable(DeviceIdVariableName, null);
                Environment.SetEnvironmentVariable(ModuleIdVariableName, null);
            }
        }
예제 #2
0
        public void TestDeserializeResponse_InvalidContentLength_ShouldThrow()
        {
            byte[]             expected = Encoding.UTF8.GetBytes("HTTP/1.1 200 OK\r\nContent-length: 5\r\n\r\nMessage is longer");
            var                memory   = new MemoryStream(expected, true);
            HttpBufferedStream stream   = new HttpBufferedStream(memory);

            System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken);
            TestAssert.ThrowsAsync <HttpRequestException>(() => new HttpRequestResponseSerializer().DeserializeResponseAsync(stream, cancellationToken)).Wait();
        }
예제 #3
0
        public void TestDeserializeResponse_MissingReasonPhrase_ShouldThrow()
        {
            byte[]             expected = Encoding.UTF8.GetBytes("HTTP/1.1 200\r\n");
            var                memory   = new MemoryStream(expected, true);
            HttpBufferedStream stream   = new HttpBufferedStream(memory);

            System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken);
            TestAssert.ThrowsAsync <HttpRequestException>(() => new HttpRequestResponseSerializer().DeserializeResponseAsync(stream, cancellationToken)).Wait();
        }
예제 #4
0
        public void TestDeserializeResponse_InvalidEndOfStream_ShouldThrow()
        {
            byte[]             expected = Encoding.UTF8.GetBytes("invalid");
            var                memory   = new MemoryStream(expected, true);
            HttpBufferedStream stream   = new HttpBufferedStream(memory);

            System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken);
            TestAssert.ThrowsAsync <IOException>(() => new HttpRequestResponseSerializer().DeserializeResponseAsync(stream, cancellationToken)).Wait();
        }
예제 #5
0
        public void TestDeserializeResponse_InvalidStatusCode_ShouldThrow()
        {
            byte[]             expected = Encoding.UTF8.GetBytes("HTTP/1.1 2000 OK\r\n");
            var                memory   = new MemoryStream(expected, true);
            HttpBufferedStream stream   = new HttpBufferedStream(memory);

            System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken);
            TestAssert.ThrowsAsync <ArgumentOutOfRangeException>(() => new HttpRequestResponseSerializer().DeserializeResponse(stream, cancellationToken)).Wait();
        }
        public void TestDeserializeResponse_InvalidProtocolVersionSeparator_ShouldThrow()
        {
            byte[]             expected = Encoding.UTF8.GetBytes("HTTP-1.1 200 OK\r\n");
            var                memory   = new MemoryStream(expected, true);
            HttpBufferedStream stream   = new HttpBufferedStream(memory);

            System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken);
            TestAssert.ThrowsAsync <HttpRequestException>(() => HttpRequestResponseSerializer.DeserializeResponseAsync(stream, cancellationToken)).Wait();
        }
예제 #7
0
        public async Task TestDeserializeResponse_InvalidEndOfStatusMessage_ShouldThrow()
        {
            byte[]             expected = Encoding.UTF8.GetBytes("HTTP/1.1 200 OK \r\n");
            var                memory   = new MemoryStream(expected, true);
            HttpBufferedStream stream   = new HttpBufferedStream(memory);

            CancellationToken cancellationToken = default(System.Threading.CancellationToken);
            await TestAssert.ThrowsAsync <IOException>(() => HttpRequestResponseSerializer.DeserializeResponseAsync(stream, cancellationToken));
        }
예제 #8
0
        public async Task TestSafeCreateNewToken_WhenIotEdgedThrows_ShouldThrow()
        {
            var httpClient = new Mock <ISignatureProvider>();

            httpClient.Setup(p => p.SignAsync(this.moduleId, this.generationId, It.IsAny <string>())).Throws(new HttpHsmComunicationException(It.IsAny <string>(), It.IsAny <int>()));

            var authenticationWithHsm = new ModuleAuthenticationWithHsm(httpClient.Object, this.deviceId, this.moduleId, this.generationId);

            await TestAssert.ThrowsAsync <HttpHsmComunicationException>(async() => await authenticationWithHsm.GetTokenAsync(this.iotHub));
        }