secure-husky-setup 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Readme.md +110 -21
- package/package.json +8 -4
package/Readme.md
CHANGED
|
@@ -1,49 +1,138 @@
|
|
|
1
|
+
# secure-husky-setup
|
|
2
|
+
|
|
3
|
+
> One-command security and CI setup for any Node.js project.
|
|
4
|
+
|
|
5
|
+
Automatically configures **Gitleaks**, **SonarQube**, **Smoke Tests**, and **Newman API Tests** as git hooks — so your team catches secrets, bad code, and broken APIs before they ever reach your repo.
|
|
1
6
|
|
|
2
7
|
---
|
|
3
8
|
|
|
4
|
-
|
|
5
|
-
# Secure Husky Setup
|
|
9
|
+
## What It Does
|
|
6
10
|
|
|
7
|
-
|
|
11
|
+
| Hook | Tool | What It Checks |
|
|
12
|
+
|------|------|----------------|
|
|
13
|
+
| Pre-commit | Gitleaks | Scans staged files for hardcoded secrets, API keys, tokens |
|
|
14
|
+
| Pre-commit | SonarQube | Scans staged files for code quality issues, blocks on Quality Gate failure |
|
|
15
|
+
| Pre-push | Smoke Tests | Starts your server and runs `npm test` before every push |
|
|
16
|
+
| Pre-push | Newman | Runs your Postman collections automatically before every push |
|
|
17
|
+
| GitHub Actions | All of the above | Runs the full CI pipeline on every push to any branch |
|
|
8
18
|
|
|
9
|
-
|
|
10
|
-
- Gitleaks (Secret scanning)
|
|
11
|
-
- Pre-commit protection
|
|
19
|
+
**All hooks run on git diff only** — only changed files are scanned, keeping commits and pushes fast.
|
|
12
20
|
|
|
13
21
|
---
|
|
14
22
|
|
|
15
|
-
##
|
|
16
|
-
|
|
17
|
-
Inside your project directory:
|
|
23
|
+
## Installation
|
|
18
24
|
|
|
19
25
|
```bash
|
|
20
|
-
|
|
26
|
+
npx secure-husky-setup init
|
|
21
27
|
```
|
|
22
28
|
|
|
29
|
+
That's it. No manual configuration needed.
|
|
23
30
|
|
|
24
31
|
---
|
|
25
32
|
|
|
26
|
-
##
|
|
33
|
+
## What Gets Set Up Automatically
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
your-project/
|
|
37
|
+
├── .husky/
|
|
38
|
+
│ ├── pre-commit ← Gitleaks + SonarQube on staged files
|
|
39
|
+
│ └── pre-push ← Smoke Tests + Newman on changed files
|
|
40
|
+
├── .github/
|
|
41
|
+
│ └── workflows/
|
|
42
|
+
│ └── ci-tests.yml ← GitHub Actions CI pipeline
|
|
43
|
+
├── scripts/
|
|
44
|
+
│ └── run-ci-checks.sh ← Standalone CI script (can be run manually)
|
|
45
|
+
├── sonar-project.properties ← Auto-generated SonarQube config
|
|
46
|
+
└── .gitleaksignore ← Excludes false-positive files
|
|
47
|
+
```
|
|
27
48
|
|
|
28
|
-
|
|
49
|
+
---
|
|
29
50
|
|
|
30
|
-
|
|
31
|
-
|
|
51
|
+
## How It Works
|
|
52
|
+
|
|
53
|
+
### Pre-Commit Hook
|
|
54
|
+
Every time you run `git commit`, the hook:
|
|
55
|
+
1. Gets the list of staged files via `git diff --cached`
|
|
56
|
+
2. Copies staged files to a temp directory
|
|
57
|
+
3. Runs **Gitleaks** on the temp directory — blocks commit if secrets found
|
|
58
|
+
4. Runs **SonarQube** on staged files only — blocks commit if Quality Gate fails
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
git commit
|
|
62
|
+
→ [Gitleaks] Secrets found? → BLOCK commit
|
|
63
|
+
→ [SonarQube] Quality Gate fail? → BLOCK commit
|
|
64
|
+
→ All clear? → commit goes through
|
|
32
65
|
```
|
|
33
66
|
|
|
34
|
-
|
|
67
|
+
### Pre-Push Hook
|
|
68
|
+
Every time you run `git push`, the hook:
|
|
69
|
+
1. Checks git diff between local and remote — skips if nothing changed
|
|
70
|
+
2. Starts your server (`npm start`)
|
|
71
|
+
3. Runs your tests (`npm test`) — blocks push if tests fail
|
|
72
|
+
4. Looks for `*.postman_collection.json` files and runs them via Newman
|
|
35
73
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
74
|
+
```
|
|
75
|
+
git push
|
|
76
|
+
→ [Smoke Tests] Server starts + npm test passes? → or BLOCK
|
|
77
|
+
→ [Newman] All API tests pass? → or BLOCK
|
|
78
|
+
→ All clear? → push goes through
|
|
79
|
+
```
|
|
39
80
|
|
|
40
81
|
---
|
|
41
82
|
|
|
42
|
-
##
|
|
83
|
+
## SonarQube
|
|
43
84
|
|
|
44
|
-
|
|
85
|
+
The package is pre-configured to connect to the company SonarQube server. Projects are **created automatically** — no manual setup needed on the SonarQube dashboard.
|
|
45
86
|
|
|
46
|
-
|
|
87
|
+
To switch servers, update these values in `lib/sonarqube.js`:
|
|
88
|
+
```javascript
|
|
89
|
+
const SONAR_HOST_URL = 'http://your-server:9000';
|
|
90
|
+
const SONAR_TOKEN = 'your-token';
|
|
91
|
+
```
|
|
47
92
|
|
|
48
93
|
---
|
|
49
94
|
|
|
95
|
+
## Newman (Postman API Tests)
|
|
96
|
+
|
|
97
|
+
Newman runs automatically if it finds a `*.postman_collection.json` file anywhere in your project. HTML reports are saved to `newman-reports/` after each run.
|
|
98
|
+
|
|
99
|
+
To add API tests:
|
|
100
|
+
1. Export your Postman collection as JSON
|
|
101
|
+
2. Place it anywhere in your project (not in `node_modules`)
|
|
102
|
+
3. Newman will find and run it automatically on every push
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## Manually Running CI Checks
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
# Run smoke tests + Newman manually
|
|
110
|
+
sh scripts/run-ci-checks.sh
|
|
111
|
+
|
|
112
|
+
# Run pre-commit checks manually
|
|
113
|
+
sh .husky/pre-commit
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
## Moving Tests to Pre-Commit
|
|
119
|
+
|
|
120
|
+
By default, Smoke Tests + Newman run on **pre-push**. To move them to pre-commit, add one line to `.husky/pre-commit`:
|
|
121
|
+
|
|
122
|
+
```sh
|
|
123
|
+
./scripts/run-ci-checks.sh
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
## Requirements
|
|
129
|
+
|
|
130
|
+
- Node.js >= 16
|
|
131
|
+
- Git
|
|
132
|
+
- Java (required by SonarQube scanner — downloaded automatically)
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## License
|
|
137
|
+
|
|
138
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "secure-husky-setup",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Automatic Husky + Gitleaks setup for any JS project",
|
|
5
5
|
"main": "bin/index.js",
|
|
6
6
|
"bin": {
|
|
7
|
-
"secure-husky-setup": "
|
|
7
|
+
"secure-husky-setup": "bin/index.js"
|
|
8
8
|
},
|
|
9
9
|
"keywords": [
|
|
10
10
|
"husky",
|
|
@@ -14,11 +14,15 @@
|
|
|
14
14
|
],
|
|
15
15
|
"author": "Your Name",
|
|
16
16
|
"license": "MIT",
|
|
17
|
-
"files": [
|
|
17
|
+
"files": [
|
|
18
|
+
"bin",
|
|
19
|
+
"lib",
|
|
20
|
+
"templates"
|
|
21
|
+
],
|
|
18
22
|
"dependencies": {
|
|
19
23
|
"chalk": "^4.1.2",
|
|
20
24
|
"execa": "^5.1.1",
|
|
21
25
|
"fs-extra": "^11.3.3",
|
|
22
26
|
"sonarqube-scanner": "^4.0.0"
|
|
23
27
|
}
|
|
24
|
-
}
|
|
28
|
+
}
|