summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/webstore_inline_installer_unittest.cc
blob: e5616bf0008962f66afc506b024677bd6c7c58eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/extensions/webstore_inline_installer.h"
#include "googleurl/src/gurl.h"
#include "testing/gtest/include/gtest/gtest.h"

// A macro, so that the IsRequestorURLInVerifiedSite calls are inside of the
// the test, which is marked as a friend of WebstoreInlineInstaller.
#define IsVerified(requestor_url, verified_site) \
  WebstoreInlineInstaller::IsRequestorURLInVerifiedSite( \
      GURL(requestor_url), verified_site)

TEST(WebstoreInlineInstallerTest, DomainVerification) {
  // Exact domain match.
  EXPECT_TRUE(IsVerified("http://example.com", "example.com"));

  // The HTTPS scheme is allowed.
  EXPECT_TRUE(IsVerified("https://example.com", "example.com"));

  // The file: scheme is not allowed.
  EXPECT_FALSE(IsVerified("file:///example.com", "example.com"));

  // Trailing slash in URL.
  EXPECT_TRUE(IsVerified("http://example.com/", "example.com"));

  // Page on the domain.
  EXPECT_TRUE(IsVerified("http://example.com/page.html", "example.com"));

  // Page on a subdomain.
  EXPECT_TRUE(IsVerified("http://sub.example.com/page.html", "example.com"));

  // Root domain when only a subdomain is verified.
  EXPECT_FALSE(IsVerified("http://example.com/", "sub.example.com"));

  // Different subdomain when only a subdomain is verified.
  EXPECT_FALSE(IsVerified("http://www.example.com/", "sub.example.com"));

  // Port matches.
  EXPECT_TRUE(IsVerified("http://example.com:123/", "example.com:123"));

  // Port doesn't match.
  EXPECT_FALSE(IsVerified("http://example.com:456/", "example.com:123"));

  // Port is missing in the requestor URL.
  EXPECT_FALSE(IsVerified("http://example.com/", "example.com:123"));

  // Port is missing in the verified site (any port matches).
  EXPECT_TRUE(IsVerified("http://example.com:123/", "example.com"));

  // Path matches.
  EXPECT_TRUE(IsVerified("http://example.com/path", "example.com/path"));

  // Path doesn't match.
  EXPECT_FALSE(IsVerified("http://example.com/foo", "example.com/path"));

  // Path is missing.
  EXPECT_FALSE(IsVerified("http://example.com", "example.com/path"));

  // Path matches (with trailing slash).
  EXPECT_TRUE(IsVerified("http://example.com/path/", "example.com/path"));

  // Path matches (is a file under the path).
  EXPECT_TRUE(IsVerified(
      "http://example.com/path/page.html", "example.com/path"));

  // Path and port match.
  EXPECT_TRUE(IsVerified(
      "http://example.com:123/path/page.html", "example.com:123/path"));
}