tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

TestPrincipalHash.cpp (975B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 #include "gtest/gtest.h"
      5 #include "mozilla/gtest/MozAssertions.h"
      6 #include "nsIPrincipal.h"
      7 #include "nsScriptSecurityManager.h"
      8 #include "nsNetUtil.h"
      9 
     10 TEST(PrincipalHash, DocumentDomain)
     11 {
     12  nsCOMPtr<nsIScriptSecurityManager> ssm =
     13      nsScriptSecurityManager::GetScriptSecurityManager();
     14  nsCOMPtr<nsIPrincipal> principal;
     15  nsresult rv = ssm->CreateContentPrincipalFromOrigin(
     16      "https://sub.mozilla.org"_ns, getter_AddRefs(principal));
     17  EXPECT_NS_SUCCEEDED(rv);
     18 
     19  const auto hash = principal->GetHashValue();
     20 
     21  nsCOMPtr<nsIURI> domain;
     22  rv = NS_NewURI(getter_AddRefs(domain), "https://mozilla.org"_ns);
     23  EXPECT_NS_SUCCEEDED(rv);
     24  principal->SetDomain(domain);
     25 
     26  ASSERT_EQ(principal->GetHashValue(), hash)
     27      << "Principal hash shouldn't change";
     28 }