Exemple #1
0
        public void GetSets()
        {
            OpenIdConnectProtocolValidationContext validationContext = new OpenIdConnectProtocolValidationContext();
            Type type = typeof(OpenIdConnectProtocolValidationContext);

            PropertyInfo[] properties = type.GetProperties();
            if (properties.Length != 6)
            {
                Assert.True(true, "Number of properties has changed from 6 to: " + properties.Length + ", adjust tests");
            }

            GetSetContext context =
                new GetSetContext
            {
                PropertyNamesAndSetGetValue = new List <KeyValuePair <string, List <object> > >
                {
                    new KeyValuePair <string, List <object> >("State", new List <object> {
                        (string)null, "AuthorizationCode", "AuthorizationCode_AuthorizationCode"
                    }),
                    new KeyValuePair <string, List <object> >("Nonce", new List <object> {
                        (string)null, "Nonce", "Nonce_Nonce"
                    }),
                },
                Object = validationContext,
            };

            TestUtilities.GetSet(context);
            TestUtilities.AssertFailIfErrors("OpenIdConnectProtocolValidationContext_GetSets", context.Errors);
        }
Exemple #2
0
        public void GetSets()
        {
            var authenticationProtocolMessage = new DerivedAuthenticationProtocolMessage()
            {
                IssuerAddress = "http://www.gotjwt.com"
            };

            var properties = new List <string>()
            {
                "IssuerAddress",
                "PostTitle",
                "ScriptButtonText",
                "ScriptDisabledText",
            };

            var context = new GetSetContext();

            foreach (string property in properties)
            {
                TestUtilities.SetGet(authenticationProtocolMessage, property, null, ExpectedException.ArgumentNullException(substringExpected: "value"), context);
                TestUtilities.SetGet(authenticationProtocolMessage, property, property, ExpectedException.NoExceptionExpected, context);
                TestUtilities.SetGet(authenticationProtocolMessage, property, "    ", ExpectedException.NoExceptionExpected, context);
                TestUtilities.SetGet(authenticationProtocolMessage, property, "\t\n\r", ExpectedException.NoExceptionExpected, context);
            }

            TestUtilities.AssertFailIfErrors(context.Errors);
        }
Exemple #3
0
        public void GetSets()
        {
            HttpDocumentRetriever docRetriever = new HttpDocumentRetriever();
            Type type = typeof(HttpDocumentRetriever);

            PropertyInfo[] properties = type.GetProperties();
            if (properties.Length != 1)
            {
                Assert.True(true, "Number of properties has changed from 1 to: " + properties.Length + ", adjust tests");
            }

            GetSetContext context =
                new GetSetContext
            {
                PropertyNamesAndSetGetValue = new List <KeyValuePair <string, List <object> > >
                {
                    new KeyValuePair <string, List <object> >("RequireHttps", new List <object> {
                        true, false, true
                    }),
                },
                Object = docRetriever,
            };

            TestUtilities.GetSet(context);
            TestUtilities.AssertFailIfErrors("HttpDocumentRetrieverTests_GetSets", context.Errors);
        }
