Skip to content

Commit

Permalink
Improve Audit result table views
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Sverdlov <[email protected]>
  • Loading branch information
sverdlov93 committed Aug 30, 2023
1 parent a1be5ea commit 1d25d71
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
10 changes: 5 additions & 5 deletions utils/tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions xray/audit/commonutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions xray/audit/npm/npm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 1d25d71

Please sign in to comment.