@@ -12,7 +12,7 @@ import (
1212 "github.com/stretchr/testify/assert"
1313)
1414
15- func TestInstallAndUninstallPreCommitHook (t * testing.T ) {
15+ func TestHooksPreCommitInstallAndUninstallPreCommitHook (t * testing.T ) {
1616 tmpDir , cleanup := setupTempDir (t )
1717 defer cleanup ()
1818
@@ -35,43 +35,32 @@ func TestInstallAndUninstallPreCommitHook(t *testing.T) {
3535 assert .NotContains (t , string (data ), "cx-secret-detection" , "Hook content should be cleared after uninstall" )
3636}
3737
38- func TestUpdatePreCommitHook (t * testing.T ) {
38+ func TestHooksPreCommitValidateLicenseIntegration (t * testing.T ) {
39+ mockJWT := & mock.JWTMockWrapper {
40+ AIEnabled : mock .AIProtectionDisabled ,
41+ }
42+
43+ err := validateLicense (mockJWT )
44+
45+ assert .Error (t , err )
46+ assert .Contains (t , err .Error (), "License validation failed" )
47+ }
48+
49+ func TestHooksPreCommitUpdatePreCommitHook (t * testing.T ) {
3950 tmpDir , cleanup := setupTempDir (t )
4051 defer cleanup ()
4152
4253 // Initialize Git repository
4354 execCmd (t , tmpDir , "git" , "init" )
4455
4556 // Install pre-commit hook locally
46- _ = executeCmdNilAssertion (t , "Installing pre-commit hook" , "hooks" , "pre-commit" , "secrets-install-git-hookss " )
57+ _ = executeCmdNilAssertion (t , "Installing pre-commit hook" , "hooks" , "pre-commit" , "secrets-install-git-hook " )
4758
4859 // Update pre-commit hook
4960 output := executeCmdNilAssertion (t , "Updating pre-commit hook" , "hooks" , "pre-commit" , "secrets-update-git-hook" )
5061 assert .Contains (t , output , "updated successfully" , "Hook should update successfully" )
5162}
5263
53- //func TestHooksPreCommitLicenseValidation(t *testing.T) {
54- // // Store original environment variables
55- // originals := getOriginalEnvVars()
56- //
57- // // Set only the API key to invalid value
58- // setEnvVars(map[string]string{
59- // params.AstAPIKeyEnv: invalidAPIKey,
60- // })
61- //
62- // // Restore original environment variables after test
63- // defer setEnvVars(originals)
64- //
65- // // Define command arguments for installing the pre-commit hook
66- // args := []string{
67- // "hooks", "pre-commit", "secrets-install-git-hook",
68- // }
69- //
70- // // Execute the command and verify it fails with the expected error
71- // err, _ := executeCommand(t, args...)
72- // assert.Error(t, err, "Error validating scan types: Token decoding error: token is malformed: token contains an invalid number of segments")
73- //}
74-
7564// Helper functions
7665func execCmd (t * testing.T , dir string , name string , args ... string ) {
7766 cmd := exec .Command (name , args ... )
0 commit comments