feat(cli): add verbose logging option for CLI commands
Some checks failed
CI / build-and-test (push) Failing after -32m43s
Some checks failed
CI / build-and-test (push) Failing after -32m43s
* Introduced a new flag `--verbose` to enable detailed logging. * Implemented logging for connection events in SSE and stdio commands. * Added a utility function to handle verbose logging.
This commit is contained in:
47
internal/requestip/requestip_test.go
Normal file
47
internal/requestip/requestip_test.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package requestip
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFromRequestPrefersXRealIP(t *testing.T) {
|
||||
req := httptest.NewRequest(http.MethodGet, "/", nil)
|
||||
req.RemoteAddr = "10.0.0.10:5555"
|
||||
req.Header.Set("X-Forwarded-Host", "proxy.example.com")
|
||||
req.Header.Set("X-Real-IP", "203.0.113.10")
|
||||
|
||||
if got := FromRequest(req); got != "203.0.113.10" {
|
||||
t.Fatalf("FromRequest() = %q, want %q", got, "203.0.113.10")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFromRequestUsesXForwardedHostWhenRealIPMissing(t *testing.T) {
|
||||
req := httptest.NewRequest(http.MethodGet, "/", nil)
|
||||
req.RemoteAddr = "10.0.0.10:5555"
|
||||
req.Header.Set("X-Forwarded-Host", "203.0.113.22")
|
||||
|
||||
if got := FromRequest(req); got != "203.0.113.22" {
|
||||
t.Fatalf("FromRequest() = %q, want %q", got, "203.0.113.22")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFromRequestUsesXForwardedForFirstValue(t *testing.T) {
|
||||
req := httptest.NewRequest(http.MethodGet, "/", nil)
|
||||
req.RemoteAddr = "10.0.0.10:5555"
|
||||
req.Header.Set("X-Forwarded-For", "198.51.100.7, 10.1.1.2")
|
||||
|
||||
if got := FromRequest(req); got != "198.51.100.7" {
|
||||
t.Fatalf("FromRequest() = %q, want %q", got, "198.51.100.7")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFromRequestFallsBackToRemoteAddr(t *testing.T) {
|
||||
req := httptest.NewRequest(http.MethodGet, "/", nil)
|
||||
req.RemoteAddr = "192.0.2.5:1234"
|
||||
|
||||
if got := FromRequest(req); got != "192.0.2.5" {
|
||||
t.Fatalf("FromRequest() = %q, want %q", got, "192.0.2.5")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user