public void ToComplexEntity_WhenSimpleEntity_ExpectMapSuccess() { // Arrange var mockPropertyMapper = new Mock<IPropertyGetSettersTyped<Scope>>(); mockPropertyMapper.Setup(r => r.GetSetters(It.IsAny<Type>())) .Returns(new Dictionary<string, TypedSetter<Scope>>()); var scopeMappers = new ScopeMappers<Scope>(mockPropertyMapper.Object); var scopeClaim = new ScopeClaim("Name", true) { Description = "Description" }; var secret = new Secret("Value", "Description", new DateTimeOffset(new DateTime(2016, 1, 1))) { Type = "Type" }; var simpleScope = new SimpleScope { Claims = new List<ScopeClaim> { scopeClaim }, Type = ScopeType.Identity, Enabled = true, AllowUnrestrictedIntrospection = true, ScopeSecrets = new List<Secret> { secret }, DisplayName = "DisplayName", Emphasize = true, ClaimsRule = "ClaimsRule", IncludeAllClaimsForUser = true, Name = "Name", Required = true, ShowInDiscoveryDocument = true, Description = "Description" }; // Act var stopwatch = Stopwatch.StartNew(); var complexEntity = scopeMappers.ToComplexEntity(simpleScope); stopwatch.Stop(); // Assert this.WriteTimeElapsed(stopwatch); Assert.That(complexEntity, Is.Not.Null); Assert.That(complexEntity.Claims, Is.Not.Null); Assert.That(complexEntity.Claims.Count, Is.EqualTo(1)); Assert.That(complexEntity.Type, Is.EqualTo(ScopeType.Identity)); Assert.That(complexEntity.Enabled, Is.True); Assert.That(complexEntity.AllowUnrestrictedIntrospection, Is.True); Assert.That(complexEntity.ScopeSecrets, Is.Not.Null); Assert.That(complexEntity.ScopeSecrets.Count, Is.EqualTo(1)); Assert.That(complexEntity.DisplayName, Is.EqualTo("DisplayName")); Assert.That(complexEntity.Emphasize, Is.True); Assert.That(complexEntity.ClaimsRule, Is.EqualTo("ClaimsRule")); Assert.That(complexEntity.IncludeAllClaimsForUser, Is.True); Assert.That(complexEntity.Name, Is.EqualTo("Name")); Assert.That(complexEntity.Required, Is.True); Assert.That(complexEntity.ShowInDiscoveryDocument, Is.True); Assert.That(complexEntity.Description, Is.EqualTo("Description")); }
internal static StoredSecret ToDbFormat(Secret secret) { return new StoredSecret { Description = secret.Description, Type = secret.Type, Value = secret.Value, Expiration = secret.Expiration }; }
/// <summary> /// http://openid.net/specs/openid-connect-registration-1_0.html#RegistrationResponse /// The same Client Secret value MUST NOT be assigned to multiple Clients. /// </summary> /// <returns></returns> public async Task<Secret> GenerateSecretAsync(IClientConfigurationDbContext db) { Secret secret = null; bool exists = false; do { string clientSecretString = RandomStringGenerator.GetRandomString(12); secret = new Secret(clientSecretString.Sha256()); // setting for sha version? exists = await db.Clients.AnyAsync(c => c.ClientSecrets.Any(s => s.Value == secret.Value)); } while (exists); return secret; }
public void ToComplexEntity_WhenSimpleEntity_ExpectMapSuccess() { // Arrange var mockClaimsMapper = new Mock<IMapper<SimpleClaim, Claim>>(); var mockPropertyMapper = new Mock<IPropertyGetSettersTyped<Client>>(); mockClaimsMapper.Setup(r => r.ToComplexEntity(It.IsAny<IEnumerable<SimpleClaim>>())).Returns(new List<Claim> { new Claim("DEFAULT", "DEFAULT") }); mockPropertyMapper.Setup(r => r.GetSetters(It.IsAny<Type>())).Returns(new Dictionary<string, TypedSetter<Client>>()); var clientMappers = new ClientMappers<Client>(mockClaimsMapper.Object, mockPropertyMapper.Object); var secret = new Secret("Value", "Description", new DateTimeOffset(new DateTime(2016, 1, 1))) { Type = "Type" }; var simpleClient = new SimpleClient { Claims = new List<SimpleClaim>(), Enabled = true, AccessTokenType = AccessTokenType.Jwt, AbsoluteRefreshTokenLifetime = 1, AccessTokenLifetime = 1, AllowAccessToAllCustomGrantTypes = true, AllowAccessToAllScopes = true, AllowRememberConsent = true, EnableLocalLogin = true, AllowAccessTokensViaBrowser = true, LogoutSessionRequired = true, Flow = Flows.AuthorizationCode, AlwaysSendClientClaims = true, PrefixClientClaims = true, ClientSecrets = new List<Secret> { secret }, RefreshTokenExpiration = TokenExpiration.Absolute, RequireSignOutPrompt = true, RefreshTokenUsage = TokenUsage.OneTimeOnly, IdentityTokenLifetime = 1, SlidingRefreshTokenLifetime = 1, RequireConsent = true, AllowClientCredentialsOnly = true, IncludeJwtId = true, AuthorizationCodeLifetime = 1, UpdateAccessTokenClaimsOnRefresh = true, ClientName = "ClientName", LogoutUri = "LogoutUri", RedirectUris = new List<string>(), ClientUri = "ClientUri", AllowedCustomGrantTypes = new List<string>(), AllowedScopes = new List<string>(), ClientId = "ClientId", PostLogoutRedirectUris = new List<string>(), AllowedCorsOrigins = new List<string>(), IdentityProviderRestrictions = new List<string>(), LogoUri = "LogoUri" }; // Act var stopwatch = Stopwatch.StartNew(); var complexEntity = clientMappers.ToComplexEntity(simpleClient); stopwatch.Stop(); // Assert this.WriteTimeElapsed(stopwatch); Assert.That(complexEntity, Is.Not.Null); }