4.0 KiB
Environment, Test Env, and Security
Test environment (prevent data loss)
.env is production/live. Changes to .env can affect real tickets, Discord, Gmail, and MongoDB. To try config changes safely:
-
Copy the test template:
cp .env.test.example .env.test -
Edit
.env.testwith test-only values (e.g. test guild, test MongoDB database name, test API URL). Use a separate test DB inMONGODB_URIto avoid touching production data. -
Run the bot with the test env:
npm run start:test
Or:ENV_FILE=.env.test node broccolini-discord.js -
Other scripts with test env:
npm run test-mongodb:test— test MongoDB connection using.env.test
-
After confirming behavior, migrate only the desired variables from
.env.testinto.env(manually). Do not overwrite.envblindly.
Rule: New or risky env changes are done in .env.test first; only after confirmation are they applied to .env.
Agent / AI rules
- Changes to
.envby an agent (e.g. Cursor) must require explicit user confirmation. Do not modify.envautomatically. Prefer proposing changes to.env.testor listing the exact edits for the user to apply to.env. - Do not commit
.envor.env.test. Only.env.exampleand.env.test.exampleare committed (no secrets).
Security checklist
- Secrets: All secrets live in
.env(or.env.testfor test). Never commit them..gitignoreexcludes.envand.env.*except.env.exampleand.env.test.example. - Code: No
eval()ornew Function()of user input. No hardcoded tokens, passwords, or API keys in source. - Config: Credentials are read from
process.envviaconfig.js; config is loaded once at startup from the file specified byENV_FILEor default.env. - MongoDB: Use a dedicated user and database; restrict network access (Atlas IP allowlist or VPC). For test, use a separate DB or cluster.
- Discord / Google: Use tokens with minimal required scopes; rotate if compromised.
- HTML in emails:
LOGO_URL,EMAIL_SIGNATURE, and closure messages are escaped in outbound HTML to prevent injection. - Healthcheck: Optional
HEALTHCHECK_HOST=127.0.0.1in.envbinds the healthcheck server to localhost only; omit to listen on all interfaces. - Dependencies: Run
npm auditperiodically and fix or accept risk for reported vulnerabilities.
Cleanup and redundancy
- Single source of truth for env keys:
.env.exampleand.env.test.examplelist all supported variables. Defaults for optional vars live inconfig.js; do not duplicate default values in both.env.exampleandconfig.jsfor the same value (.env.exampledocuments,config.jsimplements). - No duplicate env files: Use
.envfor live,.env.testfor test; do not commit.env.local,.env.production, etc. unless documented and gitignored as needed. - Parent repo (IB-Discord-Bot): Broccolini Bot does not reference sibling paths (e.g.
../ngrok) in code. Run order and ports are documented in~/IB-Discord-Bot/README.md.
Connection to IB-Discord-Bot stack
Broccolini Bot is a subproject of IB-Discord-Bot. It does not import or require files outside broccolini-bot/. Integration is via:
- Ports: Broccolini Bot healthcheck uses
DISCORD_ONLY_PORT(default 5000). Use a different port in.env.test(e.g. 5001) if running bot and test bot on the same machine.
See parent ~/IB-Discord-Bot/README.md for run order, ports, and troubleshooting.
Quick reference
| File / command | Purpose |
|---|---|
.env |
Live config (never commit). |
.env.test |
Test config (never commit). |
.env.example |
Template for .env (committed). |
.env.test.example |
Template for .env.test (committed). |
ENV_FILE=.env.test |
Load .env.test instead of .env. |
npm run start:test |
Run bot with .env.test. |
npm run test-mongodb:test |
Test MongoDB using .env.test. |