fixed bug in the server configuration parser
All checks were successful
CI / build (push) Successful in 2m50s

added Jacoco test report
This commit is contained in:
2025-01-20 20:23:09 +08:00
parent 1a78c8092b
commit fc9900d821
4 changed files with 32 additions and 11 deletions

View File

@@ -66,6 +66,15 @@ allprojects { subproject ->
} }
} }
pluginManager.withPlugin('jacoco') {
test {
finalizedBy jacocoTestReport
}
jacocoTestReport {
dependsOn test
}
}
pluginManager.withPlugin(catalog.plugins.kotlin.jvm.get().pluginId) { pluginManager.withPlugin(catalog.plugins.kotlin.jvm.get().pluginId) {
tasks.withType(KotlinCompile.class) { tasks.withType(KotlinCompile.class) {
compilerOptions.jvmTarget = JvmTarget.JVM_21 compilerOptions.jvmTarget = JvmTarget.JVM_21

View File

@@ -1,6 +1,7 @@
plugins { plugins {
id 'java-library' id 'java-library'
alias catalog.plugins.kotlin.jvm alias catalog.plugins.kotlin.jvm
id 'jacoco'
id 'maven-publish' id 'maven-publish'
} }

View File

@@ -20,7 +20,8 @@ import javax.net.ssl.X509TrustManager
class ClientCertificateValidator private constructor( class ClientCertificateValidator private constructor(
private val sslHandler: SslHandler, private val sslHandler: SslHandler,
private val x509TrustManager: X509TrustManager) : ChannelInboundHandlerAdapter() { private val x509TrustManager: X509TrustManager
) : ChannelInboundHandlerAdapter() {
override fun userEventTriggered(ctx: ChannelHandlerContext, evt: Any) { override fun userEventTriggered(ctx: ChannelHandlerContext, evt: Any) {
if (evt is SslHandshakeCompletionEvent) { if (evt is SslHandshakeCompletionEvent) {
if (evt.isSuccess) { if (evt.isSuccess) {
@@ -42,7 +43,8 @@ class ClientCertificateValidator private constructor(
val validator = CertPathValidator.getInstance("PKIX").apply { val validator = CertPathValidator.getInstance("PKIX").apply {
val rc = revocationChecker as PKIXRevocationChecker val rc = revocationChecker as PKIXRevocationChecker
rc.options = EnumSet.of( rc.options = EnumSet.of(
PKIXRevocationChecker.Option.NO_FALLBACK) PKIXRevocationChecker.Option.NO_FALLBACK
)
} }
val params = PKIXParameters(trustStore).apply { val params = PKIXParameters(trustStore).apply {
isRevocationEnabled = certificateRevocationEnabled isRevocationEnabled = certificateRevocationEnabled
@@ -72,11 +74,16 @@ class ClientCertificateValidator private constructor(
} }
} else { } else {
val trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()) val trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm())
trustManagerFactory.trustManagers.asSequence().filter { it is X509TrustManager }.single() as X509TrustManager trustManagerFactory.trustManagers.asSequence().filter { it is X509TrustManager }
.single() as X509TrustManager
} }
} }
fun of(sslHandler : SslHandler, trustStore : KeyStore?, certificateRevocationEnabled : Boolean) : ClientCertificateValidator { fun of(
sslHandler: SslHandler,
trustStore: KeyStore?,
certificateRevocationEnabled: Boolean
): ClientCertificateValidator {
return ClientCertificateValidator(sslHandler, getTrustManager(trustStore, certificateRevocationEnabled)) return ClientCertificateValidator(sslHandler, getTrustManager(trustStore, certificateRevocationEnabled))
} }
} }

View File

@@ -200,8 +200,12 @@ object Parser {
}.toSet() }.toSet()
private fun parseUserRefs(root: Element) = root.asIterable().asSequence().map { private fun parseUserRefs(root: Element) = root.asIterable().asSequence().map {
it.renderAttribute("ref") when(it.localName) {
}.toSet() "user" -> it.renderAttribute("ref")
"anonymous" -> ""
else -> ConfigurationException("Unrecognized tag '${it.localName}'")
}
}
private fun parseUsers(root: Element): Sequence<User> { private fun parseUsers(root: Element): Sequence<User> {
return root.asIterable().asSequence().filter { return root.asIterable().asSequence().filter {