diff --git a/utils/tests/utils.go b/utils/tests/utils.go index 0b8acfe3f..3211255bb 100644 --- a/utils/tests/utils.go +++ b/utils/tests/utils.go @@ -125,15 +125,15 @@ func compare(expected, actual []string) error { } // CompareTree returns true iff the two trees contain the same nodes (regardless of their order) -func CompareTree(a, b *xrayUtils.GraphNode) bool { - if a.Id != b.Id { +func CompareTree(expected, actual *xrayUtils.GraphNode) bool { + if expected.Id != actual.Id { return false } // Make sure all children are equal, when order doesn't matter - for _, nodeA := range a.Nodes { + for _, expectedNode := range expected.Nodes { found := false - for _, nodeB := range b.Nodes { - if CompareTree(nodeA, nodeB) { + for _, actualNode := range actual.Nodes { + if CompareTree(expectedNode, actualNode) { found = true break } diff --git a/xray/audit/commonutils.go b/xray/audit/commonutils.go index 3a03fd309..807cff463 100644 --- a/xray/audit/commonutils.go +++ b/xray/audit/commonutils.go @@ -21,7 +21,7 @@ import ( "testing" ) -const maxUniqueAppearances = 5 +const maxUniqueAppearances = 10 func BuildXrayDependencyTree(treeHelper map[string][]string, nodeId string) (*xrayUtils.GraphNode, []string) { rootNode := &xrayUtils.GraphNode{ @@ -42,7 +42,7 @@ func populateXrayDependencyTree(currNode *xrayUtils.GraphNode, treeHelper map[st Nodes: []*xrayUtils.GraphNode{}, Parent: currNode, } - if (*dependencyAppearances)[childDepId] > maxUniqueAppearances || childNode.NodeHasLoop() { + if (*dependencyAppearances)[childDepId] >= maxUniqueAppearances || childNode.NodeHasLoop() { continue } currNode.Nodes = append(currNode.Nodes, childNode) diff --git a/xray/audit/npm/npm_test.go b/xray/audit/npm/npm_test.go index 51e3f1fde..a1bfdfcf9 100644 --- a/xray/audit/npm/npm_test.go +++ b/xray/audit/npm/npm_test.go @@ -76,12 +76,11 @@ func TestParseNpmDependenciesList(t *testing.T) { }}, {Id: "npm://next:12.0.10", Nodes: []*xrayUtils.GraphNode{ {Id: "npm://react-dom:18.2.0", Nodes: []*xrayUtils.GraphNode{ - {Id: "npm://react:18.2.0", Nodes: looseEnvifyJsTokens}, - {Id: "npm://loose-envify:1.4.0", Nodes: []*xrayUtils.GraphNode{{Id: "npm://js-tokens:4.0.0"}}}, - {Id: "npm://scheduler:0.23.0", Nodes: looseEnvifyJsTokens}}}, + {Id: "npm://react:18.2.0"}, + {Id: "npm://scheduler:0.23.0"}}}, {Id: "npm://styled-jsx:5.0.0"}, {Id: "npm://@next/swc-darwin-arm64:12.0.10"}, - {Id: "npm://react:18.2.0", Nodes: looseEnvifyJsTokens}, + {Id: "npm://react:18.2.0"}, {Id: "npm://@next/env:12.0.10"}, {Id: "npm://caniuse-lite:1.0.30001486"}, {Id: "npm://postcss:8.4.5", Nodes: []*xrayUtils.GraphNode{