AegisShield automatically generates security test cases in Gherkin format (Given-When-Then) that can be directly integrated into your testing framework to validate defenses against identified threats.
Feature: User Authentication Security Scenario: Prevent brute force attacks Given the login endpoint is accessible When a user attempts to login with invalid credentials 10 times Then the account should be locked And subsequent login attempts should be blocked for 30 minutes
The AI uses specific instructions to generate test cases:
From test_cases.py:25-44
Act as a cyber security expert with more than 20 years experience of using the STRIDE threat modelling methodology. Your task is to provide Gherkin test cases for the threats identified in a threat model. It is very important that your responses are tailored to reflect the details of the threats.Below is the list of identified threats:{threats}Use the threat descriptions in the 'Given' steps so that the test cases are specific to the threats identified. Put the Gherkin syntax inside triple backticks (```) to format the test cases in Markdown. Add a title for each test case.For example: ```gherkin Given a user with a valid account When the user logs in Then the user should be able to access the system
YOUR RESPONSE (do not add introductory text, just provide the Gherkin test cases):
## Example OutputGenerated test cases for a web application:```gherkin Spoofing test cases### Test Case 1: Prevent OAuth2 Provider Spoofing```gherkinFeature: OAuth2 Authentication Security Scenario: Detect fake OAuth2 provider Given the application uses OAuth2 for authentication And the legitimate OAuth2 provider is at https://auth.example.com When a user is redirected to a different OAuth2 endpoint Then the application should reject the authentication And the user should be warned about the suspicious redirect
Feature: Session Token Security Scenario: Prevent session hijacking via XSS Given a user is logged into the application And the session token is stored in an HTTP-only cookie When an attacker attempts to execute JavaScript to access the session token Then the JavaScript should not be able to access the cookie And the session should remain secure
Feature: Database Query Security Scenario: Prevent SQL injection in search functionality Given the application has a search feature When a user enters SQL injection payload "'; DROP TABLE users; --" Then the query should be parameterized And the malicious input should be treated as literal text And no database tables should be modified
<Note>Each test case is tailored to a specific threat from your threat model, making them immediately actionable.</Note>## Test ImplementationGenerated tests can be implemented in various frameworks.**pytest-bdd (Python):**```pythonfrom pytest_bdd import scenarios, given, when, thenimport requestsscenarios('features/oauth_security.feature')@given('the application uses OAuth2 for authentication')def app_uses_oauth(test_app): assert test_app.config['AUTH_METHOD'] == 'oauth2'@when('a user is redirected to a different OAuth2 endpoint')def redirect_to_fake_provider(test_client): response = test_client.get('/auth/callback?provider=https://evil.com') return response@then('the application should reject the authentication')def verify_rejection(response): assert response.status_code == 403 assert 'invalid provider' in response.text.lower()
Cucumber (JavaScript):
const { Given, When, Then } = require('@cucumber/cucumber');const assert = require('assert');Given('the application uses OAuth2 for authentication', function() { this.authMethod = 'oauth2';});When('a user is redirected to a different OAuth2 endpoint', async function() { this.response = await this.app.get('/auth/callback?provider=https://evil.com');});Then('the application should reject the authentication', function() { assert.strictEqual(this.response.status, 403);});
Behave (Python):
from behave import given, when, then@given('the application uses OAuth2 for authentication')def step_impl(context): context.auth_method = 'oauth2'@when('a user is redirected to a different OAuth2 endpoint')def step_impl(context): context.response = context.client.get('/auth/callback?provider=https://evil.com')@then('the application should reject the authentication')def step_impl(context): assert context.response.status_code == 403
if not api_key: handle_exception( ValueError("OpenAI API key is required"), "OpenAI API key is required" )if not prompt: handle_exception( ValueError("Prompt is required for test cases generation"), "Prompt is required for test cases generation" )