コード例 #1
0
        public async Task X509ManualProvision()
        {
            CancellationToken token = this.TestToken;

            await this.runtime.DeployConfigurationAsync(token);

            string leafDeviceId =
                IdentityLimits.CheckLeafId($"{Context.Current.DeviceId}-x509-quickstart-certs");

            var leaf = await LeafDevice.CreateAsync(
                leafDeviceId,
                Protocol.Amqp,
                AuthenticationType.Sas,
                Option.Some(Context.Current.DeviceId + "-x509"),
                false,
                CertificateAuthority.GetQuickstart(),
                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 QuickstartCerts()
        {
            CancellationToken token = this.TestToken;

            await this.runtime.DeployConfigurationAsync(token, this.device.NestedEdge.IsNestedEdge);

            string leafDeviceId = DeviceId.Current.Generate();

            var leaf = await LeafDevice.CreateAsync(
                leafDeviceId,
                Protocol.Amqp,
                AuthenticationType.Sas,
                Option.Some(this.runtime.DeviceId),
                false,
                this.ca,
                this.IotHub,
                this.device.NestedEdge.DeviceHostname,
                token,
                Option.None <string>(),
                this.device.NestedEdge.IsNestedEdge);

            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
ファイル: X509Device.cs プロジェクト: v-gpettibone/iotedge
        public async Task X509ManualProvision()
        {
            CancellationToken token = this.TestToken;

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

            string leafDeviceId = DeviceId.Current.Generate();

            var leaf = await LeafDevice.CreateAsync(
                leafDeviceId,
                Protocol.Amqp,
                AuthenticationType.Sas,
                Option.Some(this.runtime.DeviceId),
                false,
                this.ca,
                this.IotHub,
                Context.Current.Hostname.GetOrElse(Dns.GetHostName().ToLower()),
                token,
                Option.None <string>(),
                Context.Current.NestedEdge);

            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
        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);
            });
        }
コード例 #5
0
        protected internal override Statement VisitTryFinally(TryFinally inst)
        {
            var tryCatch = MakeTryCatch(inst.TryBlock);

            tryCatch.FinallyBlock = ConvertAsBlock(inst.FinallyBlock);
            return(tryCatch);
        }
コード例 #6
0
        public async Task QuickstartCerts()
        {
            CancellationToken token = this.cts.Token;

            await this.runtime.DeployConfigurationAsync(token);

            string leafDeviceId = $"{Context.Current.DeviceId}-quickstart-certs";

            var leaf = await LeafDevice.CreateAsync(
                leafDeviceId,
                Protocol.Amqp,
                AuthenticationType.Sas,
                Option.None <string>(),
                false,
                CertificateAuthority.GetQuickstart(),
                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);
            });
        }
コード例 #7
0
 protected internal override void VisitTryFinally(TryFinally inst)
 {
     Assert.IsTrue(IsPotentiallyUninitialized(state, v));
     base.VisitTryFinally(inst);
     Assert.IsTrue(state.IsReachable);
     Assert.AreEqual(1, GetStores(state, v).Count());
     Assert.IsFalse(IsPotentiallyUninitialized(state, v));
 }
コード例 #8
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);
            });
        }
コード例 #9
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);
            });
        }
コード例 #10
0
ファイル: DataFlowVisitor.cs プロジェクト: wanglong/ILSpy
        protected internal override void VisitTryFinally(TryFinally inst)
        {
            DebugStartPoint(inst);
            // At first, handle 'try { .. } finally { .. }' like 'try { .. } catch {} .. if (?) rethrow; }'
            State onException = HandleTryBlock(inst);
            State onSuccess   = state.Clone();

            state.JoinWith(onException);
            inst.FinallyBlock.AcceptVisitor(this);
            PropagateStateOnException();
            // Use MeetWith() to ensure points after the try-finally are reachable only if both the
            // try and the finally endpoints are reachable.
            state.MeetWith(onSuccess);
            DebugEndPoint(inst);
        }
コード例 #11
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);
            });
        }
