package com.peachpasswords.ui.vault import org.junit.Assert.assertEquals import org.junit.Assert.assertNull import org.junit.Test class ExternalUrlPolicyTest { @Test fun `bare host is normalized to HTTPS`() { assertEquals("https://example.com/login", normalizeExternalHttpsUrl("example.com/login")) } @Test fun `valid HTTPS URL is canonicalized`() { assertEquals( "https://example.com:8443/a?q=1#top", normalizeExternalHttpsUrl(" HTTPS://Example.COM:8443/a?q=1#top "), ) } @Test fun `non HTTPS schemes are rejected`() { listOf( "http://example.com", "intent://example.com/#Intent;scheme=https;end", "file:///data/local/tmp/secret", "peach://example.com/open", "javascript:alert(1)", ).forEach { assertNull(it, normalizeExternalHttpsUrl(it)) } } @Test fun `malformed or ambiguous authorities are rejected`() { listOf( "https:%2f%2fevil.example", "https://user@example.com", "https://example.com\\@evil.example", "https://", "https://example.com:99999", "https://exa mple.com", "https://example.com\u0000.evil", ).forEach { assertNull(it, normalizeExternalHttpsUrl(it)) } } }