import Foundation import Testing @testable import EquipoKit @Suite struct TaskWebNavigationTests { @Test func taskPagesUseTheOriginAndFixedPathsOnly() { let origin = URL(string: "https://team.example:8443/old?token=secret#fragment")! for path in ["/tasks/task_1", "/tasks/task_1/preview", "/tasks/task_1/move"] { var opened: URL? SettingsNavigation.open(origin: origin, path: path) { opened = $0 } #expect(opened?.absoluteString == "https://team.example:8443" + path) } 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"] { var opened = false SettingsNavigation.open(origin: origin, path: path) { _ in opened = true } #expect(!opened) } } @Test func changesOnlyOpenOnTheSessionOriginOrKnownForge() { let origin = URL(string: "https://team.example:8443")! for address in ["https://team.example:8443/change/1", "https://amadan.net/team/repo/commit/abc"] { var opened: URL? SettingsNavigation.openChanges(origin: origin, url: URL(string: address)!) { opened = $0 } #expect(opened?.absoluteString == address) } 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"] { var opened = false SettingsNavigation.openChanges(origin: origin, url: URL(string: address)!) { _ in opened = true } #expect(!opened) } } }