Add error code for ipfs navigations when ipfs is disabled
Resolves https://github.com/brave/brave-browser/issues/24166
This commit is contained in:
@@ -32,20 +32,25 @@ int OnBeforeURLRequest_IPFSRedirectWork(
|
||||
auto* prefs = user_prefs::UserPrefs::Get(ctx->browser_context);
|
||||
const bool ipfs_disabled = IsIpfsResolveMethodDisabled(prefs);
|
||||
|
||||
if (has_ipfs_scheme && ipfs_disabled) {
|
||||
ctx->blocked_by = brave::kOtherBlocked;
|
||||
return net::OK;
|
||||
}
|
||||
|
||||
if (has_ipfs_scheme && !brave::IsRegularProfile(ctx->browser_context)) {
|
||||
// Don't allow IPFS requests without translation of IPFS urls.
|
||||
ctx->blocked_by = brave::kOtherBlocked;
|
||||
// Only net::OK navigation will be actually blocked without commit.
|
||||
// Show proper error for mainframe navigation.
|
||||
return ctx->resource_type == blink::mojom::ResourceType::kMainFrame
|
||||
? net::ERR_INCOGNITO_IPFS_NOT_ALLOWED
|
||||
: net::OK;
|
||||
}
|
||||
|
||||
if (has_ipfs_scheme && ipfs_disabled) {
|
||||
ctx->blocked_by = brave::kOtherBlocked;
|
||||
// Only net::OK navigation will be actually blocked without commit.
|
||||
// Show proper error for mainframe navigation.
|
||||
return ctx->resource_type == blink::mojom::ResourceType::kMainFrame
|
||||
? net::ERR_IPFS_DISABLED
|
||||
: net::OK;
|
||||
}
|
||||
|
||||
GURL new_url;
|
||||
if (ipfs::TranslateIPFSURI(ctx->request_url, &new_url, ctx->ipfs_gateway_url,
|
||||
false)) {
|
||||
|
||||
@@ -72,7 +72,7 @@ IN_PROC_BROWSER_TEST_F(IpfsRedirectNetworkDelegateHelperBrowserTest,
|
||||
}
|
||||
|
||||
IN_PROC_BROWSER_TEST_F(IpfsRedirectNetworkDelegateHelperBrowserTest,
|
||||
IPFSResolveRedirectsToErrorPage) {
|
||||
IPFSResolveRedirectsToErrorPage_Incognito) {
|
||||
GetPrefs()->SetInteger(
|
||||
kIPFSResolveMethod,
|
||||
static_cast<int>(IPFSResolveMethodTypes::IPFS_GATEWAY));
|
||||
@@ -92,4 +92,24 @@ IN_PROC_BROWSER_TEST_F(IpfsRedirectNetworkDelegateHelperBrowserTest,
|
||||
EXPECT_EQ(net::ERR_INCOGNITO_IPFS_NOT_ALLOWED, observer.net_error_code());
|
||||
}
|
||||
|
||||
IN_PROC_BROWSER_TEST_F(IpfsRedirectNetworkDelegateHelperBrowserTest,
|
||||
IPFSResolveRedirectsToErrorPage_IpfsDisabled) {
|
||||
GetPrefs()->SetInteger(
|
||||
kIPFSResolveMethod,
|
||||
static_cast<int>(IPFSResolveMethodTypes::IPFS_DISABLED));
|
||||
|
||||
EXPECT_TRUE(ui_test_utils::NavigateToURL(browser(), ipfs_url()));
|
||||
EXPECT_EQ(web_contents()->GetURL(), gateway_url());
|
||||
|
||||
auto* wc = browser()->tab_strip_model()->GetActiveWebContents();
|
||||
|
||||
content::NavigationHandleObserver observer(wc, ipfs_url());
|
||||
|
||||
// Try to navigate to the url. The navigation should be canceled and the
|
||||
// NavigationHandle should have the right error code.
|
||||
EXPECT_TRUE(ui_test_utils::NavigateToURL(browser(), ipfs_url()));
|
||||
EXPECT_TRUE(wc->GetMainFrame()->IsErrorDocument());
|
||||
EXPECT_EQ(net::ERR_IPFS_DISABLED, observer.net_error_code());
|
||||
}
|
||||
|
||||
} // namespace ipfs
|
||||
|
||||
@@ -60,6 +60,10 @@ class IPFSRedirectNetworkDelegateHelperTest : public testing::Test {
|
||||
};
|
||||
|
||||
TEST_F(IPFSRedirectNetworkDelegateHelperTest, TranslateIPFSURIHTTPScheme) {
|
||||
profile()->GetPrefs()->SetInteger(
|
||||
kIPFSResolveMethod,
|
||||
static_cast<int>(IPFSResolveMethodTypes::IPFS_GATEWAY));
|
||||
|
||||
GURL url("http://a.com/ipfs/QmfM2r8seH2GiRaC4esTjeraXEachRt8ZsSeGaWTPLyMoG");
|
||||
auto brave_request_info = std::make_shared<brave::BraveRequestInfo>(url);
|
||||
brave_request_info->browser_context = profile();
|
||||
@@ -70,6 +74,9 @@ TEST_F(IPFSRedirectNetworkDelegateHelperTest, TranslateIPFSURIHTTPScheme) {
|
||||
}
|
||||
|
||||
TEST_F(IPFSRedirectNetworkDelegateHelperTest, TranslateIPFSURIIPFSSchemeLocal) {
|
||||
profile()->GetPrefs()->SetInteger(
|
||||
kIPFSResolveMethod, static_cast<int>(IPFSResolveMethodTypes::IPFS_LOCAL));
|
||||
|
||||
GURL url("ipfs://QmfM2r8seH2GiRaC4esTjeraXEachRt8ZsSeGaWTPLyMoG");
|
||||
auto brave_request_info = std::make_shared<brave::BraveRequestInfo>(url);
|
||||
brave_request_info->browser_context = profile();
|
||||
@@ -85,6 +92,22 @@ TEST_F(IPFSRedirectNetworkDelegateHelperTest, TranslateIPFSURIIPFSSchemeLocal) {
|
||||
"QmfM2r8seH2GiRaC4esTjeraXEachRt8ZsSeGaWTPLyMoG");
|
||||
}
|
||||
|
||||
TEST_F(IPFSRedirectNetworkDelegateHelperTest,
|
||||
ProperMainFrameErrorCodeWhenIPFSDisabled) {
|
||||
profile()->GetPrefs()->SetInteger(
|
||||
kIPFSResolveMethod,
|
||||
static_cast<int>(IPFSResolveMethodTypes::IPFS_DISABLED));
|
||||
|
||||
GURL url("ipfs://QmfM2r8seH2GiRaC4esTjeraXEachRt8ZsSeGaWTPLyMoG");
|
||||
auto brave_request_info = std::make_shared<brave::BraveRequestInfo>(url);
|
||||
brave_request_info->resource_type = blink::mojom::ResourceType::kMainFrame;
|
||||
brave_request_info->browser_context = profile();
|
||||
int rc = ipfs::OnBeforeURLRequest_IPFSRedirectWork(brave::ResponseCallback(),
|
||||
brave_request_info);
|
||||
EXPECT_EQ(rc, net::ERR_IPFS_DISABLED);
|
||||
EXPECT_EQ(brave_request_info->blocked_by, brave::kOtherBlocked);
|
||||
}
|
||||
|
||||
TEST_F(IPFSRedirectNetworkDelegateHelperTest,
|
||||
SubFrameRequestDisabledWhenIPFSDisabled) {
|
||||
profile()->GetPrefs()->SetInteger(
|
||||
@@ -204,6 +227,10 @@ TEST_F(IPFSRedirectNetworkDelegateHelperTest,
|
||||
}
|
||||
|
||||
TEST_F(IPFSRedirectNetworkDelegateHelperTest, TranslateIPFSURIIPFSScheme) {
|
||||
profile()->GetPrefs()->SetInteger(
|
||||
kIPFSResolveMethod,
|
||||
static_cast<int>(IPFSResolveMethodTypes::IPFS_GATEWAY));
|
||||
|
||||
GURL url("ipfs://QmfM2r8seH2GiRaC4esTjeraXEachRt8ZsSeGaWTPLyMoG");
|
||||
auto brave_request_info = std::make_shared<brave::BraveRequestInfo>(url);
|
||||
brave_request_info->browser_context = profile();
|
||||
@@ -219,6 +246,9 @@ TEST_F(IPFSRedirectNetworkDelegateHelperTest, TranslateIPFSURIIPFSScheme) {
|
||||
}
|
||||
|
||||
TEST_F(IPFSRedirectNetworkDelegateHelperTest, TranslateIPFSURIIPNSSchemeLocal) {
|
||||
profile()->GetPrefs()->SetInteger(
|
||||
kIPFSResolveMethod, static_cast<int>(IPFSResolveMethodTypes::IPFS_LOCAL));
|
||||
|
||||
GURL url("ipns://QmSrPmbaUKA3ZodhzPWZnpFgcPMFWF4QsxXbkWfEptTBJd");
|
||||
auto brave_request_info = std::make_shared<brave::BraveRequestInfo>(url);
|
||||
brave_request_info->browser_context = profile();
|
||||
@@ -235,6 +265,10 @@ TEST_F(IPFSRedirectNetworkDelegateHelperTest, TranslateIPFSURIIPNSSchemeLocal) {
|
||||
}
|
||||
|
||||
TEST_F(IPFSRedirectNetworkDelegateHelperTest, TranslateIPFSURIIPNSScheme) {
|
||||
profile()->GetPrefs()->SetInteger(
|
||||
kIPFSResolveMethod,
|
||||
static_cast<int>(IPFSResolveMethodTypes::IPFS_GATEWAY));
|
||||
|
||||
GURL url("ipns://QmSrPmbaUKA3ZodhzPWZnpFgcPMFWF4QsxXbkWfEptTBJd");
|
||||
auto brave_request_info = std::make_shared<brave::BraveRequestInfo>(url);
|
||||
brave_request_info->browser_context = profile();
|
||||
|
||||
@@ -17,6 +17,15 @@
|
||||
SHOW_NO_BUTTONS, \
|
||||
}); \
|
||||
return &error; \
|
||||
} else if (error_code == net::ERR_IPFS_DISABLED) { \
|
||||
static LocalizedErrorMap error({ \
|
||||
net::ERR_IPFS_DISABLED, \
|
||||
IDS_ERRORPAGES_IPFS_DISABLED_HEADING, \
|
||||
IDS_ERRORPAGES_IPFS_DISABLED_SUMMARY, \
|
||||
SUGGEST_NONE, \
|
||||
SHOW_BUTTON_RELOAD, \
|
||||
}); \
|
||||
return &error; \
|
||||
}
|
||||
|
||||
namespace error_page {
|
||||
|
||||
@@ -11,3 +11,4 @@
|
||||
// Error occurs when user tries to access ipfs sites in
|
||||
// incognito context
|
||||
NET_ERROR(INCOGNITO_IPFS_NOT_ALLOWED, -10001)
|
||||
NET_ERROR(IPFS_DISABLED, -10002)
|
||||
|
||||
@@ -169,6 +169,12 @@
|
||||
<message name="IDS_ERRORPAGES_IPFS_INCOGNITO_SUMMARY" desc="Summary in the error page when IPFS failed in incognito mode.">
|
||||
IPFS pages are not allowed in private windows.
|
||||
</message>
|
||||
<message name="IDS_ERRORPAGES_IPFS_DISABLED_HEADING" desc="Heading of the IPFS disabled error page.">
|
||||
IPFS page cannot be loaded.
|
||||
</message>
|
||||
<message name="IDS_ERRORPAGES_IPFS_DISABLED_SUMMARY" desc="Summary in the error page when IPFS failed because it is disabled.">
|
||||
IPFS is disabled. Select IPFS resolve method in settings to open this site.
|
||||
</message>
|
||||
<!-- WebUI newtab resources -->
|
||||
<message name="IDS_BRAVE_NEW_TAB_TOTAL_ADS_TRACKERS_BLOCKED" desc="total number of ads and trackers blocked">Trackers & ads blocked</message>
|
||||
<message name="IDS_BRAVE_NEW_TAB_TOTAL_HTTPS_UPGRADES" desc="total number of HTTPS upgrades">HTTPS Upgrades</message>
|
||||
|
||||
Reference in New Issue
Block a user