Athena — mahmoud-consultancy/archive/old-docs/SECURITY_TESTING_QUICK_REFERENCE.md

Security Testing Quick Reference Guide

Project: InterimPlaza Recruitment Platform For: Development & QA Teams Last Updated: October 10, 2025


Quick Start

Run All Security Tests

cd /workspace/backend
./mvnw test -Dtest="*SecurityTest"

Run Specific Test Suite

# Authentication Security
./mvnw test -Dtest=AuthControllerSecurityTest

# JWT Token Security
./mvnw test -Dtest=JwtTokenSecurityTest

# Password Security
./mvnw test -Dtest=PasswordSecurityTest

# Security Headers & CORS
./mvnw test -Dtest=SecurityHeadersTest

# Rate Limiting & DDoS
./mvnw test -Dtest=RateLimitingSecurityTest

Generate Coverage Report

./mvnw clean test jacoco:report
open target/site/jacoco/index.html

Test Suites Overview

1. AuthController Security Tests

File: AuthControllerSecurityTest.java Tests: 50+ Coverage: SQL injection, XSS, authentication, input validation

Key Test Categories:

  • ✅ SQL Injection Protection
  • ✅ XSS Protection
  • ✅ Authentication Bypass Prevention
  • ✅ Password Security Validation
  • ✅ Email Verification Security
  • ✅ CORS Configuration
  • ✅ Security Headers

Example Test:

@Test
void testSqlInjectionProtection_Login() {
    // Verifies SQL injection is blocked
}

2. JWT Token Security Tests

File: JwtTokenSecurityTest.java Tests: 40+ Coverage: Token generation, validation, tampering detection

Key Test Categories:

  • ✅ Token Generation
  • ✅ Token Validation
  • ✅ Tampering Detection
  • ✅ Expiration Enforcement
  • ✅ Algorithm Security
  • ✅ Claim Validation

Example Test:

@Test
void testValidateToken_WrongSignature() {
    // Verifies tampered tokens are rejected
}

3. Password Security Tests

File: PasswordSecurityTest.java Tests: 30+ Coverage: Hashing, strength validation, common password detection

Key Test Categories:

  • ✅ BCrypt Hashing
  • ✅ Password Strength
  • ✅ Common Password Detection
  • ✅ Rainbow Table Prevention
  • ✅ Timing Attack Prevention
  • ✅ HaveIBeenPwned Integration

Example Test:

@Test
void testPasswordHashing_UniqueSalts() {
    // Verifies each password gets unique salt
}

4. Security Headers Tests

File: SecurityHeadersTest.java Tests: 35+ Coverage: CORS, CSP, XSS protection, security headers

Key Test Categories:

  • ✅ CORS Configuration
  • ✅ Content Security Policy
  • ✅ X-Frame-Options
  • ✅ X-Content-Type-Options
  • ✅ X-XSS-Protection
  • ✅ Referrer-Policy

Example Test:

@Test
void testCors_LocalhostOriginsAllowed() {
    // Verifies CORS from localhost:4200
}

5. Rate Limiting Tests

File: RateLimitingSecurityTest.java Tests: 20+ Coverage: Brute force protection, DDoS prevention, concurrent requests

Key Test Categories:

  • ✅ Brute Force Protection
  • ✅ Concurrent Request Handling
  • ✅ Endpoint-Specific Limits
  • ✅ DDoS Protection
  • ✅ Account Lockout
  • ✅ IP-Based Rate Limiting

Example Test:

@Test
void testBruteForceProtection_MultipleFailedLogins() {
    // Verifies system handles brute force attacks
}

Common Test Patterns

1. Testing SQL Injection

@Test
void testSqlInjection() {
    String maliciousInput = "' OR '1'='1' --";

    mockMvc.perform(post("/api/auth/login")
            .contentType(MediaType.APPLICATION_JSON)
            .content("{\"email\":\"" + maliciousInput + "\"}"))
        .andExpect(status().isUnauthorized());
}

2. Testing XSS Protection

@Test
void testXssProtection() {
    String xssAttempt = "<script>alert('XSS')</script>";
    RegisterRequest request = RegisterRequest.builder()
        .firstName(xssAttempt)
        .build();

    mockMvc.perform(post("/api/auth/register")
            .content(objectMapper.writeValueAsString(request)))
        .andExpect(status().isBadRequest());
}

3. Testing JWT Token Validation

@Test
void testJwtValidation() {
    String token = jwtTokenProvider.generateToken(userDetails);

    assertTrue(jwtTokenProvider.isTokenValid(token, userDetails));
}

4. Testing Password Security

@Test
void testPasswordStrength() {
    String weakPassword = "weak";

    assertFalse(isPasswordStrong(weakPassword));
}

5. Testing Security Headers

@Test
void testSecurityHeaders() {
    mockMvc.perform(get("/api/jobs"))
        .andExpect(header().exists("X-Frame-Options"))
        .andExpect(header().exists("X-XSS-Protection"));
}

