151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)/* 251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * Copyright (C) 2013 Google Inc. All rights reserved. 351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * 451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * Redistribution and use in source and binary forms, with or without 551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * modification, are permitted provided that the following conditions are 651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * met: 751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * 851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * * Redistributions of source code must retain the above copyright 951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * notice, this list of conditions and the following disclaimer. 1051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * * Redistributions in binary form must reproduce the above 1151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * copyright notice, this list of conditions and the following disclaimer 1251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * in the documentation and/or other materials provided with the 1351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * distribution. 1451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * * Neither the name of Google Inc. nor the names of its 1551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * contributors may be used to endorse or promote products derived from 1651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * this software without specific prior written permission. 1751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * 1851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 2051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) */ 3051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 3151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)#include "config.h" 3251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)#include "platform/weborigin/OriginAccessEntry.h" 3351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 3451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)#include "platform/weborigin/KURL.h" 3551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)#include "platform/weborigin/SecurityOrigin.h" 3651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)#include "public/platform/Platform.h" 3751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)#include "public/platform/WebPublicSuffixList.h" 3851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)#include <gtest/gtest.h> 3951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 40c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)using blink::SecurityOrigin; 41c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)using blink::OriginAccessEntry; 4251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 4351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)namespace { 4451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 4551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)class OriginAccessEntryTestSuffixList : public blink::WebPublicSuffixList { 4651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)public: 4751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) virtual size_t getPublicSuffixLength(const blink::WebString&) 4851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) { 4951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) return 3; // e.g. "com" 5051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } 5151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)}; 5251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 5351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)class OriginAccessEntryTestPlatform : public blink::Platform { 5451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)public: 5551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) virtual blink::WebPublicSuffixList* publicSuffixList() 5651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) { 5751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) return &m_suffixList; 5851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } 5951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 6051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) // Stub for pure virtual method. 6151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) virtual void cryptographicallyRandomValues(unsigned char*, size_t) { ASSERT_NOT_REACHED(); } 6251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 6351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)private: 6451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) OriginAccessEntryTestSuffixList m_suffixList; 6551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)}; 6651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 6751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)TEST(OriginAccessEntryTest, PublicSuffixListTest) 6851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){ 6951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) OriginAccessEntryTestPlatform platform; 7051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) blink::Platform::initialize(&platform); 7151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 7251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) RefPtr<SecurityOrigin> origin = SecurityOrigin::createFromString("http://www.google.com"); 7351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) OriginAccessEntry entry1("http", "google.com", OriginAccessEntry::AllowSubdomains, OriginAccessEntry::TreatIPAddressAsIPAddress); 7451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) OriginAccessEntry entry2("http", "hamster.com", OriginAccessEntry::AllowSubdomains, OriginAccessEntry::TreatIPAddressAsIPAddress); 7551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) OriginAccessEntry entry3("http", "com", OriginAccessEntry::AllowSubdomains, OriginAccessEntry::TreatIPAddressAsIPAddress); 7651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) EXPECT_EQ(OriginAccessEntry::MatchesOrigin, entry1.matchesOrigin(*origin)); 7751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) EXPECT_EQ(OriginAccessEntry::DoesNotMatchOrigin, entry2.matchesOrigin(*origin)); 7851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) EXPECT_EQ(OriginAccessEntry::MatchesOriginButIsPublicSuffix, entry3.matchesOrigin(*origin)); 7951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 8051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) blink::Platform::shutdown(); 8151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)} 8251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 8351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)} // namespace 8451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 85