Commit c85006f0 authored by johnme's avatar johnme Committed by Commit bot

Push API: Avoid false positive DCHECK.

PushMessagingAppIdentifier::FindByAppId was DCHECKing when called from
PushMessagingServiceImpl::CanHandle to see if an app_id belongs to
Push, since it assumes that it would only be called with valid Push
app_ids.

This patch makes it test whether the app_id is a Push Messaging app_id
before performing any validation DCHECKs.

BUG=489304

Review URL: https://codereview.chromium.org/1140873005

Cr-Commit-Position: refs/heads/master@{#330378}
parent b31210c4
......@@ -75,9 +75,15 @@ PushMessagingAppIdentifier PushMessagingAppIdentifier::Generate(
// static
PushMessagingAppIdentifier PushMessagingAppIdentifier::FindByAppId(
Profile* profile, const std::string& app_id) {
// Check case of app_id hasn't been mangled (crbug.com/461867).
DCHECK_GE(app_id.size(), kPrefixLength + kGuidLength);
if (!StartsWithASCII(app_id, kPushMessagingAppIdentifierPrefix,
false /* case_sensitive */)) {
return PushMessagingAppIdentifier();
}
// Since we now know this is a Push Messaging app_id, check the case hasn't
// been mangled (crbug.com/461867).
DCHECK_EQ(kPushMessagingAppIdentifierPrefix, app_id.substr(0, kPrefixLength));
DCHECK_GE(app_id.size(), kPrefixLength + kGuidLength);
DCHECK_EQ(app_id.substr(app_id.size() - kGuidLength),
StringToUpperASCII(app_id.substr(app_id.size() - kGuidLength)));
......
......@@ -76,6 +76,13 @@ TEST_F(PushMessagingAppIdentifierTest, UniqueGuids) {
GURL("https://www.example.com/"), 1).app_id());
}
TEST_F(PushMessagingAppIdentifierTest, FindInvalidAppId) {
// These calls to FindByAppId should not DCHECK.
EXPECT_TRUE(PushMessagingAppIdentifier::FindByAppId(profile(), "").is_null());
EXPECT_TRUE(PushMessagingAppIdentifier::FindByAppId(
profile(), "amhfneadkjmnlefnpidcijoldiibcdnd").is_null());
}
TEST_F(PushMessagingAppIdentifierTest, PersistAndFind) {
ASSERT_TRUE(PushMessagingAppIdentifier::FindByAppId(
profile(), original_.app_id()).is_null());
......
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