コード例 #1
0
        public void SaslPrepStored_throws_argument_exception_with_RandALCat_and_LCat_characters()
        {
            var exception = Record.Exception(() => SaslPrepHelper.SaslPrepStored("\u0627\u0041\u0627"));

            exception.Should().BeOfType <ArgumentException>();
            exception.Message.Should().Be("Contains both RandALCat characters and LCat characters");
        }
コード例 #2
0
        public void SaslPrepStored_throws_exception_when_passed_an_undefined_codepoint()
        {
            var strWithUnassignedCodepoint = $"abc{char.ConvertFromUtf32(_unassignedCodePoint.Value)}";

            var exception = Record.Exception(() => SaslPrepHelper.SaslPrepStored(strWithUnassignedCodepoint));

            exception.Should().BeOfType <ArgumentException>();
            exception.Message.Should().Be("Character at position 3 is unassigned");
        }
コード例 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UsernamePasswordCredential"/> class.
 /// Less secure when used in conjunction with SCRAM-SHA-256, due to the need to store the password in a managed
 /// string in order to SaslPrep it.
 /// See <a href="https://github.com/mongodb/specifications/blob/master/source/auth/auth.rst#scram-sha-256">Driver Authentication: SCRAM-SHA-256</a>
 /// for additional details.
 /// </summary>
 /// <param name="source">The source.</param>
 /// <param name="username">The username.</param>
 /// <param name="password">The password.</param>
 public UsernamePasswordCredential(string source, string username, SecureString password)
 {
     _source   = Ensure.IsNotNullOrEmpty(source, nameof(source));
     _username = Ensure.IsNotNullOrEmpty(username, nameof(username));
     _password = Ensure.IsNotNull(password, nameof(password));
     // defer computing the saslPreppedPassword until we need to since this will leak the password into managed
     // memory
     _saslPreppedPassword = new Lazy <SecureString>(
         () => ConvertPasswordToSecureString(SaslPrepHelper.SaslPrepStored(GetInsecurePassword())));
 }
コード例 #4
0
        // constructors
        /// <summary>
        /// Initializes a new instance of the <see cref="UsernamePasswordCredential"/> class.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="username">The username.</param>
        /// <param name="password">The password.</param>
        public UsernamePasswordCredential(string source, string username, string password)
            : this(source, username, ConvertPasswordToSecureString(password))
        {
            // Compute saslPreppedPassword immediately and store it securely while the password is already in
            // managed memory. We don't create a closure over the password so that it will hopefully get
            // garbage-collected sooner rather than later.
            var saslPreppedPassword = ConvertPasswordToSecureString(SaslPrepHelper.SaslPrepStored(password));

            _saslPreppedPassword = new Lazy <SecureString>(() => saslPreppedPassword);
        }
コード例 #5
0
        public void SaslPrep_throws_argument_exception_when_passed_Rfc4013_examples(string expectedError, string input)
        {
            var exception = Record.Exception(() => SaslPrepHelper.SaslPrepStored(input));

            exception.Should().BeOfType <ArgumentException>().Subject.Message.Should().Be(expectedError);
        }
コード例 #6
0
 public void SaslPrepStored_returns_expected_output_when_passed_Rfc4013_examples(string expected, string input)
 {
     SaslPrepHelper.SaslPrepStored(input).Should().Be(expected);
 }
コード例 #7
0
 [InlineData("IV", "I\u00ADV")] // "IV", "I-V"
 public void SaslPrepStored_returns_expected_output_when_passed_partially_SaslPrepped_strings(
     string expected,
     string partiallyPreppedStr)
 {
     SaslPrepHelper.SaslPrepStored(partiallyPreppedStr).Should().Be(expected);
 }
コード例 #8
0
 [InlineData("IV", "\u2163")] // "IV", Roman numeral four
 public void SaslPrepStored_returns_expected_output_when_passed_nonNormalized_strings(
     string expected,
     string nonNormalizedStr)
 {
     SaslPrepHelper.SaslPrepStored(nonNormalizedStr).Should().Be(expected);
 }
コード例 #9
0
 public void SaslPrepStored_maps_space_equivalents_to_space(string expected, string input)
 {
     SaslPrepHelper.SaslPrepStored(input).Should().Be(expected);
 }
コード例 #10
0
 public void SaslPrepStored_accepts_RandALCat_Characters_in_first_and_last_position()
 {
     SaslPrepHelper.SaslPrepStored("\u0627\u0031\u0627").Should().Be("\u0627\u0031\u0627");
 }
コード例 #11
0
        public void SaslPrepQuery_accepts_undefined_codepoint()
        {
            var strWithUnassignedCodepoint = $"abc{char.ConvertFromUtf32(_unassignedCodePoint.Value)}";

            SaslPrepHelper.SaslPrepQuery(strWithUnassignedCodepoint).Should().Be(strWithUnassignedCodepoint);
        }