Skip to content

Commit 1839faa

Browse files
committed
refactor: replace deprecated methods, remove unnecessary non-null safe calls
1 parent 134bfcb commit 1839faa

21 files changed

+43
-43
lines changed

src/main/kotlin/no/nav/security/mock/oauth2/debugger/Client.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ internal fun OkHttpClient.post(tokenRequest: TokenRequest): String =
9999
.build(),
100100
).execute()
101101
.body
102-
?.string() ?: throw RuntimeException("could not get response body from url=${tokenRequest.url}")
102+
.string()
103103

104104
fun OkHttpClient.withSsl(
105105
ssl: Ssl,

src/main/kotlin/no/nav/security/mock/oauth2/grant/AuthorizationCodeHandler.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ internal class AuthorizationCodeHandler(
9292

9393
private fun getLoginTokenCallbackOrDefault(
9494
code: AuthorizationCode,
95-
OAuth2TokenCallback: OAuth2TokenCallback,
95+
oAuth2TokenCallback: OAuth2TokenCallback,
9696
): OAuth2TokenCallback =
9797
takeLoginFromCache(code)?.let {
98-
LoginOAuth2TokenCallback(it, OAuth2TokenCallback)
99-
} ?: OAuth2TokenCallback
98+
LoginOAuth2TokenCallback(it, oAuth2TokenCallback)
99+
} ?: oAuth2TokenCallback
100100

101101
private fun takeLoginFromCache(code: AuthorizationCode): Login? = codeToLoginCache.remove(code)
102102

@@ -120,7 +120,7 @@ internal class AuthorizationCodeHandler(
120120
try {
121121
jsonMapper
122122
.readTree(it)
123-
.fields()
123+
.properties()
124124
.forEach { field ->
125125
put(field.key, jsonMapper.readValue(field.value.toString()))
126126
}

src/main/kotlin/no/nav/security/mock/oauth2/http/OAuth2HttpServer.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import io.netty.channel.ChannelFuture
66
import io.netty.channel.ChannelHandlerContext
77
import io.netty.channel.ChannelInitializer
88
import io.netty.channel.ChannelOption
9+
import io.netty.channel.MultiThreadIoEventLoopGroup
910
import io.netty.channel.ServerChannel
1011
import io.netty.channel.SimpleChannelInboundHandler
11-
import io.netty.channel.nio.NioEventLoopGroup
12+
import io.netty.channel.nio.NioIoHandler
1213
import io.netty.channel.socket.SocketChannel
1314
import io.netty.channel.socket.nio.NioServerSocketChannel
1415
import io.netty.handler.codec.http.DefaultHttpResponse
@@ -71,8 +72,7 @@ interface OAuth2HttpServer : AutoCloseable {
7172
fun sslConfig(): Ssl?
7273
}
7374

74-
class
75-
MockWebServerWrapper
75+
class MockWebServerWrapper
7676
@JvmOverloads
7777
constructor(
7878
val ssl: Ssl? = null,
@@ -139,8 +139,8 @@ class NettyWrapper
139139
constructor(
140140
val ssl: Ssl? = null,
141141
) : OAuth2HttpServer {
142-
private val masterGroup = NioEventLoopGroup()
143-
private val workerGroup = NioEventLoopGroup()
142+
private val masterGroup = MultiThreadIoEventLoopGroup(NioIoHandler.newFactory())
143+
private val workerGroup = MultiThreadIoEventLoopGroup(NioIoHandler.newFactory())
144144
private var closeFuture: ChannelFuture? = null
145145
private lateinit var address: InetSocketAddress
146146
private var port by Delegates.notNull<Int>()

src/test/kotlin/examples/kotlin/ktor/client/OAuth2Client.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ val httpClient =
2929
install(ContentNegotiation) {
3030
jackson {
3131
configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
32-
setSerializationInclusion(JsonInclude.Include.NON_NULL)
32+
setDefaultPropertyInclusion(JsonInclude.Include.NON_NULL)
3333
}
3434
}
3535
}

src/test/kotlin/examples/kotlin/ktor/login/OAuth2LoginApp.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ internal val httpClient =
134134
install(ContentNegotiation) {
135135
jackson {
136136
configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
137-
setSerializationInclusion(JsonInclude.Include.NON_NULL)
137+
setDefaultPropertyInclusion(JsonInclude.Include.NON_NULL)
138138
}
139139
}
140140
}

src/test/kotlin/examples/kotlin/ktor/resourceserver/OAuth2ResourceServerApp.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class AuthConfig(
106106
install(ContentNegotiation) {
107107
jackson {
108108
configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
109-
setSerializationInclusion(JsonInclude.Include.NON_NULL)
109+
setDefaultPropertyInclusion(JsonInclude.Include.NON_NULL)
110110
}
111111
}
112112
}

src/test/kotlin/no/nav/security/mock/oauth2/MockOAuth2ServerTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class MockOAuth2ServerTest {
1616
@Test
1717
fun `server takeRequest() should return sent request`() {
1818
withMockOAuth2Server {
19-
client.post(this.baseUrl(), mapOf("param1" to "value1")).body?.close()
19+
client.post(this.baseUrl(), mapOf("param1" to "value1")).body.close()
2020

2121
this.takeRequest().asClue {
2222
it.requestUrl shouldBe this.baseUrl()
@@ -33,7 +33,7 @@ class MockOAuth2ServerTest {
3333
"scope" to "scope1",
3434
),
3535
).body
36-
?.close()
36+
.close()
3737

3838
this.takeRequest().asClue {
3939
it.requestUrl shouldBe this.tokenEndpointUrl("test")

src/test/kotlin/no/nav/security/mock/oauth2/e2e/InteractiveLoginIntegrationTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class InteractiveLoginIntegrationTest {
6868
val loginUrl = server.authorizationEndpointUrl(issuerId).authenticationRequest()
6969
client.get(loginUrl).asClue {
7070
it.code shouldBe 200
71-
it.body?.string() shouldContain "<html"
71+
it.body.string() shouldContain "<html"
7272
}
7373

7474
return client

src/test/kotlin/no/nav/security/mock/oauth2/e2e/LoginPageIntegrationTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class LoginPageIntegrationTest {
1818
@Test
1919
fun `authorization with interactive login should return built-in login page`() {
2020
val server = MockOAuth2Server(OAuth2Config(interactiveLogin = true)).apply { start() }
21-
val body = client.get(server.authorizationEndpointUrl("default").authenticationRequest()).body?.string()
21+
val body = client.get(server.authorizationEndpointUrl("default").authenticationRequest()).body.string()
2222

2323
body shouldNotBe null
2424
body shouldContain "<h2 class=\"title\">Mock OAuth2 Server Sign-in</h2>"
@@ -33,7 +33,7 @@ class LoginPageIntegrationTest {
3333
loginPagePath = "./src/test/resources/login.example.html",
3434
),
3535
).apply { start() }
36-
val body = client.get(server.authorizationEndpointUrl("default").authenticationRequest()).body?.string()
36+
val body = client.get(server.authorizationEndpointUrl("default").authenticationRequest()).body.string()
3737

3838
body shouldNotBe null
3939
body shouldContain "Mock OAuth2 Server Example"

src/test/kotlin/no/nav/security/mock/oauth2/e2e/MockOAuth2ServerIntegrationTest.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ class MockOAuth2ServerIntegrationTest {
4949
).apply {
5050
start()
5151
}
52-
client.get(s.wellKnownUrl("someissuer")).body?.string() shouldContain s.issuerUrl("someissuer").toString()
53-
client.get(s.url("/custom")).body?.string() shouldBe "custom route"
54-
client.get(s.url("/someissuer/custom")).body?.string() shouldBe "custom route"
52+
client.get(s.wellKnownUrl("someissuer")).body.string() shouldContain s.issuerUrl("someissuer").toString()
53+
client.get(s.url("/custom")).body.string() shouldBe "custom route"
54+
client.get(s.url("/someissuer/custom")).body.string() shouldBe "custom route"
5555
}
5656

5757
@Test
@@ -146,7 +146,7 @@ class MockOAuth2ServerIntegrationTest {
146146
),
147147
)
148148
val wellKnown = client.get(this.wellKnownUrl("default")).parse<WellKnown>()
149-
val jwks = client.get(wellKnown.jwksUri.toHttpUrl()).body?.let { JWKSet.parse(it.string()) }
149+
val jwks = client.get(wellKnown.jwksUri.toHttpUrl()).body.let { JWKSet.parse(it.string()) }
150150

151151
jwks.shouldNotBeNull()
152152

@@ -176,7 +176,7 @@ class MockOAuth2ServerIntegrationTest {
176176
)
177177

178178
val wellKnown = client.get(this.wellKnownUrl("default")).parse<WellKnown>()
179-
val jwks = client.get(wellKnown.jwksUri.toHttpUrl()).body?.let { JWKSet.parse(it.string()) }
179+
val jwks = client.get(wellKnown.jwksUri.toHttpUrl()).body.let { JWKSet.parse(it.string()) }
180180

181181
jwks.shouldNotBeNull()
182182

0 commit comments

Comments
 (0)