mirror of
https://github.com/safedep/pmg.git
synced 2026-08-03 07:24:09 +02:00
Skip mitm for unsupported registries (#185)
* implement mitm decider for npm * fix: Skip MITM for registries not supported for analysis
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
package interceptors
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/safedep/pmg/proxy"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNpmRegistryInterceptor_ShouldMITM(t *testing.T) {
|
||||
interceptor := NewNpmRegistryInterceptor(nil, nil, nil, nil)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
hostname string
|
||||
wantMITM bool
|
||||
}{
|
||||
{"public registry is MITM'd", "registry.npmjs.org", true},
|
||||
{"yarn registry is MITM'd", "registry.yarnpkg.com", true},
|
||||
{"github packages is NOT MITM'd", "npm.pkg.github.com", false},
|
||||
{"github blob storage is NOT MITM'd", "pkg-npm.githubusercontent.com", false},
|
||||
{"unknown registry is NOT MITM'd", "registry.example.com", false},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
ctx := &proxy.RequestContext{Hostname: tt.hostname}
|
||||
assert.Equal(t, tt.wantMITM, interceptor.ShouldMITM(ctx))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestNpmRegistryInterceptor_ShouldIntercept(t *testing.T) {
|
||||
interceptor := NewNpmRegistryInterceptor(nil, nil, nil, nil)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
hostname string
|
||||
wantIntercept bool
|
||||
}{
|
||||
{"public registry", "registry.npmjs.org", true},
|
||||
{"yarn registry", "registry.yarnpkg.com", true},
|
||||
{"github packages", "npm.pkg.github.com", true},
|
||||
{"github blob storage", "pkg-npm.githubusercontent.com", true},
|
||||
{"unknown registry", "registry.example.com", false},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
ctx := &proxy.RequestContext{Hostname: tt.hostname}
|
||||
assert.Equal(t, tt.wantIntercept, interceptor.ShouldIntercept(ctx))
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user