Beispiel #1
0
        public void RangeTest()
        {
            var       random   = new StandardRandomNumberGenerator();
            const int minValue = 8;
            const int maxValue = 5;

            random.Next(minValue, maxValue);
        } //ncrunch: no coverage
Beispiel #2
0
        public void RangeTest()
        {
            var       random   = new StandardRandomNumberGenerator();
            const int minValue = 8;
            const int maxValue = 5;

            Assert.Throws <ArgumentOutOfRangeException>(() => random.Next(minValue, maxValue));
        } //ncrunch: no coverage
Beispiel #3
0
        public AuthCodeServiceTests()
        {
            var randomNumberGenerator = new StandardRandomNumberGenerator();

            _AuthCodeGenerator = new AuthCodeGenerator(randomNumberGenerator);
            var cache = new MemoryDistributedCache(Options.Create(new MemoryDistributedCacheOptions()));

            _AuthCodeService = new AuthCodeService(cache, _AuthCodeGenerator);
        }
Beispiel #4
0
        public void Valid()
        {
            var       random   = new StandardRandomNumberGenerator();
            const int minValue = 1;
            const int maxValue = 99999999;

            var result = random.Next(minValue, maxValue);

            Assert.True(result >= minValue);
            Assert.True(result <= maxValue);
        }
        public void NewEksStuffingGeneratorTest()
        {
            var rng = new StandardRandomNumberGenerator(); var eksConfigMock = new Mock <IEksConfig>(MockBehavior.Strict);

            eksConfigMock.Setup(x => x.LifetimeDays).Returns(14);
            var dtp = new StandardUtcDateTimeProvider();

            var stuffer = new EksStuffingGeneratorMk2(new TransmissionRiskLevelCalculationMk2(), rng, dtp, eksConfigMock.Object);

            var result = stuffer.Execute(10);

            Assert.Equal(10, result.Length);
        }
Beispiel #6
0
        public async Task AddExampleContent()
        {
            var r2 = new StandardRandomNumberGenerator();

            await using var tx = await _Provider.Database.BeginTransactionAsync();

            var wfs1 = new TekReleaseWorkflowStateEntity
            {
                LabConfirmationId = _LabConfirmationIdService.Next(),
                BucketId          = r2.NextByteArray(_WorkflowConfig.BucketIdLength),
                ConfirmationKey   = r2.NextByteArray(_WorkflowConfig.ConfirmationKeyLength),
                Created           = new DateTime(2020, 5, 1, 0, 0, 0, DateTimeKind.Utc),
            };

            var key1 = new TekEntity
            {
                Owner              = wfs1,
                PublishingState    = PublishingState.Unpublished,
                RollingPeriod      = 2,
                RollingStartNumber = DateTime.UtcNow.Date.ToRollingStartNumber(),
                KeyData            = r2.NextByteArray(_TekValidatorConfig.KeyDataLength),
                Region             = "NL"
            };


            var key2 = new TekEntity
            {
                Owner              = wfs1,
                PublishingState    = PublishingState.Unpublished,
                RollingPeriod      = 144,
                RollingStartNumber = DateTime.UtcNow.Date.ToRollingStartNumber(),
                KeyData            = r2.NextByteArray(_TekValidatorConfig.KeyDataLength),
                Region             = "NL"
            };

            await _Provider.KeyReleaseWorkflowStates.AddAsync(wfs1);

            await _Provider.TemporaryExposureKeys.AddRangeAsync(key1, key2);

            _Provider.SaveAndCommit();
        }
