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); }); }
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); }); }
public async Task TransparentGateway( [Values] TestAuthenticationType testAuth, [Values(Protocol.Mqtt, Protocol.Amqp)] Protocol protocol) { 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); }); }
public Context() { IConfiguration context = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("context.json") .AddEnvironmentVariables("E2E_") .Build(); string Get(string name) => context.GetValue <string>(name); string GetOrDefault(string name, string defaultValue) => context.GetValue(name, defaultValue); IEnumerable <(string, string, string)> GetAndValidateRegistries() { var result = new List <(string, string, string)>(); var registries = context.GetSection("registries").GetChildren().ToArray(); foreach (var reg in registries) { string address = reg.GetValue <string>("address"); string username = reg.GetValue <string>("username"); // To specify a password as an environment variable instead of in the // JSON file (so it's not stored in the clear on the filesystem), name // the variable like this: E2E_REGISTRIES__<index>__PASSWORD, where // <index> is the 0-based number corresponding to an element in the // "registries" JSON array. string password = reg.GetValue <string>("PASSWORD"); // If any container registry arguments (server, username, password) // are given, then they must *all* be given, otherwise throw an error. Preconditions.CheckNonWhiteSpace(address, nameof(address)); Preconditions.CheckNonWhiteSpace(username, nameof(username)); Preconditions.CheckNonWhiteSpace(password, nameof(password)); result.Add((address, username, password)); } return(result); } Option <(string, string, string)> GetAndValidateRootCaKeys() { // If any root CA key materials (cert file, key file, password) are // given, then they must *all* be given, otherwise throw an error. string certificate = Get("rootCaCertificatePath"); string key = Get("rootCaPrivateKeyPath"); string password = Get("ROOT_CA_PASSWORD"); if (!string.IsNullOrWhiteSpace(certificate) || !string.IsNullOrWhiteSpace(key) || !string.IsNullOrWhiteSpace(password)) { Preconditions.CheckNonWhiteSpace(certificate, nameof(certificate)); Preconditions.CheckNonWhiteSpace(key, nameof(key)); Preconditions.CheckNonWhiteSpace(password, nameof(password)); Preconditions.CheckArgument(File.Exists(certificate)); Preconditions.CheckArgument(File.Exists(key)); return(Option.Some((certificate, key, password))); } return(Option.None <(string, string, string)>()); } string defaultId = $"e2e-{string.Concat(Dns.GetHostName().Take(14)).TrimEnd(new[] { '-' })}-{DateTime.Now:yyMMdd'-'HHmmss'.'fff}"; this.CaCertScriptPath = Option.Maybe(Get("caCertScriptPath")); this.ConnectionString = Get("IOT_HUB_CONNECTION_STRING"); this.DeviceId = IdentityLimits.CheckEdgeId(GetOrDefault("deviceId", defaultId)); this.DpsIdScope = Option.Maybe(Get("dpsIdScope")); this.DpsGroupKey = Option.Maybe(Get("DPS_GROUP_KEY")); this.EdgeAgentImage = Option.Maybe(Get("edgeAgentImage")); this.EdgeHubImage = Option.Maybe(Get("edgeHubImage")); this.EventHubEndpoint = Get("EVENT_HUB_ENDPOINT"); this.InstallerPath = Option.Maybe(Get("installerPath")); this.LogFile = Option.Maybe(Get("logFile")); this.MethodReceiverImage = Option.Maybe(Get("methodReceiverImage")); this.MethodSenderImage = Option.Maybe(Get("methodSenderImage")); this.OptimizeForPerformance = context.GetValue("optimizeForPerformance", true); this.PackagePath = Option.Maybe(Get("packagePath")); this.Proxy = Option.Maybe(context.GetValue <Uri>("proxy")); this.Registries = GetAndValidateRegistries(); this.RootCaKeys = GetAndValidateRootCaKeys(); this.SetupTimeout = TimeSpan.FromMinutes(context.GetValue("setupTimeoutMinutes", 5)); this.TeardownTimeout = TimeSpan.FromMinutes(context.GetValue("teardownTimeoutMinutes", 2)); this.TempSensorImage = Option.Maybe(Get("tempSensorImage")); this.TempFilterImage = Option.Maybe(Get("tempFilterImage")); this.TestTimeout = TimeSpan.FromMinutes(context.GetValue("testTimeoutMinutes", 5)); this.Verbose = context.GetValue <bool>("verbose"); }