|
1 | 1 | package org.opensearch.dataprepper.plugins.source.crowdstrike.configuration; |
2 | 2 |
|
| 3 | +import com.fasterxml.jackson.core.JsonProcessingException; |
| 4 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 5 | +import org.junit.jupiter.api.Test; |
| 6 | + |
| 7 | +import java.util.HashMap; |
| 8 | +import java.util.Map; |
| 9 | + |
| 10 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 11 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
| 12 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 13 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 14 | + |
3 | 15 | public class AuthenticationConfigTest { |
| 16 | + |
| 17 | + private final ObjectMapper objectMapper = new ObjectMapper(); |
| 18 | + |
| 19 | + @Test |
| 20 | + void testValidConfigWithClientIdAndSecret() throws JsonProcessingException { |
| 21 | + Map<String, Object> yamlConfig = new HashMap<>(); |
| 22 | + yamlConfig.put("client_id", "dummy-client-id"); |
| 23 | + yamlConfig.put("client_secret", "dummy-client-secret"); |
| 24 | + |
| 25 | + String json = objectMapper.writeValueAsString(yamlConfig); |
| 26 | + AuthenticationConfig loadedConfig = objectMapper.readValue(json, AuthenticationConfig.class); |
| 27 | + |
| 28 | + assertNotNull(loadedConfig.getClientId()); |
| 29 | + assertEquals("dummy-client-id", loadedConfig.getClientId()); |
| 30 | + assertEquals("dummy-client-secret", loadedConfig.getClientSecret()); |
| 31 | + assertTrue(loadedConfig.isValidConfig(), "Expected config to be valid when both clientId and clientSecret are set"); |
| 32 | + } |
| 33 | + |
| 34 | + @Test |
| 35 | + void testInvalidConfigWithMissingClientId() throws JsonProcessingException { |
| 36 | + Map<String, Object> yamlConfig = new HashMap<>(); |
| 37 | + yamlConfig.put("client_id", "dummy-client-id"); |
| 38 | + String json = objectMapper.writeValueAsString(yamlConfig); |
| 39 | + AuthenticationConfig loadedConfig = objectMapper.readValue(json, AuthenticationConfig.class); |
| 40 | + assertFalse(loadedConfig.isValidConfig(), "Expected config to be invalid when clientId is missing"); |
| 41 | + } |
| 42 | + |
| 43 | + |
| 44 | + @Test |
| 45 | + void testInvalidConfigWithNoCredentials() { |
| 46 | + AuthenticationConfig config = new AuthenticationConfig(); |
| 47 | + assertFalse(config.isValidConfig(), "Expected config to be invalid when both clientId and clientSecret are missing"); |
| 48 | + } |
4 | 49 | } |
0 commit comments