-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...ension/deployment/src/test/java/io/quarkus/config/SecretKeysConfigInterceptorFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package io.quarkus.config; | ||
|
||
import java.util.Set; | ||
|
||
import io.smallrye.config.ConfigSourceInterceptor; | ||
import io.smallrye.config.ConfigSourceInterceptorContext; | ||
import io.smallrye.config.ConfigSourceInterceptorFactory; | ||
import io.smallrye.config.SecretKeysConfigSourceInterceptor; | ||
|
||
public class SecretKeysConfigInterceptorFactory implements ConfigSourceInterceptorFactory { | ||
@Override | ||
public ConfigSourceInterceptor getInterceptor(final ConfigSourceInterceptorContext configSourceInterceptorContext) { | ||
return new SecretKeysConfigSourceInterceptor(Set.of("secrets.my.secret")); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...-extension/extension/deployment/src/test/java/io/quarkus/config/SecretKeysConfigTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package io.quarkus.config; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.smallrye.config.ConfigMapping; | ||
import io.smallrye.config.SmallRyeConfig; | ||
|
||
public class SecretKeysConfigTest { | ||
@RegisterExtension | ||
static final QuarkusUnitTest TEST = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClass(SecretKeysConfigInterceptorFactory.class) | ||
.addAsServiceProvider("io.smallrye.config.ConfigSourceInterceptorFactory", | ||
SecretKeysConfigInterceptorFactory.class.getName())) | ||
.overrideConfigKey("secrets.my.secret", "secret"); | ||
|
||
@Inject | ||
SmallRyeConfig config; | ||
@Inject | ||
@ConfigProperty(name = "secrets.my.secret") | ||
String secret; | ||
@Inject | ||
MappingSecret mappingSecret; | ||
|
||
@Test | ||
void secrets() { | ||
assertThrows(SecurityException.class, () -> config.getConfigValue("secrets.my.secret")); | ||
|
||
assertEquals("secret", secret); | ||
assertEquals("secret", mappingSecret.secret()); | ||
} | ||
|
||
@ConfigMapping(prefix = "secrets.my") | ||
interface MappingSecret { | ||
String secret(); | ||
} | ||
} |