private (TemporaryExposureKeyGatewayDto, Country) CreateMockedUeGatewayExposureKey()
        {
            var countries = new List <string>()
            {
                "NL", "DK", "GR",
            };

            var originCountry = new Country()
            {
                Id   = 1,
                Code = "PL",
                PullingFromGatewayEnabled = true,
            };

            var mockedKey = new TemporaryExposureKeyGatewayDto()
            {
                KeyData       = Encoding.UTF8.GetBytes("keyToday"),
                RollingPeriod = 144,
                RollingStartIntervalNumber = (uint)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalMinutes / 10,
                TransmissionRiskLevel      = (int)RiskLevel.RISK_LEVEL_LOW,
                Origin           = originCountry.Code,
                VisitedCountries = countries.OrderBy(c => c).ToList(),
                ReportType       = "RECURSIVE"
            };

            return(mockedKey, originCountry);
        }
예제 #2
0
        private byte[] GenerateSignaturePayloadFromKey(TemporaryExposureKeyGatewayDto key)
        {
            MemoryStream memStream = new MemoryStream();

            WriteBytesInByteArray(key.KeyData, memStream);
            WriteSeparatorInArray(memStream);
            WriteBigEndianUInt(key.RollingStartIntervalNumber, memStream);
            WriteSeparatorInArray(memStream);
            WriteBigEndianUInt(key.RollingPeriod, memStream);
            WriteSeparatorInArray(memStream);
            WriteBigEndianInt(key.TransmissionRiskLevel, memStream);
            WriteSeparatorInArray(memStream);
            WriteVisitedCountries(key.VisitedCountries, memStream);
            WriteSeparatorInArray(memStream);
            WriteBase64StringInByteArray(key.Origin, memStream);
            WriteSeparatorInArray(memStream);
            WriteBigEndianInt((int)key.ReportType, memStream);
            WriteSeparatorInArray(memStream);
            WriteBigEndianInt(key.DaysSinceOnsetOfSymptoms, memStream);
            WriteSeparatorInArray(memStream);

            var result = memStream.ToArray();

            return(result);
        }
예제 #3
0
        public IEnumerable <TemporaryExposureKeyCountry> Resolve(
            TemporaryExposureKeyGatewayDto source,
            TemporaryExposureKey destination,
            IEnumerable <TemporaryExposureKeyCountry> destMember,
            ResolutionContext context)
        {
            if (source.VisitedCountries == null)
            {
                return(new List <TemporaryExposureKeyCountry>());
            }

            var visitedDbCountries = _countryRepository.FindByIsoCodes(source.VisitedCountries).ToList();

            // log countries that haven't been found
            if (source.VisitedCountries != null && visitedDbCountries.Count() != source.VisitedCountries.Count)
            {
                var notMappedCountries = source.VisitedCountries
                                         .Where(countryCodeFromSource => !visitedDbCountries.Where(country => country.Code.ToLower() == countryCodeFromSource.ToLower()).Any())
                                         .ToList();
                var notMappedCountriesStr = string.Join(", ", notMappedCountries);
                _logger.LogError($"Country codes have not been found in the DataBase: {notMappedCountriesStr}");
            }

            var interectionEnties = visitedDbCountries.Select(
                country => new TemporaryExposureKeyCountry()
            {
                Country                = country,
                CountryId              = country.Id,
                TemporaryExposureKey   = destination,
                TemporaryExposureKeyId = destination.Id
            })
                                    .ToList();

            return(interectionEnties);
        }
예제 #4
0
        public TemporaryExposureKeyGatewayDto MockTemporaryExposureKeyDTO()
        {
            var keyDTO = new TemporaryExposureKeyGatewayDto
            {
                KeyData       = _rndGenerator.GenerateKeyData(16),
                RollingPeriod = 10,
                RollingStartIntervalNumber = Convert.ToUInt32(_epochConverter.ConvertToEpoch(DateTime.Today)),
                Origin           = GenerateOrigin(),
                ReportType       = _rndGenerator.GetReportType(),
                VisitedCountries = new List <string> {
                    "DK", "DE", "NL"
                }
            };

            return(keyDTO);
        }
예제 #5
0
        private EuGatewayService CreateGatewayServiceAndDependencies(IGatewayHttpClient httpClient)
        {
            var translationsRepositoryMock = new Mock <IGenericRepository <Translation> >(MockBehavior.Strict);
            var gatewayDto = new TemporaryExposureKeyGatewayDto();

            IOriginSpecificSettings originConfig = new AppSettingsConfig()
            {
                OriginCountryCode = _originCountry.Code.ToUpper()
            };
            var countryRepository = new CountryRepository(_dbContext, translationsRepositoryMock.Object, originConfig);
            var keysRepository    = new TemporaryExposureKeyRepository(_dbContext, countryRepository, _logger.Object);

            var signatureServiceMock = new Mock <ISignatureService>(MockBehavior.Strict);

            signatureServiceMock.Setup(sigService => sigService.Sign(It.IsAny <TemporaryExposureKeyGatewayBatchProtoDto>(), Domain.SortOrder.ASC))
            .Returns(new byte[] { 1, 2, 3, 4, 5, 6, 7 });

            var webContextReaderMock = new Mock <IGatewayWebContextReader>(MockBehavior.Strict);

            webContextReaderMock.Setup(mock => mock.ReadHttpContextStream(It.IsAny <HttpResponseMessage>())).Returns(expectedJson);
            webContextReaderMock.Setup(mock => mock.GetItemsFromRequest(It.IsAny <string>())).Returns(new List <TemporaryExposureKeyGatewayDto> {
                gatewayDto
            });

            var loggerMock    = new Mock <ILogger <EuGatewayService> >(MockBehavior.Loose);
            var keyFilterMock = new Mock <IKeyFilter>(MockBehavior.Strict);
            var storeService  = new Mock <IEFGSKeyStoreService>(MockBehavior.Strict);

            storeService.Setup(mock => mock.FilterAndSaveKeys(It.IsAny <IList <TemporaryExposureKeyGatewayDto> >())).Returns(new List <TemporaryExposureKey> {
                new TemporaryExposureKey()
            });

            var autoMapper = CreateAutoMapperWithDependencies(countryRepository);

            return(CreateGatewayService(keysRepository,
                                        signatureServiceMock.Object,
                                        autoMapper,
                                        httpClient,
                                        keyFilterMock.Object,
                                        webContextReaderMock.Object,
                                        storeService.Object,
                                        loggerMock.Object,
                                        _config
                                        ));
        }