public void ErrorTest() { Guid lowellSurrogateKey = Guid.NewGuid(); this._sessionState.Setup(ss => ss.GetTopLowellSurrogateKey()).Returns(lowellSurrogateKey); ViewResult result = (ViewResult)this._controller.Error(""); Assert.AreEqual(null, result.ViewName); OpenWrksErrorVm errorVm = (OpenWrksErrorVm)result.Model; Assert.AreEqual("", errorVm.OccurrenceId); Assert.AreEqual(lowellSurrogateKey, errorVm.LowellFinancialAccountSurrogateKey); }
public IActionResult Error(string occurrenceId) { if (!_portalSetting.Features.EnableOpenWrks) { return(NotFound()); } occurrenceId ??= Request.Headers.ContainsKey(TraceMiddleware.TraceHeaderName) ? Request.Headers[TraceMiddleware.TraceHeaderName].ToString() : ""; var errorModel = new OpenWrksErrorVm { LowellFinancialAccountSurrogateKey = ApplicationSessionState.GetTopLowellSurrogateKey(), OccurrenceId = occurrenceId }; return(View(errorModel)); }
public async Task BudgetCompleteTest_ErrorCode() { string lowellReference = "123456789"; Guid lowellSurrogateKey = Guid.NewGuid(); string customerReference = _caseflowUserId; this._sessionState.Setup(x => x.GetTopLowellSurrogateKey()).Returns(lowellSurrogateKey); this._sessionState.Setup(x => x.GetTopLowellReference()).Returns(lowellReference); this._webActivityService.Setup(x => x.LogOpenBankingError(lowellReference, _caseflowUserId)) .Returns(Task.CompletedTask); ViewResult result = (ViewResult)await this._controller.BudgetComplete(customerReference, "ERR"); Assert.AreEqual("Error", result.ViewName); OpenWrksErrorVm errorVm = (OpenWrksErrorVm)result.Model; Assert.AreEqual("", errorVm.OccurrenceId); Assert.AreEqual(lowellSurrogateKey, errorVm.LowellFinancialAccountSurrogateKey); }
public async Task <IActionResult> BudgetComplete( [FromQuery(Name = "customerReference")] string base64EncodedEncryptedCustomerReference, [FromQuery(Name = "errorCode")] string errorCode) { if (!_portalSetting.Features.EnableOpenWrks) { return(NotFound()); } var lowellSurrogateKey = ApplicationSessionState.GetTopLowellSurrogateKey(); var lowellReference = ApplicationSessionState.GetTopLowellReference(); if (lowellSurrogateKey == null || lowellSurrogateKey == Guid.Empty) { // At this point it looks like the Users's session has expired and was forced to re-login. // As a result all the surrogatekeys will be empty the following lines will save surrogate key to session again // then we will simply get the top key. var accountSummaries = await _accountService.GetAccounts(GetCaseflowUserId()); var lowellReferences = accountSummaries.Select(x => x.AccountReference).ToList(); var surrogateKeysByLowellReference = ApplicationSessionState.AddLowellReferenceSurrogateKeys(lowellReferences); lowellSurrogateKey = ApplicationSessionState.GetTopLowellSurrogateKey(); lowellReference = ApplicationSessionState.GetTopLowellReference(); } var occurrenceId = Request.Headers.ContainsKey(TraceMiddleware.TraceHeaderName) ? Request.Headers[TraceMiddleware.TraceHeaderName].ToString() : ""; var errorModel = new OpenWrksErrorVm { LowellFinancialAccountSurrogateKey = lowellSurrogateKey, OccurrenceId = occurrenceId }; var caseflowUserId = GetCaseflowUserId(); var decryptedCustomerReference = ""; try { var base64DecodedEncryptedCustomerRefAsString = GetBase64DecodeString(base64EncodedEncryptedCustomerReference); decryptedCustomerReference = _cryptoAlgorithm.DecryptUsingAes(base64DecodedEncryptedCustomerRefAsString); } catch (Exception e) { Logger.LogError(e, $"Unable to decode and decrypt the customerReference provided by OpenWrks. customerReference - {base64EncodedEncryptedCustomerReference}."); await _webActivityService.LogOpenBankingError(lowellReference, GetCaseflowUserId()); return(View("Error", errorModel)); } if (string.IsNullOrEmpty(errorCode) && string.Equals(decryptedCustomerReference, caseflowUserId, StringComparison.OrdinalIgnoreCase)) { if (!string.IsNullOrWhiteSpace(lowellReference)) { var model = new OpenWrksSuccessVm { LowellFinancialAccountSurrogateKey = lowellSurrogateKey, OccurrenceId = occurrenceId }; if (_openWrksSetting.UseLandingPage) { return(View("Success", model)); } Logger.LogInformation("Fetching translated budget from API GW"); var customerReference = GenerateOpenWrksCustomerReference(); var budget = await _openWrkService.GetOpenWorksBudgetTranslatedToCaseflowBudgetModel( base64EncodedEncryptedCustomerReference); Logger.LogInformation("Saving budget to Distributed Cache."); ApplicationSessionState.SaveIncomeAndExpenditure( budget, model.LowellFinancialAccountSurrogateKey.Value); try { Logger.LogInformation("Saving budget to Caseflow."); await _budgetCalculatorService.SaveIncomeAndExpenditure(budget, lowellReference); await _webActivityService.LogOpenBankingComplete(lowellReference, GetCaseflowUserId()); return(RedirectToAction( "BudgetSummary", "BudgetCalculator", new { id = model.LowellFinancialAccountSurrogateKey })); } catch (Exception ex) { Logger.LogError(ex, $"Saving OpenBanking budget to Caseflow has returned error with code - {errorCode}."); await _webActivityService.LogOpenBankingError(lowellReference, GetCaseflowUserId()); return(View("Error", errorModel)); } } Logger.LogWarning("Account reference number is not found."); } else if (!string.IsNullOrEmpty(errorCode)) { Logger.LogError($"OpenBanking has returned error with code - {errorCode}."); } else { Logger.LogError( $"OpenBanking has returned invalid customer reference in BudgetComplete notification. Customer Reference {base64EncodedEncryptedCustomerReference} is not matched with {GetCaseflowUserId()}"); } await _webActivityService.LogOpenBankingError(lowellReference, GetCaseflowUserId()); return(View("Error", errorModel)); }