Skip to content

Pre receive feature command (AST-89345) #1146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 54 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
e42cc3d
Moved to common hooks place
cx-anjali-deore May 16, 2025
d287c4b
removed common hooks code
cx-anjali-deore May 16, 2025
b302afc
Added pre receive commands
cx-anjali-deore May 16, 2025
f37bb27
Adding the commit version of secret detection
cx-anjali-deore May 16, 2025
93ec1ee
Added pre receive in Hooks doc
cx-anjali-deore May 19, 2025
d9aa18e
formatted
cx-anjali-deore May 19, 2025
7c493c2
typo changes
cx-anjali-deore May 21, 2025
1dfe755
formatted the file
cx-anjali-deore May 21, 2025
115655e
Adding secret detection to depgaurd allow list
cx-anjali-deore May 21, 2025
3da2035
removed whitespace
cx-anjali-deore May 23, 2025
67852a9
formatted with gofmt
cx-anjali-deore May 26, 2025
22452ff
indentation
cx-anjali-deore May 26, 2025
de8151b
indentation
cx-anjali-deore May 26, 2025
834ea6c
indentation
cx-anjali-deore May 26, 2025
9c5c8c5
url and formatting fixes
cx-anjali-deore May 27, 2025
53dc14a
indentation alignment
cx-anjali-deore May 27, 2025
1e8c4ae
Unit and integration tests
cx-anjali-deore Jun 2, 2025
0f5a3b4
lint issues fixed
cx-anjali-deore Jun 2, 2025
7cd195b
formatted unit test file
cx-anjali-deore Jun 2, 2025
d54f6bb
setting global config git
cx-anjali-deore Jun 2, 2025
9e1b19f
changing cx path
cx-anjali-deore Jun 2, 2025
5b10c5b
adjusting cx path
cx-anjali-deore Jun 2, 2025
f573902
check if cx path exist
cx-anjali-deore Jun 2, 2025
df5695c
check if cx path exist
cx-anjali-deore Jun 2, 2025
48339d1
added cxPath
cx-anjali-deore Jun 2, 2025
67a2ab8
Adding githubUser and email
cx-anjali-deore Jun 2, 2025
bdd2931
renaming functions
cx-anjali-deore Jun 3, 2025
9b1f99b
url and formatting fixes
cx-anjali-deore May 27, 2025
22e4b03
indentation alignment
cx-anjali-deore May 27, 2025
5e2b2cd
Unit and integration tests
cx-anjali-deore Jun 2, 2025
a717987
lint issues fixed
cx-anjali-deore Jun 2, 2025
34646d6
formatted unit test file
cx-anjali-deore Jun 2, 2025
2cd4dff
setting global config git
cx-anjali-deore Jun 2, 2025
aeb1fc7
changing cx path
cx-anjali-deore Jun 2, 2025
f12c04d
adjusting cx path
cx-anjali-deore Jun 2, 2025
df0845c
check if cx path exist
cx-anjali-deore Jun 2, 2025
7245ce8
check if cx path exist
cx-anjali-deore Jun 2, 2025
471c608
added cxPath
cx-anjali-deore Jun 2, 2025
69fbbd1
Adding githubUser and email
cx-anjali-deore Jun 2, 2025
85157f7
renaming functions
cx-anjali-deore Jun 3, 2025
63a975c
removed the git username
cx-anjali-deore Jun 3, 2025
3450218
using github actor
cx-anjali-deore Jun 3, 2025
50313d1
go mod file updated
cx-anjali-deore Jun 4, 2025
08ac679
Added additional tests for coverage
cx-anjali-deore Jun 10, 2025
1600a56
secret detection version upgrade
cx-anjali-deore Jun 16, 2025
7108369
degraded the version
cx-anjali-deore Jun 16, 2025
073ff3c
updegraded the version
cx-anjali-deore Jun 16, 2025
15c0d3e
updegraded the version
cx-anjali-deore Jun 16, 2025
0c23521
updegraded the version
cx-anjali-deore Jun 16, 2025
b53fb4f
updegraded the version
cx-anjali-deore Jun 16, 2025
c9c278e
Fix found vulnerabilities on trivy (#1192)
cx-margarita-levitm Jun 16, 2025
27fbb23
added latest version of secret detection 1.2.1
cx-anjali-deore Jun 17, 2025
59c87e2
added previous version
cx-anjali-deore Jun 17, 2025
212f21d
go mod tidy
cx-anjali-deore Jun 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ jobs:
BITBUCKET_USERNAME: ${{ secrets.BITBUCKET_USERNAME }}
BITBUCKET_PASSWORD: ${{ secrets.BITBUCKET_PASSWORD }}
GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }}
GITHUB_ACTOR: ${{ github.actor }}
PR_BITBUCKET_TOKEN: ${{ secrets.PR_BITBUCKET_TOKEN }}
PR_BITBUCKET_NAMESPACE: "AstSystemTest"
PR_BITBUCKET_REPO_NAME: "cliIntegrationTest"
Expand Down
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ linters-settings:
- github.com/CheckmarxDev/containers-resolver/pkg/containerResolver
- github.com/Checkmarx/manifest-parser/pkg/parser/models
- github.com/Checkmarx/manifest-parser/pkg/parser
- github.com/Checkmarx/secret-detection/pkg/hooks/pre-commit
- github.com/Checkmarx/secret-detection/pkg/hooks/pre-receive
- github.com/Checkmarx/gen-ai-prompts/prompts/sast_result_remediation
- github.com/spf13/viper
- github.com/checkmarx/2ms/v3/lib/reporting
Expand Down
7 changes: 3 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ require (
github.com/Checkmarx/gen-ai-prompts v0.0.0-20240807143411-708ceec12b63
github.com/Checkmarx/gen-ai-wrapper v1.0.2
github.com/Checkmarx/manifest-parser v0.0.9
github.com/Checkmarx/secret-detection v0.0.3-0.20250327150305-31c2c3be9edf
github.com/Checkmarx/secret-detection v1.2.1
github.com/MakeNowJust/heredoc v1.0.0
github.com/bouk/monkey v1.0.0
github.com/checkmarx/2ms/v3 v3.20.0
github.com/checkmarx/2ms/v3 v3.20.1
github.com/gofrs/flock v0.12.1
github.com/golang-jwt/jwt/v5 v5.2.2
github.com/gomarkdown/markdown v0.0.0-20241102151059-6bc1ffdc6e8c
Expand Down Expand Up @@ -85,7 +85,6 @@ require (
github.com/charmbracelet/x/ansi v0.8.0 // indirect
github.com/charmbracelet/x/cellbuf v0.0.13 // indirect
github.com/charmbracelet/x/term v0.2.1 // indirect
github.com/checkmarx/2ms v1.4.1-0.20250327145719-b78804cb08c7 // indirect
github.com/cloudflare/circl v1.6.1 // indirect
github.com/containerd/cgroups/v3 v3.0.5 // indirect
github.com/containerd/containerd v1.7.27 // indirect
Expand Down Expand Up @@ -127,7 +126,7 @@ require (
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.8 // indirect
github.com/github/go-spdx/v2 v2.3.2 // indirect
github.com/gitleaks/go-gitdiff v0.9.0 // indirect
github.com/gitleaks/go-gitdiff v0.9.1 // indirect
github.com/go-errors/errors v1.5.1 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.6.2 // indirect
Expand Down
14 changes: 6 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ github.com/Checkmarx/gen-ai-wrapper v1.0.2 h1:T6X40+4hYnwfDsvkjWs9VIcE6s1O+8DUu0
github.com/Checkmarx/gen-ai-wrapper v1.0.2/go.mod h1:xwRLefezwNNnRGu1EjGS6wNiR9FVV/eP9D+oXwLViVM=
github.com/Checkmarx/manifest-parser v0.0.9 h1:+H63riEKjhOuneTZ0eYzvwABHia04RZTuojtz2EJKz8=
github.com/Checkmarx/manifest-parser v0.0.9/go.mod h1:hh5FX5FdDieU8CKQEkged4hfOaSylpJzub8PRFXa4kA=
github.com/Checkmarx/secret-detection v0.0.3-0.20250327150305-31c2c3be9edf h1:lKiogedU3WzWBc/xI6Xj1BhX2Gp1QBJj8C+czY7CcaE=
github.com/Checkmarx/secret-detection v0.0.3-0.20250327150305-31c2c3be9edf/go.mod h1:mtAHOm1mHGh7MVu6JdYUyitANsLcHNLUTBIh9pTERNI=
github.com/Checkmarx/secret-detection v1.2.1 h1:Hzpz74dcN/L14Q86ARvPOZpKBnERzGTpy6sl1RXKOTo=
github.com/Checkmarx/secret-detection v1.2.1/go.mod h1:kbXbtIQisDdB/TNuV7r9HPclEznUyBHLQ5yr7IX7vBQ=
github.com/CycloneDX/cyclonedx-go v0.9.2 h1:688QHn2X/5nRezKe2ueIVCt+NRqf7fl3AVQk+vaFcIo=
github.com/CycloneDX/cyclonedx-go v0.9.2/go.mod h1:vcK6pKgO1WanCdd61qx4bFnSsDJQ6SbM2ZuMIgq86Jg=
github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7OputlJIzU=
Expand Down Expand Up @@ -217,10 +217,8 @@ github.com/charmbracelet/x/cellbuf v0.0.13 h1:/KBBKHuVRbq1lYx5BzEHBAFBP8VcQzJejZ
github.com/charmbracelet/x/cellbuf v0.0.13/go.mod h1:xe0nKWGd3eJgtqZRaN9RjMtK7xUYchjzPr7q6kcvCCs=
github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ=
github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg=
github.com/checkmarx/2ms v1.4.1-0.20250327145719-b78804cb08c7 h1:COsC3skOJeJaSoCPuhLZ0byRGKm+ZHlyw5qm9ydlab0=
github.com/checkmarx/2ms v1.4.1-0.20250327145719-b78804cb08c7/go.mod h1:Bnd2YSh8LQSc4fHAFN0BKz8LYThB6qHg3Wn/+H+WZ4I=
github.com/checkmarx/2ms/v3 v3.20.0 h1:dr3vSVUoYXwS40DUGR5ueXaPROKTkMs+9xAij2/vzUA=
github.com/checkmarx/2ms/v3 v3.20.0/go.mod h1:f5ZwVFEDBr8WRa/9aXluPnufi2wuq6tGWCROcW3CdbA=
github.com/checkmarx/2ms/v3 v3.20.1 h1:WJaC8XTbtFHJyGKTiUL/OokI9SCT91XKoMQ1dfc32/E=
github.com/checkmarx/2ms/v3 v3.20.1/go.mod h1:8VIXk2A6F9TfTP3nfH1yOI00aUfmMhEnBedvXusWu6w=
github.com/chromedp/cdproto v0.0.0-20230802225258-3cf4e6d46a89/go.mod h1:GKljq0VrfU4D5yc+2qA6OVr8pmO/MBbPEWqWQ/oqGEs=
github.com/chromedp/chromedp v0.9.2/go.mod h1:LkSXJKONWTCHAfQasKFUZI+mxqS4tZqhmtGzzhLsnLs=
github.com/chromedp/sysutil v1.0.0/go.mod h1:kgWmDdq8fTzXYcKIBqIYvRRTnYb9aNS9moAV0xufSww=
Expand Down Expand Up @@ -372,8 +370,8 @@ github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrP
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/github/go-spdx/v2 v2.3.2 h1:IfdyNHTqzs4zAJjXdVQfRnxt1XMfycXoHBE2Vsm1bjs=
github.com/github/go-spdx/v2 v2.3.2/go.mod h1:2ZxKsOhvBp+OYBDlsGnUMcchLeo2mrpEBn2L1C+U3IQ=
github.com/gitleaks/go-gitdiff v0.9.0 h1:SHAU2l0ZBEo8g82EeFewhVy81sb7JCxW76oSPtR/Nqg=
github.com/gitleaks/go-gitdiff v0.9.0/go.mod h1:pKz0X4YzCKZs30BL+weqBIG7mx0jl4tF1uXV9ZyNvrA=
github.com/gitleaks/go-gitdiff v0.9.1 h1:ni6z6/3i9ODT685OLCTf+s/ERlWUNWQF4x1pvoNICw0=
github.com/gitleaks/go-gitdiff v0.9.1/go.mod h1:pKz0X4YzCKZs30BL+weqBIG7mx0jl4tF1uXV9ZyNvrA=
github.com/glebarez/go-sqlite v1.20.3 h1:89BkqGOXR9oRmG58ZrzgoY/Fhy5x0M+/WV48U5zVrZ4=
github.com/glebarez/go-sqlite v1.20.3/go.mod h1:u3N6D/wftiAzIOJtZl6BmedqxmmkDfH3q+ihjqxC9u0=
github.com/gliderlabs/ssh v0.3.8 h1:a4YXD1V7xMF9g5nTkdfnja3Sxy1PVDCj1Zg4Wb8vY6c=
Expand Down
49 changes: 49 additions & 0 deletions internal/commands/hooks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package commands

import (
"github.com/MakeNowJust/heredoc"
"github.com/checkmarx/ast-cli/internal/params"
"github.com/checkmarx/ast-cli/internal/wrappers"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)

// NewHooksCommand creates the hooks command with pre-commit subcommand
func NewHooksCommand(jwtWrapper wrappers.JWTWrapper) *cobra.Command {
hooksCmd := &cobra.Command{
Use: "hooks",
Short: "Manage Git hooks",
Long: "The hooks command enables the ability to manage Git hooks for Checkmarx One.",
Example: heredoc.Doc(
`
$ cx hooks pre-commit secrets-install-git-hook
$ cx hooks pre-commit secrets-scan
$ cx hooks pre-receive secrets-scan
`,
),
Annotations: map[string]string{
"command:doc": heredoc.Doc(
`
https://checkmarx.com/resource/documents/en/34965-365503-hooks.html
`,
),
},
}

// Add pre-commit and pre-receive subcommand
hooksCmd.AddCommand(PreCommitCommand(jwtWrapper))
hooksCmd.AddCommand(PreReceiveCommand(jwtWrapper))

return hooksCmd
}

func validateLicense(jwtWrapper wrappers.JWTWrapper) error {
allowed, err := jwtWrapper.IsAllowedEngine(params.EnterpriseSecretsLabel)
if err != nil {
return errors.Wrapf(err, "Failed checking license")
}
if !allowed {
return errors.New("Error: License validation failed. Please verify your CxOne license includes Enterprise Secrets.")
}
return nil
}
49 changes: 49 additions & 0 deletions internal/commands/pre-receive.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package commands

import (
prereceive "github.com/Checkmarx/secret-detection/pkg/hooks/pre-receive"
"github.com/MakeNowJust/heredoc"
"github.com/checkmarx/ast-cli/internal/wrappers"
"github.com/spf13/cobra"
)

func PreReceiveCommand(jwtWrapper wrappers.JWTWrapper) *cobra.Command {
preReceiveCmd := &cobra.Command{
Use: "pre-receive",
Short: "Manage pre-receive hooks and run secret detection scans",
Long: "The pre-receive command is used for managing Git pre-receive hooks for secret detection",
Example: heredoc.Doc(
`
$ cx hooks pre-receive secrets-scan
`,
),
}
preReceiveCmd.AddCommand(scanSecretsPreReceiveCommand(jwtWrapper))

return preReceiveCmd
}

func scanSecretsPreReceiveCommand(jwtWrapper wrappers.JWTWrapper) *cobra.Command {
var configFile string
scanPrereceiveCmd := &cobra.Command{
Use: "secrets-scan",
Short: "Run a pre-receive secret detection scan on the pushed branch",
Long: "Runs pre-receive secret detection scans on each pushed branch that is about to enter the remote git repository",
Example: heredoc.Doc(
`
$ cx hooks pre-receive secrets-scan
$ cx hooks pre-receive secrets-scan --config /path/to/config.yaml
`,
),
PreRunE: func(cmd *cobra.Command, args []string) error {
return validateLicense(jwtWrapper)
},
RunE: func(cmd *cobra.Command, args []string) error {
return prereceive.Scan(configFile)
},
}

scanPrereceiveCmd.Flags().StringVarP(&configFile, "config", "c", "", "path to config.yaml file")

return scanPrereceiveCmd
}
56 changes: 8 additions & 48 deletions internal/commands/pre_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,19 @@ package commands

import (
"fmt"
precommit "github.com/Checkmarx/secret-detection/pkg/hooks"
precommit "github.com/Checkmarx/secret-detection/pkg/hooks/pre-commit"
"github.com/MakeNowJust/heredoc"
"github.com/checkmarx/ast-cli/internal/params"
"github.com/checkmarx/ast-cli/internal/wrappers"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"strings"
)

// NewHooksCommand creates the hooks command with pre-commit subcommand
func NewHooksCommand(jwtWrapper wrappers.JWTWrapper) *cobra.Command {
hooksCmd := &cobra.Command{
Use: "hooks",
Short: "Manage Git hooks",
Long: "The hooks command enables the ability to manage Git hooks for Checkmarx One",
Example: heredoc.Doc(
`
$ cx hooks pre-commit secrets-install-git-hook
$ cx hooks pre-commit secrets-scan
`,
),
Annotations: map[string]string{
"command:doc": heredoc.Doc(
`
https://checkmarx.com/resource/documents/en/xxxxx-xxxxx-hooks.html
`,
),
},
}

// Add pre-commit subcommand
hooksCmd.AddCommand(PreCommitCommand(jwtWrapper))

return hooksCmd
}

// PreCommitCommand creates the pre-commit subcommand
func PreCommitCommand(jwtWrapper wrappers.JWTWrapper) *cobra.Command {
preCommitCmd := &cobra.Command{
Use: "pre-commit",
Short: "Manage pre-commit hooks and run secret detection scans",
Long: "The pre-commit command enables the ability to manage Git pre-commit hooks for secret detection",
Long: "The pre-commit command enables the ability to manage Git pre-commit hooks for secret detection.",
Example: heredoc.Doc(
`
$ cx hooks pre-commit secrets-install-git-hook
Expand All @@ -64,23 +35,12 @@ func PreCommitCommand(jwtWrapper wrappers.JWTWrapper) *cobra.Command {
}

// / validateLicense verifies the user has the required license for secret detection
func validateLicense(jwtWrapper wrappers.JWTWrapper) error {

allowed, err := jwtWrapper.IsAllowedEngine(params.EnterpriseSecretsLabel)
if err != nil {
return errors.Wrapf(err, "Failed checking license")
}
if !allowed {
return errors.New("Error: License validation failed. Please verify your CxOne license includes Enterprise Secrets.")
}
return nil
}

func secretsInstallGitHookCommand(jwtWrapper wrappers.JWTWrapper) *cobra.Command {
cmd := &cobra.Command{
Use: "secrets-install-git-hook",
Short: "Install the pre-commit hook",
Long: "Install the pre-commit hook for secret detection in your repository",
Long: "Install the pre-commit hook for secret detection in your repository.",
Example: heredoc.Doc(
`
$ cx hooks pre-commit secrets-install-git-hook
Expand All @@ -102,7 +62,7 @@ func secretsUninstallGitHookCommand(jwtWrapper wrappers.JWTWrapper) *cobra.Comma
cmd := &cobra.Command{
Use: "secrets-uninstall-git-hook",
Short: "Uninstall the pre-commit hook",
Long: "Uninstall the pre-commit hook for secret detection from your repository",
Long: "Uninstall the pre-commit hook for secret detection from your repository.",
Example: heredoc.Doc(
`
$ cx hooks pre-commit secrets-uninstall-git-hook
Expand All @@ -121,7 +81,7 @@ func secretsUpdateGitHookCommand(jwtWrapper wrappers.JWTWrapper) *cobra.Command
cmd := &cobra.Command{
Use: "secrets-update-git-hook",
Short: "Update the pre-commit hook",
Long: "Update the pre-commit hook for secret detection to the latest version",
Long: "Update the pre-commit hook for secret detection to the latest version.",
Example: heredoc.Doc(
`
$ cx hooks pre-commit secrets-update-git-hook
Expand All @@ -143,7 +103,7 @@ func secretsScanCommand(jwtWrapper wrappers.JWTWrapper) *cobra.Command {
return &cobra.Command{
Use: "secrets-scan",
Short: "Run the real-time secret detection scan",
Long: "Run a real-time scan to detect secrets in your code before committing",
Long: "Run a real-time scan to detect secrets in your code before committing.",
Example: heredoc.Doc(
`
$ cx hooks pre-commit secrets-scan
Expand All @@ -165,7 +125,7 @@ func secretsIgnoreCommand(jwtWrapper wrappers.JWTWrapper) *cobra.Command {
cmd := &cobra.Command{
Use: "secrets-ignore",
Short: "Ignore one or more detected secrets",
Long: "Add detected secrets to the ignore list so they won't be flagged in future scans",
Long: "Add detected secrets to the ignore list so they won't be flagged in future scans.",
Example: heredoc.Doc(
`
$ cx hooks pre-commit secrets-ignore --resultIds=a1b2c3d4e5f6,f1e2d3c4b5a6
Expand Down Expand Up @@ -209,7 +169,7 @@ func secretsHelpCommand() *cobra.Command {
return &cobra.Command{
Use: "secrets-help",
Short: "Display help for pre-commit commands",
Long: "Display detailed information about the pre-commit commands and options",
Long: "Display detailed information about the pre-commit commands and options.",
RunE: func(cmd *cobra.Command, args []string) error {
return cmd.Parent().Help()
},
Expand Down
49 changes: 49 additions & 0 deletions internal/commands/pre_receive_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package commands

import (
"os"
"path/filepath"
"testing"

"github.com/checkmarx/ast-cli/internal/wrappers/mock"
"github.com/stretchr/testify/assert"
)

func TestPreReceiveCommand(t *testing.T) {
mockJWT := &mock.JWTMockWrapper{}
cmd := PreReceiveCommand(mockJWT)
assert.NotNil(t, cmd)
assert.Equal(t, "pre-receive", cmd.Use)
subCmds := cmd.Commands()
subCmdName := make([]string, len(subCmds))
for i, subCmd := range subCmds {
subCmdName[i] = subCmd.Name()
}
expectedSubCmds := []string{
"secrets-scan",
}

for i, expectedSubCmd := range expectedSubCmds {
assert.Contains(t, expectedSubCmd, subCmdName[i])
}
}

func TestPreReceiveCommand_withConfig(t *testing.T) {
cmd := createASTTestCommand()
workDir, _ := os.Getwd()
configFile := filepath.Join(workDir, "config.yaml")
_ = os.WriteFile(configFile, []byte(""), 0644)
err := executeTestCommand(
cmd,
"hooks", "pre-receive", "secrets-scan", "--config", "config.yaml",
)
assert.Nil(t, err)
}

func TestPreReceiveCommand_withWrongFlagConfig(t *testing.T) {
err := execCmdNotNilAssertion(
t,
"hooks", "pre-receive", "secrets-scan", "--cf", "/path/config.yaml",
)
assert.NotNil(t, err)
}
2 changes: 2 additions & 0 deletions test/integration/data/pre-receive-data/excludeFile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
exclude_path:
- "*.txt"
2 changes: 2 additions & 0 deletions test/integration/data/pre-receive-data/excludeFolder.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
exclude_path:
- "integration/*"
3 changes: 3 additions & 0 deletions test/integration/data/pre-receive-data/ignoreResultId.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ignore_result_id:
- "986e5d5a73bcc5972e2d697ec0846db79b03dd75"
- "976014fdd1ef77be2c2ff1c1b6a3fe63d2b237f4"
2 changes: 2 additions & 0 deletions test/integration/data/pre-receive-data/ignoreRuleId.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ignore_rule_id:
- "github-pat"
Loading
Loading