const test = require('node:test'); const assert = require('node:assert/strict'); const fs = require('node:fs'); const path = require('node:path'); const root = path.resolve(__dirname, '..'); const styles = fs.readFileSync(path.join(root, 'styles.css'), 'utf8'); const mailUi = fs.readFileSync(path.join(root, 'mail-ui.js'), 'utf8'); const app = fs.readFileSync(path.join(root, 'app.js'), 'utf8'); const transport = fs.readFileSync(path.join(root, 'android', 'app', 'src', 'main', 'java', 'studio', 'daybreak', 'mail', 'AndroidMailTransport.kt'), 'utf8'); const mainActivity = fs.readFileSync(path.join(root, 'android', 'app', 'src', 'main', 'java', 'studio', 'daybreak', 'mail', 'MainActivity.java'), 'utf8'); const plugin = fs.readFileSync(path.join(root, 'android', 'app', 'src', 'main', 'java', 'studio', 'daybreak', 'mail', 'EpMailPlugin.kt'), 'utf8'); const vault = fs.readFileSync(path.join(root, 'android', 'app', 'src', 'main', 'java', 'studio', 'daybreak', 'mail', 'AndroidAccountVault.kt'), 'utf8'); const androidMailService = fs.readFileSync(path.join(root, 'android', 'app', 'src', 'main', 'java', 'studio', 'daybreak', 'mail', 'AndroidMailService.kt'), 'utf8'); const androidPgpPolicy = fs.readFileSync(path.join(root, 'android', 'app', 'src', 'main', 'java', 'studio', 'daybreak', 'mail', 'AndroidPgpPolicy.kt'), 'utf8'); const androidPgpConfirmationGate = fs.readFileSync(path.join(root, 'android', 'app', 'src', 'main', 'java', 'studio', 'daybreak', 'mail', 'AndroidPgpConfirmationGate.kt'), 'utf8'); const productivity = fs.readFileSync(path.join(root, 'productivity.js'), 'utf8'); const androidBridge = fs.readFileSync(path.join(root, 'scripts', 'android-bridge.js'), 'utf8'); const androidPgp = fs.readFileSync(path.join(root, 'scripts', 'android-pgp.js'), 'utf8'); const pgpMailUi = fs.readFileSync(path.join(root, 'pgp-mail-ui.js'), 'utf8'); const packageJson = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8')); const packageLock = JSON.parse(fs.readFileSync(path.join(root, 'package-lock.json'), 'utf8')); test('mobile layout removes desktop minimum width and provides a compact reader flow', () => { assert.match(styles, /min-width:320px/); assert.match(styles, /@media\(max-width:1000px\),\(max-height:500px\) and \(orientation:landscape\)/); assert.match(styles, /@media\(max-height:500px\) and \(orientation:landscape\)/); assert.match(styles, /overflow-wrap:anywhere;word-break:break-word/); assert.match(styles, /\.hidden,\[hidden\]\{display:none!important\}/); assert.match(styles, /body\.reader-open \.mail-layout \.list-pane/); assert.match(app, /id="reader-back"/); assert.match(app, /classList\.add\('reader-open'\)/); assert.match(app, /\$\$\('\.folder'\)\.forEach/); assert.match(app, /if\(!m\)\{state\.activeMessage=null;document\.body\.classList\.remove\('reader-open'\);return;\}/); }); test('mailbox setup exposes ports and TLS modes and submits them to Android', () => { for (const id of ['mail-account-imap-port', 'mail-account-imap-secure', 'mail-account-smtp-port', 'mail-account-smtp-secure']) { assert.ok(mailUi.includes(`id="${id}"`), `missing account field ${id}`); } assert.match(mailUi, /imapPort,/); assert.match(mailUi, /imapSecure:/); assert.match(mailUi, /smtpPort,/); assert.match(mailUi, /smtpSecure:/); }); test('Android mail transport supports verified implicit TLS and required STARTTLS modes', () => { assert.match(transport, /"imaps" else "imap"/); assert.match(transport, /mail\.\$protocol\.starttls\.required/); assert.match(transport, /mail\.smtp\.ssl\.enable/); assert.match(transport, /mail\.smtp\.starttls\.required/); assert.match(transport, /ssl\.checkserveridentity/); }); test('Capacitor mail plugin is registered before BridgeActivity creates the bridge', () => { assert.ok(mainActivity.indexOf('registerPlugin(EpMailPlugin.class)') < mainActivity.indexOf('super.onCreate(savedInstanceState)')); }); test('OpenPGP.js is pinned to the exact version in the lockfile pending security review', () => { assert.equal(packageJson.dependencies.openpgp, packageLock.packages['node_modules/openpgp'].version); assert.match(packageJson.dependencies.openpgp, /^\d+\.\d+\.\d+$/); }); test('Android app lock is native-enforced and requires a secure device credential', () => { assert.match(plugin, /fun getAppLockSettings/); assert.match(plugin, /fun setAppLockEnabled/); assert.match(plugin, /keyguard\.isDeviceSecure/); assert.match(mainActivity, /setJavaScriptEnabled\(false\)/); assert.match(mainActivity, /createConfirmDeviceCredentialIntent/); assert.match(mainActivity, /android\.R\.id\.content/); assert.match(mainActivity, /settings\.setAllowFileAccess\(false\)/); assert.match(mainActivity, /settings\.setAllowContentAccess\(false\)/); assert.match(mainActivity, /setJavaScriptCanOpenWindowsAutomatically\(false\)/); assert.match(mainActivity, /MIXED_CONTENT_NEVER_ALLOW/); assert.match(mainActivity, /setWebContentsDebuggingEnabled\(BuildConfig\.DEBUG\)/); assert.match(mainActivity, /addFlags\(WindowManager\.LayoutParams\.FLAG_SECURE\)/); assert.match(mainActivity, /clearFlags\(WindowManager\.LayoutParams\.FLAG_SECURE\)/); assert.match(mainActivity, /createVaultRecoveryOverlay/); assert.match(mainActivity, /setJavaScriptEnabled\(false\)/); assert.match(androidBridge, /getAppLockSettings/); assert.match(androidBridge, /setAppLockEnabled/); assert.match(productivity, /Lock when leaving ep-mail/); }); test('Android OpenPGP uses the encrypted vault and queues only built MIME data', () => { assert.match(plugin, /fun pgpLoadStore/); assert.match(plugin, /fun pgpSaveStore/); assert.match(plugin, /fun pgpGetMessageSource/); assert.match(plugin, /pgpStoreChangeWarning/); assert.match(plugin, /plaintextSendWarning/); assert.match(plugin, /Send plaintext/); assert.match(plugin, /showPgpConfirmation\(/); assert.match(plugin, /onCancelled = \{ call\.reject\("OpenPGP key change cancelled\."\) \}/); assert.match(plugin, /onConfirmed = \{ sendPrepared\(call, input\) \}/); assert.match(plugin, /PLAINTEXT_CANCELLED/); assert.match(androidPgpConfirmationGate, /compareAndSet\(false, true\)/); assert.match(androidPgpPolicy, /fun storeChangeWarning/); assert.match(androidPgpPolicy, /fun plaintextSendWarning/); assert.match(androidPgp, /curve25519Legacy/); assert.match(androidPgp, /multipart\/encrypted/); assert.match(androidPgp, /MAX_MESSAGE_BYTES = 25 \* 1024 \* 1024/); assert.match(androidPgp, /async function verifyMessage/); assert.match(androidPgp, /readCleartextMessage/); assert.match(androidPgp, /readSignature/); assert.match(pgpMailUi, /message\.signed/); assert.match(androidBridge, /buildOutgoing\(message\)/); assert.match(androidBridge, /rawBase64, envelope: \{ from, to \}, text: '', attachments: \[\]/); assert.match(androidMailService, /validateOpenPgpMime\(message\)/); assert.match(androidMailService, /private fun validateOpenPgpMime/); assert.match(androidMailService, /"send" -> send\(account, data\)/); assert.match(androidMailService, /private fun isEncryptedMessage/); }); test('Android vault refuses to replace a missing key when encrypted data exists', () => { assert.match(vault, /shouldCreateKey\(hasEncryptedData\)/); assert.match(vault, /MISSING_KEY_MESSAGE/); assert.match(mainActivity, /AndroidAccountVault\.INSTANCE\.read\(\)/); assert.match(mainActivity, /Saved data could not be opened/); assert.match(mainActivity, /ACTION_APPLICATION_DETAILS_SETTINGS/); });