From 46217d1fc736a770b7cce80ab6fcd9f1308609a1 Mon Sep 17 00:00:00 2001 From: Matheus Alcantara Date: Tue, 16 Nov 2021 11:28:03 -0300 Subject: [PATCH] vulnhash: improvement tests asserts Previously the testcases of vulnhash package does not assert the generated hash using all the fields used to generate the hash. This commit change the testcases to assert the generated hash with all fields filled. The testcase also was change to assert the valid and invalid generated hash Updates #718 Signed-off-by: Matheus Alcantara --- internal/utils/vuln_hash/vuln_hash_test.go | 33 ++++++++-------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/internal/utils/vuln_hash/vuln_hash_test.go b/internal/utils/vuln_hash/vuln_hash_test.go index 220108b3c..c0ef563f6 100644 --- a/internal/utils/vuln_hash/vuln_hash_test.go +++ b/internal/utils/vuln_hash/vuln_hash_test.go @@ -20,30 +20,21 @@ import ( "github.com/stretchr/testify/assert" "github.com/ZupIT/horusec-devkit/pkg/entities/vulnerability" - "github.com/ZupIT/horusec-devkit/pkg/utils/crypto" ) func TestBind(t *testing.T) { - t.Run("should bind the vuln hash in VulnHash field", func(t *testing.T) { - vuln := &vulnerability.Vulnerability{ - Code: "test", - File: "test.go", - } - - vuln = Bind(vuln) - assert.NotEmpty(t, vuln.VulnHash) - }) - - t.Run("should generate the hash from Code and File attrs", func(t *testing.T) { - expected := crypto.GenerateSHA256("test", "test.go") - vuln := &vulnerability.Vulnerability{ - Code: "test", - File: "test.go", - } - - vuln = Bind(vuln) - assert.Equal(t, expected, vuln.VulnHash) - }) + vuln := vulnerability.Vulnerability{ + Code: `fmt.Println("testing")`, + Line: "10", + Details: "testing", + File: "main.go", + CommitEmail: "foo@bar", + } + + Bind(&vuln) + + assert.Equal(t, "278facfff87828631a37b27d76d1a926bed37466b05cab7d365d7f5c7345ac6d", vuln.VulnHash) + assert.Equal(t, "751cf1c4e4f0fbf59777eea1d14c062b913a57fd3c0e457400ec134577c89686", vuln.VulnHashInvalid) } func TestToOneLine(t *testing.T) {