| 1 | import Foundation |
| 2 | import Testing |
| 3 | @testable import EquipoKit |
| 4 | |
| 5 | @Suite struct TaskWebNavigationTests { |
| 6 | @Test func taskPagesUseTheOriginAndFixedPathsOnly() { |
| 7 | let origin = URL(string: "https://team.example:8443/old?token=secret#fragment")! |
| 8 | for path in ["/tasks/task_1", "/tasks/task_1/preview", "/tasks/task_1/move"] { |
| 9 | var opened: URL? |
| 10 | SettingsNavigation.open(origin: origin, path: path) { opened = $0 } |
| 11 | #expect(opened?.absoluteString == "https://team.example:8443" + path) |
| 12 | } |
| 13 | for path in ["/evil", "/tasks/t/evil", "/tasks/../evil", "/tasks/t?redirect=evil", "https://evil.example/tasks/t", "/tasks/t/preview/extra", "/tasks/a%2fb"] { |
| 14 | var opened = false |
| 15 | SettingsNavigation.open(origin: origin, path: path) { _ in opened = true } |
| 16 | #expect(!opened) |
| 17 | } |
| 18 | } |
| 19 | @Test func changesOnlyOpenOnTheSessionOriginOrKnownForge() { |
| 20 | let origin = URL(string: "https://team.example:8443")! |
| 21 | for address in ["https://team.example:8443/change/1", "https://amadan.net/team/repo/commit/abc"] { |
| 22 | var opened: URL? |
| 23 | SettingsNavigation.openChanges(origin: origin, url: URL(string: address)!) { opened = $0 } |
| 24 | #expect(opened?.absoluteString == address) |
| 25 | } |
| 26 | for address in ["https://evil.example/change", "https://amadan.net.evil.example/change", "https://evil.amadan.net/change", "https://amadan.net:444/change", "https://user:password@amadan.net/change", "http://amadan.net/change", "javascript:alert(1)", "https://team.example/change", "https://github.com/team/repo"] { |
| 27 | var opened = false |
| 28 | SettingsNavigation.openChanges(origin: origin, url: URL(string: address)!) { _ in opened = true } |
| 29 | #expect(!opened) |
| 30 | } |
| 31 | } |
| 32 | } |
| 33 | |