Commit 6eea28e0 authored by Frédéric Wang's avatar Frédéric Wang Committed by Chromium LUCI CQ

Use a standard scheme to test potential trustworthiness

In [1] a test was added to to verify trustworthiness of custom schemes.
However, the ones using IsOriginPotentiallyTrustworthy fails because
non-opaque origin must be a "standard scheme" i.e. follow [2]. This CL
adjusts the tests to actually use a "standard scheme", which is closer
the intent to test chrome-extension URLs. It also removes corresponding
test from SecurityOriginTest, as it does work well with url utils [3].

[1] https://chromium-review.googlesource.com/c/chromium/src/+/2593629
[2] https://tools.ietf.org/html/rfc3986#section-3
[3] crbug.com/1163060

Bug: 1153336, 1163060
Change-Id: I3e7f1d91558a97b1722a742d89c514b984b56ac2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2595424Reviewed-by: default avatarMike West <mkwst@chromium.org>
Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Commit-Queue: Frédéric Wang <fwang@igalia.com>
Cr-Commit-Position: refs/heads/master@{#841991}
parent 9cd5d4b9
...@@ -51,7 +51,6 @@ TEST(IsPotentiallyTrustworthy, Origin) { ...@@ -51,7 +51,6 @@ TEST(IsPotentiallyTrustworthy, Origin) {
EXPECT_FALSE(IsOriginPotentiallyTrustworthy("javascript:alert('blah')")); EXPECT_FALSE(IsOriginPotentiallyTrustworthy("javascript:alert('blah')"));
EXPECT_FALSE(IsOriginPotentiallyTrustworthy("data:test/plain;blah")); EXPECT_FALSE(IsOriginPotentiallyTrustworthy("data:test/plain;blah"));
EXPECT_FALSE(IsOriginPotentiallyTrustworthy("custom-scheme://example.com"));
EXPECT_TRUE( EXPECT_TRUE(
IsOriginPotentiallyTrustworthy("quic-transport://example.com/counter")); IsOriginPotentiallyTrustworthy("quic-transport://example.com/counter"));
} }
...@@ -150,18 +149,39 @@ TEST(IsPotentiallyTrustworthy, Url) { ...@@ -150,18 +149,39 @@ TEST(IsPotentiallyTrustworthy, Url) {
EXPECT_TRUE( EXPECT_TRUE(
IsUrlPotentiallyTrustworthy("quic-transport://example.com/counter")); IsUrlPotentiallyTrustworthy("quic-transport://example.com/counter"));
EXPECT_FALSE(IsUrlPotentiallyTrustworthy("custom-scheme://example.com"));
} }
// Tests the trustworthiness of an URL and origin whose scheme was added to the
// custom sets of standard and secure schemes. A scheme must be added to both
// to be considered trustworthy.
TEST(IsPotentiallyTrustworthy, CustomScheme) { TEST(IsPotentiallyTrustworthy, CustomScheme) {
const char* custom_scheme = "custom-scheme";
const char* custom_scheme_example = "custom-scheme://example.com";
EXPECT_FALSE(IsOriginPotentiallyTrustworthy(custom_scheme_example));
EXPECT_FALSE(IsUrlPotentiallyTrustworthy(custom_scheme_example));
{
url::ScopedSchemeRegistryForTests scoped_registry; url::ScopedSchemeRegistryForTests scoped_registry;
url::AddSecureScheme("custom-scheme"); url::AddSecureScheme(custom_scheme);
EXPECT_FALSE(IsOriginPotentiallyTrustworthy(custom_scheme_example));
EXPECT_FALSE(IsUrlPotentiallyTrustworthy(custom_scheme_example));
}
// TODO(crbug.com/1159371): These tests should return true. {
EXPECT_FALSE(IsOriginPotentiallyTrustworthy( url::ScopedSchemeRegistryForTests scoped_registry;
"custom-scheme://578223a1-8c13-17b3-84d5-eca045ae384a/fun.js")); url::AddStandardScheme(custom_scheme, url::SchemeType::SCHEME_WITH_HOST);
EXPECT_FALSE(IsUrlPotentiallyTrustworthy( EXPECT_FALSE(IsOriginPotentiallyTrustworthy(custom_scheme_example));
"custom-scheme://578223a1-8c13-17b3-84d5-eca045ae384a/fun.js")); EXPECT_FALSE(IsUrlPotentiallyTrustworthy(custom_scheme_example));
}
{
url::ScopedSchemeRegistryForTests scoped_registry;
url::AddStandardScheme(custom_scheme, url::SchemeType::SCHEME_WITH_HOST);
url::AddSecureScheme(custom_scheme);
EXPECT_TRUE(IsOriginPotentiallyTrustworthy(custom_scheme_example));
EXPECT_TRUE(IsUrlPotentiallyTrustworthy(custom_scheme_example));
}
} }
// Tests that were for the removed blink::network_utils::IsOriginSecure. // Tests that were for the removed blink::network_utils::IsOriginSecure.
......
...@@ -159,6 +159,8 @@ TEST_F(SecurityOriginTest, IsPotentiallyTrustworthy) { ...@@ -159,6 +159,8 @@ TEST_F(SecurityOriginTest, IsPotentiallyTrustworthy) {
{false, false, "http://foobar.com"}, {false, false, "http://foobar.com"},
{false, false, "http://foobar.com:443"}, {false, false, "http://foobar.com:443"},
{false, false, "ws://foobar.com"}, {false, false, "ws://foobar.com"},
// TODO(crbug.com/1163060): Test registration of secure schemes.
{false, false, "custom-scheme://example.com"},
// Local files are considered trustworthy. // Local files are considered trustworthy.
{true, false, "file:///home/foobar/index.html"}, {true, false, "file:///home/foobar/index.html"},
...@@ -238,6 +240,7 @@ TEST_F(SecurityOriginTest, IsSecure) { ...@@ -238,6 +240,7 @@ TEST_F(SecurityOriginTest, IsSecure) {
{false, {false,
"filesystem:blob:https://example.com/" "filesystem:blob:https://example.com/"
"578223a1-8c13-17b3-84d5-eca045ae384a"}, "578223a1-8c13-17b3-84d5-eca045ae384a"},
// TODO(crbug.com/1163060): Test registration of secure schemes.
{false, "custom-scheme://example.com"}, {false, "custom-scheme://example.com"},
{true, "quic-transport://example.com/counter"}, {true, "quic-transport://example.com/counter"},
{false, ""}, {false, ""},
...@@ -251,12 +254,6 @@ TEST_F(SecurityOriginTest, IsSecure) { ...@@ -251,12 +254,6 @@ TEST_F(SecurityOriginTest, IsSecure) {
EXPECT_FALSE(SecurityOrigin::IsSecure(NullURL())); EXPECT_FALSE(SecurityOrigin::IsSecure(NullURL()));
} }
TEST_F(SecurityOriginTest, IsCustomSchemeSecure) {
url::ScopedSchemeRegistryForTests scoped_registry;
url::AddSecureScheme("custom-scheme");
EXPECT_TRUE(SecurityOrigin::IsSecure(KURL("custom-scheme://example.com")));
}
TEST_F(SecurityOriginTest, IsSecureViaTrustworthy) { TEST_F(SecurityOriginTest, IsSecureViaTrustworthy) {
// TODO(crbug.com/1153336): Should SecurityOrigin::IsSecure be aligned with // TODO(crbug.com/1153336): Should SecurityOrigin::IsSecure be aligned with
// network::IsURLPotentiallyTrustworthy? // network::IsURLPotentiallyTrustworthy?
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment