public void WhatDoesDicOfDicLookLike()
        {
            IJsonSerializer jsonSerializer = new StandardJsonSerializer();

            var argle = new ResourceBundleArgs
            {
                Text = new Dictionary <string, Dictionary <string, string> >
                {
                    {
                        "en-GB", new Dictionary <string, string>()
                        {
                            { "InfectedMessage", "You're possibly infected" }
                        }
                    },
                    {
                        "nl-NL", new Dictionary <string, string>
                        {
                            { "InfectedMessage", "U bent mogelijk geïnfecteerd" }
                        }
                    }
                }
            };

            var stuff = jsonSerializer.Serialize(argle);
        }
        public async Task Run([ServiceBusTrigger("vwspt-queue", Connection = "Queue", IsSessionsEnabled = true)]
                              Message message,
                              ExecutionContext executionContext
                              )
        {
            SetConfig(executionContext);
            var json = Encoding.UTF8.GetString(message.Body);
            var args = new StandardJsonSerializer().Deserialize <StorageAccountSyncMessage>(json);

            if (args.MutableContent)
            {
                await new MutableBlobCopyCommand(new StorageAccountAppSettings(Configuration, "Source"), new StorageAccountAppSettings(Configuration, "Destination"))
                .Execute(args.RelativePath);
            }
            else
            {
                await new ImmutableBlobCopyCommand(new StorageAccountAppSettings(Configuration, "Source"), new StorageAccountAppSettings(Configuration, "Destination"))
                .Execute(args.RelativePath);
            }
        }
        private ManifestUpdateCommand CreateManifestJob()
        {
            var eksConfig = new Mock <IEksConfig>(MockBehavior.Strict);

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

            var _Dtp = new StandardUtcDateTimeProvider();

            var jsonSerializer = new StandardJsonSerializer();

            return(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)
                       ));
        }
Ejemplo n.º 4
0
        public ManifestUpdateCommandTest(IDbProvider <ContentDbContext> contentDbProvider)
        {
            _contentDbProvider = contentDbProvider ?? throw new ArgumentException();

            var nlSignerMock = new Mock <IContentSigner>();

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

            var eksConfigMock = new Mock <IEksConfig>(MockBehavior.Strict);

            eksConfigMock.Setup(x => x.LifetimeDays)
            .Returns(14);

            _dateTimeProviderMock = new Mock <IUtcDateTimeProvider>();
            _dateTimeProviderMock.Setup(x => x.Snapshot)
            .Returns(_mockedTime);

            var loggerFactory         = new LoggerFactory();
            var jsonSerializer        = new StandardJsonSerializer();
            var loggingExtensionsMock = new ManifestUpdateCommandLoggingExtensions(
                loggerFactory.CreateLogger <ManifestUpdateCommandLoggingExtensions>());

            Func <IContentEntityFormatter> contentFormatterInjector = () =>
                                                                      new StandardContentEntityFormatter(
                new ZippedSignedContentFormatter(nlSignerMock.Object),
                new Sha256HexPublishingIdService(),
                jsonSerializer);

            _sut = new ManifestUpdateCommand(
                new ManifestV2Builder(_contentDbProvider.CreateNew(), eksConfigMock.Object, _dateTimeProviderMock.Object),
                new ManifestV3Builder(_contentDbProvider.CreateNew(), eksConfigMock.Object, _dateTimeProviderMock.Object),
                new ManifestV4Builder(_contentDbProvider.CreateNew(), eksConfigMock.Object, _dateTimeProviderMock.Object),
                _contentDbProvider.CreateNew,
                loggingExtensionsMock,
                _dateTimeProviderMock.Object,
                jsonSerializer,
                contentFormatterInjector
                );
        }
        private ManifestUpdateCommand CompileManifestUpdateCommand()
        {
            var eksConfigMock       = new Mock <IEksConfig>();
            var lf                  = new LoggerFactory();
            var dateTimeProvider    = new StandardUtcDateTimeProvider();
            var jsonSerialiser      = new StandardJsonSerializer();
            var entityFormatterMock = new Mock <IContentEntityFormatter>();

            Func <IContentEntityFormatter> formatterForV3 = () =>
                                                            new StandardContentEntityFormatter(
                new ZippedSignedContentFormatter(
                    TestSignerHelpers.CreateCmsSignerEnhanced(lf)),
                new Sha256HexPublishingIdService(),
                jsonSerialiser
                );

            var result = new ManifestUpdateCommand(
                new ManifestBuilder(
                    _ContentDbProvider.CreateNew(),
                    eksConfigMock.Object,
                    dateTimeProvider),
                new ManifestBuilderV3(
                    _ContentDbProvider.CreateNew(),
                    eksConfigMock.Object,
                    dateTimeProvider),
                new ManifestBuilderV4(
                    _ContentDbProvider.CreateNew(),
                    eksConfigMock.Object,
                    dateTimeProvider),
                _ContentDbProvider.CreateNew,
                new ManifestUpdateCommandLoggingExtensions(lf.CreateLogger <ManifestUpdateCommandLoggingExtensions>()),
                dateTimeProvider,
                jsonSerialiser,
                entityFormatterMock.Object,
                formatterForV3
                );

            return(result);
        }
Ejemplo n.º 6
0
        public async Task PostWorkflowTest(string file, int keyCount, int mm, int dd)
        {
            _fakeTimeProvider.Value = new DateTime(2020, mm, dd, 0, 0, 0, DateTimeKind.Utc);

            // Arrange
            var client = _factory.CreateClient();

            await using var inputStream = Assembly.GetExecutingAssembly().GetEmbeddedResourceStream(file);
            var data = inputStream.ToArray();

            var args = new StandardJsonSerializer().Deserialize <PostTeksArgs>(Encoding.UTF8.GetString(data));

            await WriteBucket(Convert.FromBase64String(args.BucketId));

            var tekDates = args.Keys
                           .OrderBy(x => x.RollingStartNumber)
                           .Select(x => new { x, Date = x.RollingStartNumber.FromRollingStartNumber() });

            foreach (var i in tekDates)
            {
                Trace.WriteLine($"RSN:{i.x.RollingStartNumber} Date:{i.Date:yyyy-MM-dd}.");
            }

            var signature = HttpUtility.UrlEncode(HmacSigner.Sign(new byte[32], data));
            var content   = new ByteArrayContent(data);

            content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");

            // Act
            var result = await client.PostAsync($"v1/postkeys?sig={signature}", content);

            // Assert
            var items = await _workflowDbProvider.CreateNew().TemporaryExposureKeys.ToListAsync();

            Assert.Equal(HttpStatusCode.OK, result.StatusCode);
            Assert.Equal(keyCount, items.Count);
        }
        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>())));
        }