package com.zioinfo.cms.integration;

import org.junit.jupiter.api.Test;

import java.util.List;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.*;

/** ItsmSecuritySanitizer — 민감 필드 재귀 제거 테스트. */
class ItsmSecuritySanitizerTest {

    @Test
    @SuppressWarnings("unchecked")
    void clean_removesSensitiveKeys() {
        Map<String, Object> input = Map.of(
            "name", "srv-01",
            "ip_addr", "10.0.0.1",
            "ssh_user", "opsagent",
            "os_pw_enc", "ENCRYPTED",
            "nested", Map.of("password", "secret", "port", 22)
        );
        Map<String, Object> cleaned = (Map<String, Object>) ItsmSecuritySanitizer.clean(input);
        assertFalse(cleaned.containsKey("ip_addr"));
        assertFalse(cleaned.containsKey("ssh_user"));
        assertFalse(cleaned.containsKey("os_pw_enc"));
        assertEquals("srv-01", cleaned.get("name"));
        Map<String, Object> nested = (Map<String, Object>) cleaned.get("nested");
        assertFalse(nested.containsKey("password"));
        assertEquals(22, nested.get("port"));
    }

    @Test
    @SuppressWarnings("unchecked")
    void clean_handlesList() {
        List<Object> input = List.of(
            Map.of("name", "a", "token", "xyz"),
            Map.of("name", "b", "secret", "123")
        );
        List<Object> cleaned = (List<Object>) ItsmSecuritySanitizer.clean(input);
        assertEquals(2, cleaned.size());
        assertFalse(((Map<String, Object>) cleaned.get(0)).containsKey("token"));
        assertFalse(((Map<String, Object>) cleaned.get(1)).containsKey("secret"));
    }
}
