Files
iptvnator/apps/electron-backend-e2e/src/stalker-playback-headers.e2e.ts
T
4grayandClaude Fable 5 c2d1bff89d fix(playback): apply header override to Stalker radio, redact mock cookie log
Address Codex review feedback on #1335:

- The radio branch of the Stalker live layout renders the dedicated audio
  player, never WebPlayerViewComponent, so the resolved portal headers were
  built but never applied — an auth-gated radio stream still 403'd. The
  override sync is extracted into ElectronStreamHeadersService (single owner
  of the scoped override slot, with clear-only-while-owning semantics so a
  destroyed consumer cannot wipe a newer consumer's override), applied by
  WebPlayerViewComponent for video players and by the radio branch before
  the audio element gets its URL. The service feature-detects the bridge
  method so partial bridges behave like the PWA instead of throwing.
- The gated-stream mock no longer logs the raw Cookie header on 403 —
  presence only, matching the Authorization logging.
- The gated scenario now serves an audio fixture for radio create_link and
  the Electron e2e covers the radio path end-to-end (bare request 403s,
  built-in audio player advances past the gate).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-02 08:34:21 +02:00

149 lines
5.4 KiB
TypeScript

import {
addStalkerPortal,
closeElectronApp,
expect,
launchElectronApp,
resetMockServers,
stalkerMockServer,
test,
waitForStalkerCatalog,
} from './electron-test-fixtures';
/**
* End-to-end proof that a BUILT-IN player's media requests carry the portal
* credentials (mac cookie + Bearer token) — the root of the long-running
* "only VLC works" cluster (#849, #910, #732): the web players used to
* receive only User-Agent/Referer/Origin, so any stream gated on the portal
* session could never play inline.
*
* The mock's `gated-stream` scenario makes `create_link` return this
* server's own `/stream/gated/video.mp4`, which answers 403 unless the
* request presents the mac cookie AND the MAC's current access token. A unit
* test cannot show that a header reached the video element; playback
* advancing past that gate can only happen when the scoped Electron header
* override attached the credentials to the actual media request.
*/
const GATED_MAC = '00:1A:79:00:00:09';
const GATED_STREAM_URL = `${stalkerMockServer}/stream/gated/video.mp4`;
// The full-portal URL shape: the app handshakes and holds a Bearer token,
// which is exactly what the gated stream endpoint demands.
const FULL_PORTAL_URL = `${stalkerMockServer}/stalker_portal/server/load.php`;
test('@electron @stalker built-in player plays an auth-gated portal stream', async ({
dataDir,
request,
}) => {
await resetMockServers(request, ['stalker']);
// First prove the gate is real: a credential-less request is refused, so
// a green playback assertion below cannot be a permissive-mock artifact.
const bareResponse = await request.get(GATED_STREAM_URL);
expect(bareResponse.status()).toBe(403);
const app = await launchElectronApp(dataDir);
try {
await addStalkerPortal(app.mainWindow, {
macAddress: GATED_MAC,
portalUrl: FULL_PORTAL_URL,
});
await waitForStalkerCatalog(app.mainWindow);
// The portal lands on Movies; live playback lives in the ITV layout.
await app.mainWindow
.getByRole('link', { name: /live|itv/i })
.click();
await app.mainWindow.waitForURL(/stalker.*itv/);
// The ITV view renders channels only after a category is selected;
// index 0 is the "All channels" pseudo-category.
const categories = app.mainWindow.locator('.category-item');
await expect(categories.first()).toBeVisible({ timeout: 10_000 });
await categories.first().click();
const channels = app.mainWindow.locator(
'[data-test-id="channel-item"]'
);
await expect(channels.first()).toBeVisible({ timeout: 20_000 });
await channels.first().click();
const video = app.mainWindow
.locator('app-web-player-view video')
.first();
await expect(video).toBeVisible({ timeout: 15_000 });
// Advancing playback past the 403 gate is only possible when the
// media requests carried the portal cookie and Authorization header.
await expect
.poll(
() =>
video.evaluate(
(element: HTMLVideoElement) => element.currentTime
),
{ timeout: 20_000 }
)
.toBeGreaterThan(0.5);
await expect(
app.mainWindow.getByTestId('playback-diagnostic-banner')
).toBeHidden();
} finally {
await closeElectronApp(app);
}
});
test('@electron @stalker built-in audio player plays an auth-gated radio stream', async ({
dataDir,
request,
}) => {
await resetMockServers(request, ['stalker']);
// The radio branch renders the dedicated audio player instead of
// WebPlayerViewComponent, so it exercises the Stalker live layout's own
// header wiring — a gap the ITV test above cannot catch.
const bareResponse = await request.get(
`${stalkerMockServer}/stream/gated/audio.mp4`
);
expect(bareResponse.status()).toBe(403);
const app = await launchElectronApp(dataDir);
try {
await addStalkerPortal(app.mainWindow, {
macAddress: GATED_MAC,
portalUrl: FULL_PORTAL_URL,
});
await waitForStalkerCatalog(app.mainWindow);
await app.mainWindow.getByRole('link', { name: /radio/i }).click();
await app.mainWindow.waitForURL(/stalker.*radio/);
const categories = app.mainWindow.locator('.category-item');
await expect(categories.first()).toBeVisible({ timeout: 10_000 });
await categories.first().click();
const channels = app.mainWindow.locator(
'[data-test-id="channel-item"]'
);
await expect(channels.first()).toBeVisible({ timeout: 20_000 });
await channels.first().click();
// The bare <audio> element renders zero-size (its UI is custom), so
// assert attachment rather than visibility.
const audio = app.mainWindow.locator('app-audio-player audio').first();
await expect(audio).toBeAttached({ timeout: 15_000 });
await expect
.poll(
() =>
audio.evaluate(
(element: HTMLAudioElement) => element.currentTime
),
{ timeout: 20_000 }
)
.toBeGreaterThan(0.5);
} finally {
await closeElectronApp(app);
}
});