Cotton code
37 lines · 1.9 KB · KotlinRaw
package com.cottondb.notesimport org.junit.Assert.assertFalseimport org.junit.Assert.assertTrueimport org.junit.Test/** * RULE (owner, 21 Nov 2026; CONTRACT.md section 13): a web page an assistant made is read sealed, as the iPhone's * viewer reads it: its own local file, data and blob URLs it made, https to the few library and font hosts, and * nothing else; a link the person follows leaves for the browser. */class NotesPageSealTest {    private val file = "/data/user/0/com.cottondb.notes.dev/files/media/invented-page.html"    @Test fun thePageLoadsItsOwnFileAndTheLibraryHostsOnly() {        assertTrue(NotesPageSeal.allows("file://$file", file))        assertTrue(NotesPageSeal.allows("https://cdnjs.cloudflare.com/ajax/libs/d3/7.9.0/d3.min.js", file))        assertTrue(NotesPageSeal.allows("https://fonts.gstatic.com/s/inter.woff2", file))        assertTrue(NotesPageSeal.allows("data:image/png;base64,AAAA", file))        assertTrue(NotesPageSeal.allows("blob:null/1234", file))    }    @Test fun everyOtherLoadIsRefused() {        assertFalse("another file", NotesPageSeal.allows("file:///data/user/0/com.cottondb.notes.dev/databases/personal.db", file))        assertFalse("another host", NotesPageSeal.allows("https://tracker.example/pixel.gif", file))        assertFalse("plain http to a library host", NotesPageSeal.allows("http://cdnjs.cloudflare.com/x.js", file))        assertFalse("a host that only ends like one", NotesPageSeal.allows("https://evil-unpkg.com/x.js", file))        assertFalse("content", NotesPageSeal.allows("content://com.android.contacts/contacts", file))    }    @Test fun aFollowedLinkLeavesForTheBrowser() {        assertTrue(NotesPageSeal.leaves("https://example.com/"))        assertTrue(NotesPageSeal.leaves("mailto:invented@example.com"))        assertFalse(NotesPageSeal.leaves("javascript:alert(1)"))        assertFalse(NotesPageSeal.leaves("file:///etc/hosts"))    }}