コード例 #12
0
        public async Task DisableReenableParentEdge()
        {
            CancellationToken token = this.TestToken;

            Log.Information("Deploying L3 Edge");
            await this.runtime.DeployConfigurationAsync(token, Context.Current.NestedEdge);

            // Disable the parent Edge device
            Log.Information("Disabling Edge device");
            await this.IotHub.UpdateEdgeEnableStatus(this.runtime.DeviceId, false);

            await Task.Delay(TimeSpan.FromSeconds(10));

            // Re-enable parent Edge
            Log.Information("Re-enabling Edge device");
            await this.IotHub.UpdateEdgeEnableStatus(this.runtime.DeviceId, true);

            await Task.Delay(TimeSpan.FromSeconds(10));

            // Try connecting
            string leafDeviceId = DeviceId.Current.Generate();
            var    leaf         = await LeafDevice.CreateAsync(
                leafDeviceId,
                Protocol.Amqp,
                AuthenticationType.Sas,
                Option.Some(this.runtime.DeviceId),
                false,
                this.ca,
                this.IotHub,
                Context.Current.Hostname.GetOrElse(Dns.GetHostName().ToLower()),
                token,
                Option.None <string>(),
                Context.Current.NestedEdge);

            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);
            });
        }
コード例 #13
0
ファイル: SetupFixture.cs プロジェクト: wpgnss/iotedge
        public Task AfterAllAsync() => TryFinally.DoAsync(
            () => Profiler.Run(
                async() =>
        {
            using (var cts = new CancellationTokenSource(Context.Current.TeardownTimeout))
            {
                CancellationToken token = cts.Token;

                await this.daemon.StopAsync(token);

                Assert.IsNotNull(this.device);
                await this.device.MaybeDeleteIdentityAsync(token);
            }
        },
                "Completed end-to-end test teardown"),
            () =>
        {
            Log.CloseAndFlush();
        });
コード例 #14
0
        public async Task PlugAndPlayDeviceClient(Protocol protocol)
        {
            CancellationToken token        = this.TestToken;
            string            leafDeviceId = DeviceId.Current.Generate();

            Action <EdgeConfigBuilder> config     = this.BuildAddEdgeHubConfig(protocol);
            EdgeDeployment             deployment = await this.runtime.DeployConfigurationAsync(
                config,
                token,
                Context.Current.NestedEdge);

            var leaf = await LeafDevice.CreateAsync(
                leafDeviceId,
                protocol,
                AuthenticationType.Sas,
                Option.Some(this.runtime.DeviceId),
                false,
                this.ca,
                this.IotHub,
                Context.Current.Hostname.GetOrElse(Dns.GetHostName().ToLower()),
                token,
                Option.Some(TestModelId),
                Context.Current.NestedEdge);

            await TryFinally.DoAsync(
                async() =>
            {
                DateTime seekTime = DateTime.Now;
                await leaf.SendEventAsync(token);
                await leaf.WaitForEventsReceivedAsync(seekTime, token);
                await this.ValidateIdentity(leafDeviceId, Option.None <string>(), TestModelId, token);
            },
                async() =>
            {
                await leaf.DeleteIdentityAsync(token);
            });
        }
コード例 #15
0
ファイル: cs-parser.cs プロジェクト: furesoft/NRefactory
void case_989()
#line 6601 "cs-parser.jay"
{
		yyVal = new TryFinally (new TryCatch ((Block) yyVals[-3+yyTop], (List<Catch>) yyVals[-2+yyTop], GetLocation (yyVals[-4+yyTop]), true), (ExplicitBlock) yyVals[0+yyTop], GetLocation (yyVals[-4+yyTop]));
		lbag.AddStatement (yyVal, GetLocation (yyVals[-1+yyTop]));
	  }
コード例 #16
0
ファイル: cs-parser.cs プロジェクト: furesoft/NRefactory
void case_988()
#line 6596 "cs-parser.jay"
{
		yyVal = new TryFinally ((Statement) yyVals[-2+yyTop], (ExplicitBlock) yyVals[0+yyTop], GetLocation (yyVals[-3+yyTop]));
		lbag.AddStatement (yyVal, GetLocation (yyVals[-1+yyTop]));
	  }
コード例 #17
0
ファイル: method.cs プロジェクト: furesoft/NRefactory
		public override void Emit()
		{
			var base_type = Parent.PartialContainer.BaseType;
			if (base_type != null && Block != null) {
				var base_dtor = MemberCache.FindMember (base_type,
					new MemberFilter (MetadataName, 0, MemberKind.Destructor, null, null), BindingRestriction.InstanceOnly) as MethodSpec;

				if (base_dtor == null)
					throw new NotImplementedException ();

				MethodGroupExpr method_expr = MethodGroupExpr.CreatePredefined (base_dtor, base_type, Location);
				method_expr.InstanceExpression = new BaseThis (base_type, Location);

				var try_block = new ExplicitBlock (block, block.StartLocation, block.EndLocation) {
					IsCompilerGenerated = true
				};
				var finaly_block = new ExplicitBlock (block, Location, Location) {
					IsCompilerGenerated = true
				};

				//
				// 0-size arguments to avoid CS0250 error
				// TODO: Should use AddScopeStatement or something else which emits correct
				// debugger scope
				//
				finaly_block.AddStatement (new StatementExpression (new Invocation (method_expr, new Arguments (0)), Location.Null));

				var tf = new TryFinally (try_block, finaly_block, Location);
				block.WrapIntoDestructor (tf, try_block);
			}

			base.Emit ();
		}
