testing-cqrs-security
Skill0 starsChanged 6 months agoMITView on GitHub
Test CQRSTemplate security features end-to-end. Use when verifying session auth, CSRF, CSP, DTO rendering, role-based access, registration, or logout behavior.
- Reads credentials
In this repository14 other files it gives its agents.
- .claude/CLAUDE.mdCLAUDE.md
- api-endpoint-creationSkill
- database-migrationsSkill
- local-dev-testingSkill
- business-rule-additionSkill
- chrome-devtools-expertSkill
- code-reviewSkill
- context7-docsSkill
- domain-scaffoldingSkill
- markitdown-converterSkill
- playwright-automationSkill
- property-additionSkill
- serena-code-generatorSkill
- strategic-plannerSkill
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 0 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 73
Check response headers on any page for Content-Security-Policy containing cdn.jsdelivr.net
- Very specific: line 84
Create a cookie via /cookies/create
- Very specific: line 86
If DTO transformation is broken, views would throw errors trying ->getName()->getValue() on a DTO
- Very specific: line 113
No external secrets required.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Testing CQRSTemplate Security Features
Prerequisites
MySQL Setup
sudo systemctl start mysql
# Database: ci4_cqrs, User: ci4user/ci4pass (created during initial setup)Database Seeding
Seed the database with test accounts and sample data:
cd /home/ubuntu/repos/CQRSTemplate
php spark migrate --all
php spark db:seed DatabaseSeederThis creates:
admin@example.com/password123(admin role)customer@example.com/password123(customer role)- Sample cookie records
Note: Seeded accounts bypass password complexity validation since the seeder hashes passwords directly with Argon2id.
JWT Secret Key
The JwtService validates that JWT_SECRET_KEY is not weak. Use a strong hex key (48+ bytes):
STRONG_KEY=$(openssl rand -hex 48)
# In .env, use CI4 format with quotes:
# JWT_SECRET_KEY = '<key>'Gotcha: Base64 keys with = signs may cause CI4's .env parser issues. Use hex encoding instead.
Gotcha: The JWT key must be set as an environment variable when starting the dev server, OR correctly formatted in .env. If using php spark serve, the .env file is read by CI4's DotEnv loader, but you may need to also export JWT_SECRET_KEY=... in the shell for reliability.
Start Dev Server
export JWT_SECRET_KEY='<your-strong-key>'
cd /home/ubuntu/repos/CQRSTemplate
php spark serve --port 8080User Registration
The register form at /auth/register has three fields: Full Name, Email, Password.
Password complexity requirements (enforced by PasswordComplexity value object):
- Minimum 12 characters
- At least one uppercase letter
- At least one digit
- At least one special character
Example valid password: TestPass123!@
Alternatively, register users via curl:
CSRF=$(curl -s -c /tmp/reg.txt http://localhost:8080/auth/register | grep -oP 'name="csrf_test_name" value="\K[^"]+')
curl -s -c /tmp/reg.txt -b /tmp/reg.txt -X POST http://localhost:8080/auth/register \
-d "name=Test+User&email=testuser@example.com&password=TestPass123!@&csrf_test_name=${CSRF}"Key Test Flows
1. Session Auth Middleware (C-1)
- Navigate to
/cookiesor/dashboardwithout being logged in - Expected: 302 redirect to
/auth/loginwith flash "Please log in to continue."
2. CSP Headers and External CSS (M-1)
- Check response headers on any page for
Content-Security-Policycontainingcdn.jsdelivr.net - Auth pages should link to
/css/auth.csswith no inline<style>blocks - Layout pages should have SRI
integrityattributes on Bootstrap CDN links
3. Login and Session Regeneration (C-2)
- Login with valid credentials (use seeded accounts or register a new user)
- Expected: Redirect to
/dashboard, Bootstrap-styled layout renders correctly - Navbar should show: ERP Template, Dashboard, Cookies links + Logout button on the right
- The "Users" link only appears for admin users
4. Cookie CRUD with DTO Rendering (H-5)
- Create a cookie via
/cookies/create - Expected: Cookie list and detail views render DTO properties (
$cookie->name,$cookie->formattedPrice,$cookie->stock) - If DTO transformation is broken, views would throw errors trying
->getName()->getValue()on a DTO
5. Role-Based Access (SessionRoleMiddleware)
- Login as customer, navigate to
/admin/users - Expected: Redirect to
/dashboardwith "You do not have permission to access this resource." - The "Users" link in the navbar is only visible to admin users.
6. Logout
- Click the Logout button in the navbar (right side, styled as
btn-outline-light btn-sm) - Expected: Redirected to
/auth/login. Attempting to access/cookieswhile logged out returns redirect to/auth/loginwith "Please log in to continue." flash message.
7. API 401/403 Response (H-10)
curl http://localhost:8080/api/v1/users -H 'Accept: application/json'- Expected: JSON with
errorandmessagekeys. Noyour_roleorrequired_rolefields.
8. CSRF Token Randomization (M-6, M-7)
- Load
/auth/logintwice, extractcsrf_test_namevalues - Expected: Tokens differ between loads
Static Analysis
composer phpstan # PHPStan Level 8, expect 0 errors
composer phpcs # PHPCS, expect 0 violations
composer test # PHPUnit, expect all tests to passDevin Secrets Needed
No external secrets required. JWT_SECRET_KEY is generated locally for testing.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

