AutofillFlagSecureTest.kt

2.0 KB · raw

1package com.peachpasswords.autofill23import android.content.Intent4import android.view.WindowManager5import androidx.test.core.app.ActivityScenario6import androidx.test.core.app.ApplicationProvider7import androidx.test.ext.junit.runners.AndroidJUnit48import androidx.test.platform.app.InstrumentationRegistry9import org.junit.Assert.assertTrue10import org.junit.Test11import org.junit.runner.RunWith1213/**14 * Real-device coverage for audit H-05. The autofill entry picker shows vault15 * metadata (usernames, sites, last-used) and must set FLAG_SECURE so16 * screenshots, screen recording, and the recents thumbnail cannot leak those17 * entries. Debug builds are secure by default too; only an explicit18 * `qa_disable_secure_flag` intent extra bypasses the policy.19 *20 * Launching with NO extras must not crash — the picker renders with UNKNOWN21 * trust and zero preselected entries, which is the correct fail-closed state.22 */23@RunWith(AndroidJUnit4::class)24class AutofillFlagSecureTest {25    @Test26    fun pickerWindowActuallyEnablesFlagSecure() {27        val context = InstrumentationRegistry.getInstrumentation().targetContext28        assertTrue(29            "target must be release or its correctly suffixed debug id",30            context.packageName == "com.peachpasswords" ||31                context.packageName == "com.peachpasswords.debug",32        )33        // Launch with an empty intent — no origin, no trust extras. The picker34        // must tolerate this and still set FLAG_SECURE before rendering.35        val intent = Intent(context, AutofillEntryPickerActivity::class.java)36        val scenario = ActivityScenario.launch<AutofillEntryPickerActivity>(intent)37        try {38            scenario.onActivity { activity ->39                assertTrue(40                    "autofill picker window must set FLAG_SECURE",41                    activity.window.attributes.flags and WindowManager.LayoutParams.FLAG_SECURE != 0,42                )43            }44        } finally {45            scenario.close()46        }47    }48}