test(signserver): push coverage from 62.9% to 70.3%

Add handlePacket dispatch tests for all switch cases (DSGN, SIGN,
DLTSKEYSIGN, PS4SGN, PS3SGN, VITASGN, WIIUSGN, COGLNK, VITACOGLNK,
DELETE). Add makeSignResponse branch tests covering PSN client PSNID
field, CapLink key/host paths, MezFes minigame switch, non-localhost
remote addr, and PSN token registration. Add startSignCapture
enabled-path tests with temp dir and default output dir.
This commit is contained in:
Houmgaor
2026-02-27 13:07:12 +01:00
parent 3ad2836088
commit 156b5c53f7
4 changed files with 624 additions and 1 deletions

View File

@@ -2,6 +2,7 @@ package signserver
import (
"net"
"os"
"testing"
cfg "erupe-ce/config"
@@ -80,3 +81,76 @@ func TestStartSignCapture_EnabledButSignDisabled(t *testing.T) {
}
cleanup()
}
func TestStartSignCapture_EnabledSuccess(t *testing.T) {
outputDir := t.TempDir()
server := &Server{
logger: zap.NewNop(),
erupeConfig: &cfg.Config{
Host: "127.0.0.1",
Sign: cfg.Sign{Port: 53312},
Capture: cfg.CaptureOptions{
Enabled: true,
CaptureSign: true,
OutputDir: outputDir,
},
},
}
mc := newMockConn()
origConn := network.NewCryptConn(mc, cfg.ZZ, nil)
remoteAddr := &net.TCPAddr{IP: net.ParseIP("127.0.0.1"), Port: 12345}
resultConn, cleanup := startSignCapture(server, origConn, remoteAddr)
defer cleanup()
if resultConn == origConn {
t.Error("startSignCapture() enabled should return a different (recording) conn")
}
}
func TestStartSignCapture_DefaultOutputDir(t *testing.T) {
// Use a temp dir as working directory to avoid polluting the project
origDir, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
tmpDir := t.TempDir()
if err := os.Chdir(tmpDir); err != nil {
t.Fatal(err)
}
defer func() { _ = os.Chdir(origDir) }()
server := &Server{
logger: zap.NewNop(),
erupeConfig: &cfg.Config{
Host: "127.0.0.1",
Sign: cfg.Sign{Port: 53312},
Capture: cfg.CaptureOptions{
Enabled: true,
CaptureSign: true,
OutputDir: "", // empty → should default to "captures"
},
},
}
mc := newMockConn()
origConn := network.NewCryptConn(mc, cfg.ZZ, nil)
remoteAddr := &net.TCPAddr{IP: net.ParseIP("127.0.0.1"), Port: 12345}
resultConn, cleanup := startSignCapture(server, origConn, remoteAddr)
defer cleanup()
if resultConn == origConn {
t.Error("startSignCapture() with default dir should return recording conn")
}
// Verify the "captures" directory was created
info, err := os.Stat("captures")
if err != nil {
t.Fatalf("default 'captures' directory not created: %v", err)
}
if !info.IsDir() {
t.Error("'captures' should be a directory")
}
}