mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-09-19 09:40:12 +00:00
36 lines
1.0 KiB
Go
36 lines
1.0 KiB
Go
//go:build !agentcompat
|
|
|
|
package rpc
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
|
|
"github.com/nezhahq/nezha/model"
|
|
"github.com/nezhahq/nezha/pkg/agentcompatcontract"
|
|
)
|
|
|
|
func TestPrepareNATCapabilityDefaultPreservesHeaderAsOrdinaryRequestData(t *testing.T) {
|
|
// Given
|
|
request := &http.Request{Header: make(http.Header)}
|
|
request.Header.Set(agentcompatcontract.IOStreamCapabilityHeader, "ordinary-data")
|
|
request.Header.Set("Authorization", "Bearer deterministic-secret")
|
|
|
|
// When
|
|
lease, err := prepareNATCapability(request, &model.NAT{Common: model.Common{ID: 91}, ServerID: 81})
|
|
|
|
// Then
|
|
if err != nil {
|
|
t.Fatalf("default NAT capability hook returned error: %v", err)
|
|
}
|
|
if lease.active {
|
|
t.Fatal("default NAT capability hook unexpectedly activated")
|
|
}
|
|
if got := request.Header.Get(agentcompatcontract.IOStreamCapabilityHeader); got != "ordinary-data" {
|
|
t.Fatalf("default NAT capability hook changed header to %q", got)
|
|
}
|
|
if got := request.Header.Get("Authorization"); got != "" {
|
|
t.Fatalf("default NAT capability hook retained Authorization %q", got)
|
|
}
|
|
}
|