Example #1
0
            public void CopiesAllValues()
            {
                ClaimDataRecord actual = null;
                Action          act    = () => actual = ClaimDataRecord.FromClaim(_clientId, _claim);

                act.Should().NotThrow();

                var expected = new ClaimDataRecord {
                    ClientId       = "c001",
                    Type           = "t1",
                    Value          = "v1",
                    OriginalIssuer = "oi",
                    Issuer         = "i",
                    ValueType      = "vt"
                };

                actual.Should().BeEquivalentTo(expected);
            }
        public async Task Register(Client client)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            var clientRecord = new ClientDataRecord {
                Id                    = client.Id,
                Name                  = client.Name,
                NonceLifetime         = client.NonceLifetime.TotalSeconds,
                ClockSkew             = client.ClockSkew.TotalSeconds,
                RequestTargetEscaping = client.RequestTargetEscaping.ToString(),
                Claims                = client.Claims?.Select(c => ClaimDataRecord.FromClaim(client.Id, c))?.ToList() ?? new List <ClaimDataRecord>(),
                V = ClientDataRecord.GetV()
            };

            _signatureAlgorithmConverter.SetSignatureAlgorithm(clientRecord, client.SignatureAlgorithm, _settings.SharedSecretEncryptionKey);

            using (var connection = new SqlConnection(_settings.ConnectionString)) {
                await connection.OpenAsync();

                try {
                    using (var transaction = connection.BeginTransaction()) {
                        await connection.ExecuteAsync(_mergeClientSql.Value, clientRecord, transaction).ConfigureAwait(continueOnCapturedContext: false);

                        await connection.ExecuteAsync(_deleteClientClaimsSql.Value, new { ClientId = client.Id.Value }, transaction).ConfigureAwait(continueOnCapturedContext: false);

                        if (clientRecord.Claims.Count > 0)
                        {
                            foreach (var claim in clientRecord.Claims)
                            {
                                await connection.ExecuteAsync(_insertClientClaimSql.Value, claim, transaction).ConfigureAwait(continueOnCapturedContext: false);
                            }
                        }
                        transaction.Commit();
                    }
                }
                finally {
                    connection.Close();
                }
            }
        }
Example #3
0
            public void GivenMinimalClaim_DoesNotThrow()
            {
                var minimalClaim = new Claim("t1", "v1");

                ClaimDataRecord actual = null;
                Action          act    = () => actual = ClaimDataRecord.FromClaim(_clientId, minimalClaim);

                act.Should().NotThrow();

                var expected = new ClaimDataRecord {
                    ClientId       = "c001",
                    Type           = "t1",
                    Value          = "v1",
                    OriginalIssuer = "LOCAL AUTHORITY",
                    Issuer         = "LOCAL AUTHORITY",
                    ValueType      = "http://www.w3.org/2001/XMLSchema#string"
                };

                actual.Should().BeEquivalentTo(expected);
            }
Example #4
0
            public void GivenNullOrEmptyClientId_ThrowsArgumentNullException(string nullOrEmpty)
            {
                Action act = () => ClaimDataRecord.FromClaim(nullOrEmpty, _claim);

                act.Should().Throw <ArgumentException>();
            }
Example #5
0
 public ClaimDataRecordTests()
 {
     _sut = new ClaimDataRecord();
 }
Example #6
0
            public void GivenNullClaim_ThrowsArgumentNullException()
            {
                Action act = () => ClaimDataRecord.FromClaim(_clientId, null);

                act.Should().Throw <ArgumentNullException>();
            }