Skip to content

Commit

Permalink
move siging key logic
Browse files Browse the repository at this point in the history
  • Loading branch information
darwin67 committed Feb 26, 2024
1 parent 8763bf4 commit d248233
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 44 deletions.
18 changes: 0 additions & 18 deletions inngest-core/src/main/kotlin/com/inngest/Environment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,6 @@ object Environment {
return System.getenv(InngestSystem.EventKey.value) ?: ""
}

fun inngestSigningKey(
env: InngestEnv,
key: String? = null,
): String {
if (key != null) return key

return when (env) {
InngestEnv.Dev -> "test"
else -> {
val signingKey = System.getenv(InngestSystem.SigningKey.value)
if (signingKey == null) {
throw Exception("signing key is required")
}
signingKey
}
}
}

fun inngestEventApiBaseUrl(
env: InngestEnv,
url: String? = null,
Expand Down
12 changes: 11 additions & 1 deletion inngest-core/src/main/kotlin/com/inngest/ServeConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,17 @@ class ServeConfig(

fun signingKey(): String {
if (signingKey != null) return signingKey
return System.getenv(InngestSystem.EventKey.value) ?: ""

return when (client.env) {
InngestEnv.Dev -> "test"
else -> {
val signingKey = System.getenv(InngestSystem.SigningKey.value)
if (signingKey == null) {
throw Exception("signing key is required")
}
signingKey
}
}
}

fun baseUrl(): String {
Expand Down
23 changes: 0 additions & 23 deletions inngest-core/src/test/kotlin/com/inngest/EnvironmentTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,6 @@ internal class EnvironmentTest {
// @Test
// fun `test inngestEventKey with INNGEST_EVENT_KEY value`() {}

// Signing key
@Test
fun `test inngestSigningKey - dev`() {
assertEquals("test", Environment.inngestSigningKey(InngestEnv.Dev))
}

@Test
fun `test inngestSigningKey with key value`() {
val key = "signing key"
assertEquals(key, Environment.inngestSigningKey(InngestEnv.Dev, key))
}

@Test
fun `test inngestSigningKey - prod`() {
assertFails(
"signing key is required",
{ Environment.inngestSigningKey(InngestEnv.Prod) },
)
}

// @Test
// fun `test inngestSigningKey with INNGEST_SIGNING_KEY value - prod`() {}

// EventAPI URL
@Test
fun `test inngestEventApiBaseUrl - dev`() {
Expand Down
37 changes: 35 additions & 2 deletions inngest-core/src/test/kotlin/com/inngest/ServeConfigTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,50 @@ package com.inngest
import kotlin.test.*

internal class ServeConfigTest {
val client = Inngest(appId = "test")

// appId()
@Test
fun `should return client appId if none are passed in`() {
val client = Inngest(appId = "test")
val config = ServeConfig(client)
assertEquals(client.appId, config.appId())
}

@Test
fun `should return serve appId if passed in`() {
val client = Inngest(appId = "test")
val config = ServeConfig(client = client, id = "hello")
assertEquals("hello", config.appId())
}

// signingKey()
@Test
fun `should return test string if not set - dev`() {
val config = ServeConfig(client = client)
assertEquals("test", config.signingKey())
}

@Test
fun `should throw error if not set - prod`() {
val prodClient = Inngest(appId = client.appId, env = "prod")
val config = ServeConfig(client = prodClient)
assertFails(
"signing key is required",
{ config.signingKey() },
)
}

// @Test
// fun `should return INNGEST_SIGNING_KEY value - prod`() {}

@Test
fun `should return passed in value`() {
val key = "sigingkey"
val config = ServeConfig(client = client, signingKey = key)
assertEquals(key, config.signingKey())
}

// baseUrl()
// serveOrigin()
// servePath()
// logLevel()
}

0 comments on commit d248233

Please sign in to comment.