コード例 #1
0
        public async Task TransparentGateway(
            [Values] TestAuthenticationType testAuth,
            [Values(Protocol.Mqtt, Protocol.Amqp)] Protocol protocol)
        {
            CancellationToken token = this.TestToken;

            string leafDeviceId = DeviceId.Current.Generate();

            Option <string> parentId = testAuth == TestAuthenticationType.SasOutOfScope
                ? Option.None <string>()
                : Option.Some(this.runtime.DeviceId);

            var leaf = await LeafDevice.CreateAsync(
                leafDeviceId,
                protocol,
                testAuth.ToAuthenticationType(),
                parentId,
                testAuth.UseSecondaryCertificate(),
                this.ca,
                this.iotHub,
                token);

            await TryFinally.DoAsync(
                async() =>
            {
                DateTime seekTime = DateTime.Now;
                await leaf.SendEventAsync(token);
                await leaf.WaitForEventsReceivedAsync(seekTime, token);
                await leaf.InvokeDirectMethodAsync(token);
            },
                async() =>
            {
                await leaf.DeleteIdentityAsync(token);
            });
        }
コード例 #2
0
        public async Task TransparentGateway(
            [Values] TestAuthenticationType testAuth,
            [Values(Protocol.Mqtt, Protocol.Amqp)] Protocol protocol)
        {
            CancellationToken token = this.TestToken;

            await this.runtime.DeployConfigurationAsync(token, Context.Current.NestedEdge);

            string leafDeviceId = DeviceId.Current.Generate();

            Option <string> parentId = testAuth == TestAuthenticationType.SasOutOfScope
                ? Option.None <string>()
                : Option.Some(this.runtime.DeviceId);

            LeafDevice leaf = null;

            try
            {
                leaf = await LeafDevice.CreateAsync(
                    leafDeviceId,
                    protocol,
                    testAuth.ToAuthenticationType(),
                    parentId,
                    testAuth.UseSecondaryCertificate(),
                    this.ca,
                    this.iotHub,
                    Context.Current.Hostname.GetOrElse(Dns.GetHostName().ToLower()),
                    token,
                    Option.None <string>(),
                    Context.Current.NestedEdge);
            }
            catch (Exception) when(!parentId.HasValue)
            {
                return;
            }

            if (!parentId.HasValue)
            {
                Assert.Fail("Expected to fail when not in scope.");
            }

            Assert.NotNull(leaf);

            await TryFinally.DoAsync(
                async() =>
            {
                DateTime seekTime = DateTime.Now;
                await leaf.SendEventAsync(token);
                await leaf.WaitForEventsReceivedAsync(seekTime, token);
                await leaf.InvokeDirectMethodAsync(token);
            },
                async() =>
            {
                await leaf.DeleteIdentityAsync(token);
            });
        }
コード例 #3
0
        public async Task TransparentGateway(
            [Values] TestAuthenticationType testAuth,
            [Values(Protocol.Mqtt, Protocol.Amqp)] Protocol protocol)
        {
            if (!OsPlatform.IsWindows() && (protocol == Protocol.Amqp))
            {
                switch (testAuth)
                {
                case TestAuthenticationType.SelfSignedPrimary:
                case TestAuthenticationType.SelfSignedSecondary:
                case TestAuthenticationType.CertificateAuthority:
                    Assert.Ignore("Skipping the test case due to BUG 5234369");
                    break;

                default:
                    // Intentionally left blank
                    break;
                }
            }

            CancellationToken token = this.TestToken;

            string leafDeviceId = IdentityLimits.CheckLeafId(
                $"{Context.Current.DeviceId}-{protocol}-{testAuth}");

            Option <string> parentId = testAuth == TestAuthenticationType.SasOutOfScope
                ? Option.None <string>()
                : Option.Some(Context.Current.DeviceId.ToString());

            var leaf = await LeafDevice.CreateAsync(
                leafDeviceId,
                protocol,
                testAuth.ToAuthenticationType(),
                parentId,
                testAuth.UseSecondaryCertificate(),
                this.ca,
                this.iotHub,
                token);

            await TryFinally.DoAsync(
                async() =>
            {
                DateTime seekTime = DateTime.Now;
                await leaf.SendEventAsync(token);
                await leaf.WaitForEventsReceivedAsync(seekTime, token);
                await leaf.InvokeDirectMethodAsync(token);
            },
                async() =>
            {
                await leaf.DeleteIdentityAsync(token);
            });
        }
