105 lines
3.5 KiB
C#
105 lines
3.5 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Security.Cryptography;
|
|
using System.Threading.Tasks;
|
|
using Paca.Server;
|
|
using Paca.Server.Gateway;
|
|
using Xunit;
|
|
|
|
namespace Paca.Tests.Mobile;
|
|
|
|
/// <summary>
|
|
/// Gate 139 ~ 143: 백그라운드 게이트웨이 상주 서비스, 신뢰 기기 원클릭 페어링 핸드셰이크, Windows 시작 등록 규격 검증
|
|
/// </summary>
|
|
public class MobileGatewayDaemonAndHandshakeGateTests
|
|
{
|
|
[Fact]
|
|
public void Gate139_TrustedDevicesStore_Add_And_Authorize()
|
|
{
|
|
var store = new TrustedDevicesStore();
|
|
Assert.Empty(store.GetTrustedDevices());
|
|
|
|
var device = new TrustedDevice(
|
|
DeviceId: "device-uuid-99",
|
|
DeviceName: "Galaxy-S24-Ultra",
|
|
Fingerprint: "FP-GALAXY-99",
|
|
IsApproved: true,
|
|
RegisteredAt: DateTimeOffset.UtcNow,
|
|
LastSeenAt: DateTimeOffset.UtcNow
|
|
);
|
|
|
|
store.RegisterDevice(device);
|
|
Assert.Single(store.GetTrustedDevices());
|
|
Assert.True(store.IsDeviceTrusted("device-uuid-99"));
|
|
Assert.False(store.IsDeviceTrusted("unknown-device"));
|
|
}
|
|
|
|
[Fact]
|
|
public void Gate140_OneClickPairing_Handshake_Resolves_Token()
|
|
{
|
|
var store = new TrustedDevicesStore();
|
|
var handshakeEngine = new OneClickPairingEngine(store, serverToken: "MASTER-PACA-TOKEN-SECRET");
|
|
|
|
// 1. 신규 기기 핸드셰이크 요청 (페어링 허용 모드)
|
|
var req = new PairingHandshakeRequest(
|
|
ClientDeviceId: "client-phone-01",
|
|
ClientDeviceName: "iPhone 16 Pro",
|
|
ClientFingerprint: "FINGERPRINT-IPHONE",
|
|
IsOneClickRequest: true
|
|
);
|
|
|
|
var resp = handshakeEngine.ProcessHandshake(req, autoApproveNewLanClients: true);
|
|
Assert.NotNull(resp);
|
|
Assert.True(resp.Success);
|
|
Assert.Equal("MASTER-PACA-TOKEN-SECRET", resp.IssuedToken);
|
|
Assert.True(store.IsDeviceTrusted("client-phone-01"));
|
|
|
|
// 2. 신규 기기 등록 불허 모드에서는 거절
|
|
var req2 = new PairingHandshakeRequest(
|
|
ClientDeviceId: "untrusted-stranger",
|
|
ClientDeviceName: "Unknown-Device",
|
|
ClientFingerprint: "FP-UNKNOWN",
|
|
IsOneClickRequest: true
|
|
);
|
|
var resp2 = handshakeEngine.ProcessHandshake(req2, autoApproveNewLanClients: false);
|
|
Assert.NotNull(resp2);
|
|
Assert.False(resp2.Success);
|
|
Assert.Null(resp2.IssuedToken);
|
|
}
|
|
|
|
[Fact]
|
|
public void Gate141_GatewayStartupConfig_Command_Arguments()
|
|
{
|
|
var config = new GatewayStartupConfig(
|
|
RunOnWindowsStartup: true,
|
|
StartMinimizedToTray: true,
|
|
AutoPortForwarding: true,
|
|
HttpPort: 52100
|
|
);
|
|
|
|
var args = config.ToCommandLineArgs();
|
|
Assert.Contains("--gateway-daemon", args);
|
|
Assert.Contains("--tray", args);
|
|
Assert.Contains("--port 52100", args);
|
|
|
|
var parsed = GatewayStartupConfig.ParseArgs(args);
|
|
Assert.True(parsed.StartMinimizedToTray);
|
|
Assert.Equal(52100, parsed.HttpPort);
|
|
}
|
|
|
|
[Fact]
|
|
public void Gate142_GatewayDaemon_Heartbeat_And_Status()
|
|
{
|
|
var daemon = new PacaGatewayDaemonState(
|
|
DeviceName: "Encep-Studio-PC",
|
|
HttpPort: 52100,
|
|
LanBeaconActive: true,
|
|
WanGatewayActive: true,
|
|
ConnectCode: "PACA-982143"
|
|
);
|
|
|
|
Assert.True(daemon.IsOperational);
|
|
Assert.Equal("PACA-982143", daemon.ConnectCode);
|
|
Assert.Equal("http://localhost:52100", daemon.LocalEndpoint);
|
|
}
|
|
}
|