Beispiel #7
0
        public void GetZero()
        {
            var zeros = 0;
            var ones  = 0;
            var r     = new StandardRandomNumberGenerator();

            for (var i = 0; i < 1000; i++)
            {
                var next = r.Next(0, 1);
                Assert.True(next == 0 || next == 1);
                if (next == 0)
                {
                    zeros++;
                }
                if (next == 1)
                {
                    ones++;
                }
            }

            Assert.True(zeros > 0);
            Assert.True(ones > 0);
        }
        public EksEngineTests(IDbProvider <WorkflowDbContext> workflowDbProvider, IDbProvider <DkSourceDbContext> dkSourceDbProvider, IDbProvider <EksPublishingJobDbContext> eksPublishingJobDbProvider, IDbProvider <ContentDbContext> contentDbProvider, IWrappedEfExtensions efExtensions)
        {
            _lf = new LoggerFactory();

            _efExtensions               = efExtensions;
            _workflowDbProvider         = workflowDbProvider;
            _dkSourceDbProvider         = dkSourceDbProvider;
            _eksPublishingJobDbProvider = eksPublishingJobDbProvider;
            _contentDbProvider          = contentDbProvider;

            // Configuration
            var eksHeaderConfig = new Mock <IEksHeaderInfoConfig>(MockBehavior.Strict);
            var eksConfig       = new Mock <IEksConfig>(MockBehavior.Strict);

            eksConfig.Setup(x => x.TekCountMax).Returns(750000);
            eksConfig.Setup(x => x.LifetimeDays).Returns(14);

            var gaSigner = new Mock <IGaContentSigner>(MockBehavior.Strict);

            gaSigner.Setup(x => x.GetSignature(It.IsAny <byte[]>())).Returns(new byte[] { 1 });

            var nlSigner = new Mock <IContentSigner>(MockBehavior.Loose);

            nlSigner.Setup(x => x.GetSignature(new byte[0])).Returns(new byte[] { 2 });

            _snapshot = new SnapshotWorkflowTeksToDksCommand(
                _lf.CreateLogger <SnapshotWorkflowTeksToDksCommand>(),
                _dtp,
                new TransmissionRiskLevelCalculationMk2(),
                _workflowDbProvider.CreateNew(),
                _workflowDbProvider.CreateNew,
                _dkSourceDbProvider.CreateNew,
                _efExtensions,
                new IDiagnosticKeyProcessor[] { }
                );

            var countriesOut = new Mock <IOutboundFixedCountriesOfInterestSetting>();

            countriesOut.Setup(x => x.CountriesOfInterest).Returns(new[] { "ET" });
            _rng    = new StandardRandomNumberGenerator();
            _eksJob = new ExposureKeySetBatchJobMk3(
                eksConfig.Object,
                new EksBuilderV1(eksHeaderConfig.Object, gaSigner.Object, nlSigner.Object, _dtp, new GeneratedProtobufEksContentFormatter(),
                                 new EksBuilderV1LoggingExtensions(_lf.CreateLogger <EksBuilderV1LoggingExtensions>())
                                 ),
                _eksPublishingJobDbProvider.CreateNew,
                _dtp,
                new EksEngineLoggingExtensions(_lf.CreateLogger <EksEngineLoggingExtensions>()),
                new EksStuffingGeneratorMk2(new TransmissionRiskLevelCalculationMk2(), _rng, _dtp, eksConfig.Object),
                new SnapshotDiagnosisKeys(new SnapshotLoggingExtensions(new TestLogger <SnapshotLoggingExtensions>()), _dkSourceDbProvider.CreateNew(), _eksPublishingJobDbProvider.CreateNew,
                                          new Infectiousness(new Dictionary <InfectiousPeriodType, HashSet <int> > {
                {
                    InfectiousPeriodType.Symptomatic,
                    new HashSet <int>()
                    {
                        -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
                    }
                },
                {
                    InfectiousPeriodType.Asymptomatic,
                    new HashSet <int>()
                    {
                        0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
                    }
                }
            })),
                new MarkDiagnosisKeysAsUsedLocally(_dkSourceDbProvider.CreateNew, eksConfig.Object, _eksPublishingJobDbProvider.CreateNew, _lf.CreateLogger <MarkDiagnosisKeysAsUsedLocally>()),
                new EksJobContentWriter(_contentDbProvider.CreateNew, _eksPublishingJobDbProvider.CreateNew, new Sha256HexPublishingIdService(), new EksJobContentWriterLoggingExtensions(_lf.CreateLogger <EksJobContentWriterLoggingExtensions>())),
                new WriteStuffingToDiagnosisKeys(_dkSourceDbProvider.CreateNew(), _eksPublishingJobDbProvider.CreateNew(),
                                                 new IDiagnosticKeyProcessor[] {
                new FixedCountriesOfInterestOutboundDiagnosticKeyProcessor(countriesOut.Object),
                new NlToEfgsDsosDiagnosticKeyProcessorMk1()
            }
                                                 ),
                _efExtensions
                );

            var jsonSerializer = new StandardJsonSerializer();

            _manifestJob = new ManifestUpdateCommand(
                new ManifestV2Builder(_contentDbProvider.CreateNew(), eksConfig.Object, _dtp),
                new ManifestV3Builder(_contentDbProvider.CreateNew(), eksConfig.Object, _dtp),
                new ManifestV4Builder(_contentDbProvider.CreateNew(), eksConfig.Object, _dtp),
                _contentDbProvider.CreateNew,
                new ManifestUpdateCommandLoggingExtensions(_lf.CreateLogger <ManifestUpdateCommandLoggingExtensions>()),
                _dtp,
                jsonSerializer,
                () => new StandardContentEntityFormatter(new ZippedSignedContentFormatter(nlSigner.Object), new Sha256HexPublishingIdService(), jsonSerializer)
                );

            var thumbprintConfig = new Mock <IThumbprintConfig>(MockBehavior.Strict);

            _resign = new NlContentResignExistingV1ContentCommand(
                new NlContentResignCommand(_contentDbProvider.CreateNew, nlSigner.Object, new ResignerLoggingExtensions(_lf.CreateLogger <ResignerLoggingExtensions>())));
        }
        public EksEngineTests(IDbProvider <WorkflowDbContext> workflowDbProvider, IDbProvider <DkSourceDbContext> dkSourceDbProvider, IDbProvider <EksPublishingJobDbContext> eksPublishingJobDbProvider, IDbProvider <ContentDbContext> contentDbProvider, IWrappedEfExtensions efExtensions)
        {
            _Lf = new LoggerFactory();

            _EfExtensions               = efExtensions;
            _WorkflowDbProvider         = workflowDbProvider;
            _DkSourceDbProvider         = dkSourceDbProvider;
            _EksPublishingJobDbProvider = eksPublishingJobDbProvider;
            _ContentDbProvider          = contentDbProvider;

            ////Configuration
            var tekValidatorConfig = new Mock <ITekValidatorConfig>(MockBehavior.Strict);
            var eksHeaderConfig    = new Mock <IEksHeaderInfoConfig>(MockBehavior.Strict);
            var eksConfig          = new Mock <IEksConfig>(MockBehavior.Strict);

            eksConfig.Setup(x => x.TekCountMax).Returns(750000);
            eksConfig.Setup(x => x.LifetimeDays).Returns(14);

            var gaSigner = new Mock <IGaContentSigner>(MockBehavior.Strict);

            //gaSigner.Setup(x => x.SignatureOid).Returns("The OID");
            gaSigner.Setup(x => x.GetSignature(It.IsAny <byte[]>())).Returns(new byte[] { 1 });

            var nlSigner = new Mock <IContentSigner>(MockBehavior.Loose);

            nlSigner.Setup(x => x.GetSignature(new byte[0])).Returns(new byte[] { 2 });

            _Snapshot = new SnapshotWorkflowTeksToDksCommand(
                _Lf.CreateLogger <SnapshotWorkflowTeksToDksCommand>(),
                _Dtp,
                new TransmissionRiskLevelCalculationMk2(),
                _WorkflowDbProvider.CreateNew(),
                _WorkflowDbProvider.CreateNew,
                _DkSourceDbProvider.CreateNew,
                _EfExtensions,
                new IDiagnosticKeyProcessor[] {
            });


            _CountriesOut = new Mock <IOutboundFixedCountriesOfInterestSetting>();
            _CountriesOut.Setup(x => x.CountriesOfInterest).Returns(new[] { "ET" });
            _Rng    = new StandardRandomNumberGenerator();
            _EksJob = new ExposureKeySetBatchJobMk3(
                eksConfig.Object,
                new EksBuilderV1(eksHeaderConfig.Object, gaSigner.Object, nlSigner.Object, _Dtp, new GeneratedProtobufEksContentFormatter(),
                                 new EksBuilderV1LoggingExtensions(_Lf.CreateLogger <EksBuilderV1LoggingExtensions>())
                                 ),
                _EksPublishingJobDbProvider.CreateNew,
                _Dtp,
                new EksEngineLoggingExtensions(_Lf.CreateLogger <EksEngineLoggingExtensions>()),
                new EksStuffingGeneratorMk2(new TransmissionRiskLevelCalculationMk2(), _Rng, _Dtp, eksConfig.Object),
                new SnapshotDiagnosisKeys(new SnapshotLoggingExtensions(new TestLogger <SnapshotLoggingExtensions>()), _DkSourceDbProvider.CreateNew(), _EksPublishingJobDbProvider.CreateNew),
                new MarkDiagnosisKeysAsUsedLocally(_DkSourceDbProvider.CreateNew, eksConfig.Object, _EksPublishingJobDbProvider.CreateNew, _Lf.CreateLogger <MarkDiagnosisKeysAsUsedLocally>()),
                new EksJobContentWriter(_ContentDbProvider.CreateNew, _EksPublishingJobDbProvider.CreateNew, new Sha256HexPublishingIdService(), new EksJobContentWriterLoggingExtensions(_Lf.CreateLogger <EksJobContentWriterLoggingExtensions>())),
                new WriteStuffingToDiagnosisKeys(_DkSourceDbProvider.CreateNew(), _EksPublishingJobDbProvider.CreateNew(),
                                                 new IDiagnosticKeyProcessor[] {
                new FixedCountriesOfInterestOutboundDiagnosticKeyProcessor(_CountriesOut.Object),
                new NlToEfgsDsosDiagnosticKeyProcessorMk1()
            }
                                                 ),
                _EfExtensions
                );

            var jsonSerializer = new StandardJsonSerializer();

            _ManifestJob = new ManifestUpdateCommand(
                new ManifestBuilder(_ContentDbProvider.CreateNew(), eksConfig.Object, _Dtp),
                new ManifestBuilderV3(_ContentDbProvider.CreateNew(), eksConfig.Object, _Dtp),
                new ManifestBuilderV4(_ContentDbProvider.CreateNew(), eksConfig.Object, _Dtp),
                _ContentDbProvider.CreateNew,
                new ManifestUpdateCommandLoggingExtensions(_Lf.CreateLogger <ManifestUpdateCommandLoggingExtensions>()),
                _Dtp,
                jsonSerializer,
                new StandardContentEntityFormatter(new ZippedSignedContentFormatter(nlSigner.Object), new Sha256HexPublishingIdService(), jsonSerializer),
                () => new StandardContentEntityFormatter(new ZippedSignedContentFormatter(nlSigner.Object), new Sha256HexPublishingIdService(), jsonSerializer)
                );

            var thumbmprintConfig = new Mock <IThumbprintConfig>(MockBehavior.Strict);

            _Resign = new NlContentResignExistingV1ContentCommand(
                new NlContentResignCommand(_ContentDbProvider.CreateNew, nlSigner.Object, new ResignerLoggingExtensions(_Lf.CreateLogger <ResignerLoggingExtensions>())));
        }