public override TokenCredential GetTokenCredential(TokenCredentialOptions options) { var pwshOptions = new AzurePowerShellCredentialOptions { Diagnostics = { IsAccountIdentifierLoggingEnabled = options.Diagnostics.IsAccountIdentifierLoggingEnabled } }; var(_, _, processOutput) = CredentialTestHelpers.CreateTokenForAzurePowerShell(TimeSpan.FromSeconds(30)); var testProcess = new TestProcess { Output = processOutput }; return(InstrumentClient( new AzurePowerShellCredential(pwshOptions, CredentialPipeline.GetInstance(null), new TestProcessService(testProcess, true)))); }
public async Task AuthenticateWithAzurePowerShellCredential( [Values(null, TenantIdHint)] string tenantId, [Values(true)] bool allowMultiTenantAuthentication, [Values(null, TenantId)] string explicitTenantId) { var context = new TokenRequestContext(new[] { Scope }, tenantId: tenantId); var options = new AzurePowerShellCredentialOptions { TenantId = explicitTenantId, AllowMultiTenantAuthentication = allowMultiTenantAuthentication }; string expectedTenantId = TenantIdResolver.Resolve(explicitTenantId, context, options.AllowMultiTenantAuthentication); var(expectedToken, expectedExpiresOn, processOutput) = CredentialTestHelpers.CreateTokenForAzurePowerShell(TimeSpan.FromSeconds(30)); var testProcess = new TestProcess { Output = processOutput }; AzurePowerShellCredential credential = InstrumentClient( new AzurePowerShellCredential(options, CredentialPipeline.GetInstance(null), new TestProcessService(testProcess, true))); AccessToken actualToken = await credential.GetTokenAsync(context); Assert.AreEqual(expectedToken, actualToken.Token); Assert.AreEqual(expectedExpiresOn, actualToken.ExpiresOn); var iStart = testProcess.StartInfo.Arguments.IndexOf("EncodedCommand"); iStart = testProcess.StartInfo.Arguments.IndexOf('\"', iStart) + 1; var iEnd = testProcess.StartInfo.Arguments.IndexOf('\"', iStart); var commandString = testProcess.StartInfo.Arguments.Substring(iStart, iEnd - iStart); var b = Convert.FromBase64String(commandString); commandString = Encoding.Unicode.GetString(b); var expectTenantId = expectedTenantId != null; if (expectTenantId) { Assert.That(commandString, Does.Contain($"-TenantId {expectedTenantId}")); } else { Assert.That(commandString, Does.Not.Contain("-TenantId")); } }
public void ValidateConstructorOverload1() { // tests the AzurePowerShellCredential constructor overload // public AzurePowerShellCredential(AzurePowerShellCredentialOptions options) // null var credential = new AzurePowerShellCredential(null); AssertOptionsHonored(new AzurePowerShellCredentialOptions(), credential); // with options var options = new AzurePowerShellCredentialOptions { UseLegacyPowerShell = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) }; credential = new AzurePowerShellCredential(options); AssertOptionsHonored(options, credential); }
public void AssertOptionsHonored(AzurePowerShellCredentialOptions options, AzurePowerShellCredential credential) { Assert.AreEqual(options.UseLegacyPowerShell, credential.UseLegacyPowerShell); }