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
@Configuration | |
public class FilePollingConfiguration { | |
@Bean(name="inboundReadDirectory") | |
public File inboundReadDirectory(@Value("${inbound.read.path}") String path) { | |
return makeDirectory(path); | |
} | |
@Bean(name="inboundProcessedDirectory") | |
public File inboundProcessedDirectory(@Value("${inbound.processed.path}") String path) { |
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
<profile> | |
<id>native</id> | |
<activation> | |
<property> | |
<name>native</name> | |
</property> | |
</activation> | |
<build> | |
<plugins> | |
<plugin> |
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
private fun getAccessToken(): String { | |
val clientId = "backend-service" | |
val clientSecret = "8155b2ad-cd9d-48ae-a5e1-ea11d5cfcb79" | |
val response = RestAssured.given() | |
.auth().preemptive().basic(clientId, clientSecret) | |
.contentType("application/x-www-form-urlencoded") | |
.formParam("grant_type", "client_credentials") | |
.post("http://localhost:$authServerPort/auth/realms/porterhead/protocol/openid-connect/token") | |
.then() | |
.extract() |
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
var keycloakContainer = KGenericContainer("quay.io/keycloak/keycloak:11.0.0") | |
.withNetwork(network) | |
.withNetworkAliases("keycloak") | |
.withExposedPorts(8080) | |
.withEnv("KEYCLOAK_USER", "admin") | |
.withEnv("KEYCLOAK_PASSWORD", "admin") | |
.withEnv("KEYCLOAK_IMPORT", "/tmp/realm.json") | |
.withEnv("JAVA_OPTS", "-Dkeycloak.profile.feature.scripts=enabled -Dkeycloak.profile.feature.upload_scripts=enabled") | |
.withClasspathResourceMapping("config/porterhead-realm.json", "/tmp/realm.json", BindMode.READ_ONLY) | |
.waitingFor(Wait.forHttp("/auth")) |
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
@Test | |
@DisplayName("POST /v1/sms with valid request returns 202") | |
fun testSuccessfulSend() { | |
whenever(smsService.createMessage(any(), any())).thenReturn(testDouble()) | |
given() | |
.`when`() | |
.contentType(ContentType.JSON) | |
.auth().oauth2(generateJWT(keyPair)) | |
.body("""{"text":"Hello World", "fromNumber":"+1234567890", "toNumber":"+1234567899"}""") | |
.post("/v1/sms") |
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
fun generateJWT(keyPair: RSAKey): String { | |
val signer: JWSSigner = RSASSASigner(keyPair.toRSAKey()) | |
// Prepare JWT with claims set | |
val claimsSet = JWTClaimsSet.Builder() | |
.subject("backend-service") | |
.issuer("https://example.com") | |
.expirationTime(Date(Date().time + 60 * 1000)) | |
.build() | |
val signedJWT = SignedJWT( | |
JWSHeader.Builder(JWSAlgorithm.RS256).keyID(keyPair.keyID).type(JOSEObjectType.JWT).build(), |
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
postStubMapping(publicKeysStub(keyPair.toPublicJWK().toJSONString())) | |
private fun publicKeysStub(keys: String): String { | |
return """ | |
{ | |
"name": "public_keys_stub", | |
"request": { | |
"method": "GET", | |
"url": "/v1/keys" | |
}, |
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
private fun oidcConfigurationStub(): String { | |
return """ | |
{ | |
"name": "oidc_configuration", | |
"request": { | |
"method": "GET", | |
"url": "/mock-server/.well-known/openid-configuration" | |
}, | |
"response": { | |
"status": 200, |
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
fun generatePrivateKey() :RSAKey { | |
return RSAKeyGenerator(2048) | |
.keyID("123").keyUse(KeyUse.SIGNATURE) | |
.generate() | |
} |
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
open class WiremockTestResource : QuarkusTestResourceLifecycleManager { | |
lateinit var wireMockServer: WireMockServer | |
lateinit var keyPair: RSAKey | |
override fun start(): MutableMap<String, String> { | |
wireMockServer = WireMockServer(WireMockConfiguration().dynamicPort()) | |
wireMockServer.start() | |
keyPair = generatePrivateKey() | |
postStubMapping(oidcConfigurationStub()) |