Skip to content

Commit

Permalink
Validate IPFS Cid using Rust CID lib (#19451)
Browse files Browse the repository at this point in the history
* Validate IPFS Cid using Rust CID lib
Resolves brave/brave-browser#31145
  • Loading branch information
cypt4 committed Aug 10, 2023
1 parent 87099c1 commit 307ac53
Show file tree
Hide file tree
Showing 8 changed files with 397 additions and 183 deletions.
24 changes: 19 additions & 5 deletions browser/ipfs/ipfs_tab_helper_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
using content::NavigationHandle;
using content::WebContents;

namespace {
constexpr char kCid1[] =
"bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi";
} // namespace

class IpfsTabHelperBrowserTest : public InProcessBrowserTest {
public:
IpfsTabHelperBrowserTest()
Expand Down Expand Up @@ -173,12 +178,15 @@ IN_PROC_BROWSER_TEST_F(IpfsTabHelperBrowserTest, ResolvedIPFSLinkLocal) {
resolver_raw->ResetResolveCalled();
SetXIpfsPathHeader("/ipfs/bafy");
test_url = embedded_test_server()->GetURL(
"a.com", "/ipfs/bafy1/wiki/empty.html?query#ref");
"a.com", base::StringPrintf("/ipfs/%s/wiki/"
"empty.html?query#ref",
kCid1));
ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), test_url));
ASSERT_TRUE(WaitForLoadStop(active_contents()));
ASSERT_FALSE(resolver_raw->resolve_called());
resolved_url = helper->GetIPFSResolvedURL();
EXPECT_EQ(resolved_url, GURL("ipfs://bafy1/wiki/empty.html?query#ref"));
EXPECT_EQ(resolved_url, GURL(base::StringPrintf(
"ipfs://%s/wiki/empty.html?query#ref", kCid1)));
}

IN_PROC_BROWSER_TEST_F(IpfsTabHelperBrowserTest, ResolvedIPFSLinkGateway) {
Expand Down Expand Up @@ -304,7 +312,9 @@ IN_PROC_BROWSER_TEST_F(IpfsTabHelperBrowserTest,
EXPECT_EQ(helper->GetIPFSResolvedURL().spec(), std::string());

const GURL test_url = embedded_test_server()->GetURL(
"a.com", "/ipfs/bafy1/wiki/empty.html?query#ref");
"a.com", base::StringPrintf("/ipfs/%s/wiki/"
"empty.html?query#ref",
kCid1));

ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), test_url));
ASSERT_TRUE(WaitForLoadStop(active_contents()));
Expand Down Expand Up @@ -342,7 +352,9 @@ IN_PROC_BROWSER_TEST_F(IpfsTabHelperBrowserTest, GatewayRedirectToIPFS) {
SetXIpfsPathHeader("/ipns/other");

const GURL test_url = embedded_test_server()->GetURL(
"navigate_to.com", "/ipfs/bafy1/wiki/empty.html?query#ref");
"navigate_to.com", base::StringPrintf("/ipfs/%s/wiki/"
"empty.html?query#ref",
kCid1));

GURL gateway_url = embedded_test_server()->GetURL("a.com", "/");
prefs->SetString(kIPFSPublicGatewayAddress, gateway_url.spec());
Expand All @@ -353,7 +365,9 @@ IN_PROC_BROWSER_TEST_F(IpfsTabHelperBrowserTest, GatewayRedirectToIPFS) {

// gateway url.
GURL expected_final_url;
ipfs::TranslateIPFSURI(GURL("ipfs://bafy1/wiki/empty.html?query#ref"),
ipfs::TranslateIPFSURI(GURL(base::StringPrintf("ipfs://%s/"
"wiki/empty.html?query#ref",
kCid1)),
&expected_final_url, gateway_url, false);

EXPECT_EQ(active_contents()->GetVisibleURL(), expected_final_url);
Expand Down
Loading

0 comments on commit 307ac53

Please sign in to comment.