public async Task DownloadCARevocationRequestsAsync_ValidResponseTest()
 {
     Mock <IIntuneClient>   mock   = CreateDownloadMock(validDownloadResponse);
     IntuneRevocationClient client = new IntuneRevocationClient(configProperties, intuneClient: mock.Object);
     string transactionId          = Guid.NewGuid().ToString();
     await client.DownloadCARevocationRequestsAsync(transactionId, 10);
 }
 public async Task UploadCARequestResults_NoValueResponse()
 {
     Mock <IIntuneClient>   mock   = CreateUploadMock(new JObject(new JProperty("not_value", true)));
     IntuneRevocationClient client = new IntuneRevocationClient(configProperties, intuneClient: mock.Object);
     string transactionId          = Guid.NewGuid().ToString();
     await client.UploadRevocationResultsAsync(transactionId, validRequestResults);
 }
 public async Task UploadCARequestResults_InvalidTransactionId()
 {
     Mock <IIntuneClient>   mock   = CreateUploadMock(new JObject(new JProperty("value", true)));
     IntuneRevocationClient client = new IntuneRevocationClient(configProperties, intuneClient: mock.Object);
     string transactionId          = null;
     await client.UploadRevocationResultsAsync(transactionId, validRequestResults);
 }
 public async Task DownloadCARevocationRequestsAsync_InvalidResponseTest_NoValue()
 {
     Mock <IIntuneClient>   mock   = CreateDownloadMock(new JObject(new JProperty("not_value", "test")));
     IntuneRevocationClient client = new IntuneRevocationClient(configProperties, intuneClient: mock.Object);
     string transactionId          = Guid.NewGuid().ToString();
     await client.DownloadCARevocationRequestsAsync(transactionId, 10);
 }
 public async Task DownloadCARevocationRequestsAsync_InvalidResponseTest()
 {
     string invalidResponse        = "This is an invalid response that should fail deserialization";
     Mock <IIntuneClient>   mock   = CreateDownloadMock(new JObject(new JProperty("value", invalidResponse)));
     IntuneRevocationClient client = new IntuneRevocationClient(configProperties, intuneClient: mock.Object);
     string transactionId          = Guid.NewGuid().ToString();
     await client.DownloadCARevocationRequestsAsync(transactionId, 10);
 }
Пример #6
0
        static void Main(string[] args)
        {
            // If scenario requires the use of a proxy with authentication then you need to supply your own WebProxy like the following.
            string proxyHost = "http://localhost";
            string proxyPort = "8888";
            string proxyUser = "******";
            string proxyPass = "******";

            var proxy = new WebProxy()
            {
                Address = new Uri($"{proxyHost}:{proxyPort}"),
                UseDefaultCredentials = false,

                // *** These creds are given to the proxy server, not the web server ***
                Credentials = new NetworkCredential(
                    userName: proxyUser,
                    password: proxyPass)
            };

            // Uncomment the following line to use a proxy
            //System.Net.WebRequest.DefaultWebProxy = proxy;

            // Populate properties dictionary with properties needed for API.
            // This example uses a simple Java like properties file to pass in the settings to maintain consistency.
            var configProperties = SimpleIniParser.Parse("com.microsoft.intune.props");

            var trace = new TraceSource("log");

            var transactionId = Guid.NewGuid(); // A GUID that will uniquley identify the entire transaction to allow for log correlation accross Validate and Notification calls.

            // Create CARevocationRequest Client
            var revocationClient = new IntuneRevocationClient(
                configProperties,
                trace: trace
                );

            // Set Download Parameters
            int    maxRequests = 100;  // Maximum number of Revocation requests to download at a time
            string issuerName  = null; // Optional Parameter: Set this value if you want to filter
                                       //   the request to only download request matching this Issuer Name

            // Download CARevocationRequests from Intune
            List <CARevocationRequest> caRevocationRequests = (revocationClient.DownloadCARevocationRequestsAsync(transactionId.ToString(), maxRequests, issuerName)).Result;

            Console.WriteLine($"Downloaded {caRevocationRequests.Count} number of Revocation requests from Intune.");

            // Process CARevocationRequest List
            List <CARevocationResult> revocationResults = new List <CARevocationResult>();

            foreach (CARevocationRequest request in caRevocationRequests)
            {
                // Revoke the certificate
                RevokeCertificate(
                    request.SerialNumber,
                    out bool succeeded,
                    out CARequestErrorCode errorCode,
                    out string errorMessage);

                // Add result to list
                revocationResults.Add(new CARevocationResult(request.RequestContext, succeeded, errorCode, errorMessage));
            }

            if (revocationResults.Count > 0)
            {
                try
                {
                    Console.WriteLine($"Uploading {revocationResults.Count} Revocation Results to Intune.");

                    // Upload Results to Intune
                    (revocationClient.UploadRevocationResultsAsync(transactionId.ToString(), revocationResults)).Wait();
                }
                catch (AggregateException e)
                {
                    Console.WriteLine($"Upload of results to to Intune Failed. Exception: {e.InnerException}");
                }
            }
        }