Exemple #4
0
        public void GetSets()
        {
            TestUtilities.WriteHeader($"{this}.GetSets", "GetSets", true);

            var  configManager = new ConfigurationManager <OpenIdConnectConfiguration>("OpenIdConnectMetadata.json", new OpenIdConnectConfigurationRetriever(), new FileDocumentRetriever());
            Type type          = typeof(ConfigurationManager <OpenIdConnectConfiguration>);

            PropertyInfo[] properties = type.GetProperties();
            if (properties.Length != 2)
            {
                Assert.True(false, "Number of properties has changed from 2 to: " + properties.Length + ", adjust tests");
            }

            var defaultAutomaticRefreshInterval = ConfigurationManager <OpenIdConnectConfiguration> .DefaultAutomaticRefreshInterval;
            var defaultRefreshInterval          = ConfigurationManager <OpenIdConnectConfiguration> .DefaultRefreshInterval;
            var context = new GetSetContext
            {
                PropertyNamesAndSetGetValue = new List <KeyValuePair <string, List <object> > >
                {
                    new KeyValuePair <string, List <object> >("AutomaticRefreshInterval", new List <object> {
                        defaultAutomaticRefreshInterval, TimeSpan.FromHours(1), TimeSpan.FromHours(10)
                    }),
                    new KeyValuePair <string, List <object> >("RefreshInterval", new List <object> {
                        defaultRefreshInterval, TimeSpan.FromHours(1), TimeSpan.FromHours(10)
                    }),
                },
                Object = configManager,
            };

            TestUtilities.GetSet(context);
            TestUtilities.SetGet(configManager, "AutomaticRefreshInterval", TimeSpan.FromMilliseconds(1), ExpectedException.ArgumentOutOfRangeException(substringExpected: "IDX20107:"), context);
            TestUtilities.SetGet(configManager, "RefreshInterval", TimeSpan.FromMilliseconds(1), ExpectedException.ArgumentOutOfRangeException(substringExpected: "IDX20106:"), context);
            TestUtilities.SetGet(configManager, "RefreshInterval", Timeout.InfiniteTimeSpan, ExpectedException.ArgumentOutOfRangeException(substringExpected: "IDX20106:"), context);
            TestUtilities.AssertFailIfErrors("ConfigurationManager_GetSets", context.Errors);
        }
