Skip to content

Commit

Permalink
Merge branch 'PB-34225_As-a-user-I-want-to-see-the-error-message-scre…
Browse files Browse the repository at this point in the history
…en-without-it-to-crash_Pierre-Colart' into 'release'

Pb 34225 as a user i want to see the error message screen without it to crash pierre colart

See merge request passbolt/desktop/passbolt-windows!155
  • Loading branch information
scadra committed Jul 29, 2024
2 parents b63513c + 9f7fc1c commit 53594b2
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 9 deletions.
14 changes: 14 additions & 0 deletions passbolt/Controllers/MainController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ public async Task BackgroundNavigationStarting(WebView2 sender, CoreWebView2Navi

if (currentAccountMetaData != null)
{
//When the application start the main controller save the metadata and init the httpservice trusted domain
this.httpService.setTrustedDomain(currentAccountMetaData.domain);
//If the credential locker is not empty we launch the authentication applications.
await LocalFolderService.Instance.CreateRenderedIndex("index-auth.html", "rendered-auth", "ext_authentication.min.css", currentAccountMetaData.domain);
await LocalFolderService.Instance.CreateBackgroundIndex("index-auth.html", "background-auth", currentAccountMetaData.domain);
Expand All @@ -101,6 +103,18 @@ public async Task BackgroundNavigationStarting(WebView2 sender, CoreWebView2Navi
await this.LoadWebviews();
this.SetWebviewSettings(webviewBackground);
}
//When credentials are saved from import and we navigate to auth application we init the trusted domain to check API calls
if(currentAccountMetaData == null && this.backgroundNavigationService.IsAuthApplication(args.Uri))
{
currentAccountMetaData = await this.credentialLockerService.GetAccountMetadata();
this.httpService.setTrustedDomain(currentAccountMetaData.domain);
}
//In case of we are facing to an authentication error during import we delete trusted domain from the HTTPServices
if (currentAccountMetaData != null && this.backgroundNavigationService.IsImportApplication(args.Uri))
{
currentAccountMetaData = null;
this.httpService.unSetTrustedDomain();
}
}

/// <summary>
Expand Down
28 changes: 21 additions & 7 deletions passbolt/Services/HttpService/HttpService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,32 @@ public HttpService()
/// <param name="sender"></param>
/// <param name="webviewRequest"></param>
/// <exception cref="UnauthorizedAPICallException"></exception>
public async void CheckAPICall(CoreWebView2 sender, CoreWebView2WebResourceRequestedEventArgs webviewRequest)
public void CheckAPICall(CoreWebView2 sender, CoreWebView2WebResourceRequestedEventArgs webviewRequest)
{
if(this.trustedDomain == null)
{
var metaData = await this.credentialLockerService.GetAccountMetadata();
this.trustedDomain = metaData != null ? metaData.domain : null;
}

if (!this.isCallToServer(webviewRequest) && !this.isCallToPownedService(webviewRequest))
{
throw new UnauthorizedAPICallException();
}
}

/// <summary>
/// Init the trusted domain if this one is not set yet
/// </summary>
/// <param name="trustedDomainFromMetadata"></param>
public void setTrustedDomain(String trustedDomainFromMetadata)
{
// Only init trustedDomain if not set yet
if(this.trustedDomain == null)
{
this.trustedDomain = trustedDomainFromMetadata;
}
}
/// <summary>
/// Unset the trusted domain
/// </summary>
public void unSetTrustedDomain()
{
this.trustedDomain = null;
}

/// <summary>
Expand Down
13 changes: 11 additions & 2 deletions passbolt/Services/NavigationService/BackgroundNavigationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,17 @@ public void SetPreviousNavigation(string url)
public bool IsAuthApplication(string url)
{
return url == $"https://{this.trustedUrl}/Background/index-auth.html";
}

}

/// <summary>
/// Check if background webview is running the import file
/// </summary>
/// <returns></returns>
public bool IsImportApplication(string url)
{
return url == $"https://{this.trustedUrl}/Background/index-import.html";
}

/// <summary>
/// Check navigation history to verify if workspace loading comes from importation
/// </summary>
Expand Down

0 comments on commit 53594b2

Please sign in to comment.