Security Checklist for Developers

Before Committing Code

  • [ ] Run all security tests
  • [ ] Verify no new security warnings
  • [ ] Check test coverage (>= 80%)
  • [ ] Review security-sensitive changes
  • [ ] Update tests if needed

Before Deploying to Production

  • [ ] All security tests pass
  • [ ] Security coverage >= 85%
  • [ ] Manual security testing completed
  • [ ] Security headers verified
  • [ ] Rate limiting configured
  • [ ] Secrets management verified
  • [ ] HTTPS enabled
  • [ ] Security monitoring active

Common Issues & Solutions

Issue 1: Tests Failing Due to Missing Dependencies

Solution:

./mvnw clean install
./mvnw test -Dtest="*SecurityTest"

Issue 2: JWT Token Tests Failing

Solution: Check that JWT secret is properly configured in test profile

# application-test.yml
security:
  jwt:
    secret: test-secret-key-minimum-256-bits-long

Issue 3: CORS Tests Failing

Solution: Verify CORS origins in SecurityConfig.java match test expectations

Issue 4: Rate Limiting Tests Slow

Solution: Rate limiting tests include concurrent operations; this is expected

# Run without rate limiting tests
./mvnw test -Dtest="*SecurityTest" -Dtest="!RateLimitingSecurityTest"

Security Testing Best Practices

1. Test Isolation

  • Each test should be independent
  • Use @Transactional for automatic rollback
  • Clean up test data in @BeforeEach or @AfterEach

2. Meaningful Test Names

// Good
@Test
@DisplayName("Should reject SQL injection in login email field")
void testSqlInjectionProtection_Login() { }

// Bad
@Test
void test1() { }

3. Comprehensive Coverage

  • Test happy path
  • Test edge cases
  • Test attack scenarios
  • Test error handling

4. Clear Assertions

// Good
assertFalse(isPasswordStrong(weakPassword),
    "Weak passwords should be rejected");

// Bad
assertFalse(isPasswordStrong(weakPassword));

5. Use Parameterized Tests

@ParameterizedTest
@ValueSource(strings = {"admin", "password", "123456"})
void testCommonPasswords(String password) {
    assertTrue(isCommonPassword(password));
}

CI/CD Integration

GitHub Actions Workflow

name: Security Tests

on: [push, pull_request]

jobs:
  security-tests:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Set up JDK 17
        uses: actions/setup-java@v3
        with:
          java-version: '17'
      - name: Run Security Tests
        run: ./mvnw test -Dtest="*SecurityTest"
      - name: Generate Coverage Report
        run: ./mvnw jacoco:report
      - name: Upload Coverage
        uses: codecov/codecov-action@v3

Performance Benchmarks

| Test Suite | Execution Time | Status | |------------|----------------|--------| | AuthController Security | ~15 seconds | ✅ Fast | | JWT Token Security | ~8 seconds | ✅ Fast | | Password Security | ~12 seconds | ✅ Fast | | Security Headers | ~10 seconds | ✅ Fast | | Rate Limiting | ~25 seconds | ⚠️ Moderate | | Total | ~70 seconds | ✅ Acceptable |


Coverage Targets

| Component | Target | Current | Status | |-----------|--------|---------|--------| | AuthController | 80% | 85% | ✅ Met | | JWT Token Provider | 80% | 92% | ✅ Exceeded | | Password Encoder | 80% | 95% | ✅ Exceeded | | Security Config | 80% | 88% | ✅ Exceeded | | Overall | 80% | 87% | ✅ Exceeded |


Debugging Security Tests

Enable Debug Logging

# application-test.yml
logging:
  level:
    nl.glorylabs: DEBUG
    org.springframework.security: DEBUG

Run Single Test with Debug

./mvnw test -Dtest=AuthControllerSecurityTest#testSqlInjectionProtection_Login -X

View Test Reports

# HTML report
open target/surefire-reports/index.html

# Console output
cat target/surefire-reports/TEST-*.xml

Useful Commands

Find All Security Tests

find backend/src/test -name "*Security*Test.java"

Count Test Cases

grep -r "@Test" backend/src/test/java/*Security* | wc -l

Check Test Coverage

./mvnw jacoco:report
grep -A 3 "Total" target/site/jacoco/index.html

Run Tests in Parallel

./mvnw test -Dtest="*SecurityTest" -DforkCount=4

Additional Resources

Internal Documentation

External Resources


Support

Getting Help

  • Review test documentation in test files
  • Check error messages in test output
  • Review security best practices documentation
  • Consult OWASP guidelines

Reporting Issues

If you find security issues:

  1. Do not commit the issue to version control
  2. Report to security team immediately
  3. Include test case demonstrating the issue
  4. Provide steps to reproduce

Last Updated: October 10, 2025 Maintained by: Development Team Project: InterimPlaza Recruitment Platform


"Testing is not just about finding bugs; it's about preventing them." 🛡️

Reacties

Nog geen reacties