|
10 | 10 | package org.opensearch.security.grpc; |
11 | 11 |
|
12 | 12 | import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope; |
| 13 | +import io.grpc.ManagedChannel; |
13 | 14 | import io.grpc.StatusRuntimeException; |
14 | 15 | import org.junit.ClassRule; |
15 | 16 | import org.junit.Test; |
|
19 | 20 | import org.opensearch.test.framework.cluster.LocalCluster; |
20 | 21 |
|
21 | 22 | import java.io.IOException; |
| 23 | +import java.util.UUID; |
22 | 24 |
|
23 | 25 | import static org.hamcrest.MatcherAssert.assertThat; |
24 | 26 | import static org.junit.Assert.assertEquals; |
25 | 27 | import static org.junit.Assert.assertThrows; |
26 | | -import static org.opensearch.security.grpc.GrpcHelpers.CLIENT_AUTH_OPT; |
| 28 | +import static org.opensearch.security.grpc.GrpcHelpers.CLIENT_AUTH_NONE; |
27 | 29 | import static org.opensearch.security.grpc.GrpcHelpers.baseGrpcCluster; |
28 | 30 |
|
29 | 31 | @RunWith(com.carrotsearch.randomizedtesting.RandomizedRunner.class) |
30 | 32 | @ThreadLeakScope(ThreadLeakScope.Scope.NONE) |
31 | | -public class GrpcTestsClientAuthOptionalTest { |
| 33 | +public class GrpcClientAuthNoneTests { |
32 | 34 | @ClassRule |
33 | 35 | public static LocalCluster cluster = baseGrpcCluster() |
34 | | - .nodeSettings(CLIENT_AUTH_OPT) |
| 36 | + .nodeSettings(CLIENT_AUTH_NONE) |
35 | 37 | .build(); |
36 | 38 |
|
37 | | - @Test |
38 | | - public void testPlaintextChannelFails() { |
39 | | - long testDocs = 1; |
40 | | - String testIndex = "plaintext-test-index"; |
41 | | - StatusRuntimeException exception = assertThrows(StatusRuntimeException.class, () -> { |
42 | | - GrpcHelpers.doBulk(GrpcHelpers.plaintextChannel(), testIndex, testDocs); |
43 | | - }); |
44 | | - assertEquals("UNAVAILABLE: Network closed for unknown reason", exception.getMessage()); |
45 | | - } |
| 39 | + public static void assertBulkAndSearchTestIndex(ManagedChannel channel) { |
| 40 | + int testDocs = (int)(Math.random() * 101); |
| 41 | + String testIndex = UUID.randomUUID().toString().substring(0, 10); |
46 | 42 |
|
47 | | - @Test |
48 | | - public void testBulkAndSearchInsecureChannel() { |
49 | | - long testDocs = 9; |
50 | | - String testIndex = "test-index"; |
51 | | - |
52 | | - BulkResponse bulkResp = GrpcHelpers.doBulk(GrpcHelpers.insecureChannel(), testIndex, testDocs); |
| 43 | + BulkResponse bulkResp = GrpcHelpers.doBulk(channel, testIndex, testDocs); |
53 | 44 | assertThat("Bulk response should not be null", bulkResp != null); |
54 | 45 | assertThat("Bulk response should not contain errors", !bulkResp.hasBulkErrorResponse()); |
55 | 46 | assertThat("Bulk response should have response for all docs indexed", bulkResp.getBulkResponseBody().getItemsCount() == testDocs); |
56 | 47 |
|
57 | | - SearchResponse searchResp = GrpcHelpers.doMatchAll(GrpcHelpers.insecureChannel(), testIndex, 100); |
| 48 | + SearchResponse searchResp = GrpcHelpers.doMatchAll(channel, testIndex, 10); |
58 | 49 | assertThat("Search response should not be null", searchResp != null); |
59 | 50 | assertThat("Search response should indicate success", searchResp.getResponseCase().getNumber() == SearchResponse.ResponseCase.RESPONSE_BODY.getNumber()); |
60 | 51 | assertThat("Search response has correct hits count", searchResp.getResponseBody().getHits().getTotal().getTotalHits().getValue() == testDocs); |
61 | 52 | } |
62 | 53 |
|
63 | 54 | @Test |
64 | | - public void testBulkAndSearchSecureChannel() throws IOException { |
65 | | - long testDocs = 9; |
66 | | - String testIndex = "test-index"; |
| 55 | + public void testPlaintextChannel() { |
| 56 | + StatusRuntimeException exception = assertThrows(StatusRuntimeException.class, () -> { |
| 57 | + assertBulkAndSearchTestIndex(GrpcHelpers.plaintextChannel()); |
| 58 | + }); |
| 59 | + assertEquals("UNAVAILABLE: Network closed for unknown reason", exception.getMessage()); |
| 60 | + } |
67 | 61 |
|
68 | | - BulkResponse bulkResp = GrpcHelpers.doBulk(GrpcHelpers.secureChannel(), testIndex, testDocs); |
69 | | - assertThat("Bulk response should not be null", bulkResp != null); |
70 | | - assertThat("Bulk response should not contain errors", !bulkResp.hasBulkErrorResponse()); |
71 | | - assertThat("Bulk response should have response for all docs indexed", bulkResp.getBulkResponseBody().getItemsCount() == testDocs); |
| 62 | + @Test |
| 63 | + public void testBulkAndSearchInsecureChannel() { |
| 64 | + assertBulkAndSearchTestIndex(GrpcHelpers.insecureChannel()); |
| 65 | + } |
72 | 66 |
|
73 | | - SearchResponse searchResp = GrpcHelpers.doMatchAll(GrpcHelpers.secureChannel(), testIndex, 100); |
74 | | - assertThat("Search response should not be null", searchResp != null); |
75 | | - assertThat("Search response should indicate success", searchResp.getResponseCase().getNumber() == SearchResponse.ResponseCase.RESPONSE_BODY.getNumber()); |
76 | | - assertThat("Search response has correct hits count", searchResp.getResponseBody().getHits().getTotal().getTotalHits().getValue() == testDocs); |
| 67 | + @Test |
| 68 | + public void testBulkAndSearchSecureChannel() throws IOException { |
| 69 | + assertBulkAndSearchTestIndex(GrpcHelpers.secureChannel()); |
77 | 70 | } |
78 | 71 |
|
79 | 72 | @Test |
80 | | - public void testBulkAndSearchUntrustedSecureChannelFails() { |
81 | | - long testDocs = 1; |
82 | | - String testIndex = "plaintext-test-index"; |
83 | | - StatusRuntimeException exception = assertThrows(StatusRuntimeException.class, () -> { |
84 | | - GrpcHelpers.doBulk(GrpcHelpers.secureUntrustedChannel(), testIndex, testDocs); |
85 | | - }); |
86 | | - assertEquals("UNAVAILABLE: ssl exception", exception.getMessage()); |
| 73 | + public void testBulkAndSearchUntrustedSecureChannel() throws IOException { |
| 74 | + assertBulkAndSearchTestIndex(GrpcHelpers.secureUntrustedChannel()); |
87 | 75 | } |
88 | 76 | } |
0 commit comments