/threat-modeling-toolkit:tm-testsfrom threat-modeling-toolkit
Generates security test cases from threat models, creating attack scenarios, control verification tests, and regression test suites. Supports markdown, Jest, pytest, and Playwright output formats.
Ships in threat-modeling-toolkit. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Generate security test cases from your threat model to:
/tm-tests [--format markdown|jest|pytest|playwright] [--category <name>] [--control <id>] [--output <path>]
Arguments:
--format: Test output format (default: markdown)--category: Filter by threat category--control: Generate tests for specific control--output: Output directoryTests that attempt to exploit vulnerabilities:
Tests that verify security controls work:
Tests that prevent security regressions:
# Security Test Cases
## Authentication Tests
### TEST-001: Credential Stuffing Prevention
**Threat**: THREAT-001 - Credential Stuffing Attack
**Control**: CONTROL-001 - Rate Limiting
#### Test Scenario
1. Attempt 6 failed logins from same IP within 1 minute
2. Expected: 6th request should be blocked (429 Too Many Requests)
#### Steps
1. POST /api/auth/login with invalid credentials
2. Repeat 5 more times
3. Verify 6th request returns 429
#### Expected Results
- First 5 requests: 401 Unauthorized
- 6th request: 429 Too Many Requests
- Response includes retry-after header
#### Pass Criteria
- Rate limit enforced at configured threshold
- Appropriate error response returned
- Event logged for security monitoring
// security-tests/auth-security.test.ts
describe('Authentication Security', () => {
describe('Credential Stuffing Prevention', () => {
// THREAT-001: Credential Stuffing Attack
// CONTROL-001: Rate Limiting
it('should block after 5 failed attempts from same IP', async () => {
const loginAttempt = () =>
request(app)
.post('/api/auth/login')
.send({ email: '[email protected]', password: 'wrong' });
// Make 5 failed attempts
for (let i = 0; i < 5; i++) {
const response = await loginAttempt();
expect(response.status).toBe(401);
}
// 6th attempt should be blocked
const blocked = await loginAttempt();
expect(blocked.status).toBe(429);
expect(blocked.headers['retry-after']).toBeDefined();
});
it('should return consistent error messages', async () => {
// Test with valid email, wrong password
const validEmail = await request(app)
.post('/api/auth/login')
.send({ email: '[email protected]', password: 'wrong' });
// Test with invalid email
const invalidEmail = await request(app)
.post('/api/auth/login')
.send({ email: '[email protected]', password: 'wrong' });
// Messages should be identical to prevent enumeration
expect(validEmail.body.message).toBe(invalidEmail.body.message);
});
it('should log failed authentication attempts', async () => {
const spy = jest.spyOn(logger, 'warn');
await request(app)
.post('/api/auth/login')
.send({ email: '[email protected]', password: 'wrong' });
expect(spy).toHaveBeenCalledWith(
expect.objectContaining({
event: 'authentication_failure',
email: '[email protected]',
})
);
});
});
describe('Session Management', () => {
// THREAT-003: Session Hijacking
// CONTROL-003: Secure Session Configuration
it('should invalidate session on password change', async () => {
const { sessionId } = await login('[email protected]', 'password');
await changePassword('[email protected]', 'newpassword');
const response = await request(app)
.get('/api/profile')
.set('Cookie', `session=${sessionId}`);
expect(response.status).toBe(401);
});
it('should enforce session timeout', async () => {
const { sessionId } = await login('[email protected]', 'password');
// Fast-forward time past session timeout
jest.advanceTimersByTime(31 * 60 * 1000); // 31 minutes
const response = await request(app)
.get('/api/profile')
.set('Cookie', `session=${sessionId}`);
expect(response.status).toBe(401);
});
});
});
# tests/security/test_auth_security.py
import pytest
from fastapi.testclient import TestClient
class TestAuthenticationSecurity:
"""
Security tests for authentication threats.
"""
class TestCredentialStuffingPrevention:
"""
THREAT-001: Credential Stuffing Attack
CONTROL-001: Rate Limiting
"""
def test_blocks_after_failed_attempts(self, client: TestClient):
"""Should block after 5 failed login attempts from same IP."""
for i in range(5):
response = client.post(
"/api/auth/login",
json={"email": "[email protected]", "password": "wrong"}
)
assert response.status_code == 401
# 6th attempt should be blocked
response = client.post(
"/api/auth/login",
json={"email": "[email protected]", "password": "wrong"}
)
assert response.status_code == 429
assert "retry-after" in response.headers
def test_returns_consistent_error_messages(self, client: TestClient):
"""Should return identical messages for valid/invalid emails."""
valid_email = client.post(
"/api/auth/login",
json={"email": "[email protected]", "password": "wrong"}
)
invalid_email = client.post(
"/api/auth/login",
json={"email": "[email protected]", "password": "wrong"}
)
assert valid_email.json()["message"] == invalid_email.json()["message"]
class TestInputValidation:
"""
THREAT-002: SQL Injection
CONTROL-002: Parameterized Queries
"""
@pytest.mark.parametrize("payload", [
"' OR '1'='1",
"'; DROP TABLE users; --",
"' UNION SELECT * FROM users --",
])
def test_sql_injection_blocked(self, client: TestClient, payload: str):
"""Should block SQL injection attempts."""
response = client.get(f"/api/users?search={payload}")
assert response.status_code in [400, 200]
# If 200, verify no SQL error in response
if response.status_code == 200:
assert "sql" not in response.text.lower()
assert "error" not in response.text.lower()
{
"version": "1.0",
"generated": "ISO-8601",
"coverage": {
"threats_with_tests": 42,
"threats_without_tests": 5,
"controls_with_tests": 25,
"controls_without_tests": 4
},
"matrix": [
{
"threat_id": "threat-001",
"threat_title": "Credential Stuffing",
"test_ids": ["test-001", "test-002", "test-003"],
"controls_tested": ["control-001", "control-002"],
"coverage": "full"
}
],
"untested": {
"threats": ["threat-045", "threat-046"],
"controls": ["control-028"]
}
}
When executing this skill:
Load threat model:
.threatmodel/state/threats.json.threatmodel/state/controls.jsonGroup tests by category:
For each threat:
For each control:
Generate in requested format:
Create coverage matrix:
Report summary:
Test Generation Complete
========================
Format: jest
Tests Generated:
Authentication: 12 tests
Authorization: 8 tests
Input Validation: 15 tests
Session Management: 6 tests
Error Handling: 4 tests
Total: 45 tests
Coverage:
Threats with tests: 42/47 (89%)
Controls with tests: 25/29 (86%)
Untested:
- THREAT-045: Complex attack scenario
- THREAT-046: Requires manual testing
- CONTROL-028: Infrastructure control
Files Created:
.threatmodel/tests/auth-security.test.ts
.threatmodel/tests/authz-security.test.ts
.threatmodel/tests/input-validation.test.ts
.threatmodel/tests/test-matrix.json
Next Steps:
1. Review generated tests
2. Add to CI/CD pipeline
3. Create manual test procedures for untested items
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub josemlopez/threat-modeling-toolkit --plugin threat-modeling-toolkit9 skills in this plugin
/tm-complianceMap threats and controls to compliance frameworks like OWASP Top 10, SOC2, PCI-DSS, HIPAA, GDPR. Generates compliance reports with coverage percentages and gaps. Use when checking compliance status, mapping to security frameworks, or generating audit documentation./tm-driftDetect changes in the threat model since the last baseline snapshot. Identifies new assets, changed flows, new threats, and control status changes. Use when comparing threat model versions, tracking security drift, monitoring for new risks, or validating changes after updates./tm-fullRun the complete threat modeling workflow from initialization through reporting. Orchestrates all other skills in sequence. Use when performing full threat model analysis, running complete security assessment, or generating comprehensive threat documentation./tm-initInitialize a threat modeling project by analyzing architecture documentation. Creates threat model structure with asset inventory, data flows, trust boundaries, and attack surface mapping. Use when starting new threat modeling work, setting up threat model for a project, or creating initial security assessment./tm-reportGenerate comprehensive prioritized risk reports with executive summaries, threat details, gap analysis, and recommendations. Use when creating security reports, generating executive summaries, documenting risk assessments, or preparing audit documentation./tm-statusShow current threat model status including asset counts, threat distribution, control verification status, and compliance coverage. Use when checking threat model status, getting overview of security posture, or reviewing current state.