-
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.
Do not force mp.jwt.verify.publickey.location to be a build time prop…
…erty
- Loading branch information
Showing
3 changed files
with
87 additions
and
7 deletions.
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
26 changes: 26 additions & 0 deletions
26
...ment/src/test/java/io/quarkus/jwt/test/PublicKeyLocationBuildTimeConfigSourceFactory.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,26 @@ | ||
package io.quarkus.jwt.test; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.eclipse.microprofile.config.spi.ConfigSource; | ||
|
||
import io.smallrye.config.ConfigSourceContext; | ||
import io.smallrye.config.ConfigSourceFactory; | ||
import io.smallrye.config.ConfigValue; | ||
import io.smallrye.config.common.MapBackedConfigSource; | ||
|
||
public class PublicKeyLocationBuildTimeConfigSourceFactory implements ConfigSourceFactory { | ||
@Override | ||
public Iterable<ConfigSource> getConfigSources(final ConfigSourceContext context) { | ||
// This property is only available in runtime. | ||
ConfigValue value = context.getValue("quarkus.uuid"); | ||
if (value == null || value.getValue() == null) { | ||
return List.of(new MapBackedConfigSource(PublicKeyLocationBuildTimeConfigSourceFactory.class.getName(), | ||
Map.of("mp.jwt.verify.publickey.location", "${invalid}"), 1000) { | ||
}); | ||
} | ||
return Collections.emptyList(); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...mallrye-jwt/deployment/src/test/java/io/quarkus/jwt/test/PublicKeyLocationConfigTest.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,36 @@ | ||
package io.quarkus.jwt.test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.logging.Level; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.smallrye.config.ConfigSourceFactory; | ||
import io.smallrye.config.SmallRyeConfig; | ||
|
||
public class PublicKeyLocationConfigTest { | ||
@RegisterExtension | ||
static final QuarkusUnitTest TEST = new QuarkusUnitTest().withApplicationRoot((jar) -> jar.addAsResource("publicKey.pem") | ||
.addClass(PublicKeyLocationBuildTimeConfigSourceFactory.class) | ||
.addAsServiceProvider(ConfigSourceFactory.class, PublicKeyLocationBuildTimeConfigSourceFactory.class)) | ||
.overrideConfigKey("mp.jwt.verify.publickey.location", "publicKey.pem") | ||
.overrideConfigKey("quarkus.package.type", "native") | ||
.setLogRecordPredicate(record -> record.getLevel().intValue() >= Level.WARNING.intValue()) | ||
.assertLogRecords(logRecords -> { | ||
assertEquals("Cannot determine %s of mp.jwt.verify.publickey.location to register with the native image", | ||
logRecords.get(0).getMessage()); | ||
}); | ||
|
||
@Inject | ||
SmallRyeConfig config; | ||
|
||
@Test | ||
void config() { | ||
assertEquals("publicKey.pem", config.getRawValue("mp.jwt.verify.publickey.location")); | ||
} | ||
} |