|
3 | 3 | import io.jenkins.plugins.casc.SecretSourceResolver.Base64Lookup; |
4 | 4 | import io.jenkins.plugins.casc.SecretSourceResolver.FileBase64Lookup; |
5 | 5 | import io.jenkins.plugins.casc.SecretSourceResolver.FileStringLookup; |
| 6 | +import io.jenkins.plugins.casc.SecretSourceResolver.SystemPropertyLookup; |
6 | 7 | import java.io.File; |
7 | 8 | import java.net.URISyntaxException; |
8 | 9 | import java.nio.file.Files; |
@@ -46,6 +47,7 @@ public class SecretSourceResolverTest { |
46 | 47 | public static final StringLookup DECODE = StringLookupFactory.INSTANCE.base64DecoderStringLookup(); |
47 | 48 | public static final StringLookup FILE = FileStringLookup.INSTANCE; |
48 | 49 | public static final StringLookup BINARYFILE = FileBase64Lookup.INSTANCE; |
| 50 | + public static final StringLookup SYSPROP = SystemPropertyLookup.INSTANCE; |
49 | 51 |
|
50 | 52 | @Before |
51 | 53 | public void initLogging() { |
@@ -348,6 +350,24 @@ public void resolve_BinaryFileBase64() throws Exception { |
348 | 350 | assertThat(actualBytes, equalTo(expectedBytes)); |
349 | 351 | } |
350 | 352 |
|
| 353 | + @Test |
| 354 | + public void resolve_SystemProperty() throws Exception { |
| 355 | + String input = "java.version"; |
| 356 | + String expected = System.getProperty(input); |
| 357 | + String output = resolve("${sysProp:" + input + "}"); |
| 358 | + assertThat(output, equalTo(SYSPROP.lookup(input))); |
| 359 | + assertThat(output, equalTo(expected)); |
| 360 | + } |
| 361 | + |
| 362 | + @Test |
| 363 | + public void resolve_SystemPropertyNotFound() throws Exception { |
| 364 | + String input = "java.version.non-existent"; |
| 365 | + String expected = ""; |
| 366 | + String output = resolve("${sysProp:" + input + "}"); |
| 367 | + assertThat(output, equalTo(SYSPROP.lookup(input))); |
| 368 | + assertThat(output, equalTo(expected)); |
| 369 | + } |
| 370 | + |
351 | 371 | @Test |
352 | 372 | public void resolve_Json() { |
353 | 373 | String input = "{ \"a\": 1, \"b\": 2 }"; |
|
0 commit comments