public async Task TestValidationFailsAsync()
        {
            var invalidResponse = new JObject();

            invalidResponse.Add("code", IntuneScepServiceException.ErrorCode.ChallengeDecryptionError.ToString());
            invalidResponse.Add("errorDescription", "");

            var mock = new Mock <IIntuneClient>();

            mock.Setup(foo => foo.PostAsync(
                           Microsoft.Intune.IntuneScepValidator.VALIDATION_SERVICE_NAME,
                           Microsoft.Intune.IntuneScepValidator.VALIDATION_URL,
                           Microsoft.Intune.IntuneScepValidator.DEFAULT_SERVICE_VERSION,
                           It.IsAny <JObject>(),
                           It.IsAny <Guid>(),
                           It.IsAny <Dictionary <string, string> >())
                       ).Returns(
                Task.FromResult <JObject>(invalidResponse)
                );

            Microsoft.Intune.IntuneScepValidator client = new Microsoft.Intune.IntuneScepValidator(configProperties, intuneClient: mock.Object);

            Guid   transactionId = Guid.NewGuid();
            string csr           = "testing";

            await client.ValidateRequestAsync(transactionId.ToString(), csr);
        }
        public async Task TestSendFailureNotificationSucceedsAsync()
        {
            var validResponse = new JObject();

            validResponse.Add("code", IntuneScepServiceException.ErrorCode.Success.ToString());
            validResponse.Add("errorDescription", "");

            var mock = new Mock <IIntuneClient>();

            mock.Setup(foo => foo.PostAsync(
                           Microsoft.Intune.IntuneScepValidator.VALIDATION_SERVICE_NAME,
                           Microsoft.Intune.IntuneScepValidator.NOTIFY_FAILURE_URL,
                           Microsoft.Intune.IntuneScepValidator.DEFAULT_SERVICE_VERSION,
                           It.IsAny <JObject>(),
                           It.IsAny <Guid>(),
                           It.IsAny <Dictionary <string, string> >())
                       ).Returns(
                Task.FromResult <JObject>(validResponse)
                );

            Microsoft.Intune.IntuneScepValidator client = new Microsoft.Intune.IntuneScepValidator(configProperties, intuneClient: mock.Object);

            Guid   transactionId = Guid.NewGuid();
            string csr           = "testing";

            await client.SendFailureNotificationAsync(transactionId.ToString(), csr, 1, "description");
        }
        public async Task TestAuthFailureAsync()
        {
            var invalidResponse = new JObject();

            invalidResponse.Add("code", IntuneScepServiceException.ErrorCode.ChallengeDecryptionError.ToString());
            invalidResponse.Add("errorDescription", "");

            var authContextMock = new Mock <IAuthenticationContext>();

            authContextMock.Setup(foo => foo.AcquireTokenAsync(
                                      It.IsAny <string>(), It.IsAny <ClientCredential>())
                                  ).Throws(
                new AdalServiceException("", "")
                );

            var locationProviderMock = new Mock <IIntuneServiceLocationProvider>();

            locationProviderMock.Setup(foo => foo.GetServiceEndpointAsync(Microsoft.Intune.IntuneScepValidator.VALIDATION_SERVICE_NAME))
            .Returns(Task.FromResult <string>(@"http://localhost/"));


            var adalClient   = new AdalClient(configProperties);
            var intuneClient = new IntuneClient(configProperties, adalClient: adalClient, locationProvider: locationProviderMock.Object);
            var scepClient   = new Microsoft.Intune.IntuneScepValidator(configProperties, intuneClient: intuneClient);

            Guid   transactionId = Guid.NewGuid();
            string csr           = "testing";

            await scepClient.SendFailureNotificationAsync(transactionId.ToString(), csr, 1, "description");
        }
Example #4
0
        public async Task TestURLChangesAsync()
        {
            var invalidResponse = new JObject();

            invalidResponse.Add("code", IntuneScepServiceException.ErrorCode.ChallengeDecryptionError.ToString());
            invalidResponse.Add("errorDescription", "");

            var locationProviderMock = new Mock <IIntuneServiceLocationProvider>();

            locationProviderMock.Setup(foo => foo.GetServiceEndpointAsync(IntuneScepValidator.VALIDATION_SERVICE_NAME))
            .Returns(Task.FromResult <string>(@"http://localhost/"));

            var httpClientMock = new Mock <IHttpClient>();

            httpClientMock.Setup(foo => foo.PostAsync(It.IsAny <string>(), It.IsAny <HttpContent>()))
            .Throws(new HttpRequestException());

            var authClient   = new MsalClient(configProperties);
            var intuneClient = new IntuneClient(configProperties, authClient: authClient, locationProvider: locationProviderMock.Object, httpClient: httpClientMock.Object);
            var scepClient   = new Microsoft.Intune.IntuneScepValidator(configProperties, intuneClient: intuneClient);

            Guid   transactionId = Guid.NewGuid();
            string csr           = "testing";

            await scepClient.SendFailureNotificationAsync(transactionId.ToString(), csr, 1, "description");

            locationProviderMock.Verify(foo => foo.GetServiceEndpointAsync(IntuneScepValidator.VALIDATION_SERVICE_NAME), Times.Once);
            locationProviderMock.Verify(foo => foo.Clear(), Times.Once);
        }