Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
.qodana
build
.intellijPlatform
.kotlin
4 changes: 1 addition & 3 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 12 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ allprojects {
repositories {
mavenCentral()
}

configurations.configureEach {
exclude(group = "ai.grazie.spell")
exclude(group = "ai.grazie.nlp")
exclude(group = "ai.grazie.utils")
}
}

repositories {
Expand All @@ -33,7 +39,6 @@ repositories {
dependencies {
intellijPlatform {
gateway(properties("platformVersion"))
instrumentationTools()
testFramework(TestFrameworkType.Platform)
testFramework(TestFrameworkType.JUnit5)
testFramework(TestFrameworkType.Bundled)
Expand All @@ -46,11 +51,13 @@ dependencies {
exclude("io.ktor", "ktor-client-core")
exclude("io.ktor", "ktor-http-jvm")
exclude("io.ktor", "ktor-utils-jvm")
exclude("io.ktor", "ktor-io")
exclude("org.slf4j", "*")
}
testImplementation(testFixtures(project(":tunneler")))
testImplementation(libs.junitJupiterApi)
testRuntimeOnly(libs.junitJupiterEngine)
testRuntimeOnly(libs.junitPlatformLauncher)
testImplementation(libs.coroutineTest)
testImplementation(libs.mockitoKotlin)
}
Expand Down Expand Up @@ -98,8 +105,10 @@ changelog {
repositoryUrl = properties("pluginRepositoryUrl")
}
tasks {
koverReport {
check(true)
kover {
reports{
check(true)
}
}

test {
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ pluginRepositoryUrl = TODO
pluginVersion = 0.0.1

# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild = 242
pluginUntilBuild = 242.*
pluginSinceBuild = 251
pluginUntilBuild = 251.*

# IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#configuration-intellij-extension
platformVersion = 2024.2
platformVersion = 2025.1.1.1

# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
# Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22
Expand Down
26 changes: 14 additions & 12 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
[versions]
# libraries
junit = "5.11.0"
coroutine = "1.9.0"
junit = "5.12.2"
coroutine = "1.10.2"
mockito-kotlin = "5.4.0"
rdFramework = "2024.3.0"
httpClient = "4.5.14"
rdFramework = "2025.1.1"
httpClient = "5.4.4"
rawHttp = "2.6.0"
ktor = "2.3.12"
slf4j = "2.0.7"
mockWebServer = "4.11.0"
ktor = "3.0.3"
slf4j = "2.0.17"
mockWebServer = "4.12.0"

# plugins
kotlin = "2.0.20"
changelog = "2.2.0"
gradleIntelliJPlugin = "2.0.1"
kover = "0.7.6"
kotlin = "2.1.21"
changelog = "2.2.1"
gradleIntelliJPlugin = "2.6.0"
kover = "0.9.1"

[libraries]
junitJupiterApi = { group = "org.junit.jupiter", name = "junit-jupiter-api", version.ref = "junit" }
junitJupiterEngine = { group = "org.junit.jupiter", name = "junit-jupiter-engine", version.ref = "junit" }
# JUnit Platform Launcher necessary: https://youtrack.jetbrains.com/articles/SUPPORT-A-1839/IntelliJ-IDEA-incompatible-with-JUnit-5.12-TestEngine-with-ID-junit-jupiter-failed-to-discover-tests#resolution
junitPlatformLauncher = { group = "org.junit.platform", name = "junit-platform-launcher" }
coroutineTest = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-test", version.ref = "coroutine" }
coroutine = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "coroutine" }
mockitoKotlin = { group = "org.mockito.kotlin", name = "mockito-kotlin", version.ref = "mockito-kotlin" }
rdFramework = { group = "com.jetbrains.rd", name = "rd-framework", version.ref = "rdFramework" }
httpClient = { group = "org.apache.httpcomponents", name = "httpclient", version.ref = "httpClient" }
httpClient = { group = "org.apache.httpcomponents.client5", name = "httpclient5", version.ref = "httpClient" }
rawHttp = { group = "com.athaydes.rawhttp", name = "rawhttp-core", version.ref = "rawHttp" }
ktorClientCore = { group = "io.ktor", name = "ktor-client-core", version.ref = "ktor" }
ktorClientOkhttp = { group = "io.ktor", name = "ktor-client-okhttp", version.ref = "ktor" }
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
3 changes: 2 additions & 1 deletion tunneler/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import org.jetbrains.kotlin.gradle.utils.extendsFrom
plugins {
id("java")
id("java-test-fixtures")
kotlin("jvm")
alias(libs.plugins.kotlin) // Kotlin support
}

group = "com.salesforce.pomerium"
Expand All @@ -27,6 +27,7 @@ dependencies {
implementation(libs.ktorNetworkTls)
implementation(libs.slf4jApi)
testRuntimeOnly(libs.junitJupiterEngine)
testRuntimeOnly(libs.junitPlatformLauncher)
testFixturesImplementation(libs.mockitoKotlin)
testFixturesImplementation(libs.coroutineTest)
testFixturesImplementation(libs.mockWebServer)
Expand Down
2 changes: 1 addition & 1 deletion tunneler/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Jul 07 18:47:34 PDT 2023
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion tunneler/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pluginManagement {
plugins {
kotlin("jvm") version "1.9.0"
kotlin("jvm") version "2.1.21"
}
}
dependencyResolutionManagement {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@ import io.ktor.client.*
import io.ktor.client.engine.okhttp.*
import io.ktor.client.request.*
import io.ktor.client.statement.*
import io.ktor.server.application.*
import io.ktor.server.engine.*
import io.ktor.server.netty.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import kotlinx.coroutines.*
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.NonCancellable
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import org.apache.http.client.utils.URIBuilder
import kotlinx.coroutines.withContext
import org.apache.hc.core5.net.URIBuilder
import org.slf4j.LoggerFactory
import java.io.Closeable
import java.net.URI
Expand Down Expand Up @@ -203,7 +207,8 @@ class PomeriumAuthProvider (
}

suspend fun start(): Int {
return server.start().resolvedConnectors().first().port
server.start()
return server.engine.resolvedConnectors().first().port
}

override fun close() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,24 @@ import io.ktor.network.tls.*
import io.ktor.util.network.*
import io.ktor.utils.io.*
import io.ktor.utils.io.jvm.javaio.*
import kotlinx.coroutines.*
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.CoroutineName
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.NonCancellable
import kotlinx.coroutines.channels.ClosedSendChannelException
import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
import kotlinx.coroutines.joinAll
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import kotlinx.coroutines.withTimeout
import org.slf4j.LoggerFactory
import rawhttp.core.*
import rawhttp.core.HttpVersion
import rawhttp.core.RawHttp
import rawhttp.core.RawHttpHeaders
import rawhttp.core.RawHttpRequest
import rawhttp.core.RequestLine
import rawhttp.core.errors.InvalidHttpResponse
import java.io.IOException
import java.net.URI
Expand Down Expand Up @@ -103,34 +116,37 @@ class PomeriumTunneler(
when (response.statusCode) {
200 -> {
LOG.info("Pomerium tunnel established")
launch(Dispatchers.IO) {
val writer = launch(Dispatchers.IO + CoroutineName("tunneler-writer")) {
try {
localReadChannel.joinTo(writeChannel, true)
localReadChannel.copyTo(writeChannel)
} catch (e: Exception) {
handleException(e)
} finally {
withContext(NonCancellable) {
try {
tunnelSocket.close()
writeChannel.flushAndClose()
} catch (e: Exception) {
//Do nothing
}
}
}
}
try {
readChannel.joinTo(localWriteChannel, true)
} catch (e: Exception) {
handleException(e)
} finally {
withContext(NonCancellable) {
try {
tunnelSocket.close()
} catch (e: Exception) {
//Do nothing
val reader = launch(Dispatchers.IO + CoroutineName("tunneler-reader")) {
try {
readChannel.copyTo(localWriteChannel)
} catch (e: Exception) {
handleException(e)
} finally {
withContext(NonCancellable) {
try {
localWriteChannel.flushAndClose()
} catch (e: Exception) {
//Do nothing
}
}
}
}
joinAll(writer, reader)
}

301, 302, 307, 308 -> {
Expand Down Expand Up @@ -192,7 +208,7 @@ class PomeriumTunneler(

private suspend fun Socket.configure(useTls: Boolean, serverName: String, trustManager: TrustManager?): Socket {
return if (useTls) {
val handler = kotlinx.coroutines.CoroutineExceptionHandler { _, throwable ->
val handler = CoroutineExceptionHandler { _, throwable ->
LOG.error("Exception in the tunnel TLS translation", throwable)
}
tls(Dispatchers.IO + handler) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import io.ktor.util.network.*
import io.ktor.utils.io.*
import io.ktor.utils.io.jvm.javaio.*
import kotlinx.coroutines.*
import org.apache.http.client.methods.HttpGet
import org.apache.http.impl.client.HttpClients
import org.apache.hc.client5.http.classic.methods.HttpGet
import org.apache.hc.client5.http.impl.classic.HttpClients
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.extension.AfterTestExecutionCallback
import org.junit.jupiter.api.extension.ExtensionContext
Expand Down Expand Up @@ -54,7 +54,7 @@ class MockPomerium : AfterTestExecutionCallback {
HttpClients.createSystem()
.execute(HttpGet(redirect + "/?${PomeriumAuthProvider.POMERIUM_JWT_QUERY_PARAM}=$token"))
.use {
Assertions.assertEquals(200, it.statusLine.statusCode)
Assertions.assertEquals(200, it.code)
}

//This would be the response expected
Expand All @@ -79,7 +79,7 @@ class MockPomerium : AfterTestExecutionCallback {
)
response.writeTo(writeChannel.toOutputStream())
requestCount++
readChannel.joinTo(writeChannel, true)
readChannel.copyAndClose(writeChannel)
}
}
}
Expand Down
Loading