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
This commit is contained in:
Sahil Bansal
2026-02-12 13:48:01 +05:30
committed by GitHub
parent 7fe9fc8763
commit 5b0517f92a
7 changed files with 177 additions and 7 deletions
+44
View File
@@ -0,0 +1,44 @@
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)
}