@@ -26,33 +26,6 @@ func TestHooksPreCommitFullIntegration(t *testing.T) {
2626 hookPath := filepath .Join (tmpDir , ".git" , "hooks" , "pre-commit" )
2727 assert .FileExists (t , hookPath , "Hook should be installed" )
2828
29- // // Create file with mock secrets
30- // fileContent := `MOCK SECRET
31- //ghp_mocksecretAAAAAAAAAAAAAAAAAAAAAAAAA
32- //ANOTHER MOCK SECRET`
33- // secretFilePath := filepath.Join(tmpDir, "secret.txt")
34- // assert.NoError(t, os.WriteFile(secretFilePath, []byte(fileContent), 0644))
35- //
36- // // Stage the file
37- // execCmd(t, tmpDir, "git", "add", "secret.txt")
38- //
39- // // Run secrets scan (expect failure due to secret detection)
40- // err, output := executeCommand(t, "hooks", "pre-commit", "secrets-scan")
41- // assert.Error(t, err, "Scan should fail due to secret")
42- // assert.Contains(t, output.String(), "Secret detected")
43- //
44- // // Extract result IDs from output
45- // resultIds := parseResultIDs(output.String())
46- // assert.NotEmpty(t, resultIds, "Should detect result IDs")
47- //
48- // // Ignore detected secrets by ID
49- // output = executeCmdNilAssertion(t, "Ignoring detected secrets", "hooks", "pre-commit", "secrets-ignore", "--resultIds", strings.Join(resultIds, ","))
50- // assert.Contains(t, output.String(), "Added new IDs to .checkmarx_ignore")
51- //
52- // // Run secrets scan again (expect success after ignoring)
53- // output = executeCmdNilAssertion(t, "Running secrets scan after ignoring", "hooks", "pre-commit", "secrets-scan")
54- // assert.Contains(t, output.String(), "No secrets detected")
55-
5629 // Uninstall pre-commit hook
5730 _ = executeCmdNilAssertion (t , "Uninstalling pre-commit hook" , "hooks" , "pre-commit" , "secrets-uninstall-git-hook" )
5831
@@ -62,6 +35,59 @@ func TestHooksPreCommitFullIntegration(t *testing.T) {
6235 assert .NotContains (t , string (data ), "cx-secret-detection" , "Hook content should be cleared after uninstall" )
6336}
6437
38+ func TestHooksPreCommitLicenseValidation (t * testing.T ) {
39+ tmpDir , cleanup := setupTempDir (t )
40+ defer cleanup ()
41+
42+ // Initialize Git repository
43+ execCmd (t , tmpDir , "git" , "init" )
44+
45+ //// Test case 1: Without license (should fail)
46+ //t.Run("Without Enterprise License", func(t *testing.T) {
47+ // // Set environment to simulate no license
48+ // originalEnv := os.Getenv("CX_LICENSE")
49+ // os.Setenv("CX_LICENSE", "")
50+ // defer os.Setenv("CX_LICENSE", originalEnv)
51+ //
52+ // // Try to install pre-commit hook
53+ // args := []string{"hooks", "pre-commit", "secrets-install-git-hook"}
54+ // err, output := executeCommand(t, args...)
55+ //
56+ // // Verify error message
57+ // assert.Error(t, err)
58+ // assert.Contains(t, output.String(), "License validation failed")
59+ // assert.Contains(t, output.String(), "Please verify your CxOne License includes Enterprise Secrets")
60+ //
61+ // // Verify hook was not installed
62+ // hookPath := filepath.Join(tmpDir, ".git", "hooks", "pre-commit")
63+ // _, err = os.Stat(hookPath)
64+ // assert.True(t, os.IsNotExist(err), "Hook should not be installed without license")
65+ //})
66+
67+ // Test case 2: With license (should succeed)
68+ t .Run ("With Enterprise License" , func (t * testing.T ) {
69+ // Set environment to simulate valid license
70+ originalEnv := os .Getenv ("CX_LICENSE" )
71+ os .Setenv ("CX_LICENSE" , "valid-license-key" ) // Replace with actual license
72+ defer os .Setenv ("CX_LICENSE" , originalEnv )
73+
74+ // Install pre-commit hook
75+ _ = executeCmdNilAssertion (t , "Installing pre-commit hook" , "hooks" , "pre-commit" , "secrets-install-git-hook" )
76+
77+ // Verify hook installation
78+ hookPath := filepath .Join (tmpDir , ".git" , "hooks" , "pre-commit" )
79+ assert .FileExists (t , hookPath , "Hook should be installed with valid license" )
80+
81+ // Verify hook content
82+ data , err := os .ReadFile (hookPath )
83+ assert .NoError (t , err )
84+ assert .Contains (t , string (data ), "cx-secret-detection" , "Hook should contain secret detection code" )
85+
86+ // Clean up - uninstall hook
87+ _ = executeCmdNilAssertion (t , "Uninstalling pre-commit hook" , "hooks" , "pre-commit" , "secrets-uninstall-git-hook" )
88+ })
89+ }
90+
6591// Helper functions
6692func execCmd (t * testing.T , dir string , name string , args ... string ) {
6793 cmd := exec .Command (name , args ... )
0 commit comments