WebTest.swift 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 WebTest: XCTestCase {
  23. override func setUp() {
  24. super.setUp()
  25. // necessary for ValidationLogger
  26. AppGroup.setGroupId("group.ch.threema") //THREEMA_GROUP_IDENTIFIER @"group.ch.threema"
  27. }
  28. override func tearDown() {
  29. super.tearDown()
  30. }
  31. func testIsWebHostAllowedNo() -> Void {
  32. XCTAssertFalse(WCSessionManager.isWebHostAllowed(scannedHostName: "threema.ch", whiteList: "example.com"))
  33. XCTAssertFalse(WCSessionManager.isWebHostAllowed(scannedHostName: "x.example.com", whiteList: "example.com"))
  34. XCTAssertFalse(WCSessionManager.isWebHostAllowed(scannedHostName: "x.example", whiteList: "*.example.com"))
  35. }
  36. func testIsWebHostAllowedNoEmptyList() -> Void {
  37. XCTAssertFalse(WCSessionManager.isWebHostAllowed(scannedHostName: "example.com", whiteList: ""))
  38. }
  39. func testIsWebHostAllowedYesExact() -> Void {
  40. XCTAssertTrue(WCSessionManager.isWebHostAllowed(scannedHostName: "example.com", whiteList: "example.com"))
  41. XCTAssertTrue(WCSessionManager.isWebHostAllowed(scannedHostName: "x.example.com", whiteList: "example.com, x.example.com"))
  42. }
  43. func testIsWebHostAllowedYesPrefixMatch() -> Void {
  44. XCTAssertTrue(WCSessionManager.isWebHostAllowed(scannedHostName: "x.example.com", whiteList: "example.com, *.example.com"))
  45. XCTAssertTrue(WCSessionManager.isWebHostAllowed(scannedHostName: "xyz.example.com", whiteList: "example.com, *.example.com"))
  46. XCTAssertTrue(WCSessionManager.isWebHostAllowed(scannedHostName: "x.y.example.com", whiteList: "example.com, *.example.com"))
  47. }
  48. }