forked from temporalio/sdk-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServiceStubsOptionsTest.java
More file actions
180 lines (143 loc) · 5.66 KB
/
Copy pathServiceStubsOptionsTest.java
File metadata and controls
180 lines (143 loc) · 5.66 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
package io.temporal.serviceclient;
import static org.junit.Assert.*;
import org.junit.Test;
public class ServiceStubsOptionsTest {
@Test
public void testTLSEnabledByDefaultWhenAPIKeyProvided() {
ServiceStubsOptions options =
WorkflowServiceStubsOptions.newBuilder()
.setTarget("localhost:7233")
.addApiKey(() -> "test-api-key")
.validateAndBuildWithDefaults();
assertTrue(options.getEnableHttps());
}
@Test
public void testExplicitTLSDisableBeforeAPIKeyStillDisables() {
ServiceStubsOptions options =
WorkflowServiceStubsOptions.newBuilder()
.setTarget("localhost:7233")
.setEnableHttps(false)
.addApiKey(() -> "test-api-key")
.validateAndBuildWithDefaults();
// Explicit TLS=false should take precedence regardless of order
assertFalse(options.getEnableHttps());
}
@Test
public void testExplicitTLSDisableAfterAPIKeyStillDisables() {
ServiceStubsOptions options =
WorkflowServiceStubsOptions.newBuilder()
.setTarget("localhost:7233")
.addApiKey(() -> "test-api-key")
.setEnableHttps(false)
.validateAndBuildWithDefaults();
// Explicit TLS=false should take precedence regardless of order
assertFalse(options.getEnableHttps());
}
@Test
public void testTLSDisabledByDefaultWithoutAPIKey() {
ServiceStubsOptions options =
WorkflowServiceStubsOptions.newBuilder()
.setTarget("localhost:7233")
.validateAndBuildWithDefaults();
assertFalse(options.getEnableHttps());
}
@Test
public void testExplicitTLSEnableWithoutAPIKey() {
ServiceStubsOptions options =
WorkflowServiceStubsOptions.newBuilder()
.setTarget("localhost:7233")
.setEnableHttps(true)
.validateAndBuildWithDefaults();
assertTrue(options.getEnableHttps());
}
@Test
public void testBuilderFromOptionsPreservesDefaultTLSBehavior() {
ServiceStubsOptions options1 =
WorkflowServiceStubsOptions.newBuilder()
.setTarget("localhost:7233")
.validateAndBuildWithDefaults();
assertFalse(options1.getEnableHttps());
ServiceStubsOptions options2 =
WorkflowServiceStubsOptions.newBuilder(options1)
.addApiKey(() -> "test-api-key")
.validateAndBuildWithDefaults();
assertTrue(
"TLS should auto-enable when API key is added to builder from options that had default TLS behavior",
options2.getEnableHttps());
}
@Test
public void testBuilderFromOptionsWithExplicitTLSDisableStaysDisabled() {
ServiceStubsOptions options1 =
WorkflowServiceStubsOptions.newBuilder()
.setTarget("localhost:7233")
.setEnableHttps(false)
.validateAndBuildWithDefaults();
assertFalse(options1.getEnableHttps());
ServiceStubsOptions options2 =
WorkflowServiceStubsOptions.newBuilder(options1)
.addApiKey(() -> "test-api-key")
.validateAndBuildWithDefaults();
assertFalse(
"TLS should stay disabled when explicitly set to false, even with API key",
options2.getEnableHttps());
}
@Test
public void testBuilderFromOptionsWithExplicitTLSEnableStaysEnabled() {
ServiceStubsOptions options1 =
WorkflowServiceStubsOptions.newBuilder()
.setTarget("localhost:7233")
.setEnableHttps(true)
.validateAndBuildWithDefaults();
assertTrue(options1.getEnableHttps());
ServiceStubsOptions options2 =
WorkflowServiceStubsOptions.newBuilder(options1).validateAndBuildWithDefaults();
assertTrue("TLS should stay enabled when explicitly set to true", options2.getEnableHttps());
}
@Test
public void testSpringBootStyleAutoTLSWithApiKey() {
ServiceStubsOptions options1 =
WorkflowServiceStubsOptions.newBuilder()
.setTarget("my-namespace.tmprl.cloud:7233")
.addApiKey(() -> "my-api-key")
.validateAndBuildWithDefaults();
assertTrue(
"TLS should auto-enable when API key is provided without explicit TLS setting",
options1.getEnableHttps());
ServiceStubsOptions options2 =
WorkflowServiceStubsOptions.newBuilder()
.setTarget("localhost:7233")
.setEnableHttps(false)
.addApiKey(() -> "my-api-key")
.validateAndBuildWithDefaults();
assertFalse(
"TLS should stay disabled when explicitly set to false, even with API key",
options2.getEnableHttps());
ServiceStubsOptions options3 =
WorkflowServiceStubsOptions.newBuilder()
.setTarget("localhost:7233")
.validateAndBuildWithDefaults();
assertFalse(
"TLS should be disabled when no API key and no explicit TLS setting",
options3.getEnableHttps());
}
@Test
public void testGrpcCompressionDefaultsToGzip() {
ServiceStubsOptions options =
WorkflowServiceStubsOptions.newBuilder()
.setTarget("localhost:7233")
.validateAndBuildWithDefaults();
assertEquals(GrpcCompression.GZIP, options.getGrpcCompression());
}
@Test
public void testGrpcCompressionNonePassesThroughBuilderCopy() {
ServiceStubsOptions options =
WorkflowServiceStubsOptions.newBuilder()
.setTarget("localhost:7233")
.setGrpcCompression(GrpcCompression.NONE)
.validateAndBuildWithDefaults();
assertEquals(GrpcCompression.NONE, options.getGrpcCompression());
ServiceStubsOptions copied =
WorkflowServiceStubsOptions.newBuilder(options).validateAndBuildWithDefaults();
assertEquals(GrpcCompression.NONE, copied.getGrpcCompression());
}
}