public async Task Test_Create_Add_ScopesSecretsAsync() { var insertResult = await CassandraTestHelper.InsertTestData_Scopes(1); var queryNames = from item in insertResult select item.Record.Name; var nameList = queryNames.ToList(); var adminStore = new IdentityServer3AdminStore(); var stored = await adminStore.FindScopesAsync(nameList); Assert.AreEqual(stored.Count(), insertResult.Count); var secretComparer = SecretComparer.OrdinalIgnoreCase; var scopeComparer = ScopeComparer.OrdinalIgnoreCase; var scope = await insertResult[0].Record.MakeIdentityServerScopeAsync(); var storedScope = stored.FirstOrDefault(); Assert.IsTrue(scopeComparer.Equals(scope, storedScope)); List <Secret> secrets = new List <Secret>(); for (int i = 0; i < 2; ++i) { secrets.Add(new Secret() { Value = Guid.NewGuid().ToString(), Description = Guid.NewGuid().ToString(), Expiration = DateTimeOffset.UtcNow.AddHours(1), Type = Guid.NewGuid().ToString() }); } List <Secret> expected = storedScope.ScopeSecrets.Union(secrets, SecretComparer.OrdinalIgnoreCase).ToList(); await adminStore.AddScopeSecretsAsync(insertResult[0].Record.Name, secrets); stored = await adminStore.FindScopesAsync(nameList); storedScope = stored.FirstOrDefault(); Assert.IsTrue(scopeComparer.Equals(scope, storedScope)); var query = from item in storedScope.ScopeSecrets where !expected.Contains(item, secretComparer) select item; var finalList = query.ToList(); Assert.IsTrue(finalList.Count == 0); }
public async Task Test_Create_Add_ScopeClaimsAsync() { var insertResult = await CassandraTestHelper.InsertTestData_Scopes(1); var queryNames = from item in insertResult select item.Record.Name; var nameList = queryNames.ToList(); var adminStore = new IdentityServer3AdminStore(); var stored = await adminStore.FindScopesAsync(nameList); Assert.AreEqual(stored.Count(), insertResult.Count); var scopeClaimComparer = ScopeClaimComparer.MinimalScopeClaimComparer; var scopeComparer = ScopeComparer.OrdinalIgnoreCase; var scope = await insertResult[0].Record.MakeIdentityServerScopeAsync(); var storedScope = stored.FirstOrDefault(); Assert.IsTrue(scopeComparer.Equals(scope, storedScope)); List <ScopeClaim> claims = new List <ScopeClaim>(); for (int i = 0; i < 2; ++i) { claims.Add(new ScopeClaim { Name = Guid.NewGuid().ToString(), AlwaysIncludeInIdToken = true, Description = Guid.NewGuid().ToString() }); } List <ScopeClaim> expected = storedScope.Claims.Union(claims, ScopeClaimComparer.MinimalScopeClaimComparer).ToList(); await adminStore.AddScopeClaimsAsync(insertResult[0].Record.Name, claims); stored = await adminStore.FindScopesAsync(nameList); storedScope = stored.FirstOrDefault(); Assert.IsTrue(scopeComparer.Equals(scope, storedScope)); var query = from item in storedScope.Claims where !expected.Contains(item, scopeClaimComparer) select item; var finalList = query.ToList(); Assert.IsTrue(finalList.Count == 0); }
public async Task Test_Create_Add_Update_ScopeClaimsAsync() { var dao = new IdentityServer3CassandraDao(); await dao.EstablishConnectionAsync(); await dao.CreateTablesAsync(); await dao.TruncateTablesAsync(); var insertResult = await CassandraTestHelper.InsertTestData_Scopes(1); var queryNames = from item in insertResult select item.Record.Name; var nameList = queryNames.ToList(); var adminStore = new IdentityServer3AdminStore(); var stored = await adminStore.FindScopesAsync(nameList); Assert.AreEqual(stored.Count(), insertResult.Count); var scopeClaimComparer = ScopeClaimComparer.MinimalScopeClaimComparer; var scopeComparer = ScopeComparer.OrdinalIgnoreCase; var scope = await insertResult[0].Record.MakeIdentityServerScopeAsync(); var storedScope = stored.FirstOrDefault(); Assert.IsTrue(scopeComparer.Equals(scope, storedScope)); List <ScopeClaim> claims = new List <ScopeClaim>(); for (int i = 0; i < 2; ++i) { claims.Add(new ScopeClaim { Name = Guid.NewGuid().ToString(), AlwaysIncludeInIdToken = true, Description = Guid.NewGuid().ToString() }); } await adminStore.UpdateScopeByNameAsync(storedScope.Name, new List <PropertyValue>() { new PropertyValue() { Name = "Claims", Value = claims } }); stored = await adminStore.FindScopesAsync(nameList); storedScope = stored.FirstOrDefault(); Assert.IsTrue(scopeComparer.Equals(scope, storedScope)); var query = from item in storedScope.Claims where !claims.Contains(item, ScopeClaimComparer.DeepScopeClaimComparer) select item; var finalList = query.ToList(); Assert.IsTrue(finalList.Count == 0); // Do NOT update name foreach (var claim in claims) { claim.Description = Guid.NewGuid().ToString(); claim.AlwaysIncludeInIdToken = !claim.AlwaysIncludeInIdToken; } await adminStore.UpdateScopeClaimsAsync(storedScope.Name, claims); stored = await adminStore.FindScopesAsync(nameList); storedScope = stored.FirstOrDefault(); Assert.IsTrue(scopeComparer.Equals(scope, storedScope)); query = from item in storedScope.Claims where !claims.Contains(item, ScopeClaimComparer.DeepScopeClaimComparer) select item; finalList = query.ToList(); Assert.IsTrue(finalList.Count == 0); }