public async Task GenerateWorkflowsAsync(int workflowCount = 25, int tekPerWorkflowCount = 4) { var workflowConfigMock = new Mock <IWorkflowConfig>(MockBehavior.Strict); workflowConfigMock.Setup(x => x.TimeToLiveMinutes).Returns(10000); workflowConfigMock.Setup(x => x.PermittedMobileDeviceClockErrorMinutes).Returns(30); var luhnModNConfig = new LuhnModNConfig(); var luhnModNGenerator = new LuhnModNGenerator(luhnModNConfig); Func <TekReleaseWorkflowStateCreateV2> createWf = () => new TekReleaseWorkflowStateCreateV2( _workflowDbContextProvider.CreateNewWithTx(), _utcDateTimeProvider, _rng, new TekReleaseWorkflowTime(workflowConfigMock.Object), new RegisterSecretLoggingExtensionsV2(_loggerFactory.CreateLogger <RegisterSecretLoggingExtensionsV2>()), luhnModNConfig, luhnModNGenerator ); var gen = new GenerateTeksCommand(_rng, _workflowDbContextProvider.CreateNewWithTx, createWf); await gen.ExecuteAsync(new GenerateTeksCommandArgs { WorkflowCount = workflowCount, TekCountPerWorkflow = tekPerWorkflowCount }); if (workflowCount != _workflowDbContextProvider.CreateNew().KeyReleaseWorkflowStates.Count()) { throw new InvalidOperationException(); } if (workflowCount * tekPerWorkflowCount != _workflowDbContextProvider.CreateNew().TemporaryExposureKeys.Count()) { throw new InvalidOperationException(); } }
public void GoodCustomValues() { var argle = new LuhnModNConfig("BCFGJLQRSTUVXYZ23456789", 7); Assert.Equal(7, argle.ValueLength); Assert.Equal(23, argle.CharacterSet.Length); Assert.True(argle.CharacterSet.Contains('R')); Assert.True(!argle.CharacterSet.Contains('A')); }
public void GenerateTest() { var c = new LuhnModNConfig(); var g = new LuhnModNGenerator(c); var result = g.Next(6); var v = new LuhnModNValidator(c); Assert.True(v.Validate(result)); }
public void GoodCustomValues() { var argle = new LuhnModNConfig("abcdef", 3); Assert.AreEqual(3, argle.ValueLength); Assert.AreEqual(6, argle.CharacterSet.Length); Assert.IsTrue(argle.CharacterSet.Contains('c')); Assert.IsTrue(!argle.CharacterSet.Contains('g')); }
public void GenerateTest() { var c = new LuhnModNConfig(); var r = new Random(123); //Sub in a crypto method if desired. var g = new LuhnModNGenerator(c); var result = g.Next(x => r.Next(x)); var v = new LuhnModNValidator(c); Assert.IsTrue(v.Validate(result)); }
public void Execute(int WorkflowCount, Func <int, int> randomInt, Action <byte[]> randomBytes) { var luhnModNConfig = new LuhnModNConfig(); var WorkflowKeyGenerator = new GenerateWorkflowKeys(luhnModNConfig); var WorkflowValidatorConfig = new HardCodedAgWorkflowValidatorConfig(); var WorkflowKeyValidatorConfig = new HardCodedAgTemporaryExposureKeyValidatorConfig(); var writer = new WorkflowInsertDbCommand(_DbContextProvider, new StandardUtcDateTimeProvider()); var c = new HttpPostWorkflowCommand( writer, new WorkflowValidator( WorkflowValidatorConfig, new WorkflowAuthorisationTokenLuhnModNValidator(luhnModNConfig), new TemporaryExposureKeyValidator(WorkflowKeyValidatorConfig)), _DbContextProvider); var keyBuffer = new byte[WorkflowKeyValidatorConfig.DailyKeyByteCount]; for (var i = 0; i < WorkflowCount; i++) { var Workflow = new WorkflowArgs { Token = WorkflowKeyGenerator.Next(randomInt) }; var keyCount = 1 + randomInt(WorkflowValidatorConfig.WorkflowKeyCountMax - 1); var keys = new List <WorkflowKeyArgs>(keyCount); for (var j = 0; j < keyCount; j++) { randomBytes(keyBuffer); keys.Add(new WorkflowKeyArgs { KeyData = Convert.ToBase64String(keyBuffer), RollingStartNumber = WorkflowKeyValidatorConfig.RollingPeriodMin + j, RollingPeriod = 11, TransmissionRiskLevel = 2 }); } Workflow.Items = keys.ToArray(); c.Execute(Workflow); if (i > 0 && i % 100 == 0) { Console.WriteLine($"Workflow count {i}..."); } } Console.WriteLine("Generating Workflows finished."); }
public async Task Execute(int itemCount, Func <int, int> randomInt, Action <byte[]> randomBytes) { var luhnModNConfig = new LuhnModNConfig(); var tokenGenerator = new GenerateKeysFirstAuthorisationToken(luhnModNConfig); var workflowValidationConfig = new DefaultGeanTekListValidationConfig(); var tekValidatorConfig = new DefaultGaenTekValidatorConfig(); var writer = new KeysFirstEscrowInsertDbCommand(_DbContextProvider, new StandardUtcDateTimeProvider()); var c = new HttpPostKeysFirstEscrowCommand( writer, new KeysFirstEscrowValidator( workflowValidationConfig, new KeysFirstAuthorisationTokenLuhnModNValidator(luhnModNConfig), new TemporaryExposureKeyValidator(tekValidatorConfig)), _DbContextProvider); var keyBuffer = new byte[tekValidatorConfig.DailyKeyByteCount]; for (var i = 0; i < itemCount; i++) { var workflow = new KeysFirstEscrowArgs { Token = tokenGenerator.Next(randomInt) }; var keyCount = 1 + randomInt(workflowValidationConfig.TemporaryExposureKeyCountMax - 1); var keys = new List <TemporaryExposureKeyArgs>(keyCount); for (var j = 0; j < keyCount; j++) { randomBytes(keyBuffer); keys.Add(new TemporaryExposureKeyArgs { KeyData = Convert.ToBase64String(keyBuffer), RollingStartNumber = tekValidatorConfig.RollingPeriodMin + j, RollingPeriod = 11, RegionsOfInterest = new [] { "NL" } }); } workflow.Items = keys.ToArray(); await c.Execute(workflow); } }
public async Task EmptySystemSingleTek() { var workflowConfig = new Mock <IWorkflowConfig>(MockBehavior.Strict); workflowConfig.Setup(x => x.TimeToLiveMinutes).Returns(24 * 60 * 60); //Approx workflowConfig.Setup(x => x.PermittedMobileDeviceClockErrorMinutes).Returns(30); var luhnModNConfig = new LuhnModNConfig(); var luhnModNGenerator = new LuhnModNGenerator(luhnModNConfig); Func <TekReleaseWorkflowStateCreateV2> createWf = () => new TekReleaseWorkflowStateCreateV2( _workflowDbProvider.CreateNewWithTx(), _dtp, _rng, new TekReleaseWorkflowTime(workflowConfig.Object), new RegisterSecretLoggingExtensionsV2(_lf.CreateLogger <RegisterSecretLoggingExtensionsV2>()), luhnModNConfig, luhnModNGenerator ); await new GenerateTeksCommand(_rng, _workflowDbProvider.CreateNewWithTx, createWf).ExecuteAsync(new GenerateTeksCommandArgs { TekCountPerWorkflow = 1, WorkflowCount = 1 }); Assert.Equal(1, _workflowDbProvider.CreateNew().TemporaryExposureKeys.Count()); Assert.Equal(0, _dkSourceDbProvider.CreateNew().DiagnosisKeys.Count()); await _snapshot.ExecuteAsync(); //Too soon to publish TEKs await _eksJob.ExecuteAsync(); await _manifestJob.ExecuteAllAsync(); await _resign.ExecuteAsync(); Assert.Equal(1, _contentDbProvider.CreateNew().Content.Count(x => x.Type == ContentTypes.ManifestV2)); Assert.Equal(0, _contentDbProvider.CreateNew().Content.Count(x => x.Type == ContentTypes.ExposureKeySetV2)); //Obsolete - replace with raw content Assert.Equal(0, _contentDbProvider.CreateNew().Content.Count(x => x.Type == ContentTypes.ExposureKeySet)); Assert.Equal(0, _contentDbProvider.CreateNew().Content.Count(x => x.Type == ContentTypes.Manifest)); }