public async Task <bool> PostSelfExposureKeys(SelfDiagnosisSubmissionDTO selfDiagnosisSubmissionDTO, IEnumerable <ExposureKeyModel> temporaryExposureKeys, BaseWebService service) { ApiResponse response; bool requestedAnonToken; if (AuthenticationState.PersonalData?.AnonymousTokensEnabled == true) { requestedAnonToken = true; response = await PostSelfExposureKeysWithAnonTokens(selfDiagnosisSubmissionDTO, temporaryExposureKeys, service); } else { requestedAnonToken = false; response = await service.Post(selfDiagnosisSubmissionDTO, Conf.URL_PUT_UPLOAD_DIAGNOSIS_KEYS); } // HandleErrorsSilently happens even if IsSuccessfull is true other places in the code, but here // we have an if-else to avoid having to create the redacted key list if we don't have to if (!response.IsSuccessfull) { string redactedKeysJson = RedactedTekListHelper.CreateRedactedTekList(temporaryExposureKeys); HandleErrorsSilently(response, new PostExposureKeysErrorHandler(redactedKeysJson)); } else { HandleErrorsSilently(response); } ENDeveloperToolsViewModel.UpdatePushKeysInfo(response, selfDiagnosisSubmissionDTO, JsonSerializerSettings, requestedAnonToken); return(response.IsSuccessfull); }
public async void LogApiError_CreateModelsStoreInDatabasePullFromDatabaseConvertToDtos_DtosShouldContainCorrectValues() { // Clear the mock database ILoggingManager logManager = ServiceLocator.Current.GetInstance <ILoggingManager>(); await logManager.DeleteAll(); // Log apiResponse1 string urlPrefix = Conf.URL_PREFIX; ApiResponse apiResponse1 = new ApiResponse(urlPrefix + "HELLO!", HttpMethod.Get); apiResponse1.StatusCode = 200; IEnumerable <ExposureKeyModel> temporaryExposureKeys = new List <ExposureKeyModel>() { new ExposureKeyModel(new byte[5], DateTimeOffset.FromUnixTimeSeconds(1234), TimeSpan.FromHours(24), RiskLevel.Medium), new ExposureKeyModel(new byte[5], DateTimeOffset.FromUnixTimeSeconds(1234), TimeSpan.FromHours(24), RiskLevel.Medium), new ExposureKeyModel(new byte[5], DateTimeOffset.FromUnixTimeSeconds(1234), TimeSpan.FromHours(24), RiskLevel.Medium), }; string redactedKeysJson = RedactedTekListHelper.CreateRedactedTekList(temporaryExposureKeys); LogUtils.LogApiError(Enums.LogSeverity.INFO, apiResponse1, false, redactedKeysJson); //Added Mockversion to test if version is set correctly in the Logdevicedetails redactedKeysJson += " (GPS: Mock version)"; // Log apiResponse2 ApiResponse apiResponse2 = new ApiResponse(urlPrefix + "GOODBYE!", HttpMethod.Get); apiResponse2.StatusCode = 201; LogUtils.LogApiError(Enums.LogSeverity.WARNING, apiResponse2, true); // Pull the two log models from the mock database List <LogSQLiteModel> logSqliteModels = await logManager.GetLogs(10); Assert.Equal(2, logSqliteModels.Count); // Convert the models to DTOs IEnumerable <LogDTO> logDtos = logSqliteModels.Select(x => new LogDTO(x)); // Check that the DTOs contain the expected values foreach (LogDTO logDto in logDtos) { // apiReponse1 string apiVersion = $"/v{Conf.APIVersion}/"; if (logDto.Severity == Enums.LogSeverity.INFO.ToString()) { Assert.Equal(apiVersion + "HELLO!", logDto.Api); Assert.Equal(200, logDto.ApiErrorCode); // We expect AdditionalInfo to consist of redactedKeysJson, after it's been processed with RedactText Assert.Equal(RedactText(redactedKeysJson), logDto.AdditionalInfo); // This part is just to double check redaction of key data works // Before redaction, the key data is a byte array of size 5, which is shown as "AAAAAAA=" // After redaction we do not want this to be in the string string nonRedactedKeysJson = JsonConvert.SerializeObject(temporaryExposureKeys, BaseWebService.JsonSerializerSettings); Assert.Contains("AAAAAAA=", nonRedactedKeysJson); Assert.DoesNotContain("AAAAAAA=", redactedKeysJson); } // apiResponse2 else if (logDto.Severity == Enums.LogSeverity.WARNING.ToString()) { Assert.Equal(apiVersion + "GOODBYE!", logDto.Api); Assert.Equal(201, logDto.ApiErrorCode); } // Should never be reached else { throw new Exception("At least one of the ifs is expected to be true"); } } }