IDNSafetyHelperTests.swift 1.7 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // _____ _
  2. // |_ _| |_ _ _ ___ ___ _ __ __ _
  3. // | | | ' \| '_/ -_) -_) ' \/ _` |_
  4. // |_| |_||_|_| \___\___|_|_|_\__,_(_)
  5. //
  6. // Threema iOS Client
  7. // Copyright (c) 2019-2020 Threema GmbH
  8. //
  9. // This program is free software: you can redistribute it and/or modify
  10. // it under the terms of the GNU Affero General Public License, version 3,
  11. // as published by the Free Software Foundation.
  12. //
  13. // This program is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. // GNU Affero General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Affero General Public License
  19. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. import XCTest
  21. @testable import Threema
  22. class IDNSafetyHelperTests: XCTestCase {
  23. func testIsLegalUrl() {
  24. // Note: URL/NSURL cannot handle Unicode hostnames directly, so we need to pre-Punycode them
  25. XCTAssertTrue(IDNSafetyHelper.isLegalURL(url: URL(string: "https://threema.ch")!))
  26. XCTAssertFalse(IDNSafetyHelper.isLegalURL(url: URL(string: "https://xn--threem-8nf.ch")!))
  27. XCTAssertTrue(IDNSafetyHelper.isLegalURL(url: URL(string: "https://xn--gmqa5019b.xn--55qx5d")!))
  28. XCTAssertFalse(IDNSafetyHelper.isLegalURL(url: URL(string: "https://xn--gfrr-7qa.li")!))
  29. XCTAssertTrue(IDNSafetyHelper.isLegalURL(url: URL(string: "https://wikipedia.org")!))
  30. XCTAssertFalse(IDNSafetyHelper.isLegalURL(url: URL(string: "https://xn--wikipedi-86g.org")!))
  31. XCTAssertFalse(IDNSafetyHelper.isLegalURL(url: URL(string: "https://xn--wkipedia-c2a.org")!))
  32. }
  33. }