Plugins: Skip angular check for CDN source (#113163)

This commit is contained in:
Todd Treece
2025-10-29 11:33:43 -04:00
committed by GitHub
parent 7eb8a9af99
commit 3bfbbb1961
2 changed files with 31 additions and 6 deletions
@@ -35,6 +35,11 @@ func NewPatternListInspector(detectorsProvider angulardetector.DetectorsProvider
} }
func (i *PatternsListInspector) Inspect(ctx context.Context, p *plugins.Plugin) (isAngular bool, err error) { func (i *PatternsListInspector) Inspect(ctx context.Context, p *plugins.Plugin) (isAngular bool, err error) {
// CDN plugins are ignored because they should not be using Angular
if p.Class == plugins.ClassCDN {
return false, nil
}
f, err := p.FS.Open("module.js") f, err := p.FS.Open("module.js")
if err != nil { if err != nil {
if errors.Is(err, plugins.ErrFileNotExist) { if errors.Is(err, plugins.ErrFileNotExist) {
@@ -27,17 +27,17 @@ func (d *fakeDetector) String() string {
} }
func TestPatternsListInspector(t *testing.T) { func TestPatternsListInspector(t *testing.T) {
plugin := &plugins.Plugin{
FS: plugins.NewInMemoryFS(map[string][]byte{"module.js": nil}),
}
for _, tc := range []struct { for _, tc := range []struct {
name string name string
plugin *plugins.Plugin
fakeDetectors []*fakeDetector fakeDetectors []*fakeDetector
exp func(t *testing.T, r bool, err error, fakeDetectors []*fakeDetector) exp func(t *testing.T, r bool, err error, fakeDetectors []*fakeDetector)
}{ }{
{ {
name: "calls the detectors in sequence until true is returned", name: "calls the detectors in sequence until true is returned",
plugin: &plugins.Plugin{
FS: plugins.NewInMemoryFS(map[string][]byte{"module.js": nil}),
},
fakeDetectors: []*fakeDetector{ fakeDetectors: []*fakeDetector{
{returns: false}, {returns: false},
{returns: true}, {returns: true},
@@ -53,6 +53,9 @@ func TestPatternsListInspector(t *testing.T) {
}, },
{ {
name: "calls the detectors in sequence and returns false as default", name: "calls the detectors in sequence and returns false as default",
plugin: &plugins.Plugin{
FS: plugins.NewInMemoryFS(map[string][]byte{"module.js": nil}),
},
fakeDetectors: []*fakeDetector{ fakeDetectors: []*fakeDetector{
{returns: false}, {returns: false},
{returns: false}, {returns: false},
@@ -65,13 +68,30 @@ func TestPatternsListInspector(t *testing.T) {
}, },
}, },
{ {
name: "empty detectors should return false", name: "empty detectors should return false",
plugin: &plugins.Plugin{
FS: plugins.NewInMemoryFS(map[string][]byte{"module.js": nil}),
},
fakeDetectors: nil, fakeDetectors: nil,
exp: func(t *testing.T, r bool, err error, fakeDetectors []*fakeDetector) { exp: func(t *testing.T, r bool, err error, fakeDetectors []*fakeDetector) {
require.NoError(t, err) require.NoError(t, err)
require.False(t, r, "inspector should return false") require.False(t, r, "inspector should return false")
}, },
}, },
{
name: "CDN plugins return false without calling detectors",
plugin: &plugins.Plugin{
Class: plugins.ClassCDN,
},
fakeDetectors: []*fakeDetector{
{returns: true},
},
exp: func(t *testing.T, r bool, err error, fakeDetectors []*fakeDetector) {
require.NoError(t, err)
require.False(t, r, "inspector should return false for CDN plugins")
require.Equal(t, 0, fakeDetectors[0].calls, "detectors should not be called for CDN plugins")
},
},
} { } {
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
detectors := make([]angulardetector.AngularDetector, 0, len(tc.fakeDetectors)) detectors := make([]angulardetector.AngularDetector, 0, len(tc.fakeDetectors))
@@ -79,7 +99,7 @@ func TestPatternsListInspector(t *testing.T) {
detectors = append(detectors, angulardetector.AngularDetector(d)) detectors = append(detectors, angulardetector.AngularDetector(d))
} }
inspector := NewPatternListInspector(&angulardetector.StaticDetectorsProvider{Detectors: detectors}) inspector := NewPatternListInspector(&angulardetector.StaticDetectorsProvider{Detectors: detectors})
r, err := inspector.Inspect(context.Background(), plugin) r, err := inspector.Inspect(context.Background(), tc.plugin)
tc.exp(t, r, err, tc.fakeDetectors) tc.exp(t, r, err, tc.fakeDetectors)
}) })
} }