feat: add AI-based security suggestion engine and CLI integration
Introduce new package org.egothor.methodatlas.ai providing AI-assisted classification of JUnit tests for security relevance. Key changes: - add AI suggestion engine, provider abstraction, and provider clients (OpenAI-compatible, Ollama, Anthropic) - implement strict JSON prompt/response contract and taxonomy handling - integrate AI enrichment into MethodAtlas CLI output (CSV and plain modes) - add configuration via AiOptions and CLI flags - add comprehensive JUnit + Mockito test coverage for AI components and CLI integration scenarios - add realistic test fixtures for security-related test classes - update Gradle configuration for Mockito agent support on JDK 21+ - provide complete Javadoc for the AI module The AI layer is optional and degrades gracefully when providers are unavailable or responses fail.
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
package com.acme.security;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class AccessControlServiceTest {
|
||||
|
||||
@Test
|
||||
@Tag("security")
|
||||
@Tag("authz")
|
||||
void shouldAllowOwnerToReadOwnStatement() {
|
||||
String userId = "user-100";
|
||||
String ownerId = "user-100";
|
||||
|
||||
boolean allowed = userId.equals(ownerId);
|
||||
|
||||
assertEquals(true, allowed);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Tag("security")
|
||||
@Tag("authz")
|
||||
void shouldAllowAdministratorToReadAnyStatement() {
|
||||
String role = "ADMIN";
|
||||
|
||||
boolean allowed = "ADMIN".equals(role);
|
||||
|
||||
assertEquals(true, allowed);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Tag("security")
|
||||
@Tag("authz")
|
||||
void shouldDenyForeignUserFromReadingAnotherUsersStatement() {
|
||||
String requesterId = "user-200";
|
||||
String ownerId = "user-100";
|
||||
|
||||
boolean allowed = requesterId.equals(ownerId);
|
||||
|
||||
assertEquals(false, allowed);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Tag("security")
|
||||
@Tag("authn")
|
||||
void shouldRejectUnauthenticatedRequest() {
|
||||
String principal = null;
|
||||
|
||||
IllegalStateException ex = assertThrows(IllegalStateException.class, () -> {
|
||||
if (principal == null) {
|
||||
throw new IllegalStateException("Unauthenticated request");
|
||||
}
|
||||
});
|
||||
|
||||
assertEquals("Unauthenticated request", ex.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldRenderFriendlyAccountLabel() {
|
||||
String firstName = "Ada";
|
||||
String lastName = "Lovelace";
|
||||
|
||||
String label = firstName + " " + lastName;
|
||||
|
||||
assertEquals("Ada Lovelace", label);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user