public async Task TestUpdateAsync() { var dao = new IdentityServer3CassandraDao(); await dao.EstablishConnectionAsync(); var insert = await CassandraTestHelper.InsertTestData_Clients(1); var result = await dao.FindClientByClientIdAsync(insert[0].ClientId); Assert.AreEqual(insert[0].ClientName, result.ClientName); await dao.TruncateTablesAsync(); result = await dao.FindClientByClientIdAsync(insert[0].ClientId); Assert.IsNull(result); }
public async Task Test_Create_Modify_ClientAsync() { var dao = new IdentityServer3CassandraDao(); await dao.EstablishConnectionAsync(); var adminStore = new IdentityServer3AdminStore(); global::IdentityServer3.Core.Models.Client dd = new global::IdentityServer3.Core.Models.Client(); var insert = await CassandraTestHelper.InsertTestData_Clients(1); var result = await adminStore.FindClientByIdAsync(insert[0].ClientId); Assert.AreEqual(insert[0].ClientName, result.ClientName); int expectedInt = 1961; string expectedString = Guid.NewGuid().ToString(); List <string> expectedList = new List <string>() { expectedString }; #region PROPERTY_VALUES List <PropertyValue> propertyList = new List <PropertyValue> { new PropertyValue() { Name = "Claims", Value = new List <Claim>() { new Claim("Type:" + expectedString, "Value:" + expectedString, "ValueType:" + expectedString, "Issuer:" + expectedString, "OriginalIssuer:" + expectedString, new ClaimsIdentity(new List <Claim>() { new Claim("Type:" + expectedString, "Value:" + expectedString) })) } }, new PropertyValue() { Name = "ClientSecrets", Value = new List <Secret> { new Secret(expectedString.Sha256()), } }, new PropertyValue() { Name = "ClientUri", Value = expectedString }, new PropertyValue() { Name = "ClientName", Value = expectedString }, new PropertyValue() { Name = "AbsoluteRefreshTokenLifetime", Value = expectedInt }, new PropertyValue() { Name = "AccessTokenLifetime", Value = expectedInt }, new PropertyValue() { Name = "AccessTokenType", Value = expectedInt }, new PropertyValue() { Name = "AllowAccessToAllCustomGrantTypes", Value = !result.AllowAccessToAllCustomGrantTypes }, new PropertyValue() { Name = "AllowAccessToAllScopes", Value = !result.AllowAccessToAllScopes }, new PropertyValue() { Name = "AllowAccessTokensViaBrowser", Value = !result.AllowAccessTokensViaBrowser }, new PropertyValue() { Name = "AllowClientCredentialsOnly", Value = !result.AllowClientCredentialsOnly }, new PropertyValue() { Name = "AllowRememberConsent", Value = !result.AllowRememberConsent }, new PropertyValue() { Name = "AlwaysSendClientClaims", Value = !result.AlwaysSendClientClaims }, new PropertyValue() { Name = "AuthorizationCodeLifetime", Value = expectedInt }, new PropertyValue() { Name = "Enabled", Value = !result.Enabled }, new PropertyValue() { Name = "EnableLocalLogin", Value = !result.EnableLocalLogin }, new PropertyValue() { Name = "Flow", Value = expectedInt }, new PropertyValue() { Name = "IdentityTokenLifetime", Value = expectedInt }, new PropertyValue() { Name = "IncludeJwtId", Value = !result.IncludeJwtId }, new PropertyValue() { Name = "LogoutSessionRequired", Value = !result.LogoutSessionRequired }, new PropertyValue() { Name = "LogoutUri", Value = expectedString }, new PropertyValue() { Name = "PrefixClientClaims", Value = !result.PrefixClientClaims }, new PropertyValue() { Name = "RefreshTokenExpiration", Value = expectedInt }, new PropertyValue() { Name = "RefreshTokenUsage", Value = expectedInt }, new PropertyValue() { Name = "RequireConsent", Value = !result.RequireConsent }, new PropertyValue() { Name = "RequireSignOutPrompt", Value = !result.RequireSignOutPrompt }, new PropertyValue() { Name = "SlidingRefreshTokenLifetime", Value = expectedInt }, new PropertyValue() { Name = "UpdateAccessTokenClaimsOnRefresh", Value = !result.UpdateAccessTokenClaimsOnRefresh }, new PropertyValue() { Name = "AllowedCorsOrigins", Value = expectedList }, new PropertyValue() { Name = "AllowedCustomGrantTypes", Value = expectedList }, new PropertyValue() { Name = "AllowedScopes", Value = expectedList }, new PropertyValue() { Name = "IdentityProviderRestrictions", Value = expectedList }, new PropertyValue() { Name = "PostLogoutRedirectUris", Value = expectedList }, new PropertyValue() { Name = "RedirectUris", Value = expectedList }, new PropertyValue() { Name = "LogoUri", Value = expectedString }, }; #endregion await dao.UpdateClientByIdAsync(result.ClientId, propertyList); var result2 = await dao.FindClientByClientIdAsync(insert[0].ClientId); foreach (var property in propertyList) { var castTo = property.Value.GetType(); var valueRaw = result2.GetPropertyValue(property.Name); var valueActual = Cast(valueRaw, castTo); var valueExpected = property.Value; if (castTo == typeof(List <string>)) { var propertyValue = (List <string>)Convert.ChangeType(property.Value, castTo); var resultValue = (List <string>)Convert.ChangeType(valueRaw, castTo); Assert.AreEqual(propertyValue.Count, resultValue.Count); var v = from x in propertyValue where !resultValue.Contains(x) select x; Assert.IsFalse(v.Any()); } else if (castTo == typeof(List <Secret>)) { var propertyValue = (List <Secret>)Convert.ChangeType(property.Value, castTo); var resultValue = (List <Secret>)Convert.ChangeType(valueRaw, castTo); Assert.AreEqual(propertyValue.Count, resultValue.Count); IEnumerable <Secret> except = propertyValue.Except(resultValue, SecretComparer.OrdinalIgnoreCase); Assert.IsFalse(except.Any()); } else if (castTo == typeof(List <Claim>)) { var propertyValue = (List <Claim>)Convert.ChangeType(property.Value, castTo); var resultValue = (List <Claim>)Convert.ChangeType(valueRaw, castTo); Assert.AreEqual(propertyValue.Count, resultValue.Count); IEnumerable <Claim> except = propertyValue.Except(resultValue, ClaimComparer.MinimalComparer); Assert.IsFalse(except.Any()); } else { Assert.AreEqual(valueActual, valueExpected); } } }