package com.zioinfo.mes.integration;

import org.junit.jupiter.api.Test;

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

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

/** 연계 응답 자격증명 새니타이즈 테스트 (보안 불변 규칙). */
class ItsmSecuritySanitizerTest {

    @Test
    @SuppressWarnings("unchecked")
    void clean_removesSensitiveKeys() {
        Map<String, Object> input = Map.of(
            "equipment_code", "EQ-ASSY-01",
            "ip_addr", "10.0.0.5",
            "ssh_user", "opsagent",
            "os_pw_enc", "ENC(xxx)",
            "status", "DOWN"
        );
        Map<String, Object> out = (Map<String, Object>) ItsmSecuritySanitizer.clean(input);
        assertTrue(out.containsKey("equipment_code"));
        assertTrue(out.containsKey("status"));
        assertFalse(out.containsKey("ip_addr"), "ip_addr 제거");
        assertFalse(out.containsKey("ssh_user"), "ssh_user 제거");
        assertFalse(out.containsKey("os_pw_enc"), "os_pw_enc 제거");
    }

    @Test
    @SuppressWarnings("unchecked")
    void clean_recursesIntoNestedListAndMap() {
        Map<String, Object> nested = Map.of("password", "secret", "name", "srv1");
        List<Object> input = List.of(nested);
        List<Object> out = (List<Object>) ItsmSecuritySanitizer.clean(input);
        Map<String, Object> first = (Map<String, Object>) out.get(0);
        assertFalse(first.containsKey("password"), "중첩 password 제거");
        assertEquals("srv1", first.get("name"));
    }

    @Test
    void clean_passesThroughScalars() {
        assertEquals("plain", ItsmSecuritySanitizer.clean("plain"));
        assertEquals(42, ItsmSecuritySanitizer.clean(42));
    }
}
