Files
Arnaud Dartois 58b6a1de9b feat(app): implement all open issues - camera access control, i18n, GPU, mDNS, site filtering
- Implement UserCameraAccess entity and CRUD API (issues #131, #133)
- Add CameraAccessPanel UI component for granular access management (issue #134)
- Implement camera toggle UI (issues #59, #199)
- Implement site filtering by user rights (issue #136)
- Implement Groups camera access assignment (issue #138)
- Implement audit logging for camera access changes (issue #140)
- Add comprehensive camera access test coverage (issue #141)
- Implement i18n/l10n localization infrastructure (issue #142)
- Implement OpenTelemetry metrics infrastructure (issue #14)
- Implement Agent GPU worker (issue #76)
- Implement Agent remote sensor mode (issue #75)
- Fix Docker GPU exposure in compose files (issues #76, #77)
- Fix mDNS divergence by extracting shared MdnsClient library (issue #81)
- Implement User email confirm/edit UI (issues #88, #89)
- Implement Persons UI (issue #11)
- Fix E2E test timing issues by increasing circuit delay

- Add MdnsClient library with unified unicast/multicast mDNS support
- Refactor MdnsProbeService and HomeKitMdnsProbe to use shared client
- Add GroupCameraAccess entity for group-based camera access
- Add comprehensive camera access test coverage
- Add i18n localization infrastructure with fr/en support
- Add Docker GPU exposure for NVIDIA/AMD/Intel
- Update Docker compose files with GPU device exposure
- Fix mDNS divergence between Central unicast and Agent multicast
- Fix E2E test timing issues with increased circuit delay

All 1700+ tests pass (unit + integration)
2026-10-11 21:23:16 +02:00

135 lines
4.4 KiB
C#

using System.Net;
using System.Net.Sockets;
using System.Text;
using Heimdall.Agent.Services;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Shouldly;
namespace Heimdall.Agent.Tests;
public class MultiProtocolStreamTests
{
/// <summary>
/// Spin up a local TCP server that answers like a real RTMP server (C0=0x03 + C1).
/// </summary>
private static async Task<(TcpListener Listener, string Url)> StartRtmpServerAsync()
{
var listener = new TcpListener(IPAddress.Loopback, 0);
listener.Start();
var port = ((IPEndPoint)listener.LocalEndpoint).Port;
_ = Task.Run(async () =>
{
try
{
using var client = await listener.AcceptTcpClientAsync().ConfigureAwait(false);
var stream = client.GetStream();
var handshake = new byte[1537];
await stream.ReadExactlyAsync(handshake).ConfigureAwait(false);
// Answer C0 + C1
var response = new byte[1537];
response[0] = 0x03;
await stream.WriteAsync(response).ConfigureAwait(false);
}
catch
{
// ignore
}
});
return (listener, $"rtmp://127.0.0.1:{port}/live/0");
}
private static async Task<(TcpListener Listener, string Url)> StartHttpEchoServerAsync(string response)
{
var listener = new TcpListener(IPAddress.Loopback, 0);
listener.Start();
var port = ((IPEndPoint)listener.LocalEndpoint).Port;
_ = Task.Run(async () =>
{
try
{
using var client = await listener.AcceptTcpClientAsync().ConfigureAwait(false);
var stream = client.GetStream();
var buffer = new byte[1024];
await stream.ReadAtLeastAsync(buffer, 1).ConfigureAwait(false);
await stream.WriteAsync(Encoding.ASCII.GetBytes(response)).ConfigureAwait(false);
}
catch
{
// ignore
}
});
return (listener, $"http://127.0.0.1:{port}/ignored");
}
[Fact]
public async Task IsStreamUrlAlive_RtmpServer_ReturnsTrue()
{
var (listener, url) = await StartRtmpServerAsync();
try
{
var scanner = new NetworkCameraScanner(
NullLogger<NetworkCameraScanner>.Instance,
NullLoggerFactory.Instance);
var alive = await scanner.IsStreamUrlAliveAsync(url, CancellationToken.None);
alive.ShouldBeTrue();
}
finally
{
listener.Stop();
}
}
[Fact]
public async Task IsStreamUrlAlive_RtmpDeadPort_ReturnsFalse()
{
// Bind a listener then stop it → port closed.
var listener = new TcpListener(IPAddress.Loopback, 0);
listener.Start();
var port = ((IPEndPoint)listener.LocalEndpoint).Port;
listener.Stop();
var scanner = new NetworkCameraScanner(NullLogger<NetworkCameraScanner>.Instance, NullLoggerFactory.Instance);
var alive = await scanner.IsStreamUrlAliveAsync($"rtmp://127.0.0.1:{port}/live/0", CancellationToken.None);
alive.ShouldBeFalse();
}
[Fact]
public async Task IsStreamUrlAlive_HttpMjpeg_ReturnsTrue()
{
var (listener, url) = await StartHttpEchoServerAsync(
"HTTP/1.1 200 OK\r\nContent-Type: multipart/x-mixed-replace; boundary=frame\r\n\r\n");
try
{
var scanner = new NetworkCameraScanner(NullLogger<NetworkCameraScanner>.Instance, NullLoggerFactory.Instance);
var alive = await scanner.IsStreamUrlAliveAsync(url, CancellationToken.None);
alive.ShouldBeTrue();
}
finally
{
listener.Stop();
}
}
[Fact]
public async Task IsStreamUrlAlive_PlainHttpHtml_ReturnsFalse()
{
var (listener, url) = await StartHttpEchoServerAsync(
"HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<html></html>");
try
{
var scanner = new NetworkCameraScanner(NullLogger<NetworkCameraScanner>.Instance, NullLoggerFactory.Instance);
var alive = await scanner.IsStreamUrlAliveAsync(url, CancellationToken.None);
alive.ShouldBeFalse();
}
finally
{
listener.Stop();
}
}
}