Example #1
0
        public async Task Test_AzureController_SecurityException_Fail()
        {
            //Arrange

            //Authorization Code absent
            AzureADAuthModel googleAuthModel = new AzureADAuthModel
            {
                APIKey = "<api key>"
            };

            AzureAuthenticator authenticator = new AzureAuthenticator(this.SecuritySettings,
                                                                      this.MockAzureClient.Object);

            var controller = new AzureController(authenticator);

            try
            {
                //Act
                var result = await controller.Create(googleAuthModel);
            }
            catch (SecurityException ex)
            {
                //Assert
                Assert.IsType <SecurityException>(ex);
                this.MockAzureClient.Verify(x => x.PostSecurityRequest(), Times.Never);
            }
        }
        public async void Authenticator_WithValidCredentials_ProducesTokenAsync()
        {
            var azureAuthenticator = new AzureAuthenticator();
            var kv  = new KeyVaultClient(azureAuthenticator.GetToken);
            var sec = await kv.GetSecretAsync(new Secrets().SecretId);

            Assert.NotNull(sec);
        }
        public void UsingAzureFluentClient()
        {
            var azureAuthenticator = new AzureAuthenticator();
            var azure          = azureAuthenticator.GetAzureFluentClient(_subscriptionName);
            var resourceGroups = azure.ResourceGroups.List();

            foreach (var resourceGroup in resourceGroups)
            {
                Console.WriteLine($"I found resource group {resourceGroup.Name} in subscription {_subscriptionName}");
            }
        }
        private async void TranslateSubtitle(Action onCompleted)
        {
            var azureAuthenticator = new AzureAuthenticator();
            var kv  = new KeyVaultClient(azureAuthenticator.GetToken);
            var sec = await kv.GetSecretAsync(new Secrets().SecretId);

            var newItems = await TranslationService.TranslateArrayAsync(Subtitle.Items.ToArray(), _culture, sec.Value);

            for (var i = 0; i < Subtitle.Items.Count; i++)
            {
                Subtitle.Items[i].Lines = newItems[i].Lines;
            }

            onCompleted?.Invoke();
        }
Example #5
0
        /// <summary>
        /// Validates a resource group deployment.
        /// </summary>
        /// <param name="templateLink">The template link.</param>
        /// <param name="parametersLink">The parameters link.</param>
        /// <returns>The ARM tester result.</returns>
        public async Task <ArmTesterResult> ValidateResourceGroup(string templateLink, string parametersLink = null)
        {
            var azureAuthenticator = new AzureAuthenticator(
                cloud: "https://login.microsoftonline.com",
                tenantId: this.settings.TenantId);

            var resolver = new Func <Task <string> >(async() =>
            {
                var authenticationResult = await azureAuthenticator.AuthenticateFromCertificate(
                    clientId: this.settings.ClientId,
                    certificate: this.certificate,
                    resourceId: "https://management.azure.com");

                return(authenticationResult.AccessToken);
            });

            return(await new ArmTester()
                   .BeginResourceGroupDeployment(this.settings.SubscriptionId, this.settings.ResourceGroupName)
                   .Validate(resolver, templateLink, parametersLink));
        }
Example #6
0
        public async Task Test_AzureController_Pass()
        {
            //Arrange
            AzureADAuthModel azureADAuthModel = new AzureADAuthModel
            {
                APIKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
            };

            AzureAuthenticator azureAuthenticator = new AzureAuthenticator(this.SecuritySettings, this.MockAzureClient.Object);

            var controller = new AzureController(azureAuthenticator);

            //Act
            var result = await controller.Create(azureADAuthModel);

            //Assert
            Assert.IsType <ObjectResult>(result);
            Assert.True((result as ObjectResult).Value.ToString().IsValidJwtToken());
            this.MockAzureClient.Verify(x => x.PostSecurityRequest(), Times.Once);
        }
Example #7
0
        public async Task Test_AzureController_InvalidAPIKey_Fail()
        {
            //Arrange

            //Invalid API Key
            AzureADAuthModel azureADAuthModel = new AzureADAuthModel
            {
                APIKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
            };

            AzureAuthenticator azureAuthenticator = new AzureAuthenticator(this.SecuritySettings, this.MockAzureClient.Object);

            var controller = new AzureController(azureAuthenticator);

            //Act
            var result = await controller.Create(azureADAuthModel);

            //Assert
            Assert.IsType <BadRequestResult>(result);
            this.MockAzureClient.Verify(x => x.PostSecurityRequest(), Times.Never);
        }
        public void UsingAzureCredentials()
        {
            var azureAuthenticator = new AzureAuthenticator();
            var azureCredentials   = azureAuthenticator.GetAzureCredentials();
            var azureFluent        = Azure.Authenticate(azureCredentials).WithDefaultSubscription();
            var resourceGroups     = azureFluent.ResourceGroups.List();

            foreach (var resourceGroup in resourceGroups)
            {
                Console.WriteLine($"I found resource group {resourceGroup.Name} in subscription {_subscriptionName}");
            }

            var resourceManagementClient = new ResourceManagementClient(azureCredentials)
            {
                SubscriptionId = azureFluent.SubscriptionId
            };
            var resources = resourceManagementClient.Resources.List();

            foreach (var resource in resources)
            {
                Console.WriteLine($"I found resource group {resource.Name} in subscription {_subscriptionName}");
            }
        }
Example #9
0
        public async Task Test_AzureController_AzureAuth_Fail()
        {
            //Arrange

            //Azure Client returns IsAuthenticated false
            this.MockAzureClient = this.InitMockAzureClient(this.SecuritySettings, false);

            AzureADAuthModel azureADAuthModel = new AzureADAuthModel
            {
                APIKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
            };

            AzureAuthenticator azureAuthenticator = new AzureAuthenticator(this.SecuritySettings, this.MockAzureClient.Object);

            var controller = new AzureController(azureAuthenticator);

            //Act
            var result = await controller.Create(azureADAuthModel);

            //Assert
            Assert.IsType <BadRequestResult>(result);
            this.MockAzureClient.Verify(x => x.PostSecurityRequest(), Times.Once);
        }