コード例 #4
0
ファイル: Device.cs プロジェクト: wpxdong/iotedge
        public async Task TransparentGateway(
            [Values] TestAuthenticationType testAuth,
            [Values(Protocol.Mqtt, Protocol.Amqp)] Protocol protocol)
        {
            // For CA and self-signed cert tests, temporarily disable AMQP
            var auth = testAuth.ToAuthenticationType();

            if (protocol == Protocol.Amqp &&
                (auth == AuthenticationType.CertificateAuthority || auth == AuthenticationType.SelfSigned))
            {
                Assert.Ignore("x509 cert + AMQP tests disabled until bug is resolved");
            }

            CancellationToken token = this.cts.Token;

            // Generate a leaf device ID--based on the (edge) device ID--that is at most
            // (deviceId.Length + 26 chars) long. This gives us a leaf device ID of <= 63
            // characters, and gives LeafDevice.CreateAsync (called below) some wiggle room to
            // create certs with unique CNs that don't exceed the 64-char limit.
            string leafDeviceId = $"{Context.Current.DeviceId}-{protocol.ToString()}-{testAuth.ToString()}";

            Option <string> parentId = testAuth == TestAuthenticationType.SasOutOfScope
                ? Option.None <string>()
                : Option.Some(Context.Current.DeviceId);

            var leaf = await LeafDevice.CreateAsync(
                leafDeviceId,
                protocol,
                auth,
                parentId,
                testAuth.UseSecondaryCertificate(),
                this.ca,
                this.iotHub,
                token);

            await TryFinally.DoAsync(
                async() =>
            {
                DateTime seekTime = DateTime.Now;
                await leaf.SendEventAsync(token);
                await leaf.WaitForEventsReceivedAsync(seekTime, token);
                await leaf.InvokeDirectMethodAsync(token);
            },
                async() =>
            {
                await leaf.DeleteIdentityAsync(token);
            });
        }
コード例 #5
0
        public async Task GrandparentScopeDevice(
            [Values(
                 TestAuthenticationType.SasInScope,
                 TestAuthenticationType.SelfSignedPrimary,
                 TestAuthenticationType.SelfSignedSecondary)] TestAuthenticationType testAuth,
            [Values(Protocol.Mqtt, Protocol.Amqp)] Protocol protocol)
        {
            if (!this.device.NestedEdge.IsNestedEdge)
            {
                Assert.Ignore("The test can only be run in the nested edge topology");
            }

            Option <string> parentId = Option.Some(this.runtime.DeviceId);

            CancellationToken token = this.TestToken;

            await this.runtime.DeployConfigurationAsync(token, Context.Current.NestedEdge);

            string leafDeviceId = DeviceId.Current.Generate();

            LeafDevice leaf = null;

            try
            {
                leaf = await LeafDevice.CreateAsync(
                    leafDeviceId,
                    protocol,
                    testAuth.ToAuthenticationType(),
                    parentId,
                    testAuth.UseSecondaryCertificate(),
                    this.ca,
                    this.IotHub,
                    this.device.NestedEdge.ParentHostname,
                    token,
                    Option.None <string>(),
                    this.device.NestedEdge.IsNestedEdge);
            }
            catch (Exception) when(!parentId.HasValue)
            {
                return;
            }

            if (!parentId.HasValue)
            {
                Assert.Fail("Expected to fail when not in scope.");
            }

            Assert.NotNull(leaf);

            await TryFinally.DoAsync(
                async() =>
            {
                DateTime seekTime = DateTime.Now;
                await leaf.SendEventAsync(token);
                await leaf.WaitForEventsReceivedAsync(seekTime, token);
                await leaf.InvokeDirectMethodAsync(token);
            },
                async() =>
            {
                await leaf.DeleteIdentityAsync(token);
                await Task.CompletedTask;
            });
        }