コード例 #18
0
void case_926()
#line 7071 "ps-parser.jay"
{
		yyVal = new TryFinally (new TryCatch ((Block) yyVals[-3+yyTop], (List<Catch>) yyVals[-2+yyTop], Location.Null, true), (Block) yyVals[0+yyTop], GetLocation (yyVals[-4+yyTop]));
		lbag.AddStatement (yyVal, GetLocation (yyVals[-1+yyTop]));
	  }
コード例 #19
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;
            });
        }
コード例 #20
0
        public async Task QuickstartChangeSasKey()
        {
            CancellationToken token = this.TestToken;

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

            string leafDeviceId = DeviceId.Current.Generate();

            // Create leaf and send message
            var leaf = await LeafDevice.CreateAsync(
                leafDeviceId,
                Protocol.Amqp,
                AuthenticationType.Sas,
                Option.Some(this.runtime.DeviceId),
                false,
                this.ca,
                this.IotHub,
                Context.Current.Hostname.GetOrElse(Dns.GetHostName().ToLower()),
                token,
                Option.None <string>(),
                Context.Current.NestedEdge);

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

            // Re-create the leaf with the same device ID, for our purposes this is
            // the equivalent of updating the SAS keys
            var leafUpdated = await LeafDevice.CreateAsync(
                leafDeviceId,
                Protocol.Amqp,
                AuthenticationType.Sas,
                Option.Some(this.runtime.DeviceId),
                false,
                this.ca,
                this.IotHub,
                Context.Current.Hostname.GetOrElse(Dns.GetHostName().ToLower()),
                token,
                Option.None <string>(),
                Context.Current.NestedEdge);

            await TryFinally.DoAsync(
                async() =>
            {
                DateTime seekTime = DateTime.Now;
                await leafUpdated.SendEventAsync(token);
                await leafUpdated.WaitForEventsReceivedAsync(seekTime, token);
                await leafUpdated.InvokeDirectMethodAsync(token);
            },
                async() =>
            {
                await leafUpdated.Close();
                await leafUpdated.DeleteIdentityAsync(token);
            });
        }
コード例 #21
0
			public override object Visit (TryFinally tryFinallyStatement)
			{
				TryCatchStatement result;
				var location = LocationsBag.GetLocations (tryFinallyStatement);
				
				if (tryFinallyStatement.Stmt is TryCatch) {
					result = (TryCatchStatement)tryFinallyStatement.Stmt.Accept (this);
				} else {
					result = new TryCatchStatement ();
					result.AddChild (new CSharpTokenNode (Convert (tryFinallyStatement.loc), TryCatchStatement.TryKeywordRole), TryCatchStatement.TryKeywordRole);
					if (tryFinallyStatement.Stmt != null)
						result.AddChild ((BlockStatement)tryFinallyStatement.Stmt.Accept (this), TryCatchStatement.TryBlockRole);
				}
				if (location != null)
					result.AddChild (new CSharpTokenNode (Convert (location [0]), TryCatchStatement.FinallyKeywordRole), TryCatchStatement.FinallyKeywordRole);
				if (tryFinallyStatement.Fini != null)
					result.AddChild ((BlockStatement)tryFinallyStatement.Fini.Accept (this), TryCatchStatement.FinallyBlockRole);
				
				return result;
			}
コード例 #22
0
ファイル: visit.cs プロジェクト: furesoft/NRefactory
		public virtual object Visit (TryFinally tryFinallyStatement)
		{
			return null;
		}
コード例 #23
0
 public virtual object Visit(TryFinally tryFinallyStatement)
 {
     return(null);
 }
コード例 #24
0
void case_925()
#line 7066 "ps-parser.jay"
{
		yyVal = new TryFinally ((Statement) yyVals[-2+yyTop], (Block) yyVals[0+yyTop], GetLocation (yyVals[-3+yyTop]));
		lbag.AddStatement (yyVal, GetLocation (yyVals[-1+yyTop]));
	  }