Skip to content

Commit

Permalink
converted few more suits
Browse files Browse the repository at this point in the history
  • Loading branch information
karthick-vinod committed Apr 13, 2024
1 parent ffc8dcf commit 571e1ee
Show file tree
Hide file tree
Showing 10 changed files with 474 additions and 587 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ dependencies {
testImplementation("io.insert-koin:koin-test:$koin_version")
testImplementation "io.insert-koin:koin-test-junit5:$koin_version"
testImplementation("org.junit.jupiter:junit-jupiter-api:$junit_version")
testImplementation('io.mockk:mockk:1.13.4')
testImplementation('io.mockk:mockk:1.13.10')
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$junit_version")

testImplementation 'org.testcontainers:junit-jupiter:1.19.7'
Expand Down
33 changes: 2 additions & 31 deletions src/test/kotlin/com/hypto/iam/server/apis/ActionApiTest.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.hypto.iam.server.apis

import com.google.gson.Gson
import com.hypto.iam.server.Constants
import com.hypto.iam.server.helpers.AbstractContainerBaseTest
import com.hypto.iam.server.helpers.BaseSingleAppTest
import com.hypto.iam.server.helpers.DataSetupHelper.deleteOrganization
import com.hypto.iam.server.helpers.DataSetupHelperV3.createAction
import com.hypto.iam.server.helpers.DataSetupHelperV3.createOrganization
Expand All @@ -23,39 +22,11 @@ import io.ktor.http.ContentType
import io.ktor.http.HttpHeaders
import io.ktor.http.HttpStatusCode
import io.ktor.http.contentType
import io.ktor.server.config.ApplicationConfig
import io.ktor.server.testing.TestApplication
import io.ktor.test.dispatcher.testSuspend
import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import org.koin.test.inject

class ActionApiTest : AbstractContainerBaseTest() {
private val gson: Gson by inject()

companion object {
lateinit var testApp: TestApplication

@JvmStatic
@BeforeAll
fun setupTest() {
testApp =
TestApplication {
environment {
config = ApplicationConfig("application-custom.conf")
}
}
}

@JvmStatic
@AfterAll
fun teardownTest() {
testApp.stop()
}
}

class ActionApiTest : BaseSingleAppTest() {
@Test
fun `create action success case1`() {
testSuspend {
Expand Down
150 changes: 53 additions & 97 deletions src/test/kotlin/com/hypto/iam/server/apis/CredentialApiKtTest.kt

Large diffs are not rendered by default.

24 changes: 8 additions & 16 deletions src/test/kotlin/com/hypto/iam/server/apis/KeyApiTest.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.hypto.iam.server.apis

import com.google.gson.Gson
import com.hypto.iam.server.helpers.AbstractContainerBaseTest
import com.hypto.iam.server.helpers.DataSetupHelperV2.createOrganization
import com.hypto.iam.server.helpers.BaseSingleAppTest
import com.hypto.iam.server.helpers.DataSetupHelperV3.createOrganization
import com.hypto.iam.server.models.KeyResponse
import com.hypto.iam.server.models.TokenResponse
import com.hypto.iam.server.service.TokenServiceImpl
Expand All @@ -15,30 +14,23 @@ import io.ktor.http.ContentType.Application.Json
import io.ktor.http.HttpHeaders
import io.ktor.http.HttpStatusCode
import io.ktor.http.contentType
import io.ktor.server.config.ApplicationConfig
import io.ktor.server.testing.testApplication
import io.ktor.test.dispatcher.testSuspend
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertDoesNotThrow
import org.koin.test.inject
import java.security.KeyFactory
import java.security.PublicKey
import java.security.spec.X509EncodedKeySpec
import java.util.Base64

class KeyApiTest : AbstractContainerBaseTest() {
private val gson: Gson by inject()

class KeyApiTest : BaseSingleAppTest() {
@Test
fun `validate token using public key`() {
testApplication {
environment {
config = ApplicationConfig("application-custom.conf")
}
val (organizationResponse, _) = createOrganization()
testSuspend {
val (organizationResponse, _) = testApp.createOrganization()

val createTokenCall =
client.post("/organizations/${organizationResponse.organization.id}/token") {
testApp.client.post("/organizations/${organizationResponse.organization.id}/token") {
header(HttpHeaders.ContentType, Json.toString())
header(HttpHeaders.Authorization, "Bearer ${organizationResponse.rootUserToken}")
}
Expand All @@ -55,7 +47,7 @@ class KeyApiTest : AbstractContainerBaseTest() {
val kid = jwt.header.getValue(TokenServiceImpl.KEY_ID) as String

val response =
client.get(
testApp.client.get(
"/keys/$kid?format=der",
) {
header(HttpHeaders.Authorization, "Bearer ${organizationResponse.rootUserToken}")
Expand Down
Loading

0 comments on commit 571e1ee

Please sign in to comment.