Reviewer 역할 검증 보고서 smoke (runtime-role-matrix-live-20260714101723-v7-reviewer-001)
This commit is contained in:
parent
d090e6be83
commit
ecc70bca55
1 changed files with 146 additions and 0 deletions
146
src/test/java/com/klaroworks/runtime/role/RoleValidatorTest.java
Normal file
146
src/test/java/com/klaroworks/runtime/role/RoleValidatorTest.java
Normal file
|
|
@ -0,0 +1,146 @@
|
||||||
|
package com.klaroworks.runtime.role;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Nested;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for RoleValidator.
|
||||||
|
* Tests context validation and permission validation.
|
||||||
|
*/
|
||||||
|
@DisplayName("RoleValidator Tests")
|
||||||
|
public class RoleValidatorTest {
|
||||||
|
|
||||||
|
private RoleValidator validator;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
validator = new RoleValidator();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
@DisplayName("ValidateContextTests")
|
||||||
|
class ValidateContextTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("should validate valid context")
|
||||||
|
void shouldValidateValidContext() {
|
||||||
|
RoleContext context = RoleContext.SimpleRoleContext.of("user1", "ADMIN");
|
||||||
|
RoleValidator.ValidationResult result = validator.validateContext(context);
|
||||||
|
|
||||||
|
assertTrue(result.isValid());
|
||||||
|
assertTrue(result.getErrorMessage().isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("should reject null context")
|
||||||
|
void shouldRejectNullContext() {
|
||||||
|
RoleValidator.ValidationResult result = validator.validateContext(null);
|
||||||
|
|
||||||
|
assertFalse(result.isValid());
|
||||||
|
assertEquals("Context cannot be null", result.getErrorMessage().orElse(""));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("should reject context with null user ID")
|
||||||
|
void shouldRejectContextWithNullUserId() {
|
||||||
|
RoleContext context = new RoleContext.SimpleRoleContext(null, "ADMIN", Map.of());
|
||||||
|
RoleValidator.ValidationResult result = validator.validateContext(context);
|
||||||
|
|
||||||
|
assertFalse(result.isValid());
|
||||||
|
assertTrue(result.getErrorMessage().orElse("").contains("User ID"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("should reject context with blank role")
|
||||||
|
void shouldRejectContextWithBlankRole() {
|
||||||
|
RoleContext context = new RoleContext.SimpleRoleContext("user1", "", Map.of());
|
||||||
|
RoleValidator.ValidationResult result = validator.validateContext(context);
|
||||||
|
|
||||||
|
assertFalse(result.isValid());
|
||||||
|
assertTrue(result.getErrorMessage().orElse("").contains("Role"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("should reject context with unknown role")
|
||||||
|
void shouldRejectContextWithUnknownRole() {
|
||||||
|
RoleContext context = new RoleContext.SimpleRoleContext("user1", "UNKNOWN_ROLE", Map.of());
|
||||||
|
RoleValidator.ValidationResult result = validator.validateContext(context);
|
||||||
|
|
||||||
|
assertFalse(result.isValid());
|
||||||
|
assertTrue(result.getErrorMessage().orElse("").contains("Unknown role"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
@DisplayName("ValidatePermissionTests")
|
||||||
|
class ValidatePermissionTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("should validate allowed permission")
|
||||||
|
void shouldValidateAllowedPermission() {
|
||||||
|
RoleValidator.ValidationResult result = validator.validatePermission("USER", "read");
|
||||||
|
|
||||||
|
assertTrue(result.isValid());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("should reject disallowed permission")
|
||||||
|
void shouldRejectDisallowedPermission() {
|
||||||
|
RoleValidator.ValidationResult result = validator.validatePermission("USER", "delete");
|
||||||
|
|
||||||
|
assertFalse(result.isValid());
|
||||||
|
assertTrue(result.getErrorMessage().orElse("").contains("not allowed"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("should allow wildcard permission for ADMIN")
|
||||||
|
void shouldAllowWildcardPermissionForAdmin() {
|
||||||
|
RoleValidator.ValidationResult result = validator.validatePermission("ADMIN", "anyPermission");
|
||||||
|
|
||||||
|
assertTrue(result.isValid());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("should reject permission for unknown role")
|
||||||
|
void shouldRejectPermissionForUnknownRole() {
|
||||||
|
RoleValidator.ValidationResult result = validator.validatePermission("UNKNOWN", "read");
|
||||||
|
|
||||||
|
assertFalse(result.isValid());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
@DisplayName("RoleLevelTests")
|
||||||
|
class RoleLevelTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("should return correct role levels")
|
||||||
|
void shouldReturnCorrectRoleLevels() {
|
||||||
|
assertEquals(100, validator.getRoleLevel("ADMIN"));
|
||||||
|
assertEquals(50, validator.getRoleLevel("MANAGER"));
|
||||||
|
assertEquals(10, validator.getRoleLevel("USER"));
|
||||||
|
assertEquals(1, validator.getRoleLevel("GUEST"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("should return zero for unknown role")
|
||||||
|
void shouldReturnZeroForUnknownRole() {
|
||||||
|
assertEquals(0, validator.getRoleLevel("UNKNOWN"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("should compare role privileges correctly")
|
||||||
|
void shouldCompareRolePrivilegesCorrectly() {
|
||||||
|
assertTrue(validator.hasHigherPrivilege("ADMIN", "USER"));
|
||||||
|
assertTrue(validator.hasHigherPrivilege("MANAGER", "GUEST"));
|
||||||
|
assertFalse(validator.hasHigherPrivilege("USER", "ADMIN"));
|
||||||
|
assertFalse(validator.hasHigherPrivilege("USER", "USER"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue