mirror of
https://github.com/safedep/pmg.git
synced 2026-08-03 07:24:09 +02:00
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:
@@ -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)
|
||||
}
|
||||
Reference in New Issue
Block a user