import test from 'node:test'; import assert from 'node:assert/strict'; import { installationURL } from '../src/server/config'; import { installGuideData } from '../src/server/services/install-guide'; test('installation URLs require a valid HTTP(S) platform destination', () => { assert.equal(installationURL(' https://apps.apple.com/app/id123?campaign=site '), 'https://apps.apple.com/app/id123?campaign=site'); assert.equal(installationURL('http://downloads.example/app.apk'), 'http://downloads.example/app.apk'); for (const value of ['', '/download-app/', '//downloads.example/app', 'javascript:alert(1)', 'data:text/html,test', 'file:///tmp/app.apk', 'vbscript:foo', 'huakui://open', 'https://user:password@example.com/', 'https://example.com/\napp.apk']) assert.equal(installationURL(value), '', value); }); test('deep links allow universal links and app schemes while rejecting executable protocols', () => { assert.equal(installationURL('huakui://open/home', true), 'huakui://open/home'); assert.equal(installationURL('https://app.example/open', true), 'https://app.example/open'); for (const value of ['javascript://alert(1)', 'JaVaScRiPt:alert(1)', 'data://text/html,test', 'file://localhost/etc/passwd', 'vbscript://execute', 'blob://test', 'about://blank', 'chrome://settings', 'huakui:open', 'not a URL']) assert.equal(installationURL(value, true), '', value); }); test('unconfigured installation capabilities retain backend AppAddr and truthful fallback state', () => { const empty = { iosStoreURL: '', iosProfileURL: '', androidAPKURL: '', deepLinkURL: '' }; const data = installGuideData('https://download.example/real-backend-page', empty); assert.equal(data.iosStoreURL, data.fallbackURL); assert.equal(data.iosProfileURL, data.fallbackURL); assert.equal(data.androidAPKURL, data.fallbackURL); assert.equal(data.fallbackURL, 'https://download.example/real-backend-page'); assert.equal(data.hasIOSStore, false); assert.equal(data.hasIOSProfile, false); assert.equal(data.hasAndroidAPK, false); assert.equal(data.deepLinkURL, ''); assert.equal(installGuideData(undefined, empty).fallbackURL, '/app/download/'); }); test('each configured installation capability replaces only its own fallback', () => { const data = installGuideData('https://download.example/', { iosStoreURL: 'https://apps.apple.com/app/id123', iosProfileURL: '', androidAPKURL: 'https://download.example/app.apk', deepLinkURL: 'huakui://open' }); assert.equal(data.iosStoreURL, 'https://apps.apple.com/app/id123'); assert.equal(data.hasIOSStore, true); assert.equal(data.iosProfileURL, 'https://download.example/'); assert.equal(data.hasIOSProfile, false); assert.equal(data.androidAPKURL, 'https://download.example/app.apk'); assert.equal(data.hasAndroidAPK, true); assert.equal(data.deepLinkURL, 'huakui://open'); });