Skip to content

Commit 192fee6

Browse files
author
Inbal Tako
committed
Add request utils tests
1 parent d79c938 commit 192fee6

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/test/java/com/securenative/config/ConfigurationManagerTest.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.io.ByteArrayInputStream;
1010
import java.io.InputStream;
1111
import java.lang.reflect.Field;
12+
import java.util.ArrayList;
1213
import java.util.Map;
1314
import java.util.concurrent.TimeUnit;
1415

@@ -40,7 +41,8 @@ public void ParseConfigFileCorrectlyTest() throws SecureNativeConfigException {
4041
"SECURENATIVE_AUTO_SEND=true",
4142
"SECURENATIVE_DISABLE=false",
4243
"SECURENATIVE_LOG_LEVEL=fatal",
43-
"SECURENATIVE_FAILOVER_STRATEGY=fail-closed");
44+
"SECURENATIVE_FAILOVER_STRATEGY=fail-closed",
45+
"SECURENATIVE_PROXY_HEADERS=CF-Connecting-IP,Some-Random-Ip");
4446

4547
InputStream inputStream = new ByteArrayInputStream(config.getBytes());
4648

@@ -60,6 +62,7 @@ public void ParseConfigFileCorrectlyTest() throws SecureNativeConfigException {
6062
assertThat(options.getLogLevel()).isEqualTo("fatal");
6163
assertThat(options.getMaxEvents()).isEqualTo(100);
6264
assertThat(options.getTimeout()).isEqualTo(1500);
65+
assertThat(options.getProxyHeaders().size() == 0);
6366

6467
// restore resource stream
6568
ConfigurationManager.setResourceStream(new ResourceStreamImpl());
@@ -159,6 +162,7 @@ public void loadDefaultConfigTest() throws SecureNativeConfigException {
159162
assertThat(options.getDisabled()).isEqualTo(false);
160163
assertThat(options.getLogLevel()).isEqualTo("fatal");
161164
assertThat(options.getFailoverStrategy()).isEqualTo(FailoverStrategy.FAIL_OPEN);
165+
assertThat(options.getProxyHeaders().size() == 0);
162166

163167
ConfigurationManager.setResourceStream(new ResourceStreamImpl());
164168
}
@@ -177,6 +181,7 @@ public void getConfigFromEnvVariablesTest() throws SecureNativeConfigException,
177181
setEnv("SECURENATIVE_DISABLE", "true");
178182
setEnv("SECURENATIVE_LOG_LEVEL", "fatal");
179183
setEnv("SECURENATIVE_FAILOVER_STRATEGY", "fail-closed");
184+
setEnv("SECURENATIVE_PROXY_HEADERS", "CF-Connecting-IP,Some-Random-Ip");
180185

181186
SecureNativeOptions options = ConfigurationManager.loadConfig();
182187

@@ -189,6 +194,7 @@ public void getConfigFromEnvVariablesTest() throws SecureNativeConfigException,
189194
assertThat(options.getDisabled()).isEqualTo(true);
190195
assertThat(options.getLogLevel()).isEqualTo("fatal");
191196
assertThat(options.getFailoverStrategy()).isEqualTo(FailoverStrategy.FAIL_CLOSED);
197+
assertThat(options.getProxyHeaders().size() == 2);
192198

193199
setEnv("SECURENATIVE_API_KEY", "");
194200
setEnv("SECURENATIVE_API_URL", "");
@@ -199,6 +205,7 @@ public void getConfigFromEnvVariablesTest() throws SecureNativeConfigException,
199205
setEnv("SECURENATIVE_DISABLE", "");
200206
setEnv("SECURENATIVE_LOG_LEVEL", "");
201207
setEnv("SECURENATIVE_FAILOVER_STRATEGY", "");
208+
setEnv("SECURENATIVE_PROXY_HEADERS", "");
202209
}
203210

204211
@Test
@@ -215,7 +222,8 @@ public void overwriteEnvVariablesWithConfigFileTest() throws SecureNativeConfigE
215222
"SECURENATIVE_AUTO_SEND=false",
216223
"SECURENATIVE_DISABLE=false",
217224
"SECURENATIVE_LOG_LEVEL=fatal",
218-
"SECURENATIVE_FAILOVER_STRATEGY=fail-closed");
225+
"SECURENATIVE_FAILOVER_STRATEGY=fail-closed",
226+
"SECURENATIVE_PROXY_HEADERS=CF-Connecting-IP,Some-Random-Ip");
219227

220228
setEnv("SECURENATIVE_API_KEY", "API_KEY_FROM_ENV");
221229
setEnv("SECURENATIVE_API_URL", "API_URL_ENV");
@@ -226,6 +234,7 @@ public void overwriteEnvVariablesWithConfigFileTest() throws SecureNativeConfigE
226234
setEnv("SECURENATIVE_DISABLE", "true");
227235
setEnv("SECURENATIVE_LOG_LEVEL", "error");
228236
setEnv("SECURENATIVE_FAILOVER_STRATEGY", "fail-open");
237+
setEnv("SECURENATIVE_PROXY_HEADERS", "CF-Connecting-IP,Some-Random-Ip");
229238

230239
InputStream inputStream = new ByteArrayInputStream(config.getBytes());
231240

@@ -234,6 +243,9 @@ public void overwriteEnvVariablesWithConfigFileTest() throws SecureNativeConfigE
234243

235244
ConfigurationManager.setResourceStream(resourceStream);
236245
SecureNativeOptions options = ConfigurationManager.loadConfig();
246+
ArrayList<String> proxyHeaders = new ArrayList<>();
247+
proxyHeaders.add("CF-Connecting-IP");
248+
proxyHeaders.add("Some-Random-Ip");
237249

238250
assertThat(options).isNotNull();
239251
assertThat(options.getApiKey()).isEqualTo("API_KEY_FROM_FILE");
@@ -245,6 +257,7 @@ public void overwriteEnvVariablesWithConfigFileTest() throws SecureNativeConfigE
245257
assertThat(options.getDisabled()).isEqualTo(false);
246258
assertThat(options.getLogLevel()).isEqualTo("fatal");
247259
assertThat(options.getFailoverStrategy()).isEqualTo(FailoverStrategy.FAIL_CLOSED);
260+
assertThat(options.getProxyHeaders()).isEqualTo(proxyHeaders);
248261

249262
setEnv("SECURENATIVE_API_KEY", "");
250263
setEnv("SECURENATIVE_API_URL", "");
@@ -255,6 +268,7 @@ public void overwriteEnvVariablesWithConfigFileTest() throws SecureNativeConfigE
255268
setEnv("SECURENATIVE_DISABLE", "");
256269
setEnv("SECURENATIVE_LOG_LEVEL", "");
257270
setEnv("SECURENATIVE_FAILOVER_STRATEGY", "");
271+
setEnv("SECURENATIVE_PROXY_HEADERS", "");
258272

259273
// restore resource stream
260274
ConfigurationManager.setResourceStream(new ResourceStreamImpl());

0 commit comments

Comments
 (0)