コード例 #1
0
        public Task VerifyMonitorNoHttpsNoAuth(MonitorImageData imageData)
        {
            return(VerifyMonitorAsync(
                       imageData,
                       noAuthentication: true,
                       async containerName =>
            {
                if (!Config.IsHttpVerificationDisabled)
                {
                    // Verify metrics endpoint is accessible and produces zero processes
                    using HttpResponseMessage processesMessage =
                              await ImageScenarioVerifier.GetHttpResponseFromContainerAsync(
                                  containerName,
                                  DockerHelper,
                                  OutputHelper,
                                  DefaultArtifactsPort,
                                  UrlPath_Processes);

                    JsonElement rootElement = GetContentAsJsonElement(processesMessage);

                    // Verify returns an empty array (should not detect any processes)
                    Assert.Equal(JsonValueKind.Array, rootElement.ValueKind);
                    Assert.Equal(0, rootElement.GetArrayLength());
                }
            },
                       builder =>
            {
                // Reset and expose the artifacts port over http (not secure)
                builder.MonitorUrl(DefaultArtifactsPort);
            }));
        }
コード例 #2
0
        public Task VerifyListenMode(MonitorImageData imageData, SampleImageData sampleData)
        {
            return(VerifyScenarioAsync(
                       monitorImageData: imageData,
                       sampleImageData: sampleData,
                       shareTmpVolume: false,
                       listenDiagPortVolume: true,
                       noAuthentication: true,
                       async(monitorName, sampleName) =>
            {
                if (!Config.IsHttpVerificationDisabled)
                {
                    using HttpResponseMessage responseMessage =
                              await ImageScenarioVerifier.GetHttpResponseFromContainerAsync(
                                  monitorName,
                                  DockerHelper,
                                  OutputHelper,
                                  DefaultArtifactsPort,
                                  UrlPath_Processes);

                    JsonElement rootElement = GetContentAsJsonElement(responseMessage);

                    // Verify returns an array with one element (the sample container process)
                    Assert.Equal(JsonValueKind.Array, rootElement.ValueKind);
                    Assert.Equal(1, rootElement.GetArrayLength());
                }
            }));
        }
コード例 #3
0
 public Task VerifyMonitorNoHttps(MonitorImageData imageData)
 {
     return(VerifyMonitorAsync(
                imageData,
                noAuthentication: false,
                async containerName =>
     {
         if (!Config.IsHttpVerificationDisabled)
         {
             // Verify processes returns 401 (Unauthorized) since authentication was not provided.
             using HttpResponseMessage processesMessage =
                       await ImageScenarioVerifier.GetHttpResponseFromContainerAsync(
                           containerName,
                           DockerHelper,
                           OutputHelper,
                           DefaultArtifactsPort,
                           UrlPath_Processes,
                           m => VerifyStatusCode(m, HttpStatusCode.Unauthorized));
         }
     },
                builder =>
     {
         // Reset and expose the artifacts port over http (not secure)
         builder.MonitorUrl(DefaultArtifactsPort);
     }));
 }
コード例 #4
0
        /// <summary>
        /// Runs a single instance of the dotnet-monitor image.
        /// </summary>
        /// <param name="imageData">The image data of the dotnet-monitor image.</param>
        /// <param name="noAuthentication">Set to true to disable dotnet-monitor authenication.</param>
        /// <param name="verifyContainerAsync">Callback to test some aspect of the container.</param>
        /// <param name="runArgsCallback">Allows for modifying the "docker run" args of the container.</param>
        private async Task VerifyMonitorAsync(
            MonitorImageData imageData,
            bool noAuthentication,
            Func <string, Task> verifyContainerAsync      = null,
            Action <DockerRunArgsBuilder> runArgsCallback = null)
        {
            GetNames(imageData, out string monitorImageName, out string monitorContainerName);
            try
            {
                DockerRunArgsBuilder runArgsBuilder = DockerRunArgsBuilder.Create()
                                                      .ExposePort(DefaultMetricsPort);

                if (null != runArgsCallback)
                {
                    runArgsCallback(runArgsBuilder);
                }

                DockerHelper.Run(
                    image: monitorImageName,
                    name: monitorContainerName,
                    command: GetMonitorAdditionalArgs(noAuthentication),
                    detach: true,
                    optionalRunArgs: runArgsBuilder.Build());

                if (!Config.IsHttpVerificationDisabled)
                {
                    // Verify metrics endpoint is accessible
                    using HttpResponseMessage metricsMessage =
                              await ImageScenarioVerifier.GetHttpResponseFromContainerAsync(
                                  monitorContainerName,
                                  DockerHelper,
                                  OutputHelper,
                                  DefaultMetricsPort,
                                  UrlPath_Metrics);

                    string metricsContent = await metricsMessage.Content.ReadAsStringAsync();

                    // Metrics should not return any content if
                    // no processes are detected.
                    Assert.Equal(string.Empty, metricsContent);
                }

                if (null != verifyContainerAsync)
                {
                    await verifyContainerAsync(monitorContainerName);
                }
            }
            finally
            {
                DockerHelper.DeleteContainer(monitorContainerName);
            }
        }