public void Saml2SecurityTokenHandler_GetSets() { Saml2SecurityTokenHandler samlSecurityTokenHandler = new Saml2SecurityTokenHandler(); TestUtilities.SetGet(samlSecurityTokenHandler, "MaximumTokenSizeInBytes", (object)0, ExpectedException.ArgumentOutOfRangeException(substringExpected: "IDX10101")); TestUtilities.SetGet(samlSecurityTokenHandler, "MaximumTokenSizeInBytes", (object)1, ExpectedException.NoExceptionExpected); }
public void OpenIdConnectProtocolValidator_GetSets() { OpenIdConnectProtocolValidator validationParameters = new OpenIdConnectProtocolValidator(); Type type = typeof(OpenIdConnectProtocolValidator); PropertyInfo[] properties = type.GetProperties(); if (properties.Length != 9) { Assert.Fail("Number of properties has changed from 9 to: " + properties.Length + ", adjust tests"); } GetSetContext context = new GetSetContext { PropertyNamesAndSetGetValue = new List <KeyValuePair <string, List <object> > > { new KeyValuePair <string, List <object> >("NonceLifetime", new List <object> { TimeSpan.FromMinutes(60), TimeSpan.FromMinutes(10), TimeSpan.FromMinutes(100) }), new KeyValuePair <string, List <object> >("RequireAcr", new List <object> { false, true, false }), new KeyValuePair <string, List <object> >("RequireAmr", new List <object> { false, true, false }), new KeyValuePair <string, List <object> >("RequireAuthTime", new List <object> { false, true, false }), new KeyValuePair <string, List <object> >("RequireAzp", new List <object> { false, true, false }), new KeyValuePair <string, List <object> >("RequireNonce", new List <object> { true, false, true }), new KeyValuePair <string, List <object> >("RequireSub", new List <object> { false, true, false }), new KeyValuePair <string, List <object> >("RequireTimeStampInNonce", new List <object> { true, false, true }), }, Object = validationParameters, }; TestUtilities.GetSet(context); TestUtilities.AssertFailIfErrors(MethodInfo.GetCurrentMethod().Name, context.Errors); ExpectedException ee = ExpectedException.ArgumentNullException(); Assert.IsNotNull(validationParameters.HashAlgorithmMap); Assert.AreEqual(validationParameters.HashAlgorithmMap.Count, 9); ee = ExpectedException.ArgumentOutOfRangeException(); try { validationParameters.NonceLifetime = TimeSpan.Zero; ee.ProcessNoException(); } catch (Exception ex) { ee.ProcessException(ex); } }
public void ConfigurationManager_GetSets() { ConfigurationManager <OpenIdConnectConfiguration> configManager = new ConfigurationManager <OpenIdConnectConfiguration>("OpenIdConnectMetadata.json"); Type type = typeof(ConfigurationManager <OpenIdConnectConfiguration>); PropertyInfo[] properties = type.GetProperties(); if (properties.Length != 2) { Assert.Fail("Number of properties has changed from 2 to: " + properties.Length + ", adjust tests"); } TimeSpan defaultAutomaticRefreshInterval = ConfigurationManager <OpenIdConnectConfiguration> .DefaultAutomaticRefreshInterval; TimeSpan defaultRefreshInterval = ConfigurationManager <OpenIdConnectConfiguration> .DefaultRefreshInterval; GetSetContext 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.AssertFailIfErrors(MethodInfo.GetCurrentMethod().Name, context.Errors); TestUtilities.SetGet(configManager, "AutomaticRefreshInterval", TimeSpan.FromMilliseconds(1), ExpectedException.ArgumentOutOfRangeException(substringExpected: "IDX10107:")); TestUtilities.SetGet(configManager, "RefreshInterval", TimeSpan.FromMilliseconds(1), ExpectedException.ArgumentOutOfRangeException(substringExpected: "IDX10106:")); TestUtilities.SetGet(configManager, "RefreshInterval", Timeout.InfiniteTimeSpan, ExpectedException.ArgumentOutOfRangeException(substringExpected: "IDX10106:")); // AutomaticRefreshInterval interval should return same config. OpenIdConnectConfiguration configuration = configManager.GetConfigurationAsync().Result; TestUtilities.SetField(configManager, "_metadataAddress", "OpenIdConnectMetadata2.json"); OpenIdConnectConfiguration configuration2 = configManager.GetConfigurationAsync().Result; Assert.IsTrue(IdentityComparer.AreEqual <OpenIdConnectConfiguration>(configuration, configuration2)); Assert.IsTrue(object.ReferenceEquals(configuration, configuration2)); // AutomaticRefreshInterval should pick up new bits. configManager = new ConfigurationManager <OpenIdConnectConfiguration>("OpenIdConnectMetadata.json"); TestUtilities.SetField(configManager, "_automaticRefreshInterval", TimeSpan.FromMilliseconds(1)); configuration = configManager.GetConfigurationAsync().Result; Thread.Sleep(1); TestUtilities.SetField(configManager, "_metadataAddress", "OpenIdConnectMetadata2.json"); configuration2 = configManager.GetConfigurationAsync().Result; Assert.IsFalse(IdentityComparer.AreEqual <OpenIdConnectConfiguration>(configuration, configuration2)); Assert.IsFalse(object.ReferenceEquals(configuration, configuration2)); // RefreshInterval is set to MaxValue configManager = new ConfigurationManager <OpenIdConnectConfiguration>("OpenIdConnectMetadata.json"); configuration = configManager.GetConfigurationAsync().Result; configManager.RefreshInterval = TimeSpan.MaxValue; TestUtilities.SetField(configManager, "_metadataAddress", "OpenIdConnectMetadata2.json"); configuration2 = configManager.GetConfigurationAsync().Result; Assert.IsTrue(IdentityComparer.AreEqual <OpenIdConnectConfiguration>(configuration, configuration2)); Assert.IsTrue(object.ReferenceEquals(configuration, configuration2)); // Refresh should have no effect configManager = new ConfigurationManager <OpenIdConnectConfiguration>("OpenIdConnectMetadata.json"); configuration = configManager.GetConfigurationAsync().Result; configManager.RefreshInterval = TimeSpan.FromHours(10); configManager.RequestRefresh(); configuration2 = configManager.GetConfigurationAsync().Result; Assert.IsTrue(IdentityComparer.AreEqual <OpenIdConnectConfiguration>(configuration, configuration2)); Assert.IsTrue(object.ReferenceEquals(configuration, configuration2)); // Refresh should force pickup of new config configManager = new ConfigurationManager <OpenIdConnectConfiguration>("OpenIdConnectMetadata.json"); configuration = configManager.GetConfigurationAsync().Result; TestUtilities.SetField(configManager, "_refreshInterval", TimeSpan.FromMilliseconds(1)); Thread.Sleep(1); configManager.RequestRefresh(); TestUtilities.SetField(configManager, "_metadataAddress", "OpenIdConnectMetadata2.json"); configuration2 = configManager.GetConfigurationAsync().Result; Assert.IsFalse(object.ReferenceEquals(configuration, configuration2)); Assert.IsFalse(IdentityComparer.AreEqual <OpenIdConnectConfiguration>(configuration, configuration2)); // Refresh set to MaxValue configManager.RefreshInterval = TimeSpan.MaxValue; configuration = configManager.GetConfigurationAsync().Result; Assert.IsTrue(object.ReferenceEquals(configuration, configuration2)); Assert.IsTrue(IdentityComparer.AreEqual <OpenIdConnectConfiguration>(configuration, configuration2)); }