Skip to content

Commit

Permalink
vulnhash: improvement tests asserts (#775)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
matheusalcantarazup authored Nov 17, 2021
1 parent a309736 commit fe00272
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions internal/utils/vuln_hash/vuln_hash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit fe00272

Please sign in to comment.