ExternalUrlPolicyTest.kt

1.3 KB · raw

1package com.peachpasswords.ui.vault23import org.junit.Assert.assertEquals4import org.junit.Assert.assertNull5import org.junit.Test67class ExternalUrlPolicyTest {89    @Test10    fun `bare host is normalized to HTTPS`() {11        assertEquals("https://example.com/login", normalizeExternalHttpsUrl("example.com/login"))12    }1314    @Test15    fun `valid HTTPS URL is canonicalized`() {16        assertEquals(17            "https://example.com:8443/a?q=1#top",18            normalizeExternalHttpsUrl(" HTTPS://Example.COM:8443/a?q=1#top "),19        )20    }2122    @Test23    fun `non HTTPS schemes are rejected`() {24        listOf(25            "http://example.com",26            "intent://example.com/#Intent;scheme=https;end",27            "file:///data/local/tmp/secret",28            "peach://example.com/open",29            "javascript:alert(1)",30        ).forEach { assertNull(it, normalizeExternalHttpsUrl(it)) }31    }3233    @Test34    fun `malformed or ambiguous authorities are rejected`() {35        listOf(36            "https:%2f%2fevil.example",37            "https://[email protected]",38            "https://example.com\\@evil.example",39            "https://",40            "https://example.com:99999",41            "https://exa mple.com",42            "https://example.com\u0000.evil",43        ).forEach { assertNull(it, normalizeExternalHttpsUrl(it)) }44    }45}