|
| 1 | +package io.quarkiverse.githubapp.deployment; |
| 2 | + |
| 3 | +import java.util.Map; |
| 4 | + |
| 5 | +import jakarta.inject.Singleton; |
| 6 | + |
| 7 | +import org.junit.jupiter.api.Test; |
| 8 | +import org.junit.jupiter.api.extension.RegisterExtension; |
| 9 | +import org.kohsuke.github.GHEventPayload; |
| 10 | + |
| 11 | +import io.quarkiverse.githubapp.Credentials; |
| 12 | +import io.quarkiverse.githubapp.event.Label; |
| 13 | +import io.quarkus.credentials.CredentialsProvider; |
| 14 | +import io.quarkus.test.ProdBuildResults; |
| 15 | +import io.quarkus.test.ProdModeTestResults; |
| 16 | +import io.quarkus.test.QuarkusProdModeTest; |
| 17 | + |
| 18 | +public class CredentialsProviderTest { |
| 19 | + |
| 20 | + @RegisterExtension |
| 21 | + static final QuarkusProdModeTest TEST = new QuarkusProdModeTest() |
| 22 | + .withApplicationRoot((jar) -> jar |
| 23 | + .addClasses(ListeningClass.class, CustomCredentialsProvider.class) |
| 24 | + .addAsResource("application-for-prod.properties", "application.properties")) |
| 25 | + .setRun(true); |
| 26 | + |
| 27 | + @ProdBuildResults |
| 28 | + private ProdModeTestResults prodModeTestResults; |
| 29 | + |
| 30 | + @Test |
| 31 | + public void testConfigFileOrder() { |
| 32 | + // the fact that the application started is actually enough to validate the CredentialsProvider is active |
| 33 | + } |
| 34 | + |
| 35 | + static class ListeningClass { |
| 36 | + |
| 37 | + void createLabel(@Label.Created GHEventPayload.Label labelPayload) { |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + @Singleton |
| 42 | + public static class CustomCredentialsProvider implements CredentialsProvider { |
| 43 | + |
| 44 | + @Override |
| 45 | + public Map<String, String> getCredentials(String credentialsProviderName) { |
| 46 | + if (!"my-github-app".equals(credentialsProviderName)) { |
| 47 | + throw new IllegalStateException("We expect my-github-app as the provider name"); |
| 48 | + } |
| 49 | + |
| 50 | + return Map.of(Credentials.WEBHOOK_SECRET, "my webhook secret", |
| 51 | + Credentials.PRIVATE_KEY, "-----BEGIN RSA PRIVATE KEY-----\n" |
| 52 | + + "MIICWwIBAAKBgQCBbwkBgQDHP3iTKDuneQekMrkNfjZyGCl9pdvsoX1MwPAUW+tq\n" |
| 53 | + + "mcN6N+cNvUTQz91YKjB/m4sYyuP30ZhegMwXI/AbHIncG6pDGnEmz9snRyaeqyyD\n" |
| 54 | + + "1x81XX5WBepqOYN9fVH81IrhLIngCzpruhLgL8b+ZBUY7DnUANzQpWrd/QIDAQAB\n" |
| 55 | + + "AoGAdV3c+bsjnIkmabIq3cK2tiK0gNK4xh64yNG0Kc+J0iaFzMBJKYHCqrm0T1YX\n" |
| 56 | + + "540FdiPTlHLT36hirV4mX1NFPEG0qmNkGRaNCAEI7PQ8TEslAPvGRL79p7RO0oE8\n" |
| 57 | + + "DE2P+ePC6InHYevQYfk0vi27ZoL2+7tOnaDZxVXTjfR/rrUCQQD0+nZveM8jBUMh\n" |
| 58 | + + "Apw6rhedIYFrhTiH1YlDKlYqeiViWb9AhZdI12k7XGRDIPpQnZ6zIO/VtRMMNgoX\n" |
| 59 | + + "9RsWdL/zAkEAh0HJowOvj/OPGLuNUmDKlijivssCCYD/rcKxkjh/a3H2J2k5sY7y\n" |
| 60 | + + "v4maQb+t+keYqHlhxM+z/pyGhkYop3hWTwJAYdLqHFVHkZp2VeYu8Je4Qjyw63iF\n" |
| 61 | + + "PGieqT1srwWbjAx+fItb//BUyyl3t/6hNjPavXj3jIUEGCo0GaD8shjo1QJAWkra\n" |
| 62 | + + "to4xVyG6t0INF58x3ogwxjlzhLCu/mpobDp3JV0QfELMlvHcr2zGo3m4RMoi6OUP\n" |
| 63 | + + "FXmqqSAI1f5kCVhWFQJAKSSwfkx3jOKtrkmJygi69NdwWOIe+Q9cI52KtzSWhZWq\n" |
| 64 | + + "0Ih2KR36ODkbB6AYts+U2L5hiY9kTdffEFzH4qj8qw==\n" |
| 65 | + + "-----END RSA PRIVATE KEY-----"); |
| 66 | + } |
| 67 | + } |
| 68 | +} |
0 commit comments