-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy pathIndexTIFSourceConfigActionTests.java
More file actions
63 lines (53 loc) · 2.63 KB
/
IndexTIFSourceConfigActionTests.java
File metadata and controls
63 lines (53 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
package org.opensearch.securityanalytics.action;
import org.junit.Assert;
import org.junit.Test;
import org.opensearch.core.rest.RestStatus;
import org.opensearch.rest.RestRequest;
import org.opensearch.securityanalytics.threatIntel.action.SAIndexTIFSourceConfigAction;
import org.opensearch.securityanalytics.threatIntel.resthandler.RestIndexTIFSourceConfigAction;
import org.opensearch.test.OpenSearchTestCase;
import org.opensearch.test.rest.FakeRestChannel;
import org.opensearch.test.rest.FakeRestRequest;
import org.opensearch.transport.client.node.NodeClient;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.opensearch.securityanalytics.SecurityAnalyticsPlugin.THREAT_INTEL_SOURCE_URI;
public class IndexTIFSourceConfigActionTests extends OpenSearchTestCase {
public void testIndexTIFSourceConfigActionName() {
Assert.assertNotNull(SAIndexTIFSourceConfigAction.INSTANCE.name());
Assert.assertEquals(SAIndexTIFSourceConfigAction.INSTANCE.name(), SAIndexTIFSourceConfigAction.NAME);
}
@Test
public void testPrepareRequest_blockUrlDownloadCreate() throws Exception {
RestIndexTIFSourceConfigAction action = new RestIndexTIFSourceConfigAction();
NodeClient client = mock(NodeClient.class);
String requestBody = "{\n" +
" \"type\": \"URL_DOWNLOAD\",\n" +
" \"name\": \"test\",\n" +
" \"format\": \"STIX2\",\n" +
" \"source\": {\n" +
" \"url_download\": {\n" +
" \"url\": \"http://127.0.0.1:9200\",\n" +
" \"feed_format\": \"csv\"\n" +
" }\n" +
" },\n" +
" \"enabled_for_scan\": true,\n" +
" \"ioc_types\": [\"ip\"]\n" +
"}";
FakeRestRequest request = new FakeRestRequest.Builder(xContentRegistry())
.withMethod(RestRequest.Method.POST)
.withPath(THREAT_INTEL_SOURCE_URI)
.withContent(new org.opensearch.core.common.bytes.BytesArray(requestBody),
org.opensearch.common.xcontent.XContentType.JSON)
.build();
FakeRestChannel channel = new FakeRestChannel(request, true, 1);
action.handleRequest(request, channel, client);
assertEquals(RestStatus.BAD_REQUEST, channel.capturedResponse().status());
assertTrue(channel.capturedResponse().content().utf8ToString().contains("URL_DOWNLOAD"));
verifyNoInteractions(client);
}
}