public void PropertiesTest()
        {
            // preparation
            var model = new V2DiagnosisSubmissionParameter();

            // model property access
            Helper.ModelTestHelper.PropetiesTest(model);
        }
        public void CreateMethod()
        {
            // action
            var model = new V2DiagnosisSubmissionParameter();

            // assert
            Assert.IsNotNull(model);
        }
        public void DeviceVerificationTest()
        {
            var platform = "Android";
            var dummyDiagnosisKeyDataList = new [] {
                CreateDiagnosisKey("KeyData1", 10000, 140),
                CreateDiagnosisKey("KeyData2", 20000, 141),
                CreateDiagnosisKey("KeyData3", 30000, 142),
                CreateDiagnosisKey("KeyData4", 40000, 143),
                CreateDiagnosisKey("KeyData5", 50000, 70),
            };
            var dummyRegions = new string[]
            {
                "440",
                "441",
            };
            var dummyDeviceVerificationPayload = "DeviceVerificationPayload THIS STRING IS MEANINGLESS";
            var dummyAppPackageName            = "jp.go.mhlw.cocoa.unit_test";
            var dummyVerificationPayload       = "VerificationPayload THIS STRING IS MEANINGLESS";

            // This value will not affect any result.
            var dummyPadding = new Random().Next().ToString();

            // preparation
            var model = new V2DiagnosisSubmissionParameter()
            {
                Platform = platform,
                Regions  = dummyRegions,
                Keys     = dummyDiagnosisKeyDataList,
                DeviceVerificationPayload = dummyDeviceVerificationPayload,
                AppPackageName            = dummyAppPackageName,
                VerificationPayload       = dummyVerificationPayload,
                Padding = dummyPadding,
            };

            Assert.AreEqual(dummyDeviceVerificationPayload, model.JwsPayload);
            Assert.AreEqual(
                EXPECTED_CLEAR_TEXT_V2,
                model.ClearText);

            Assert.AreEqual(dummyDeviceVerificationPayload, model.DeviceToken);
            Assert.AreEqual(
                EXPECTED_TRANSACTION_ID_SEED_V2,
                model.TransactionIdSeed);
        }
 public void CreateMethod()
 {
     // action
     var model = new V2DiagnosisSubmissionParameter();
 }
示例#5
0
        public async Task RunAsyncMethod(bool isValid,
                                         bool isValidDevice,
                                         string region,
                                         string verificationPayload,
                                         string platform,
                                         bool isChaffRequest,
                                         HttpStatusCode expectedStatusCode
                                         )
        {
            // preparation
            var config = new Mock <IConfiguration>();

            config.Setup(_ => _["SupportRegions"]).Returns("Region1,Region2");

            var tekRepo          = new Mock <ITemporaryExposureKeyRepository>();
            var validationServer = new Mock <IValidationServerService>();

            validationServer.Setup(_ => _.Validate(It.IsAny <HttpRequest>())).Returns(IValidationServerService.ValidateResult.Success);


            var deviceCheck = new Mock <IDeviceValidationService>();

            deviceCheck.Setup(_ => _.Validation(It.IsAny <string>(), It.IsAny <V2DiagnosisSubmissionParameter>(), It.IsAny <DateTimeOffset>())).ReturnsAsync(isValidDevice);
            var verification = new Mock <IVerificationService>();
            var logger       = new Mock.LoggerMock <Covid19Radar.Api.V2DiagnosisApi>();
            var diagnosisApi = new V2DiagnosisApi(config.Object,
                                                  tekRepo.Object,
                                                  deviceCheck.Object,
                                                  verification.Object,
                                                  validationServer.Object,
                                                  logger);
            var context = new Mock <HttpContext>();
            var keydata = new byte[16];

            RandomNumberGenerator.Create().GetBytes(keydata);
            var keyDataString = Convert.ToBase64String(keydata);
            var startNumber   = (uint)DateTimeOffset.UtcNow.ToUnixTimeSeconds() / 600;
            var bodyJson      = new V2DiagnosisSubmissionParameter()
            {
                VerificationPayload       = verificationPayload,
                Regions                   = new[] { region },
                Platform                  = platform,
                DeviceVerificationPayload = "DeviceVerificationPayload",
                AppPackageName            = "Covid19Radar",
                Keys = new V2DiagnosisSubmissionParameter.Key[] {
                    new V2DiagnosisSubmissionParameter.Key()
                    {
                        KeyData = keyDataString, RollingPeriod = 0, RollingStartNumber = startNumber
                    },
                    new V2DiagnosisSubmissionParameter.Key()
                    {
                        KeyData = keyDataString, RollingPeriod = 0, RollingStartNumber = startNumber
                    }
                }
            };
            var bodyString = Newtonsoft.Json.JsonConvert.SerializeObject(bodyJson);

            using var stream = new System.IO.MemoryStream();
            using (var writer = new System.IO.StreamWriter(stream, leaveOpen: true))
            {
                await writer.WriteAsync(bodyString);

                await writer.FlushAsync();
            }
            stream.Seek(0, System.IO.SeekOrigin.Begin);

            context.Setup(_ => _.Request.Body).Returns(stream);

            if (isChaffRequest)
            {
                IHeaderDictionary headers = new HeaderDictionary()
                {
                    { "X-Chaff", "Foo" /* Server will check X-Chaff header existence, content no matter. */ }
                };
                context.Setup(_ => _.Request.Headers).Returns(headers);
            }

            // action
            var result = await diagnosisApi.RunAsync(context.Object.Request);

            // assert
            if (result is StatusCodeResult statusCodeResult)
            {
                Assert.AreEqual(((int)expectedStatusCode), statusCodeResult.StatusCode);
            }
            else if (result is BadRequestErrorMessageResult)
            {
                Assert.AreEqual(expectedStatusCode, HttpStatusCode.BadRequest);
            }
        }