Skip to content

Commit

Permalink
release: v0.3.5-rc1 fix supabase-kt
Browse files Browse the repository at this point in the history
  • Loading branch information
tschuehly committed Aug 18, 2024
1 parent 12f52b3 commit 53ceb13
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 44 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Java
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'adopt'
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ out/
### VS Code ###
.vscode/
/src/test/resources/dev.env
/node_modules
/node_modules
/src/test/resources/test.env
/src/test/resources/test.properties
13 changes: 6 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ plugins {
kotlin("jvm") version "1.9.22"
kotlin("plugin.spring") version "1.9.22"
kotlin("plugin.jpa") version "1.9.22"

id("maven-publish")
id("org.jreleaser") version "1.13.0"
id("signing")
}

group = "de.tschuehly"
version = "0.3.4"
version = "0.3.5-RC1"
java.sourceCompatibility = JavaVersion.VERSION_17

repositories {
Expand All @@ -36,11 +35,11 @@ dependencies {
implementation("jakarta.annotation:jakarta.annotation-api:2.1.1")
implementation("com.auth0:java-jwt:4.3.0")

implementation("io.github.jan-tennert.supabase:gotrue-kt:2.0.4")
runtimeOnly("io.ktor:ktor-client-java:2.3.7")
testRuntimeOnly("io.ktor:ktor-client-java:2.3.7")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.3")
testImplementation("io.ktor:ktor-client-mock:2.3.6")
implementation("io.github.jan-tennert.supabase:gotrue-kt:2.6.0")
runtimeOnly("io.ktor:ktor-client-java:2.3.12")
testRuntimeOnly("io.ktor:ktor-client-java:2.3.12")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.8.0")
testImplementation("io.ktor:ktor-client-mock:2.3.12")


implementation("org.jetbrains.kotlin:kotlin-reflect")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class SupabaseSecurityConfig(
val logger: Logger = LoggerFactory.getLogger(SupabaseSecurityConfig::class.java)

@Bean
@ConditionalOnMissingBean
fun filterChain(
http: HttpSecurity,
supabaseJwtFilter: SupabaseJwtFilter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import io.github.jan.supabase.exceptions.RestException
import io.github.jan.supabase.gotrue.Auth
import io.github.jan.supabase.gotrue.providers.builtin.Email
import io.github.jan.supabase.gotrue.providers.builtin.OTP
import io.github.jan.supabase.gotrue.user.UserInfo
import jakarta.servlet.http.HttpServletRequest
import jakarta.servlet.http.HttpServletResponse
import kotlinx.coroutines.CoroutineScope
Expand Down Expand Up @@ -176,7 +177,7 @@ class SupabaseUserServiceGoTrueImpl(
throw UnknownSupabaseException()
}

private fun emailConfirmationEnabled(user: Email.Result?): Boolean {
private fun emailConfirmationEnabled(user: UserInfo?): Boolean {
return user != null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,7 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerA
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration
import org.springframework.boot.runApplication

@SpringBootApplication(
exclude = [
DataSourceAutoConfiguration::class,
DataSourceTransactionManagerAutoConfiguration::class,
HibernateJpaAutoConfiguration::class
],
)
@ImportAutoConfiguration(SupabaseAutoConfiguration::class)

@SpringBootApplication
class TestApplication {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import org.junit.jupiter.api.extension.ExtendWith
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.test.web.server.LocalServerPort
import org.springframework.context.annotation.Import
import org.springframework.context.annotation.PropertySource
import org.springframework.test.context.TestPropertySource
import org.springframework.test.context.junit.jupiter.SpringExtension
import org.springframework.web.context.WebApplicationContext
Expand All @@ -23,9 +24,7 @@ import org.springframework.web.context.WebApplicationContext
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = ["debug=org.springframework.security"],
)
@TestPropertySource(
properties = ["SUPABASE_PROJECT_ID=", "SUPABASE_ANON_KEY=", "SUPABASE_DATABASE_PW=", "SUPABASE_JWT_SECRET="]
)
@PropertySource(value = ["classpath:/test.properties"], ignoreResourceNotFound = true)
@Import(GoTrueMockConfiguration::class)
class SupabaseHtmxTests {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package de.tschuehly.htmx.spring.supabase.auth.test.mock

import io.github.jan.supabase.gotrue.providers.builtin.Email
import io.github.jan.supabase.gotrue.providers.builtin.Phone
import io.github.jan.supabase.gotrue.user.UserInfo
import io.github.jan.supabase.gotrue.user.UserSession
import io.ktor.client.engine.mock.*
Expand Down Expand Up @@ -91,9 +89,9 @@ class GoTrueMock {
val token = authorizationHeader.substringAfter("Bearer ")
if (token != VALID_ACCESS_TOKEN) return respondUnauthorized()
return when (request.method) {
HttpMethod.Get -> respond(UserInfo(aud = "", id = "userid"))
HttpMethod.Get -> respondJson(UserInfo(aud = "", id = "userid"))
HttpMethod.Put -> {
respond(
respondJson(
UserInfo(
aud = "",
id = "userid",
Expand All @@ -118,25 +116,18 @@ class GoTrueMock {
return when {
body.containsKey("email") -> {
respond(
Email.Result(
"uuid",
body["email"]!!.jsonPrimitive.content,
Clock.System.now(),
Clock.System.now(),
Clock.System.now()
)
sampleUserObject(body["email"]!!.jsonPrimitive.content),
HttpStatusCode.OK,
headersOf("Content-Type" to listOf("application/json"))

)
}

body.containsKey("phone") -> {
respond(
Phone.Result(
"uuid",
body["phone"]!!.jsonPrimitive.content,
Clock.System.now(),
Clock.System.now(),
Clock.System.now()
)
sampleUserObject(body["phone"]!!.jsonPrimitive.content),
HttpStatusCode.OK,
headersOf("Content-Type" to listOf("application/json"))
)
}

Expand Down Expand Up @@ -188,15 +179,15 @@ class GoTrueMock {
}
}

private inline fun <reified T> MockRequestHandleScope.respond(data: T): HttpResponseData {
private inline fun <reified T> MockRequestHandleScope.respondJson(data: T): HttpResponseData {
return respond(
Json.encodeToString(data),
HttpStatusCode.OK,
headersOf("Content-Type" to listOf("application/json"))
)
}

private fun MockRequestHandleScope.respondValidSession() = respond(
private fun MockRequestHandleScope.respondValidSession() = respondJson(
UserSession(
NEW_ACCESS_TOKEN,
"refresh_token",
Expand Down Expand Up @@ -233,5 +224,13 @@ class GoTrueMock {
const val VALID_VERIFY_TOKEN = "valid_verify_token"
}

private fun sampleUserObject(email: String? = null, phone: String? = null) = """
{
"id": "id",
"aud": "aud",
"email": "$email",
"phone": "$phone"
}
""".trimIndent()

}

0 comments on commit 53ceb13

Please sign in to comment.