package com.peachpasswords.feedback import org.json.JSONObject import org.junit.Assert.assertEquals import org.junit.Assert.assertTrue import org.junit.Test /** * The feedback payload is the one place user-written text leaves the device. * These pin its shape so a later edit cannot quietly widen it. */ class FeedbackSubmissionTest { private fun submission(type: String = "bug", message: String = "the thing broke") = JSONObject(FeedbackRepository.buildSubmission(type, message, version = "9.9.9")) @Test fun `carries the access key, the category and the message, and nothing else`() { val json = submission() assertEquals( setOf("access_key", "subject", "message", "from_name", "botcheck"), json.keys().asSequence().toSet(), ) assertEquals(FeedbackRepository.WEB3FORMS_KEY, json.getString("access_key")) assertEquals("the thing broke", json.getString("message")) assertEquals("Peach Feedback - bug (Android 9.9.9)", json.getString("subject")) } @Test fun `sends no device or user identifier`() { val body = FeedbackRepository.buildSubmission("bug", "hello").lowercase() for (leak in listOf("device_id", "deviceid", "vault", "email", "androidid", "serial")) { assertTrue("payload must not carry $leak", !body.contains(leak)) } } @Test fun `the honeypot ships empty, or Web3Forms drops the submission`() { assertEquals("", submission().getString("botcheck")) } @Test fun `posts to the same inbox as the extension`() { assertEquals("https://api.web3forms.com/submit", FeedbackRepository.ENDPOINT) } }