mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-22 07:32:32 +01:00
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:
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user