Files
pmg/proxy/interceptors/audit_logger_test.go
Sahil BansalandGitHub 5b0517f92a add event type & logging interceptor for unknown hosts (#157)
* add event type & logging interceptor for unknown hosts

* update logging

* add break

* rename host_observation interceptor to audit_logger

* restore MITMDecider and make AuditLogger telemetry skip MITM on CONNECT
2026-02-12 13:48:01 +05:30

45 lines
1.0 KiB
Go

package interceptors
import (
"net/http"
"testing"
"github.com/safedep/pmg/proxy"
"github.com/stretchr/testify/assert"
)
func TestAuditLoggerInterceptor_Behavior(t *testing.T) {
i := NewAuditLoggerInterceptor()
assert.Equal(t, "audit-logger-interceptor", i.Name())
assert.True(t, i.ShouldIntercept(nil))
assert.False(t, i.ShouldMITM(nil))
}
func TestAuditLoggerInterceptor_KnownRegistryHost(t *testing.T) {
i := NewAuditLoggerInterceptor()
resp, err := i.HandleRequest(&proxy.RequestContext{
Hostname: "registry.npmjs.org",
Method: http.MethodConnect,
})
assert.NoError(t, err)
assert.NotNil(t, resp)
assert.Equal(t, proxy.ActionAllow, resp.Action)
}
func TestAuditLoggerInterceptor_UnknownHost(t *testing.T) {
i := NewAuditLoggerInterceptor()
resp, err := i.HandleRequest(&proxy.RequestContext{
Hostname: "unknown.example.test",
Method: http.MethodConnect,
RequestID: "req-unknown",
})
assert.NoError(t, err)
assert.NotNil(t, resp)
assert.Equal(t, proxy.ActionAllow, resp.Action)
}