|
13 | 13 | import java.io.IOException;
|
14 | 14 | import java.util.List;
|
15 | 15 |
|
| 16 | +import static org.opensearch.securityanalytics.TestHelpers.parser; |
16 | 17 | import static org.opensearch.securityanalytics.TestHelpers.randomDetector;
|
17 | 18 | import static org.opensearch.securityanalytics.TestHelpers.randomUser;
|
18 | 19 | import static org.opensearch.securityanalytics.TestHelpers.randomUserEmpty;
|
| 20 | +import static org.opensearch.securityanalytics.TestHelpers.toJsonStringWithUser; |
19 | 21 |
|
20 | 22 | public class WriteableTests extends OpenSearchTestCase {
|
21 | 23 |
|
22 | 24 | public void testDetectorAsAStream() throws IOException {
|
23 | 25 | Detector detector = randomDetector(List.of());
|
24 | 26 | detector.setInputs(List.of(new DetectorInput("", List.of(), List.of(), List.of())));
|
| 27 | + logger.error(toJsonStringWithUser(detector)); |
| 28 | + BytesStreamOutput out = new BytesStreamOutput(); |
| 29 | + detector.writeTo(out); |
| 30 | + StreamInput sin = StreamInput.wrap(out.bytes().toBytesRef().bytes); |
| 31 | + Detector newDetector = new Detector(sin); |
| 32 | + Assert.assertEquals("Round tripping Detector doesn't work", detector, newDetector); |
| 33 | + } |
| 34 | + |
| 35 | + public void testDetector() throws IOException { // an edge case of detector serialization that failed testDetectorAsAStream() intermittently |
| 36 | + String detectorString = "{\"type\":\"detector\",\"name\":\"MczAuRCrve\",\"detector_type\":\"test_windows\"," + |
| 37 | + "\"user\":{\"name\":\"QhKrfthgxw\",\"backend_roles\":[\"uYvGLCPhfX\",\"fOLkcRxMWR\"],\"roles\"" + |
| 38 | + ":[\"YuucNpVzTm\",\"all_access\"],\"custom_attribute_names\":[\"test_attr=test\"]," + |
| 39 | + "\"user_requested_tenant\":null},\"threat_intel_enabled\":false,\"enabled\":false,\"enabled_time\"" + |
| 40 | + ":null,\"schedule\":{\"period\":{\"interval\":5,\"unit\":\"MINUTES\"}},\"inputs\":[{\"detector_input\"" + |
| 41 | + ":{\"description\":\"\",\"indices\":[],\"custom_rules\":[],\"pre_packaged_rules\":[]}}],\"triggers\"" + |
| 42 | + ":[{\"id\":\"SiWfaosBBiNA8if0E1bC\",\"name\":\"windows-trigger\",\"severity\":\"1\",\"types\"" + |
| 43 | + ":[\"test_windows\"],\"ids\":[\"QuarksPwDump Clearing Access History\"],\"sev_levels\":[\"high\"]," + |
| 44 | + "\"tags\":[\"T0008\"],\"actions\":[],\"detection_types\":[\"rules\"]}],\"last_update_time\":" + |
| 45 | + "1698300892093,\"monitor_id\":[\"\"],\"workflow_ids\":[],\"bucket_monitor_id_rule_id\"" + |
| 46 | + ":{},\"rule_topic_index\":\"\",\"alert_index\":\"\",\"alert_history_index\":\"\"," + |
| 47 | + "\"alert_history_index_pattern\":\"\",\"findings_index\":\"\",\"findings_index_pattern\":\"\"}"; |
| 48 | + Detector detector = Detector.parse(parser(detectorString), null, null); |
| 49 | +// Detector detector = randomDetector(List.of()); |
| 50 | +// detector.setInputs(List.of(new DetectorInput("", List.of(), List.of(), List.of()))); |
| 51 | +// logger.error(toJsonStringWithUser(detector)); |
25 | 52 | BytesStreamOutput out = new BytesStreamOutput();
|
26 | 53 | detector.writeTo(out);
|
27 | 54 | StreamInput sin = StreamInput.wrap(out.bytes().toBytesRef().bytes);
|
|
0 commit comments