Skip to content

Commit e5fa576

Browse files
committed
various changes required for spring boot 3.4.0 on both auth and submissions
1 parent 3d6faf3 commit e5fa576

File tree

19 files changed

+87
-52
lines changed

19 files changed

+87
-52
lines changed

auth/build.gradle.kts

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apply(from = rootProject.file("buildSrc/shared.gradle.kts"))
22

33
plugins {
4-
id("org.springframework.boot") version "3.3.4" // 3.3.5 has breaking bug for appending headers https://github.com/spring-projects/spring-framework/issues/33789
4+
id("org.springframework.boot") version "3.4.0"
55
id("io.spring.dependency-management") version "1.1.6"
66
id("reportstream.project-conventions")
77
kotlin("plugin.spring") version "2.0.21"
@@ -36,11 +36,6 @@ dependencies {
3636
testImplementation("org.springframework.boot:spring-boot-starter-test")
3737
testImplementation("org.springframework.security:spring-security-test")
3838
testImplementation("org.springframework.cloud:spring-cloud-starter-contract-stub-runner")
39-
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5")
40-
testImplementation("org.mockito.kotlin:mockito-kotlin:5.4.0")
41-
testImplementation("com.squareup.okhttp3:mockwebserver:4.12.0")
42-
43-
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
4439

4540
compileOnly("org.springframework.boot:spring-boot-devtools")
4641
}
@@ -54,7 +49,7 @@ configurations.all {
5449
dependencyManagement {
5550
imports {
5651
mavenBom("com.azure.spring:spring-cloud-azure-dependencies:5.18.0")
57-
mavenBom("org.springframework.cloud:spring-cloud-dependencies:2023.0.3")
52+
mavenBom("org.springframework.cloud:spring-cloud-dependencies:2024.0.0")
5853
}
5954
}
6055

auth/src/main/kotlin/gov/cdc/prime/reportstream/auth/AuthApplicationConstants.kt

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ object AuthApplicationConstants {
1212
const val HEALTHCHECK_ENDPOINT_V1 = "/api/v1/healthcheck"
1313
}
1414

15-
1615
object Scopes {
1716
const val ORGANIZATION_SCOPE = "organization"
1817
const val SUBJECT_SCOPE = "sub"

auth/src/main/kotlin/gov/cdc/prime/reportstream/auth/config/OktaClientConfig.kt

+2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ import gov.cdc.prime.reportstream.shared.StringUtilities.base64Decode
88
import org.springframework.boot.context.properties.ConfigurationProperties
99
import org.springframework.context.annotation.Bean
1010
import org.springframework.context.annotation.Configuration
11+
import org.springframework.context.annotation.Profile
1112

1213
@Configuration
14+
@Profile("!test")
1315
class OktaClientConfig(
1416
private val oktaClientProperties: OktaClientProperties,
1517
) {

auth/src/main/kotlin/gov/cdc/prime/reportstream/auth/service/OktaGroupsService.kt

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package gov.cdc.prime.reportstream.auth.service
22

33
import gov.cdc.prime.reportstream.auth.client.OktaGroupsClient
44
import gov.cdc.prime.reportstream.shared.auth.jwt.OktaGroupsJWT
5-
import org.apache.logging.log4j.kotlin.Logging
65
import org.springframework.stereotype.Service
76

87
@Service

auth/src/main/resources/application.yml

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
spring:
22
application:
33
name: "auth"
4+
profiles:
5+
active: "local"
46
security:
57
oauth2:
68
resourceserver:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package gov.cdc.prime.reportstream.auth.config
2+
3+
import com.okta.sdk.resource.api.ApplicationGroupsApi
4+
import com.okta.sdk.resource.client.ApiClient
5+
import io.mockk.mockk
6+
import org.springframework.boot.test.context.TestConfiguration
7+
import org.springframework.context.annotation.Bean
8+
import org.springframework.context.annotation.Profile
9+
10+
/**
11+
* We don't want the Okta client to actually attempt to connect to staging Okta during tests
12+
*/
13+
@TestConfiguration
14+
@Profile("test")
15+
class TestOktaClientConfig {
16+
17+
@Bean
18+
fun apiClient(): ApiClient {
19+
return mockk()
20+
}
21+
22+
@Bean
23+
fun applicationGroupsApi(): ApplicationGroupsApi {
24+
return mockk()
25+
}
26+
}

auth/src/test/kotlin/gov/cdc/prime/reportstream/auth/controller/HealthControllerTest.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
package gov.cdc.prime.reportstream.auth.controller
22

3-
import com.okta.sdk.resource.api.ApplicationGroupsApi
43
import gov.cdc.prime.reportstream.auth.AuthApplicationConstants
4+
import gov.cdc.prime.reportstream.auth.config.TestOktaClientConfig
55
import gov.cdc.prime.reportstream.auth.model.ApplicationStatus
66
import org.junit.jupiter.api.extension.ExtendWith
77
import org.springframework.beans.factory.annotation.Autowired
88
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient
99
import org.springframework.boot.test.context.SpringBootTest
10-
import org.springframework.boot.test.mock.mockito.MockBean
10+
import org.springframework.context.annotation.Import
1111
import org.springframework.test.context.junit.jupiter.SpringExtension
1212
import org.springframework.test.web.reactive.server.WebTestClient
1313
import kotlin.test.Test
1414

1515
@ExtendWith(SpringExtension::class)
1616
@SpringBootTest
1717
@AutoConfigureWebTestClient
18+
@Import(TestOktaClientConfig::class)
1819
class HealthControllerTest @Autowired constructor(
1920
private val webTestClient: WebTestClient,
20-
@MockBean private val applicationGroupsApi: ApplicationGroupsApi // mock bean to avoid instantiating Okta API client
2121
) {
2222

2323
@Test

auth/src/test/kotlin/gov/cdc/prime/reportstream/auth/filter/AppendOktaGroupsGatewayFilterFactoryTest.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.github.tomakehurst.wiremock.client.WireMock.aResponse
44
import com.github.tomakehurst.wiremock.client.WireMock.get
55
import com.github.tomakehurst.wiremock.client.WireMock.stubFor
66
import com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo
7+
import gov.cdc.prime.reportstream.auth.config.TestOktaClientConfig
78
import gov.cdc.prime.reportstream.auth.service.OktaGroupsService
89
import io.mockk.coEvery
910
import io.mockk.mockk
@@ -19,6 +20,7 @@ import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock
1920
import org.springframework.cloud.gateway.route.RouteLocator
2021
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder
2122
import org.springframework.context.annotation.Bean
23+
import org.springframework.context.annotation.Import
2224
import org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers.mockOpaqueToken
2325
import org.springframework.test.context.junit.jupiter.SpringExtension
2426
import org.springframework.test.web.reactive.server.WebTestClient
@@ -33,6 +35,7 @@ import org.springframework.test.web.reactive.server.WebTestClient
3335
@AutoConfigureWebTestClient
3436
@SpringBootTest
3537
@AutoConfigureWireMock(port = 0)
38+
@Import(TestOktaClientConfig::class)
3639
class AppendOktaGroupsGatewayFilterFactoryTest @Autowired constructor(
3740
private val client: WebTestClient,
3841
private val oktaGroupsService: OktaGroupsService,
@@ -43,7 +46,6 @@ class AppendOktaGroupsGatewayFilterFactoryTest @Autowired constructor(
4346
@Value("\${wiremock.server.port}") val port: Int,
4447
) {
4548

46-
// we have to set this up this way rather than using @TestMock because of kotlin coroutine support
4749
@Bean
4850
fun oktaGroupsService(): OktaGroupsService {
4951
return mockk()

auth/src/test/kotlin/gov/cdc/prime/reportstream/auth/util/KeyGenerationUtils.kt

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package gov.cdc.prime.reportstream.auth.util
22

3-
import com.nimbusds.jose.jwk.JWK
43
import com.nimbusds.jose.jwk.RSAKey
5-
import gov.cdc.prime.reportstream.shared.StringUtilities.base64Decode
64
import gov.cdc.prime.reportstream.shared.StringUtilities.base64Encode
75
import java.security.KeyPairGenerator
86
import java.security.interfaces.RSAPrivateKey

auth/src/test/resources/application.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
spring:
22
application:
33
name: "auth"
4+
profiles:
5+
active: "test"
46
security:
57
oauth2:
68
resourceserver:
@@ -17,8 +19,6 @@ spring:
1719
- Path=/get
1820
filters:
1921
- AppendOktaGroups
20-
main:
21-
lazy-initialization: true
2222
server.port: 9000
2323

2424
app:

buildSrc/src/main/kotlin/reportstream.project-conventions.gradle.kts

+5-5
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ java {
2828
val compileKotlin: KotlinCompile by tasks
2929
val compileTestKotlin: KotlinCompile by tasks
3030
compileKotlin.kotlinOptions.jvmTarget = "$majorJavaVersion"
31-
compileKotlin.kotlinOptions.allWarningsAsErrors = false
31+
compileKotlin.kotlinOptions.allWarningsAsErrors = true
3232
compileTestKotlin.kotlinOptions.jvmTarget = "$majorJavaVersion"
33-
compileTestKotlin.kotlinOptions.allWarningsAsErrors = false
33+
compileTestKotlin.kotlinOptions.allWarningsAsErrors = true
3434

3535
configure<KtlintExtension> {
3636
// See ktlint versions at https://github.com/pinterest/ktlint/releases
@@ -69,10 +69,10 @@ dependencies {
6969
// Common test dependencies
7070
testImplementation(kotlin("test-junit5"))
7171
testImplementation("io.mockk:mockk:1.13.11")
72-
testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.2")
72+
testImplementation("org.junit.jupiter:junit-jupiter-api:5.11.3")
7373
testImplementation("com.willowtreeapps.assertk:assertk-jvm:0.28.1")
74-
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.10.2")
75-
testImplementation("org.junit.jupiter:junit-jupiter:5.10.2")
74+
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.11.3")
75+
testImplementation("org.junit.jupiter:junit-jupiter:5.11.3")
7676
testImplementation("org.testcontainers:testcontainers:1.19.8")
7777
testImplementation("org.testcontainers:junit-jupiter:1.19.8")
7878
testImplementation("org.testcontainers:postgresql:1.19.8")

shared/src/main/kotlin/gov/cdc/prime/reportstream/shared/auth/AuthZService.kt

+1-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import gov.cdc.prime.reportstream.shared.auth.jwt.OktaGroupsJWTReader
77
* Shared authorization service to allow routes to check if an incoming request should be allowed access
88
*/
99
class AuthZService(
10-
private val oktaGroupsJWTReader: OktaGroupsJWTReader
10+
private val oktaGroupsJWTReader: OktaGroupsJWTReader,
1111
) {
1212

1313
private val adminGroup = "DHPrimeAdmins"
@@ -24,8 +24,6 @@ class AuthZService(
2424
val oktaGroupsJWT = oktaGroupsJWTReader.read(oktaGroupsHeader)
2525
isSenderAuthorized(clientId, oktaGroupsJWT.groups)
2626
} ?: false
27-
28-
2927
}
3028

3129
/**
@@ -63,6 +61,4 @@ class AuthZService(
6361
false
6462
}
6563
}
66-
67-
6864
}

shared/src/main/kotlin/gov/cdc/prime/reportstream/shared/auth/jwt/OktaGroupsJWT.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ package gov.cdc.prime.reportstream.shared.auth.jwt
55
*/
66
data class OktaGroupsJWT(
77
val appId: String,
8-
val groups: List<String>
9-
)
8+
val groups: List<String>,
9+
)

shared/src/main/kotlin/gov/cdc/prime/reportstream/shared/auth/jwt/OktaGroupsJWTConstants.kt

-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@ object OktaGroupsJWTConstants {
77

88
// Non-application users have okta groups automatically injected into this claim
99
const val OKTA_GROUPS_JWT_GROUP_CLAIM = "groups"
10-
1110
}

shared/src/main/kotlin/gov/cdc/prime/reportstream/shared/auth/jwt/OktaGroupsJWTReader.kt

-1
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,4 @@ class OktaGroupsJWTReader(
3838
throw BadJWTException("Invalid signature")
3939
}
4040
}
41-
4241
}

shared/src/test/kotlin/gov/cdc/prime/reportstream/shared/auth/AuthZServiceTest.kt

-2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,4 @@ class AuthZServiceTest {
6060
true
6161
)
6262
}
63-
64-
6563
}

shared/src/test/kotlin/gov/cdc/prime/reportstream/shared/auth/jwt/OktaGroupsJWTReaderTest.kt

-4
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,13 @@ import kotlin.test.assertEquals
2222

2323
class OktaGroupsJWTReaderTest {
2424

25-
2625
inner class Fixture {
2726
val clock = Clock.fixed(Instant.now(), ZoneId.of("UTC"))
2827
val keyPair = generateRSAKeyPair()
2928
val privateKey = keyPair.first
3029
val publicKey = keyPair.second
3130
val service = OktaGroupsJWTReader(publicKey)
3231

33-
3432
fun generateRSAKeyPair(): Pair<RSAKey, RSAKey> {
3533
val keyGen = KeyPairGenerator.getInstance("RSA")
3634
keyGen.initialize(2048)
@@ -111,6 +109,4 @@ class OktaGroupsJWTReaderTest {
111109
f.service.read(jwt)
112110
}
113111
}
114-
115-
116112
}

submissions/build.gradle.kts

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apply(from = rootProject.file("buildSrc/shared.gradle.kts"))
22

33
plugins {
4-
id("org.springframework.boot") version "3.3.5"
4+
id("org.springframework.boot") version "3.4.0"
55
id("io.spring.dependency-management") version "1.1.6"
66
id("reportstream.project-conventions")
77
kotlin("plugin.spring") version "2.0.21"
@@ -10,9 +10,8 @@ plugins {
1010
group = "gov.cdc.prime"
1111
version = "0.0.1-SNAPSHOT"
1212

13-
extra["springCloudAzureVersion"] = "5.14.0"
14-
1513
dependencies {
14+
implementation(project(":shared"))
1615
implementation("org.springframework.boot:spring-boot-starter-web")
1716
implementation("org.springframework.boot:spring-boot-starter-security")
1817
implementation("org.springframework.boot:spring-boot-starter-oauth2-resource-server")
@@ -27,13 +26,10 @@ dependencies {
2726
testImplementation("org.springframework.boot:spring-boot-starter-test")
2827
testImplementation("org.springframework.boot:spring-boot-testcontainers")
2928
testImplementation("org.xmlunit:xmlunit-core:2.10.0")
30-
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5")
3129
testImplementation("org.mockito.kotlin:mockito-kotlin:5.4.0")
3230
testImplementation("org.apache.commons:commons-compress:1.27.1")
3331
testImplementation("org.springframework.security:spring-security-test")
34-
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
3532
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor:1.9.0")
36-
implementation(project(":shared"))
3733
}
3834

3935
// There is a conflict in logging implementations. Excluded these in favor of using log4j-slf4j2-impl
@@ -44,7 +40,7 @@ configurations.all {
4440

4541
dependencyManagement {
4642
imports {
47-
mavenBom("com.azure.spring:spring-cloud-azure-dependencies:${property("springCloudAzureVersion")}")
43+
mavenBom("com.azure.spring:spring-cloud-azure-dependencies:5.18.0")
4844
}
4945
}
5046

0 commit comments

Comments
 (0)