public SqlServerNonceStore(SqlServerNonceStoreSettings settings, IExpiredNoncesCleaner expiredNoncesCleaner)
        {
            _settings             = settings ?? throw new ArgumentNullException(nameof(settings));
            _expiredNoncesCleaner = expiredNoncesCleaner ?? throw new ArgumentNullException(nameof(expiredNoncesCleaner));

            _mergeSql = new Lazy <string>(() => {
                var thisNamespace = typeof(SqlServerNonceStore).Namespace;
                using (var stream = typeof(SqlServerNonceStore).Assembly.GetManifestResourceStream($"{thisNamespace}.Scripts.MergeNonce.sql")) {
                    // ReSharper disable once AssignNullToNotNullAttribute
                    using (var streamReader = new StreamReader(stream)) {
                        var template = streamReader.ReadToEnd();
                        return(template.Replace(TableNameToken, _settings.NonceTableName));
                    }
                }
            });
            _getSql = new Lazy <string>(() => {
                var thisNamespace = typeof(SqlServerNonceStore).Namespace;
                using (var stream = typeof(SqlServerNonceStore).Assembly.GetManifestResourceStream($"{thisNamespace}.Scripts.GetNonce.sql")) {
                    // ReSharper disable once AssignNullToNotNullAttribute
                    using (var streamReader = new StreamReader(stream)) {
                        var template = streamReader.ReadToEnd();
                        return(template.Replace(TableNameToken, _settings.NonceTableName));
                    }
                }
            });
        }
 public SqlServerNonceStoreSettingsTests()
 {
     _sut = new SqlServerNonceStoreSettings {
         ConnectionString             = "Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;",
         NonceTableName               = "signaturenonces",
         MigrationsTableName          = "noncemigrations",
         ExpiredNoncesCleanUpInterval = TimeSpan.FromMinutes(1)
     };
 }
Exemple #3
0
 public ExpiredNoncesCleanerTests(SqlServerFixture fixture)
     : base(fixture)
 {
     _systemClock           = A.Fake <ISystemClock>();
     _backgroundTaskStarter = new ImmediateBackgroundTaskStarter();
     _settings = new SqlServerNonceStoreSettings {
         ExpiredNoncesCleanUpInterval = TimeSpan.FromMinutes(1),
         ConnectionString             = fixture.SqlServerConfig.GetConnectionStringForTestDatabase()
     };
     _sut = new ExpiredNoncesCleaner(_settings, _backgroundTaskStarter, _systemClock);
 }
Exemple #4
0
        public SqlServerNonceStoreTests(SqlServerFixture fixture)
            : base(fixture)
        {
            FakeFactory.Create(out _expiredNoncesCleaner);
            _settings = new SqlServerNonceStoreSettings {
                ExpiredNoncesCleanUpInterval = TimeSpan.FromMinutes(1),
                ConnectionString             = fixture.SqlServerConfig.GetConnectionStringForTestDatabase()
            };
            _sut = new SqlServerNonceStore(_settings, _expiredNoncesCleaner);

            _now = new DateTimeOffset(
                DateTimeOffset.UtcNow.Year,
                DateTimeOffset.UtcNow.Month,
                DateTimeOffset.UtcNow.Day,
                DateTimeOffset.UtcNow.Hour,
                DateTimeOffset.UtcNow.Minute,
                DateTimeOffset.UtcNow.Second,
                DateTimeOffset.UtcNow.Millisecond,
                TimeSpan.Zero);
        }
Exemple #5
0
        public ExpiredNoncesCleaner(SqlServerNonceStoreSettings settings, IBackgroundTaskStarter backgroundTaskStarter, ISystemClock systemClock)
        {
            _settings = settings ?? throw new ArgumentNullException(nameof(settings));
            _backgroundTaskStarter = backgroundTaskStarter ?? throw new ArgumentNullException(nameof(backgroundTaskStarter));
            _systemClock           = systemClock ?? throw new ArgumentNullException(nameof(systemClock));

            _deleteExpiredSql = new Lazy <string>(() => {
                var thisNamespace = typeof(SqlServerNonceStore).Namespace;
                using (var stream = typeof(SqlServerNonceStore).Assembly.GetManifestResourceStream($"{thisNamespace}.Scripts.DeleteExpiredNonces.sql")) {
                    // ReSharper disable once AssignNullToNotNullAttribute
                    using (var streamReader = new StreamReader(stream)) {
                        var template = streamReader.ReadToEnd();
                        return(template.Replace(TableNameToken, settings.NonceTableName));
                    }
                }
            });

            _lastCleanUp = DateTimeOffset.MinValue;
            _semaphore   = new SemaphoreSlim(1, 1);
        }
Exemple #6
0
        public static IHttpMessageSigningVerificationBuilder UseSqlServerNonceStore(this IHttpMessageSigningVerificationBuilder builder, SqlServerNonceStoreSettings nonceStoreSettings)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (nonceStoreSettings == null)
            {
                throw new ArgumentNullException(nameof(nonceStoreSettings));
            }

            return(builder.UseSqlServerNonceStore(prov => nonceStoreSettings));
        }