|
6 | 6 | #include "brave/browser/ipfs/content_browser_client_helper.h"
|
7 | 7 |
|
8 | 8 | #include <memory>
|
| 9 | +#include <string> |
9 | 10 | #include <vector>
|
10 | 11 |
|
11 | 12 | #include "base/test/bind.h"
|
12 | 13 | #include "base/test/scoped_feature_list.h"
|
13 | 14 | #include "brave/components/ipfs/features.h"
|
14 | 15 | #include "brave/components/ipfs/ipfs_constants.h"
|
| 16 | +#include "brave/components/ipfs/ipfs_ports.h" |
| 17 | +#include "brave/components/ipfs/ipfs_utils.h" |
15 | 18 | #include "brave/components/ipfs/pref_names.h"
|
16 | 19 | #include "chrome/browser/prefs/browser_prefs.h"
|
17 | 20 | #include "chrome/common/channel_info.h"
|
@@ -137,4 +140,73 @@ TEST_F(ContentBrowserClientHelperUnitTest, HandleIPNSURLRewriteLocal) {
|
137 | 140 | ASSERT_TRUE(HandleIPFSURLRewrite(&ipns_uri, browser_context()));
|
138 | 141 | }
|
139 | 142 |
|
| 143 | +TEST_F(ContentBrowserClientHelperUnitTest, HandleIPFSURLReverseRewriteLocal) { |
| 144 | + profile()->GetPrefs()->SetInteger( |
| 145 | + kIPFSResolveMethod, static_cast<int>(IPFSResolveMethodTypes::IPFS_LOCAL)); |
| 146 | + |
| 147 | + GURL gateway_url("http://localhost/"); |
| 148 | + GURL::Replacements replacements; |
| 149 | + const std::string& port = ipfs::GetGatewayPort(chrome::GetChannel()); |
| 150 | + replacements.SetPortStr(port); |
| 151 | + gateway_url = gateway_url.ReplaceComponents(replacements); |
| 152 | + |
| 153 | + ASSERT_EQ( |
| 154 | + ipfs::GetConfiguredBaseGateway(browser_context(), chrome::GetChannel()), |
| 155 | + gateway_url); |
| 156 | + |
| 157 | + std::string source = "http://test.com.ipns.localhost:8000/"; |
| 158 | + GURL ipns_uri(source); |
| 159 | + ASSERT_FALSE(HandleIPFSURLReverseRewrite(&ipns_uri, browser_context())); |
| 160 | + ASSERT_EQ(ipns_uri.spec(), source); |
| 161 | + |
| 162 | + ipns_uri = GURL("http://test.com.ipns.localhost/"); |
| 163 | + ipns_uri = ipns_uri.ReplaceComponents(replacements); |
| 164 | + ASSERT_TRUE(HandleIPFSURLReverseRewrite(&ipns_uri, browser_context())); |
| 165 | + ASSERT_EQ(ipns_uri.spec(), "ipns://test.com/"); |
| 166 | +} |
| 167 | + |
| 168 | +TEST_F(ContentBrowserClientHelperUnitTest, HandleIPFSURLReverseRewriteGateway) { |
| 169 | + profile()->GetPrefs()->SetInteger( |
| 170 | + kIPFSResolveMethod, |
| 171 | + static_cast<int>(IPFSResolveMethodTypes::IPFS_GATEWAY)); |
| 172 | + ASSERT_EQ(ipfs::GetConfiguredBaseGateway(browser_context(), |
| 173 | + version_info::Channel::UNKNOWN), |
| 174 | + GURL("https://dweb.link/")); |
| 175 | + |
| 176 | + std::string source = "http://test.com.ipns.localhost:8000/"; |
| 177 | + GURL ipns_uri(source); |
| 178 | + ASSERT_FALSE(HandleIPFSURLReverseRewrite(&ipns_uri, browser_context())); |
| 179 | + ASSERT_EQ(ipns_uri.spec(), source); |
| 180 | + |
| 181 | + source = "https://ku2jvrakgpiqgx4j6fe.ipfs.dweb.link/"; |
| 182 | + ipns_uri = GURL(source); |
| 183 | + ASSERT_FALSE(HandleIPFSURLReverseRewrite(&ipns_uri, browser_context())); |
| 184 | + ASSERT_EQ(ipns_uri.spec(), source); |
| 185 | + |
| 186 | + profile()->GetPrefs()->SetString(kIPFSPublicGatewayAddress, |
| 187 | + "http://localhost:8080"); |
| 188 | + ASSERT_EQ(ipfs::GetConfiguredBaseGateway(browser_context(), |
| 189 | + version_info::Channel::UNKNOWN), |
| 190 | + GURL("http://localhost:8080")); |
| 191 | + |
| 192 | + source = "http://test.com.ipns.localhost:8000/"; |
| 193 | + ipns_uri = GURL(source); |
| 194 | + ASSERT_FALSE(HandleIPFSURLReverseRewrite(&ipns_uri, browser_context())); |
| 195 | + ASSERT_EQ(ipns_uri.spec(), source); |
| 196 | + |
| 197 | + source = "https://ku2jvrakgpiqgx4j6fe.ipfs.dweb.link/"; |
| 198 | + ipns_uri = GURL(source); |
| 199 | + ASSERT_FALSE(HandleIPFSURLReverseRewrite(&ipns_uri, browser_context())); |
| 200 | + ASSERT_EQ(ipns_uri.spec(), source); |
| 201 | + |
| 202 | + source = "https://ku2jvrakgpiqgx4j6fe.ipfs.dweb.link:8080/"; |
| 203 | + ipns_uri = GURL(source); |
| 204 | + ASSERT_FALSE(HandleIPFSURLReverseRewrite(&ipns_uri, browser_context())); |
| 205 | + ASSERT_EQ(ipns_uri.spec(), source); |
| 206 | + |
| 207 | + ipns_uri = GURL("http://test.com.ipns.localhost:8080/"); |
| 208 | + ASSERT_TRUE(HandleIPFSURLReverseRewrite(&ipns_uri, browser_context())); |
| 209 | + ASSERT_EQ(ipns_uri.spec(), "ipns://test.com/"); |
| 210 | +} |
| 211 | + |
140 | 212 | } // namespace ipfs
|
0 commit comments