SonarLint.VisualStudio.Integration.Connection.UriValidator.IsInsecureScheme C# (CSharp) Method

IsInsecureScheme() public method

True if uri's scheme is one of insecureSchemes, false otherwise.
public IsInsecureScheme ( Uri uri ) : bool
uri System.Uri to check, must not be null.
return bool
        public bool IsInsecureScheme(Uri uri)
        {
            if (uri == null)
            {
                throw new ArgumentNullException(nameof(uri));
            }

            return this.insecureSchemes?.Contains(uri.Scheme) ?? false;
        }

Usage Example

        private void VerifyIsInsecureSchemeCaseSensitivity(UriValidator validator)
        {
            Uri lowercaseUri = CreateUri("case", "localhost");
            Uri uppercaseUri = CreateUri("CASE", "localhost");
            Uri mixedcaseUri = CreateUri("cAsE", "localhost");

            // Test
            bool lowercaseInsecure = validator.IsInsecureScheme(lowercaseUri);
            bool uppercaseInsecure = validator.IsInsecureScheme(uppercaseUri);
            bool mixedcaseInsecure = validator.IsInsecureScheme(mixedcaseUri);

            // Verify
            Assert.IsTrue(lowercaseInsecure, "Lowercase scheme should be insecure");
            Assert.IsTrue(uppercaseInsecure, "Uppercase scheme should be insecure");
            Assert.IsTrue(mixedcaseInsecure, "Mixed-case scheme should be insecure");
        }