feat(sub): add Incy app-management parameters (#6650)

* feat(sub): add Incy app-management parameters

The panel already pushes a set of Happ headers, but INCY documents its own
lowercase header names and its own value domains, so a Happ-shaped payload gets
ignored by the client (per-app mode is bypass|proxy, not on|bypass, and
per-app-proxy-enable has no Happ counterpart at all). Add a sibling Incy path
that emits exactly the documented headers.

Covered, per https://docs.incy.cc/en/app-management/:
- profile-description, sort-order, support-email, announce-url, premium-url
- banner text/button/URL and the two hex colours
- hide-url, hide-check, no-limit-enabled
- per-app split tunnelling (enable/mode/list)
- TCP fragmentation (enable/length/interval/packets)
- UDP noise packets (enable/type/packet/delay)
- DoH pre-resolution (enable/domain/IP)

Each string setting is tri-state: an empty value omits the header, so an
untouched panel never overrides the subscriber's own choice in the app. Values
are validated against the documented domains and dropped when they do not
match, and non-ASCII text is base64-wrapped the way the docs require for
Cyrillic. INCY identifies itself as INCY/<version>/<platform>, which gates the
headers behind the same auto-detect switch the Happ path uses.

Headers the panel already emits for every client (Profile-Title, Support-Url,
Profile-Web-Page-Url, Announce, Profile-Update-Interval, Subscription-Userinfo)
and Incy's routing line are left as they are.

The Premium API (theme, defaultPingProtocol, fallbackHosts, ...) is a separate
encrypted endpoint and stays out of scope here.

* fix(sub): keep Incy per-app list entries separate on the wire

The Incy settings textarea takes one package per line, as Incy documents for
per-app-proxy-list, but the header path ran the value through
sanitizeHeaderValue, which deletes CR/LF. "com.google.chrome\norg.telegram.messenger"
reached the client as the single bogus package
"com.google.chromeorg.telegram.messenger", so per-app split tunnelling silently
matched no app. Join comma- or line-separated entries as CSV instead.

Also drop three tests that could not fail: TestIncyExcludesHappOnlyHeaders
(ApplyIncyHeaders has no path that emits Happ headers, and the non-Happ UA
gate is already pinned by TestApplyHappHeaders_Gating) and two UI tests that
only asserted updateSetting received the key the JSX passes it.

---------

Co-authored-by: DIMFLIX <dimflix@users.noreply.github.com>
Co-authored-by: MHSanaei <ho3ein.sanaei@gmail.com>
This commit is contained in:
DIMFLIX
2026-09-27 02:06:17 +03:00
committed by GitHub
parent bd9ccde1f4
commit 71e38367c1
30 changed files with 2994 additions and 37 deletions
@@ -0,0 +1,84 @@
import { describe, expect, it, vi } from 'vitest';
import { fireEvent } from '@testing-library/react';
import IncySettingsContent from '@/pages/settings/IncySettingsContent';
import { AllSetting } from '@/models/setting';
import { renderWithProviders } from './test-utils';
function openTab(name: string) {
const tab = Array.from(document.querySelectorAll('.ant-tabs-tab')).find((t) =>
(t.textContent ?? '').includes(name),
);
if (!tab) throw new Error(`tab '${name}' not found`);
fireEvent.click(tab);
}
function settingRow(title: string): HTMLElement {
const row = Array.from(document.querySelectorAll('li,div[class*="setting"]')).find((r) =>
(r.textContent ?? '').includes(title),
);
if (!row) throw new Error(`setting row '${title}' not found`);
return row as HTMLElement;
}
function selectFor(title: string): HTMLElement {
const select = settingRow(title).querySelector('.ant-select');
if (!select) throw new Error(`select for '${title}' not found`);
return select as HTMLElement;
}
function selectOption(title: string, option: string) {
const select = selectFor(title);
fireEvent.mouseDown(select.querySelector('.ant-select-selector') ?? select);
const match = Array.from(document.querySelectorAll('.ant-select-item-option')).find(
(o) => (o.textContent ?? '').trim() === option,
);
if (!match) throw new Error(`option '${option}' for '${title}' not found`);
fireEvent.click(match);
}
function render(subIncy: Partial<AllSetting> = {}) {
const updateSetting = vi.fn();
const allSetting = Object.assign(new AllSetting(), subIncy);
renderWithProviders(
<IncySettingsContent
allSetting={allSetting}
updateSetting={updateSetting}
isMobile={false}
remoteSourceBadge={() => null}
/>,
);
return updateSetting;
}
describe('Incy app-management settings', () => {
// Every Incy switch and enum is tri-state: "Not set" must store the empty
// value so the panel sends no header and the subscriber's app choice wins.
it('stores the empty value for "Not set" so no header is emitted', () => {
const updateSetting = render({ subIncySortOrder: 'ping' });
openTab('App');
selectOption('Server sort order', 'Not set');
expect(updateSetting).toHaveBeenCalledWith({ subIncySortOrder: '' });
});
it('sends the documented per-app literal, not the Happ on/include spelling', () => {
const updateSetting = render();
openTab('Privacy');
selectOption('Per-app mode (Android)', 'On');
expect(updateSetting).toHaveBeenCalledWith({ subIncyPerAppEnable: '1' });
});
it('offers bypass and proxy for the per-app mode', () => {
const updateSetting = render();
openTab('Privacy');
selectOption('Per-app mode type', 'Listed apps bypass');
expect(updateSetting).toHaveBeenCalledWith({ subIncyPerAppMode: 'bypass' });
});
});