Example #1
0
        public void TestSetRecordingOptionsValidTlsCert()
        {
            var certValue            = TestHelpers.GetValueFromCertificateFile("test_public-key-only_pem").Replace(Environment.NewLine, "");
            var inputObj             = string.Format("{{\"Transport\": {{\"TLSValidationCert\": \"{0}\"}}}}", certValue);
            var testRecordingHandler = new RecordingHandler(Path.Join(Path.GetTempPath(), Guid.NewGuid().ToString()));
            var inputBody            = System.Text.Json.JsonSerializer.Deserialize <Dictionary <string, object> >(inputObj, SerializerOptions);

            testRecordingHandler.SetRecordingOptions(inputBody, null);
        }
Example #2
0
        public void TestSetRecordingOptionsHandlesValidRedirectSetting(string body, bool expectedSetting)
        {
            RecordingHandler testRecordingHandler = new RecordingHandler(Directory.GetCurrentDirectory());
            var httpContext = new DefaultHttpContext();
            Dictionary <string, object> inputBody = JsonConvert.DeserializeObject <Dictionary <string, object> >(body);

            testRecordingHandler.SetRecordingOptions(inputBody);

            Assert.Equal(expectedSetting, testRecordingHandler.HandleRedirects);
        }
Example #3
0
        public void TestSetRecordingOptionsValidTransportSessionLevel(string body)
        {
            var pemKey    = TestHelpers.GetValueFromCertificateFile("test_pem_key").Replace(Environment.NewLine, "");
            var pemValue  = TestHelpers.GetValueFromCertificateFile("test_pem_value").Replace(Environment.NewLine, "");
            var inputObj  = string.Format(body, pemValue, pemKey);
            var inputBody = System.Text.Json.JsonSerializer.Deserialize <Dictionary <string, object> >(inputObj, SerializerOptions);

            RecordingHandler testRecordingHandler = new RecordingHandler(Directory.GetCurrentDirectory());

            testRecordingHandler.SetRecordingOptions(inputBody, null);
        }
Example #4
0
        public void TestSetRecordingOptionsInValidTransportSessionLevel(string body)
        {
            var pemKey               = TestHelpers.GetValueFromCertificateFile("test_pem_key").Replace(Environment.NewLine, "");
            var pemValue             = TestHelpers.GetValueFromCertificateFile("test_pem_value").Replace(Environment.NewLine, "");
            var testRecordingHandler = new RecordingHandler(Path.Join(Path.GetTempPath(), Guid.NewGuid().ToString()));
            var inputObj             = string.Format(body, pemValue, pemKey);
            var inputBody            = System.Text.Json.JsonSerializer.Deserialize <Dictionary <string, object> >(inputObj, SerializerOptions);

            var assertion = Assert.Throws <HttpException>(
                () => testRecordingHandler.SetRecordingOptions(inputBody)
                );

            Assert.Contains("Unable to instantiate a new X509 certificate from the provided value and key.", assertion.Message);
        }
Example #5
0
        public void TestSetRecordingOptionsValidTransportRecordingLevel(string body)
        {
            var pemKey               = TestHelpers.GetValueFromCertificateFile("test_pem_key").Replace(Environment.NewLine, "");
            var pemValue             = TestHelpers.GetValueFromCertificateFile("test_pem_value").Replace(Environment.NewLine, "");
            var testRecordingHandler = new RecordingHandler(Path.Join(Path.GetTempPath(), Guid.NewGuid().ToString()));
            var inputObj             = string.Format(body, pemValue, pemKey);
            var inputBody            = System.Text.Json.JsonSerializer.Deserialize <Dictionary <string, object> >(inputObj, SerializerOptions);

            HttpContext context = new DefaultHttpContext();

            testRecordingHandler.StartRecording("TestSetRecordingOptionsInValidTransportRecordingLevel.json", context.Response);
            var recordingId = context.Response.Headers["x-recording-id"].ToString();

            testRecordingHandler.SetRecordingOptions(inputBody, recordingId);
        }
Example #6
0
        public void TestSetRecordingOptionsHandlesValidStoreTypes(string body)
        {
            RecordingHandler testRecordingHandler = new RecordingHandler(Directory.GetCurrentDirectory());

            testRecordingHandler.Store = null;
            Dictionary <string, object> inputBody = null;

            if (!string.IsNullOrWhiteSpace(body))
            {
                inputBody = JsonConvert.DeserializeObject <Dictionary <string, object> >(body);
            }

            testRecordingHandler.SetRecordingOptions(inputBody);

            Assert.NotNull(testRecordingHandler.Store);
        }
Example #7
0
        public void TestSetRecordingOptionsInValidTransportWithTLSCert()
        {
            var certValue = TestHelpers.GetValueFromCertificateFile("test_public-key-only_pem").Replace(Environment.NewLine, "");
            var pemKey    = TestHelpers.GetValueFromCertificateFile("test_pem_key").Replace(Environment.NewLine, "");
            var pemValue  = TestHelpers.GetValueFromCertificateFile("test_pem_value").Replace(Environment.NewLine, "");
            var inputObj  = string.Format("{{\"Transport\": {{\"TLSValidationCert\": \"hello-there\", \"Certificates\": [ {{ \"PemValue\": \"{0}\", \"PemKey\": \"{1}\" }}]}}}}", pemValue, pemKey);

            RecordingHandler testRecordingHandler = new RecordingHandler(Directory.GetCurrentDirectory());
            var inputBody = System.Text.Json.JsonSerializer.Deserialize <Dictionary <string, object> >(inputObj, SerializerOptions);

            var assertion = Assert.Throws <HttpException>(
                () => testRecordingHandler.SetRecordingOptions(inputBody)
                );

            Assert.StartsWith("Unable to instantiate a valid cert from the value provided in Transport settings key", assertion.Message);
            Assert.Contains("No PEM encoded data found. (Parameter 'pemData')", assertion.Message);
        }
Example #8
0
        public void TestSetRecordingOptionsThrowsOnInvalidStoreTypes(string body, string errorText)
        {
            RecordingHandler            testRecordingHandler = new RecordingHandler(Directory.GetCurrentDirectory());
            Dictionary <string, object> inputBody            = null;

            if (!string.IsNullOrWhiteSpace(body))
            {
                inputBody = JsonConvert.DeserializeObject <Dictionary <string, object> >(body);
            }

            var assertion = Assert.Throws <HttpException>(
                () => testRecordingHandler.SetRecordingOptions(inputBody)
                );

            Assert.True(assertion.StatusCode.Equals(HttpStatusCode.BadRequest));
            Assert.StartsWith(errorText, assertion.Message);
        }
Example #9
0
        public void TestSetRecordingOptionsHandlesValidContextDirectory(params string[] relativePaths)
        {
            var relativePath  = Path.Combine(relativePaths);
            var testDirectory = Path.GetTempPath();

            RecordingHandler testRecordingHandler = new RecordingHandler(testDirectory);

            testDirectory = Path.Combine(testDirectory, relativePath);
            var body = $"{{ \"ContextDirectory\": \"{testDirectory.Replace("\\", "/")}\"}}";

            var httpContext = new DefaultHttpContext();
            Dictionary <string, object> inputBody = JsonConvert.DeserializeObject <Dictionary <string, object> >(body);

            testRecordingHandler.SetRecordingOptions(inputBody);

            Assert.Equal(new Uri(testDirectory), new Uri(testRecordingHandler.ContextDirectory));
        }