Skip to content

Commit 109acd0

Browse files
VihasMakwanasemgrep-app[bot]
authored andcommitted
Update src/main/java/com/splunk/hecclient/Hec.java
Co-authored-by: semgrep-app[bot] <63493438+semgrep-app[bot]@users.noreply.github.com>
1 parent be62f5e commit 109acd0

File tree

8 files changed

+36
-36
lines changed

8 files changed

+36
-36
lines changed

src/main/java/com/splunk/hecclient/Hec.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ public static SSLContext loadTrustManagerFactory(KeyStore keyStore) {
351351
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
352352
tmf.init(keyStore);
353353

354-
SSLContext sslContext = SSLContext.getInstance("TLS");
354+
SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
355355
sslContext.init(null, tmf.getTrustManagers(), new SecureRandom());
356356

357357
return sslContext;

src/main/java/com/splunk/hecclient/Indexer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ private String readAndCloseResponse(CloseableHttpResponse resp) {
241241
try {
242242
resp.close();
243243
} catch (IOException ex) {
244-
new HecException("failed to close http response", ex);
244+
throw new HecException("failed to close http response", ex);
245245
}
246246
}
247247

src/main/java/com/splunk/hecclient/JsonEventBatch.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public EventBatch createFromThis() {
4949
@Override
5050
public int hashCode() {
5151
return new HashCodeBuilder()
52-
.append(endpoint)
52+
.append(ENDPOINT)
5353
.toHashCode();
5454
}
5555

src/test/java/com/splunk/hecclient/IndexerTest.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public void sendWithSuccess() {
100100
for (int i = 0; i < 2; i++) {
101101
CloseableHttpClientMock client = new CloseableHttpClientMock();
102102
if (i == 0) {
103-
client.setResponse(CloseableHttpClientMock.success);
103+
client.setResponse(CloseableHttpClientMock.SUCCESS);
104104
}
105105
PollerMock poller = new PollerMock();
106106

@@ -112,14 +112,14 @@ public void sendWithSuccess() {
112112
Assert.assertNull(poller.getFailedBatch());
113113
Assert.assertNull(poller.getException());
114114
Assert.assertEquals(indexer.getChannel(), poller.getChannel());
115-
Assert.assertEquals(CloseableHttpClientMock.success, poller.getResponse());
115+
Assert.assertEquals(CloseableHttpClientMock.SUCCESS, poller.getResponse());
116116
}
117117
}
118118

119119
@Test
120120
public void sendWithInvalidData() {
121121
CloseableHttpClientMock client = new CloseableHttpClientMock();
122-
client.setResponse(CloseableHttpClientMock.invalidDataFormat);
122+
client.setResponse(CloseableHttpClientMock.INVALID_DATA_FORMAT);
123123
PollerMock poller = new PollerMock();
124124

125125
Indexer indexer = new Indexer(baseUrl, client, poller, hecConfig);
@@ -130,14 +130,14 @@ public void sendWithInvalidData() {
130130
Assert.assertNull(poller.getFailedBatch());
131131
Assert.assertNull(poller.getException());
132132
Assert.assertEquals(indexer.getChannel(), poller.getChannel());
133-
Assert.assertEquals(CloseableHttpClientMock.success, poller.getResponse());
133+
Assert.assertEquals(CloseableHttpClientMock.SUCCESS, poller.getResponse());
134134
}
135135

136136

137137
@Test
138138
public void sendWithServerBusy() {
139139
CloseableHttpClientMock client = new CloseableHttpClientMock();
140-
client.setResponse(CloseableHttpClientMock.serverBusy);
140+
client.setResponse(CloseableHttpClientMock.SERVER_BUSY);
141141

142142
Indexer indexer = assertFailure(client);
143143
Assert.assertTrue(indexer.hasBackPressure());
@@ -151,7 +151,7 @@ public void sendWithServerBusy() {
151151
@Test
152152
public void ConfirmShortBackPressureConfig() {
153153
CloseableHttpClientMock client = new CloseableHttpClientMock();
154-
client.setResponse(CloseableHttpClientMock.serverBusy);
154+
client.setResponse(CloseableHttpClientMock.SERVER_BUSY);
155155

156156
Indexer indexer = assertFailure(client);
157157
Assert.assertTrue(indexer.hasBackPressure());
@@ -165,22 +165,22 @@ public void ConfirmShortBackPressureConfig() {
165165
@Test
166166
public void sendWithIOError() {
167167
CloseableHttpClientMock client = new CloseableHttpClientMock();
168-
client.setResponse(CloseableHttpClientMock.exception);
168+
client.setResponse(CloseableHttpClientMock.EXCEPTION);
169169
assertFailure(client);
170170
}
171171

172172
@Test
173173
public void sendWithCloseError() {
174174
CloseableHttpClientMock client = new CloseableHttpClientMock();
175-
client.setResponse(CloseableHttpClientMock.success);
175+
client.setResponse(CloseableHttpClientMock.SUCCESS);
176176
client.setThrowOnClose(true);
177177
assertFailure(client);
178178
}
179179

180180
@Test
181181
public void sendWithReadError() {
182182
CloseableHttpClientMock client = new CloseableHttpClientMock();
183-
client.setResponse(CloseableHttpClientMock.success);
183+
client.setResponse(CloseableHttpClientMock.SUCCESS);
184184
client.setThrowOnGetContent(true);
185185
assertFailure(client);
186186
}
@@ -204,7 +204,7 @@ public void sendCompressedBatchWithSuccess() {
204204
for (int i = 0; i < 2; i++) {
205205
CloseableHttpClientMock client = new CloseableHttpClientMock();
206206
if (i == 0) {
207-
client.setResponse(CloseableHttpClientMock.success);
207+
client.setResponse(CloseableHttpClientMock.SUCCESS);
208208
}
209209
PollerMock poller = new PollerMock();
210210

@@ -217,7 +217,7 @@ public void sendCompressedBatchWithSuccess() {
217217
Assert.assertNull(poller.getFailedBatch());
218218
Assert.assertNull(poller.getException());
219219
Assert.assertEquals(indexer.getChannel(), poller.getChannel());
220-
Assert.assertEquals(CloseableHttpClientMock.success, poller.getResponse());
220+
Assert.assertEquals(CloseableHttpClientMock.SUCCESS, poller.getResponse());
221221
}
222222
}
223223

@@ -226,7 +226,7 @@ public void sendCompressedRawBatchWithSuccess() {
226226
for (int i = 0; i < 2; i++) {
227227
CloseableHttpClientMock client = new CloseableHttpClientMock();
228228
if (i == 0) {
229-
client.setResponse(CloseableHttpClientMock.success);
229+
client.setResponse(CloseableHttpClientMock.SUCCESS);
230230
}
231231
PollerMock poller = new PollerMock();
232232

@@ -239,7 +239,7 @@ public void sendCompressedRawBatchWithSuccess() {
239239
Assert.assertNull(poller.getFailedBatch());
240240
Assert.assertNull(poller.getException());
241241
Assert.assertEquals(indexer.getChannel(), poller.getChannel());
242-
Assert.assertEquals(CloseableHttpClientMock.success, poller.getResponse());
242+
Assert.assertEquals(CloseableHttpClientMock.SUCCESS, poller.getResponse());
243243
}
244244
}
245245
}

src/test/java/com/splunk/hecclient/JsonEvenBatchTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ public void addWithFailure() {
5151
@Test
5252
public void getRestEndpoint() {
5353
EventBatch batch = new JsonEventBatch();
54-
Assert.assertEquals(batch.getRestEndpoint(), JsonEventBatch.endpoint);
54+
Assert.assertEquals(batch.getRestEndpoint(), JsonEventBatch.ENDPOINT);
5555
}
5656

5757
@Test
5858
public void getContentType() {
5959
EventBatch batch = new JsonEventBatch();
60-
Assert.assertEquals(batch.getContentType(), JsonEventBatch.contentType);
60+
Assert.assertEquals(batch.getContentType(), JsonEventBatch.CONTENT_TYPE);
6161
}
6262

6363
@Test

src/test/java/com/splunk/hecclient/LoadBalancerTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void add() {
2929
String token = "mytoken";
3030
HecConfig config = new HecConfig(Arrays.asList(uri), token);
3131
CloseableHttpClientMock client = new CloseableHttpClientMock();
32-
client.setResponse(CloseableHttpClientMock.success);
32+
client.setResponse(CloseableHttpClientMock.SUCCESS);
3333
LoadBalancer lb = new LoadBalancer(config, client);
3434

3535
int numberOfChannels = 3;
@@ -48,7 +48,7 @@ public void send() {
4848
String token = "mytoken";
4949
HecConfig config = new HecConfig(Arrays.asList(uri), token);
5050
CloseableHttpClientMock client = new CloseableHttpClientMock();
51-
client.setResponse(CloseableHttpClientMock.success);
51+
client.setResponse(CloseableHttpClientMock.SUCCESS);
5252
LoadBalancer lb = new LoadBalancer(config, client); List<IndexerMock> indexers = new ArrayList<>();
5353

5454
int numberOfChannels = 3;
@@ -76,7 +76,7 @@ public void sendWithAllBackPressure() {
7676
String token = "mytoken";
7777
HecConfig config = new HecConfig(Arrays.asList(uri), token);
7878
CloseableHttpClientMock client = new CloseableHttpClientMock();
79-
client.setResponse(CloseableHttpClientMock.success);
79+
client.setResponse(CloseableHttpClientMock.SUCCESS);
8080
LoadBalancer lb = new LoadBalancer(config, client);
8181
List<IndexerMock> indexers = new ArrayList<>();
8282

@@ -98,7 +98,7 @@ public void sendWithOneBackPressure() {
9898
String token = "mytoken";
9999
HecConfig config = new HecConfig(Arrays.asList(uri), token);
100100
CloseableHttpClientMock client = new CloseableHttpClientMock();
101-
client.setResponse(CloseableHttpClientMock.success);
101+
client.setResponse(CloseableHttpClientMock.SUCCESS);
102102
LoadBalancer lb = new LoadBalancer(config, client);
103103
List<IndexerMock> indexers = new ArrayList<>();
104104

@@ -127,7 +127,7 @@ public void sendWithOneNotAvailable() {
127127
String token = "mytoken";
128128
HecConfig config = new HecConfig(Arrays.asList(uri), token);
129129
CloseableHttpClientMock client = new CloseableHttpClientMock();
130-
client.setResponse(CloseableHttpClientMock.success);
130+
client.setResponse(CloseableHttpClientMock.SUCCESS);
131131
LoadBalancer lb = new LoadBalancer(config, client);
132132
List<IndexerMock> indexers = new ArrayList<>();
133133

@@ -158,7 +158,7 @@ public void sendWithoutChannels() {
158158
String token = "mytoken";
159159
HecConfig config = new HecConfig(Arrays.asList(uri), token);
160160
CloseableHttpClientMock client = new CloseableHttpClientMock();
161-
client.setResponse(CloseableHttpClientMock.success);
161+
client.setResponse(CloseableHttpClientMock.SUCCESS);
162162
LoadBalancer lb = new LoadBalancer(config, client);
163163
lb.send(UnitUtil.createBatch());
164164
}
@@ -169,7 +169,7 @@ public void remove() {
169169
String token = "mytoken";
170170
HecConfig config = new HecConfig(Arrays.asList(uri), token);
171171
CloseableHttpClientMock client = new CloseableHttpClientMock();
172-
client.setResponse(CloseableHttpClientMock.success);
172+
client.setResponse(CloseableHttpClientMock.SUCCESS);
173173
LoadBalancer lb = new LoadBalancer(config, client);
174174
List<HecChannel> channels = new ArrayList<>();
175175

@@ -194,7 +194,7 @@ public void size() {
194194
String token = "mytoken";
195195
HecConfig config = new HecConfig(Arrays.asList(uri), token);
196196
CloseableHttpClientMock client = new CloseableHttpClientMock();
197-
client.setResponse(CloseableHttpClientMock.success);
197+
client.setResponse(CloseableHttpClientMock.SUCCESS);
198198
LoadBalancer lb = new LoadBalancer(config, client);
199199
Assert.assertEquals(0, lb.size());
200200
}

src/test/java/com/splunk/hecclient/RawEventBatchTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void addWithFailure() {
4949
public void getRestEndpoint() {
5050
// Without metadata
5151
EventBatch batch = RawEventBatch.factory().build();
52-
Assert.assertEquals(batch.getRestEndpoint(), RawEventBatch.endpoint);
52+
Assert.assertEquals(batch.getRestEndpoint(), RawEventBatch.ENDPOINT);
5353

5454
// With all metadata
5555
EventBatch rawBatch = RawEventBatch.factory()
@@ -83,7 +83,7 @@ public void getRestEndpoint() {
8383
@Test
8484
public void getContentType() {
8585
EventBatch batch = RawEventBatch.factory().build();
86-
Assert.assertEquals(batch.getContentType(), RawEventBatch.contentType);
86+
Assert.assertEquals(batch.getContentType(), RawEventBatch.CONTENT_TYPE);
8787
}
8888

8989
@Test

src/test/java/com/splunk/kafka/connect/SplunkSinkConnecterTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public void testInvalidToken() {
177177
configs.put("topics", "b");
178178
configs.put("splunk.indexes", "b");
179179
MockHecClientWrapper clientInstance = new MockHecClientWrapper();
180-
clientInstance.client.setResponse(CloseableHttpClientMock.inValidToken);
180+
clientInstance.client.setResponse(CloseableHttpClientMock.INVALID_TOKEN);
181181
((SplunkSinkConnector) connector).setHecInstance(clientInstance);
182182
Assertions.assertThrows(ConfigException.class, ()->connector.validate(configs));
183183
}
@@ -202,7 +202,7 @@ public void testInvalidIndex() {
202202
configs.put("topics", "b");
203203
configs.put("splunk.indexes", "b");
204204
MockHecClientWrapper clientInstance = new MockHecClientWrapper();
205-
clientInstance.client.setResponse(CloseableHttpClientMock.inValidIndex);
205+
clientInstance.client.setResponse(CloseableHttpClientMock.INVALID_INDEX);
206206
((SplunkSinkConnector) connector).setHecInstance(clientInstance);
207207
Assertions.assertThrows(ConfigException.class, ()->connector.validate(configs));
208208
}
@@ -217,7 +217,7 @@ public void testValidMultipleURIs() {
217217
configs.put("splunk.hec.uri", "https://localhost:8088,https://localhost:8089");
218218
configs.put("splunk.hec.ssl.validate.certs", "false");
219219
MockHecClientWrapper clientInstance = new MockHecClientWrapper();
220-
clientInstance.client.setResponse(CloseableHttpClientMock.success);
220+
clientInstance.client.setResponse(CloseableHttpClientMock.SUCCESS);
221221
((SplunkSinkConnector) connector).setHecInstance(clientInstance);
222222
Assertions.assertDoesNotThrow(()->connector.validate(configs));
223223
}
@@ -230,7 +230,7 @@ public void testValidSplunkConfigurations() {
230230
configs.put("topics", "b");
231231
configs.put("splunk.indexes", "b");
232232
MockHecClientWrapper clientInstance = new MockHecClientWrapper();
233-
clientInstance.client.setResponse(CloseableHttpClientMock.success);
233+
clientInstance.client.setResponse(CloseableHttpClientMock.SUCCESS);
234234
((SplunkSinkConnector) connector).setHecInstance(clientInstance);
235235
Assertions.assertDoesNotThrow(()->connector.validate(configs));
236236
}
@@ -243,7 +243,7 @@ public void testInvalidSplunkConfigurationsWithValidationDisabled() {
243243
configs.put("splunk.validation.disable", "true");
244244
configs.put("topics", "b");
245245
MockHecClientWrapper clientInstance = new MockHecClientWrapper();
246-
clientInstance.client.setResponse(CloseableHttpClientMock.exception);
246+
clientInstance.client.setResponse(CloseableHttpClientMock.EXCEPTION);
247247
((SplunkSinkConnector) connector).setHecInstance(clientInstance);
248248
Assertions.assertDoesNotThrow(()->connector.validate(configs));
249249
}
@@ -256,7 +256,7 @@ public void testInvalidSplunkConfigurationsWithValidationEnabled() {
256256
configs.put("splunk.validation.disable", "false");
257257
configs.put("topics", "b");
258258
MockHecClientWrapper clientInstance = new MockHecClientWrapper();
259-
clientInstance.client.setResponse(CloseableHttpClientMock.exception);
259+
clientInstance.client.setResponse(CloseableHttpClientMock.EXCEPTION);
260260
((SplunkSinkConnector) connector).setHecInstance(clientInstance);
261261
Assertions.assertThrows(ConfigException.class, ()->connector.validate(configs));
262262
}
@@ -270,7 +270,7 @@ public void testValidQueueCapacity() {
270270
configs.put("topics", "b");
271271
configs.put("splunk.indexes", "b");
272272
MockHecClientWrapper clientInstance = new MockHecClientWrapper();
273-
clientInstance.client.setResponse(CloseableHttpClientMock.success);
273+
clientInstance.client.setResponse(CloseableHttpClientMock.SUCCESS);
274274
((SplunkSinkConnector) connector).setHecInstance(clientInstance);
275275
Assertions.assertDoesNotThrow(()->connector.validate(configs));
276276
}
@@ -284,7 +284,7 @@ public void testInvalidQueueCapacity() {
284284
configs.put("topics", "b");
285285
configs.put("splunk.indexes", "b");
286286
MockHecClientWrapper clientInstance = new MockHecClientWrapper();
287-
clientInstance.client.setResponse(CloseableHttpClientMock.success);
287+
clientInstance.client.setResponse(CloseableHttpClientMock.SUCCESS);
288288
((SplunkSinkConnector) connector).setHecInstance(clientInstance);
289289
Assertions.assertThrows(ConfigException.class, ()->connector.validate(configs));
290290
}

0 commit comments

Comments
 (0)