Exemple #5
0
        public void GetSets()
        {
            var type       = typeof(Signature);
            var properties = type.GetProperties();

            Assert.True(properties.Length == 5, $"Number of properties has changed from 5 to: {properties.Length}, adjust tests");
            var context = new GetSetContext
            {
                PropertyNamesAndSetGetValue = new List <KeyValuePair <string, List <object> > >
                {
                    new KeyValuePair <string, List <object> >("Id", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("KeyInfo", new List <object> {
                        (KeyInfo)null, new KeyInfo(), new KeyInfo()
                    }),
                    new KeyValuePair <string, List <object> >("Prefix", new List <object> {
                        "", Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("SignatureValue", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("SignedInfo", new List <object> {
                        (SignedInfo)null, new SignedInfo(), new SignedInfo()
                    }),
                },
                Object = new Signature(),
            };

            TestUtilities.GetSet(context);
            TestUtilities.AssertFailIfErrors($"{this}.GetSets", context.Errors);
        }
Exemple #6
0
        public void GetSets()
        {
            var samlSecurityTokenHandler = new Saml2SecurityTokenHandler();
            var context = new GetSetContext
            {
                PropertyNamesAndSetGetValue = new List <KeyValuePair <string, List <object> > >
                {
                    new KeyValuePair <string, List <object> >("MaximumTokenSizeInBytes", new List <object> {
                        (object)TokenValidationParameters.DefaultMaximumTokenSizeInBytes, (object)1000, (object)10
                    }),
                    new KeyValuePair <string, List <object> >("SetDefaultTimesOnTokenCreation", new List <object> {
                        true, false, true
                    }),
                    new KeyValuePair <string, List <object> >("TokenLifetimeInMinutes", new List <object> {
                        (object)60, (object)1000, (object)10
                    }),
                },
                Object = samlSecurityTokenHandler
            };

            TestUtilities.GetSet(context);

            samlSecurityTokenHandler = new Saml2SecurityTokenHandler();
            TestUtilities.SetGet(samlSecurityTokenHandler, "MaximumTokenSizeInBytes", (object)0, ExpectedException.ArgumentOutOfRangeException("IDX10101:"), context);
            TestUtilities.SetGet(samlSecurityTokenHandler, "MaximumTokenSizeInBytes", (object)1, ExpectedException.NoExceptionExpected, context);
            TestUtilities.SetGet(samlSecurityTokenHandler, "Serializer", null, ExpectedException.ArgumentNullException(), context);

            TestUtilities.AssertFailIfErrors("Saml2SecurityTokenHandlerTests_GetSets", context.Errors);
        }
        public void GetSets()
        {
            var type       = typeof(SignedInfo);
            var properties = type.GetProperties();

            Assert.True(properties.Length == 5, $"Number of properties has changed from 5 to: {properties.Length}, adjust tests");
            var context = new GetSetContext
            {
                PropertyNamesAndSetGetValue = new List <KeyValuePair <string, List <object> > >
                {
                    new KeyValuePair <string, List <object> >("CanonicalizationMethod", new List <object> {
                        SecurityAlgorithms.ExclusiveC14n, SecurityAlgorithms.ExclusiveC14nWithComments
                    }),
                    new KeyValuePair <string, List <object> >("Id", new List <object> {
                        (string)null, Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("Prefix", new List <object> {
                        "", Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("SignatureMethod", new List <object> {
                        SecurityAlgorithms.RsaSha256Signature, Guid.NewGuid().ToString()
                    })
                },
                Object = new SignedInfo(),
            };

            TestUtilities.GetSet(context);
            TestUtilities.AssertFailIfErrors($"{this}.GetSets", context.Errors);
        }
Exemple #8
0
        public void GetSets()
        {
            var type       = typeof(ExclusiveCanonicalizationTransform);
            var properties = type.GetProperties();

            Assert.True(properties.Length == 3, $"Number of properties has changed from 3 to: {properties.Length}, adjust tests");

            var context = new GetSetContext
            {
                PropertyNamesAndSetGetValue = new List <KeyValuePair <string, List <object> > >
                {
                    new KeyValuePair <string, List <object> >("Algorithm", new List <object> {
                        SecurityAlgorithms.ExclusiveC14n, SecurityAlgorithms.ExclusiveC14nWithComments, SecurityAlgorithms.ExclusiveC14n
                    }),
                    new KeyValuePair <string, List <object> >("IncludeComments", new List <object> {
                        false, true
                    }),
                    new KeyValuePair <string, List <object> >("InclusiveNamespacesPrefixList", new List <object> {
                        (string)null, "saml dsig wsfed", "saml2 dsig2 wsfed2"
                    })
                },
                Object = new ExclusiveCanonicalizationTransform(false),
            };

            TestUtilities.GetSet(context);

            context = new GetSetContext
            {
                PropertyNamesAndSetGetValue = new List <KeyValuePair <string, List <object> > >
                {
                    new KeyValuePair <string, List <object> >("Algorithm", new List <object> {
                        SecurityAlgorithms.ExclusiveC14nWithComments, SecurityAlgorithms.ExclusiveC14n, SecurityAlgorithms.ExclusiveC14nWithComments
                    }),
                    new KeyValuePair <string, List <object> >("IncludeComments", new List <object> {
                        true, false, true
                    }),
                    new KeyValuePair <string, List <object> >("InclusiveNamespacesPrefixList", new List <object> {
                        (string)null, "saml dsig wsfed", "saml2 dsig2 wsfed2"
                    })
                },
                Object = new ExclusiveCanonicalizationTransform(true),
            };

            TestUtilities.GetSet(context);

            TestUtilities.AssertFailIfErrors($"{this}.GetSets", context.Errors);
        }
Exemple #9
0
        public void GetSets()
        {
            var dsigSerializer = new DSigSerializer();
            var context        = new GetSetContext
            {
                PropertyNamesAndSetGetValue = new List <KeyValuePair <string, List <object> > >
                {
                    new KeyValuePair <string, List <object> >("TransformFactory", new List <object> {
                        TransformFactory.Default
                    }),
                },
                Object = dsigSerializer
            };

            TestUtilities.GetSet(context);
            TestUtilities.AssertFailIfErrors("DSigSerializerTests_GetSets", context.Errors);
        }
Exemple #10
0
        public void Publics( )
        {
            var signature  = new Signature();
            var properties = new List <string>()
            {
                "SignatureValue",
                "SignedInfo",
            };

            var context = new GetSetContext( );

            foreach (string property in properties)
            {
                TestUtilities.SetGet(signature, property, null, ExpectedException.ArgumentNullException(substringExpected: "value"), context);
            }

            TestUtilities.AssertFailIfErrors($"{this}.Publics", context.Errors);
        }
Exemple #11
0
        public void GetSets()
        {
            var context = new GetSetContext
            {
                PropertyNamesAndSetGetValue = new List <KeyValuePair <string, List <object> > >
                {
                    new KeyValuePair <string, List <object> >("TransformFactory", new List <object> {
                        TransformFactory.Default
                    }),
                    new KeyValuePair <string, List <object> >("MaximumReferenceTransforms", new List <object> {
                        5, 11, 1
                    })
                },
                Object = new DSigSerializer()
            };

            TestUtilities.GetSet(context);
            TestUtilities.SetGet(new DSigSerializer(), "MaximumReferenceTransforms", 0, ExpectedException.NoExceptionExpected, context);
            TestUtilities.SetGet(new DSigSerializer(), "MaximumReferenceTransforms", -1, ExpectedException.ArgumentOutOfRangeException("IDX30600:"), context);

            TestUtilities.AssertFailIfErrors("DSigSerializerTests_GetSets", context.Errors);
        }
Exemple #12
0
        public void GetSets()
        {
            var type       = typeof(Reference);
            var properties = type.GetProperties();

            Assert.True(properties.Length == 9, $"Number of properties has changed from 9 to: {properties.Length}, adjust tests");
            var context = new GetSetContext
            {
                PropertyNamesAndSetGetValue = new List <KeyValuePair <string, List <object> > >
                {
                    new KeyValuePair <string, List <object> >("DigestMethod", new List <object> {
                        null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("DigestValue", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("Id", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("Prefix", new List <object> {
                        "", Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("TokenStream", new List <object> {
                        (XmlTokenStream)null, new XmlTokenStream(), new XmlTokenStream()
                    }),
                    new KeyValuePair <string, List <object> >("Type", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("Uri", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                },
                Object = new Reference(),
            };

            TestUtilities.GetSet(context);
            TestUtilities.AssertFailIfErrors($"{this}.GetSets", context.Errors);
        }
Exemple #13
0
        public void GetSets()
        {
            var type       = typeof(EnvelopedSignatureReader);
            var properties = type.GetProperties();

            Assert.True(properties.Length == 34, $"Number of properties has changed from 34 to: {properties.Length}, adjust tests");

            var reader            = XmlUtilities.CreateEnvelopedSignatureReader(Default.OuterXml);
            var defaultSerializer = reader.Serializer;
            var context           = new GetSetContext
            {
                PropertyNamesAndSetGetValue = new List <KeyValuePair <string, List <object> > >
                {
                    new KeyValuePair <string, List <object> >("Serializer", new List <object> {
                        defaultSerializer, DSigSerializer.Default
                    }),
                },
                Object = reader,
            };

            TestUtilities.GetSet(context);
            TestUtilities.AssertFailIfErrors($"{this}.GetSets", context.Errors);
        }
Exemple #14
0
        public void GetSets()
        {
            var type       = typeof(KeyInfo);
            var properties = type.GetProperties();

            Assert.True(properties.Length == 6, $"Number of properties has changed from 6 to: {properties.Length}, adjust tests");

            var keyInfo = new KeyInfo();
            var context = new GetSetContext
            {
                PropertyNamesAndSetGetValue = new List <KeyValuePair <string, List <object> > >
                {
                    new KeyValuePair <string, List <object> >("Id", new List <object> {
                        (string)null, Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("Prefix", new List <object> {
                        "", Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("RetrievalMethodUri", new List <object> {
                        (string)null, Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("RSAKeyValue", new List <object> {
                        (RSAKeyValue)null, new RSAKeyValue(Guid.NewGuid().ToString(), Guid.NewGuid().ToString())
                    }),
                    new KeyValuePair <string, List <object> >("X509Data", new List <object> {
                        keyInfo.X509Data, new List <X509Data>()
                    }),
                    new KeyValuePair <string, List <object> >("KeyName", new List <object> {
                        (string)null, Guid.NewGuid().ToString()
                    }),
                },
                Object = keyInfo
            };

            TestUtilities.GetSet(context);
            TestUtilities.AssertFailIfErrors($"{this}.GetSets", context.Errors);
        }
Exemple #15
0
        public void GetSets()
        {
            var type       = typeof(WsFederationMessage);
            var properties = type.GetProperties();

            Assert.True(properties.Length == 28, $"Number of properties has changed from 28 to: {properties.Length}, adjust tests");

            var context = new GetSetContext
            {
                PropertyNamesAndSetGetValue = new List <KeyValuePair <string, List <object> > >
                {
                    new KeyValuePair <string, List <object> >("Wa", new List <object> {
                        (string)null, Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("Wattr", new List <object> {
                        (string)null, Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("Wattrptr", new List <object> {
                        (string)null, Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("Wct", new List <object> {
                        (string)null, Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("Wctx", new List <object> {
                        (string)null, Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("Wencoding", new List <object> {
                        (string)null, Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("Wfed", new List <object> {
                        (string)null, Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("Wfresh", new List <object> {
                        (string)null, Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("Whr", new List <object> {
                        (string)null, Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("Wp", new List <object> {
                        (string)null, Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("Wpseudo", new List <object> {
                        (string)null, Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("Wpseudoptr", new List <object> {
                        (string)null, Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("Wreply", new List <object> {
                        (string)null, Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("Wreq", new List <object> {
                        (string)null, Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("Wreqptr", new List <object> {
                        (string)null, Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("Wres", new List <object> {
                        (string)null, Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("Wresult", new List <object> {
                        (string)null, Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("Wresultptr", new List <object> {
                        (string)null, Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("Wtrealm", new List <object> {
                        (string)null, Guid.NewGuid().ToString()
                    }),
                },
                Object = new WsFederationMessage(),
            };

            TestUtilities.GetSet(context);
            TestUtilities.AssertFailIfErrors($"{this}.GetSets", context.Errors);
        }
Exemple #16
0
        public void GetSets()
        {
            OpenIdConnectMessage message = new OpenIdConnectMessage();
            Type type = typeof(OpenIdConnectMessage);

            PropertyInfo[] properties = type.GetProperties();
            if (properties.Length != 48)
            {
                Assert.True(true, "Number of public fields has changed from 48 to: " + properties.Length + ", adjust tests");
            }

            GetSetContext context =
                new GetSetContext
            {
                PropertyNamesAndSetGetValue = new List <KeyValuePair <string, List <object> > >
                {
                    new KeyValuePair <string, List <object> >("AuthorizationEndpoint", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("AccessToken", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("AcrValues", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("ClaimsLocales", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("ClientAssertion", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("ClientAssertionType", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("ClientId", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("ClientSecret", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("Code", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("EnableTelemetryParameters", new List <object> {
                        true, false, false
                    }),
                    new KeyValuePair <string, List <object> >("Display", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("DomainHint", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("Error", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("ErrorDescription", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("ErrorUri", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("ExpiresIn", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("GrantType", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("IdToken", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("IdTokenHint", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("IdentityProvider", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("IssuerAddress", new List <object> {
                        string.Empty, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("MaxAge", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("Password", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("PostLogoutRedirectUri", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("Prompt", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("RedirectUri", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("RequestUri", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("ResponseMode", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("ResponseType", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("Resource", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("Scope", new List <object> {
                        null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("SessionState", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("Sid", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("State", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("TargetLinkUri", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("TokenEndpoint", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("TokenType", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("UiLocales", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("UserId", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("Username", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                },

                Object = message,
            };

            TestUtilities.GetSet(context);
            TestUtilities.AssertFailIfErrors("OpenIdConnectMessage_GetSets*** Test Failures:\n", context.Errors);
        }
        public void JwtPayload_GetSets()
        {
            // Aud, Claims, ValidFrom, ValidTo handled in Defaults.

            JwtPayload jwtPayload = new JwtPayload();
            Type       type       = typeof(JwtPayload);

            PropertyInfo[] properties = type.GetProperties();
            if (properties.Length != 20)
            {
                Assert.Fail("Number of properties has changed from 20 to: " + properties.Length + ", adjust tests");
            }

            GetSetContext context =
                new GetSetContext
            {
                PropertyNamesAndSetGetValue = new List <KeyValuePair <string, List <object> > >
                {
                    new KeyValuePair <string, List <object> >("Actort", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("Acr", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("Amr", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("AuthTime", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("Azp", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("CHash", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("Exp", new List <object> {
                        (string)null, 1, 0
                    }),
                    new KeyValuePair <string, List <object> >("Jti", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("Iat", new List <object> {
                        (string)null, 10, 0
                    }),
                    new KeyValuePair <string, List <object> >("Iss", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("Nbf", new List <object> {
                        (string)null, 1, 0
                    }),
                    new KeyValuePair <string, List <object> >("Nonce", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("Sub", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                },
                Object = jwtPayload,
            };

            TestUtilities.GetSet(context);

            if (context.Errors.Count != 0)
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine(Environment.NewLine);
                foreach (string str in context.Errors)
                {
                    sb.AppendLine(str);
                }

                Assert.Fail(sb.ToString());
            }
        }
Exemple #18
0
        public void GetSets()
        {
            OpenIdConnectConfiguration configuration = new OpenIdConnectConfiguration();
            Type type = typeof(OpenIdConnectConfiguration);

            PropertyInfo[] properties = type.GetProperties();
            if (properties.Length != 44)
            {
                Assert.True(false, "Number of properties has changed from 44 to: " + properties.Length + ", adjust tests");
            }

            TestUtilities.CallAllPublicInstanceAndStaticPropertyGets(configuration, "OpenIdConnectConfiguration_GetSets");

            GetSetContext context =
                new GetSetContext
            {
                PropertyNamesAndSetGetValue = new List <KeyValuePair <string, List <object> > >
                {
                    new KeyValuePair <string, List <object> >("AuthorizationEndpoint", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("CheckSessionIframe", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("ClaimsParameterSupported", new List <object> {
                        false, true, false
                    }),
                    new KeyValuePair <string, List <object> >("EndSessionEndpoint", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("HttpLogoutSupported", new List <object> {
                        false, true, true
                    }),
                    new KeyValuePair <string, List <object> >("Issuer", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("JwksUri", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("JsonWebKeySet", new List <object> {
                        null, new JsonWebKeySet()
                    }),
                    new KeyValuePair <string, List <object> >("LogoutSessionSupported", new List <object> {
                        false, true, true
                    }),
                    new KeyValuePair <string, List <object> >("OpPolicyUri", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("OpTosUri", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("RegistrationEndpoint", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("RequireRequestUriRegistration", new List <object> {
                        false, true, true
                    }),
                    new KeyValuePair <string, List <object> >("RequestParameterSupported", new List <object> {
                        false, true, false
                    }),
                    new KeyValuePair <string, List <object> >("RequestUriParameterSupported", new List <object> {
                        false, true, true
                    }),
                    new KeyValuePair <string, List <object> >("ServiceDocumentation", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("TokenEndpoint", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("UserInfoEndpoint", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                },

                Object = configuration,
            };

            TestUtilities.GetSet(context);
            TestUtilities.AssertFailIfErrors("OpenIdConnectConfiguration_GetSets", context.Errors);

            string authorization_Endpoint             = Guid.NewGuid().ToString();
            string end_Session_Endpoint               = Guid.NewGuid().ToString();
            string frontchannelLogoutSessionSupported = "true";
            string frontchannelLogoutSupported        = "true";
            string issuer         = Guid.NewGuid().ToString();
            string jwks_Uri       = Guid.NewGuid().ToString();
            string token_Endpoint = Guid.NewGuid().ToString();

            configuration = new OpenIdConnectConfiguration()
            {
                AuthorizationEndpoint = authorization_Endpoint,
                EndSessionEndpoint    = end_Session_Endpoint,
                FrontchannelLogoutSessionSupported = frontchannelLogoutSessionSupported,
                FrontchannelLogoutSupported        = frontchannelLogoutSupported,
                Issuer        = issuer,
                JwksUri       = jwks_Uri,
                TokenEndpoint = token_Endpoint,
            };

            List <SecurityKey> securityKeys = new List <SecurityKey> {
                new X509SecurityKey(KeyingMaterial.Cert_1024), new X509SecurityKey(KeyingMaterial.DefaultCert_2048)
            };

            configuration.SigningKeys.Add(new X509SecurityKey(KeyingMaterial.Cert_1024));
            configuration.SigningKeys.Add(new X509SecurityKey(KeyingMaterial.DefaultCert_2048));

            List <string> errors = new List <string>();

            if (!string.Equals(configuration.AuthorizationEndpoint, authorization_Endpoint))
            {
                errors.Add(string.Format(CultureInfo.InvariantCulture, "configuration.AuthorizationEndpoint != authorization_Endpoint. '{0}', '{1}'.", configuration.AuthorizationEndpoint, authorization_Endpoint));
            }

            if (!string.Equals(configuration.EndSessionEndpoint, end_Session_Endpoint))
            {
                errors.Add(string.Format(CultureInfo.InvariantCulture, "configuration.EndSessionEndpoint != end_Session_Endpoint. '{0}', '{1}'.", configuration.EndSessionEndpoint, end_Session_Endpoint));
            }

            if (!string.Equals(configuration.FrontchannelLogoutSessionSupported, frontchannelLogoutSessionSupported))
            {
                errors.Add(string.Format(CultureInfo.InvariantCulture, "configuration.FrontchannelLogoutSessionSupported != frontchannelLogoutSessionSupported. '{0}', '{1}'.", configuration.FrontchannelLogoutSessionSupported, frontchannelLogoutSessionSupported));
            }

            if (!string.Equals(configuration.FrontchannelLogoutSupported, frontchannelLogoutSupported))
            {
                errors.Add(string.Format(CultureInfo.InvariantCulture, "configuration.FrontchannelLogoutSupported != efrontchannelLogoutSessionSupported. '{0}', '{1}'.", configuration.FrontchannelLogoutSupported, frontchannelLogoutSupported));
            }

            if (!string.Equals(configuration.Issuer, issuer))
            {
                errors.Add(string.Format(CultureInfo.InvariantCulture, "configuration.Issuer != issuer. '{0}', '{1}'.", configuration.Issuer, issuer));
            }

            if (!string.Equals(configuration.JwksUri, jwks_Uri))
            {
                errors.Add(string.Format(CultureInfo.InvariantCulture, "configuration.JwksUri != jwks_Uri. '{0}', '{1}'.", configuration.JwksUri, jwks_Uri));
            }

            if (!string.Equals(configuration.TokenEndpoint, token_Endpoint))
            {
                errors.Add(string.Format(CultureInfo.InvariantCulture, "configuration.TokenEndpoint != token_Endpoint. '{0}', '{1}'.", configuration.TokenEndpoint, token_Endpoint));
            }

            CompareContext compareContext = new CompareContext();

            if (!IdentityComparer.AreEqual(configuration.SigningKeys, new Collection <SecurityKey>(securityKeys), compareContext))
            {
                errors.AddRange(compareContext.Diffs);
            }

            TestUtilities.AssertFailIfErrors("OpenIdConnectConfiguration_GetSets", errors);
        }
Exemple #19
0
        public void GetSets()
        {
            // Aud, Claims, ValidFrom, ValidTo handled in Defaults.

            JwtPayload jwtPayload = new JwtPayload();
            Type       type       = typeof(JwtPayload);

            PropertyInfo[] properties = type.GetProperties();
            if (properties.Length != 22)
            {
                Assert.True(false, "Number of properties has changed from 22 to: " + properties.Length + ", adjust tests");
            }

            GetSetContext context =
                new GetSetContext
            {
                PropertyNamesAndSetGetValue = new List <KeyValuePair <string, List <object> > >
                {
                    new KeyValuePair <string, List <object> >("Actort", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("Acr", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("AuthTime", new List <object> {
                        (string)null, 10, 12
                    }),
                    new KeyValuePair <string, List <object> >("Azp", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("CHash", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("Exp", new List <object> {
                        (string)null, 1, 0
                    }),
                    new KeyValuePair <string, List <object> >("Jti", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("Iat", new List <object> {
                        (string)null, 10, 0
                    }),
                    new KeyValuePair <string, List <object> >("Iss", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("Nbf", new List <object> {
                        (string)null, 1, 0
                    }),
                    new KeyValuePair <string, List <object> >("Nonce", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("Sub", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                },
                Object = jwtPayload,
            };

            TestUtilities.GetSet(context);
            TestUtilities.AssertFailIfErrors("JwtPayload_GetSets", context.Errors);
        }
Exemple #20
0
        public void TokenValidationParameters_GetSets()
        {
            TokenValidationParameters validationParameters = new TokenValidationParameters();
            Type type = typeof(TokenValidationParameters);

            PropertyInfo[] properties = type.GetProperties();
            if (properties.Length != 30)
            {
                Assert.Fail("Number of public fields has changed from 30 to: " + properties.Length + ", adjust tests");
            }

            GetSetContext context =
                new GetSetContext
            {
                PropertyNamesAndSetGetValue = new List <KeyValuePair <string, List <object> > >
                {
                    new KeyValuePair <string, List <object> >("AuthenticationType", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("CertificateValidator", new List <object> {
                        (string)null, X509CertificateValidator.None, X509CertificateValidatorEx.None
                    }),
                    new KeyValuePair <string, List <object> >("ClockSkew", new List <object> {
                        TokenValidationParameters.DefaultClockSkew, TimeSpan.FromHours(2), TimeSpan.FromMinutes(1)
                    }),
                    new KeyValuePair <string, List <object> >("IssuerSigningKey", new List <object> {
                        (SecurityKey)null, KeyingMaterial.DefaultAsymmetricKey_Public_2048, KeyingMaterial.DefaultSymmetricSecurityKey_256
                    }),
                    new KeyValuePair <string, List <object> >("IssuerSigningKeys", new List <object> {
                        (IEnumerable <SecurityKey>)null, new List <SecurityKey> {
                            KeyingMaterial.DefaultAsymmetricKey_Public_2048, KeyingMaterial.DefaultSymmetricSecurityKey_256
                        }, new List <SecurityKey>()
                    }),
                    new KeyValuePair <string, List <object> >("IssuerSigningToken", new List <object> {
                        (SecurityToken)null, KeyingMaterial.DefaultSymmetricSecurityToken_256, KeyingMaterial.DefaultAsymmetricX509Token_2048
                    }),
                    new KeyValuePair <string, List <object> >("IssuerSigningTokens", new List <object> {
                        (IEnumerable <SecurityToken>)null, new List <SecurityToken> {
                            KeyingMaterial.DefaultAsymmetricX509Token_2048, KeyingMaterial.DefaultSymmetricSecurityToken_256
                        }, new List <SecurityToken>()
                    }),
                    new KeyValuePair <string, List <object> >("NameClaimType", new List <object> {
                        ClaimsIdentity.DefaultNameClaimType, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("RoleClaimType", new List <object> {
                        ClaimsIdentity.DefaultRoleClaimType, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                    new KeyValuePair <string, List <object> >("RequireExpirationTime", new List <object> {
                        true, false, true
                    }),
                    new KeyValuePair <string, List <object> >("RequireSignedTokens", new List <object> {
                        true, false, true
                    }),
                    new KeyValuePair <string, List <object> >("SaveSigninToken", new List <object> {
                        false, true, false
                    }),
                    new KeyValuePair <string, List <object> >("ValidateActor", new List <object> {
                        false, true, false
                    }),
                    new KeyValuePair <string, List <object> >("ValidateAudience", new List <object> {
                        true, false, true
                    }),
                    new KeyValuePair <string, List <object> >("ValidateIssuer", new List <object> {
                        true, false, true
                    }),
                    new KeyValuePair <string, List <object> >("ValidateLifetime", new List <object> {
                        true, false, true
                    }),
                    new KeyValuePair <string, List <object> >("ValidIssuer", new List <object> {
                        (string)null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                    }),
                },
                Object = validationParameters,
            };

            TestUtilities.GetSet(context);

            if (context.Errors.Count != 0)
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine(Environment.NewLine);
                foreach (string str in context.Errors)
                {
                    sb.AppendLine(str);
                }

                Assert.Fail(sb.ToString());
            }

            Assert.IsNull(validationParameters.AudienceValidator);
            Assert.IsNotNull(validationParameters.ClientDecryptionTokens);
            Assert.AreEqual(validationParameters.ClientDecryptionTokens.Count, 0);
            Assert.IsNull(validationParameters.LifetimeValidator);
            Assert.IsNull(validationParameters.IssuerSigningKeyResolver);
            Assert.IsNull(validationParameters.IssuerValidator);
            Assert.IsNull(validationParameters.ValidAudiences);
            Assert.IsNull(validationParameters.ValidIssuers);
        }