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

Merged
merged 56 commits into from
Jul 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
4e10651
Moved to common hooks place
cx-anjali-deore May 16, 2025
8bfedac
removed common hooks code
cx-anjali-deore May 16, 2025
6f1dfbd
Added pre receive commands
cx-anjali-deore May 16, 2025
5ea7ae9
Adding the commit version of secret detection
cx-anjali-deore May 16, 2025
078ff10
Added pre receive in Hooks doc
cx-anjali-deore May 19, 2025
fd53889
formatted
cx-anjali-deore May 19, 2025
991032a
typo changes
cx-anjali-deore May 21, 2025
9af581b
formatted the file
cx-anjali-deore May 21, 2025
5460a65
Adding secret detection to depgaurd allow list
cx-anjali-deore May 21, 2025
87ccb08
removed whitespace
cx-anjali-deore May 23, 2025
09cb077
formatted with gofmt
cx-anjali-deore May 26, 2025
be9617c
indentation
cx-anjali-deore May 26, 2025
02c6c90
indentation
cx-anjali-deore May 26, 2025
1a818f0
indentation
cx-anjali-deore May 26, 2025
b2e2f80
url and formatting fixes
cx-anjali-deore May 27, 2025
38e76d3
indentation alignment
cx-anjali-deore May 27, 2025
05a542b
Unit and integration tests
cx-anjali-deore Jun 2, 2025
563d7fa
lint issues fixed
cx-anjali-deore Jun 2, 2025
f8ae885
formatted unit test file
cx-anjali-deore Jun 2, 2025
befbcf8
setting global config git
cx-anjali-deore Jun 2, 2025
ad0bd90
changing cx path
cx-anjali-deore Jun 2, 2025
9ccb46b
adjusting cx path
cx-anjali-deore Jun 2, 2025
c24077d
check if cx path exist
cx-anjali-deore Jun 2, 2025
66afd4b
check if cx path exist
cx-anjali-deore Jun 2, 2025
d123456
added cxPath
cx-anjali-deore Jun 2, 2025
6a1f000
Adding githubUser and email
cx-anjali-deore Jun 2, 2025
66ea998
renaming functions
cx-anjali-deore Jun 3, 2025
a474408
url and formatting fixes
cx-anjali-deore May 27, 2025
43f1ba6
indentation alignment
cx-anjali-deore May 27, 2025
c44c097
Unit and integration tests
cx-anjali-deore Jun 2, 2025
e1f297c
lint issues fixed
cx-anjali-deore Jun 2, 2025
96b005e
formatted unit test file
cx-anjali-deore Jun 2, 2025
00190f8
setting global config git
cx-anjali-deore Jun 2, 2025
5d5ff83
changing cx path
cx-anjali-deore Jun 2, 2025
0e63927
adjusting cx path
cx-anjali-deore Jun 2, 2025
e17532c
check if cx path exist
cx-anjali-deore Jun 2, 2025
81e8a18
check if cx path exist
cx-anjali-deore Jun 2, 2025
c322a61
added cxPath
cx-anjali-deore Jun 2, 2025
885fb31
Adding githubUser and email
cx-anjali-deore Jun 2, 2025
6217ff7
renaming functions
cx-anjali-deore Jun 3, 2025
05f9a19
removed the git username
cx-anjali-deore Jun 3, 2025
6ff768b
using github actor
cx-anjali-deore Jun 3, 2025
eec8f37
go mod file updated
cx-anjali-deore Jun 4, 2025
a13d354
Added additional tests for coverage
cx-anjali-deore Jun 10, 2025
1ee40db
secret detection version upgrade
cx-anjali-deore Jun 16, 2025
2982d85
updegraded the version
cx-anjali-deore Jun 16, 2025
ba74a52
updegraded the version
cx-anjali-deore Jun 16, 2025
330986b
updegraded the version
cx-anjali-deore Jun 16, 2025
b1c2286
added latest version of secret detection 1.2.1
cx-anjali-deore Jun 17, 2025
295ce26
pre receive validate command
cx-anjali-deore Jul 21, 2025
a6c54f5
updated the versions
cx-anjali-deore Jul 21, 2025
8fc9a2b
formatted files
cx-anjali-deore Jul 22, 2025
82ea04d
formatted imports
cx-anjali-deore Jul 22, 2025
4c5a87a
reverted the changed manifest parser version back to main
cx-anjali-deore Jul 22, 2025
d1a714f
changed the help text
cx-anjali-deore Jul 22, 2025
819c4f9
removed usused go sum
cx-anjali-deore Jul 30, 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
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ 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.1.0
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.21.0
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
10 changes: 4 additions & 6 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.1.0 h1:swnzQpBFbJap7dgoj39oI6MaIqUlnVuBp5VJzeLVevQ=
github.com/Checkmarx/manifest-parser v0.1.0/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,8 +217,6 @@ 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.21.0 h1:EcabeDypNMsSidISQbziZ062HjMZQ+Hm/uOJ5AOxK8o=
github.com/checkmarx/2ms/v3 v3.21.0/go.mod h1:e8f4F94MZ+iCetR/G3aw7nXdPe6TgPI92Zzk/NG1l0o=
github.com/chromedp/cdproto v0.0.0-20230802225258-3cf4e6d46a89/go.mod h1:GKljq0VrfU4D5yc+2qA6OVr8pmO/MBbPEWqWQ/oqGEs=
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
}
84 changes: 84 additions & 0 deletions internal/commands/pre-receive.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package commands

import (
"fmt"
"log"

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

const (
SuccessFullSecretsLicenceValidation = "License for pre-receive secret detection has been validated successfully"
)

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())
preReceiveCmd.AddCommand(validateSecretsLicence(jwtWrapper))

return preReceiveCmd
}

func scanSecretsPreReceiveCommand() *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
`,
),
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
}

func validateSecretsLicence(jwtWrapper wrappers.JWTWrapper) *cobra.Command {
validateLicence := &cobra.Command{
Use: "validate",
Short: "Validates the license for pre-receive secret detection",
Long: "Validates the license for pre-receive secret detection",
Example: heredoc.Doc(
`
$ cx hooks pre-receive validate
`,
),
RunE: checkLicence(jwtWrapper),
}
return validateLicence
}

func checkLicence(jwtWrapper wrappers.JWTWrapper) func(cmd *cobra.Command, args []string) error {
return func(cmd *cobra.Command, args []string) error {
isAllowed, err := jwtWrapper.IsAllowedEngine(params.EnterpriseSecretsLabel)
if err != nil {
log.Fatalf("%s: %s", "Failed the licence check", err)
}
if !isAllowed {
log.Fatalf("Error: License validation failed. Please ensure that your Checkmarx One license includes Enterprise Secrets")
}
_, _ = fmt.Fprintln(cmd.OutOrStdout(), SuccessFullSecretsLicenceValidation)
return nil
}
}
56 changes: 9 additions & 47 deletions internal/commands/pre_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,19 @@ import (
"fmt"
"strings"

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"
)

// 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 @@ -65,22 +37,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 +64,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 +83,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 +105,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 +127,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 +171,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
57 changes: 57 additions & 0 deletions internal/commands/pre_receive_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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)
}

func TestPreReceiveCommand_Licence_success(t *testing.T) {
cmd := createASTTestCommand()
err := executeTestCommand(
cmd,
"hooks", "pre-receive", "validate")
assert.Nil(t, err)
}
Loading
Loading