206 lines
13 KiB
JavaScript
206 lines
13 KiB
JavaScript
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 pgpUi = fs.readFileSync(path.join(root, 'pgp-ui.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'));
|
|
const index = fs.readFileSync(path.join(root, 'index.html'), 'utf8');
|
|
const manifest = fs.readFileSync(path.join(root, 'android', 'app', 'src', 'main', 'AndroidManifest.xml'), 'utf8');
|
|
const davService = fs.readFileSync(path.join(root, 'android', 'app', 'src', 'main', 'java', 'studio', 'daybreak', 'mail', 'AndroidDavService.kt'), 'utf8');
|
|
const biometricUnlock = fs.readFileSync(path.join(root, 'android', 'app', 'src', 'main', 'java', 'studio', 'daybreak', 'mail', 'AndroidPgpBiometricUnlock.kt'), 'utf8');
|
|
const boundedInputReader = fs.readFileSync(path.join(root, 'android', 'app', 'src', 'main', 'java', 'studio', 'daybreak', 'mail', 'BoundedInputReader.kt'), '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('key settings cards keep key details readable and actions wrapped', () => {
|
|
assert.match(pgpUi, /compose-modal attachments-modal pgp-keys-modal/);
|
|
assert.match(styles, /\.pgp-keys-modal \.attachment-list\{grid-template-columns:minmax\(0,1fr\)\}/);
|
|
assert.match(styles, /\.pgp-keys-modal \.attachment-row-info\{flex:1 0 100%\}/);
|
|
assert.match(styles, /\.pgp-keys-modal \.attachment-row-info small\{[^}]*white-space:normal;overflow-wrap:anywhere/);
|
|
assert.match(styles, /\.pgp-keys-modal \.pgp-actions\{flex-wrap:wrap\}/);
|
|
});
|
|
|
|
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(androidBridge, /setAppLockDelay/);
|
|
assert.match(productivity, /Lock when leaving ep-mail/);
|
|
assert.match(productivity, /app-lock-delay/);
|
|
assert.match(mainActivity, /postDelayed\(delayedAppLock/);
|
|
assert.match(mainActivity, /FLAG_SECURE/);
|
|
});
|
|
|
|
test('Android private-key picker preserves WebView restrictions and checks app lock', () => {
|
|
assert.match(plugin, /fun pickPgpPrivateKey\(call: PluginCall\)/);
|
|
assert.match(plugin, /AndroidAccountVault\.appLockEnabled\(\)/);
|
|
assert.match(plugin, /Intent\.ACTION_OPEN_DOCUMENT/);
|
|
assert.match(plugin, /uri\.scheme != "content"/);
|
|
assert.match(plugin, /BoundedInputReader\.read\(it, 200001\)/);
|
|
assert.match(plugin, /bytes\.isEmpty\(\) \|\| bytes\.size > 200000/);
|
|
});
|
|
|
|
test('Android biometric PGP unlock keeps secrets behind an authentication-bound Keystore key', () => {
|
|
assert.match(plugin, /fun setPgpBiometricUnlock/);
|
|
assert.match(plugin, /fun getPgpBiometricPassphrase/);
|
|
assert.match(plugin, /fun removePgpBiometricUnlock/);
|
|
assert.match(plugin, /fun pgpBiometricUnlockEnabled/);
|
|
assert.match(mainActivity, /authenticatePgpCipher/);
|
|
assert.match(mainActivity, /pgpAuthInProgress/);
|
|
assert.match(biometricUnlock, /setUserAuthenticationRequired\(true\)/);
|
|
assert.match(biometricUnlock, /setUserAuthenticationParameters/);
|
|
assert.match(vault, /pgpBiometricUnlocks/);
|
|
assert.match(vault, /removedFingerprints\.forEach/);
|
|
assert.match(androidPgp, /enableBiometricUnlock/);
|
|
assert.match(androidPgp, /getPgpBiometricPassphrase/);
|
|
assert.match(pgpMailUi, /BIOMETRIC_INVALIDATED/);
|
|
});
|
|
|
|
test('Android full local-data deletion is explicit, scoped, and clears stored web data', () => {
|
|
assert.match(productivity, /Delete all local data/);
|
|
assert.match(androidBridge, /deleteAllLocalData/);
|
|
assert.match(plugin, /fun deleteAllLocalData/);
|
|
assert.match(plugin, /setPositiveButton\("Delete all data"\)/);
|
|
assert.match(vault, /fun wipe\(\)/);
|
|
assert.match(androidMailService, /fun deleteSavedAttachments/);
|
|
assert.match(androidMailService, /isAppOwnedDownload/);
|
|
assert.match(androidMailService, /BoundedInputReader\.read\(it, 5 \* 1048576 \+ 1\)/);
|
|
assert.match(androidMailService, /BoundedInputReader\.read\(it, 100001\)/);
|
|
assert.match(androidMailService, /saveAttachmentStream/);
|
|
assert.match(boundedInputReader, /while \(output\.size\(\) < maxBytes\)/);
|
|
assert.match(mainActivity, /clearLocalWebData/);
|
|
assert.match(productivity, /getRegistrations\(\)/);
|
|
assert.match(productivity, /caches\.delete\(name\)/);
|
|
});
|
|
|
|
test('Android WebView CSP, manifest, navigation, and DAV transport stay constrained', () => {
|
|
const csp = /http-equiv="Content-Security-Policy" content="([^"]+)"/i.exec(index)?.[1] || '';
|
|
assert.match(csp, /default-src 'self'/);
|
|
assert.match(csp, /script-src 'self'/);
|
|
assert.match(csp, /connect-src 'none'/);
|
|
assert.match(csp, /frame-src 'none'/);
|
|
assert.match(csp, /object-src 'none'/);
|
|
assert.match(csp, /base-uri 'none'/);
|
|
assert.match(csp, /form-action 'none'/);
|
|
assert.doesNotMatch(csp, /script-src[^;]*unsafe-inline/i);
|
|
assert.match(manifest, /android:allowBackup="false"/);
|
|
assert.match(manifest, /android:usesCleartextTraffic="false"/);
|
|
assert.doesNotMatch(manifest, /READ_EXTERNAL_STORAGE|WRITE_EXTERNAL_STORAGE|MANAGE_EXTERNAL_STORAGE|REQUEST_INSTALL_PACKAGES/);
|
|
assert.match(plugin, /Only standard web links can be opened from mail/);
|
|
assert.match(plugin, /uri\.scheme\?\.lowercase\(Locale\.ROOT\) !in setOf\("http", "https"\)/);
|
|
assert.match(davService, /followRedirects\(false\)/);
|
|
assert.match(davService, /followSslRedirects\(false\)/);
|
|
assert.match(davService, /DavUrlPolicy\.requireSameOrigin/);
|
|
});
|
|
|
|
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, /AndroidPgpPolicy\.unverifiedRawMimeWarning\(\)/);
|
|
assert.match(plugin, /title = if \(rawMime\) "Send unverified MIME\?"/);
|
|
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(androidPgpPolicy, /fun unverifiedRawMimeWarning/);
|
|
assert.match(androidPgp, /curve25519Legacy/);
|
|
assert.match(androidPgp, /These recipient keys have not been verified by fingerprint/);
|
|
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(plugin, /PgpMessageUid\.requireValid\(call\.data\.opt\("uid"\)\)/);
|
|
assert.match(androidBridge, /rawBase64, envelope: \{ from, to \}, text: '', attachments: \[\]/);
|
|
assert.match(androidMailService, /validateOpenPgpMime\(message\)/);
|
|
assert.match(androidMailService, /internal 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/);
|
|
});
|