mirror of https://github.com/usbharu/Hideout.git
test: e2eテストを追加
This commit is contained in:
parent
579d6a4d3e
commit
50415688d5
|
@ -1,4 +1,3 @@
|
|||
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
import org.openapitools.generator.gradle.plugin.tasks.GenerateTask
|
||||
|
||||
|
@ -32,6 +31,10 @@ sourceSets {
|
|||
compileClasspath += sourceSets.main.get().output
|
||||
runtimeClasspath += sourceSets.main.get().output
|
||||
}
|
||||
create("e2eTest") {
|
||||
compileClasspath += sourceSets.main.get().output
|
||||
runtimeClasspath += sourceSets.main.get().output
|
||||
}
|
||||
}
|
||||
|
||||
val intTestImplementation by configurations.getting {
|
||||
|
@ -41,6 +44,14 @@ val intTestRuntimeOnly by configurations.getting {
|
|||
extendsFrom(configurations.runtimeOnly.get())
|
||||
}
|
||||
|
||||
val e2eTestImplementation by configurations.getting {
|
||||
extendsFrom(configurations.implementation.get())
|
||||
}
|
||||
|
||||
val e2eTestRuntimeOnly by configurations.getting {
|
||||
extendsFrom(configurations.runtimeOnly.get())
|
||||
}
|
||||
|
||||
val integrationTest = task<Test>("integrationTest") {
|
||||
description = "Runs integration tests."
|
||||
group = "verification"
|
||||
|
@ -52,13 +63,24 @@ val integrationTest = task<Test>("integrationTest") {
|
|||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
tasks.check { dependsOn(integrationTest) }
|
||||
val e2eTest = task<Test>("e2eTest") {
|
||||
description = "Runs e2e tests."
|
||||
group = "verification"
|
||||
|
||||
testClassesDirs = sourceSets["e2eTest"].output.classesDirs
|
||||
classpath = sourceSets["e2eTest"].runtimeClasspath
|
||||
shouldRunAfter("test")
|
||||
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
tasks.check {
|
||||
dependsOn(integrationTest)
|
||||
dependsOn(e2eTest)
|
||||
}
|
||||
|
||||
tasks.withType<Test> {
|
||||
useJUnitPlatform()
|
||||
val cpus = Runtime.getRuntime().availableProcessors()
|
||||
// maxParallelForks = max(1, cpus - 1)
|
||||
// setForkEvery(4)
|
||||
doFirst {
|
||||
jvmArgs = arrayOf(
|
||||
"--add-opens", "java.base/java.lang=ALL-UNNAMED"
|
||||
|
@ -207,6 +229,13 @@ dependencies {
|
|||
intTestImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4")
|
||||
intTestImplementation("org.mockito.kotlin:mockito-kotlin:4.1.0")
|
||||
|
||||
e2eTestImplementation("org.springframework.boot:spring-boot-starter-test")
|
||||
e2eTestImplementation("org.springframework.security:spring-security-test")
|
||||
e2eTestImplementation("org.springframework.boot:spring-boot-starter-webflux")
|
||||
e2eTestImplementation("org.jsoup:jsoup:1.17.1")
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
detekt {
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
package oauth2
|
||||
|
||||
import dev.usbharu.hideout.SpringApplication
|
||||
import org.jsoup.Jsoup
|
||||
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation
|
||||
import org.junit.jupiter.api.Order
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.TestMethodOrder
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.context.SpringBootTest
|
||||
import org.springframework.http.MediaType
|
||||
import org.springframework.test.web.reactive.server.WebTestClient
|
||||
import org.springframework.web.reactive.function.BodyInserters
|
||||
|
||||
@SpringBootTest(
|
||||
classes = [SpringApplication::class],
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
)
|
||||
@TestMethodOrder(OrderAnnotation::class)
|
||||
class OAuth2LoginTest {
|
||||
|
||||
@Autowired
|
||||
private lateinit var webTestClient: WebTestClient
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
fun アカウント作成() {
|
||||
val returnResult = webTestClient.get()
|
||||
.uri("/auth/sign_up")
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isOk
|
||||
.returnResult(String::class.java)
|
||||
|
||||
val html = returnResult
|
||||
.responseBody
|
||||
.toStream()
|
||||
.toList()
|
||||
.toList()
|
||||
.joinToString("")
|
||||
|
||||
val session = returnResult.responseCookies["JSESSIONID"]?.first()?.value!!
|
||||
|
||||
val attr = Jsoup.parse(html).selectXpath("//input[@name=\"_csrf\"]").attr("value")
|
||||
|
||||
println("CSRF TOKEN = $attr")
|
||||
|
||||
val csrfToken = attr
|
||||
|
||||
webTestClient
|
||||
.post()
|
||||
.uri("/api/v1/accounts")
|
||||
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
|
||||
.body(
|
||||
BodyInserters.fromFormData("username", "oatuh-login-test")
|
||||
.with("password", "very-secure-password").with("_csrf", csrfToken)
|
||||
)
|
||||
.cookie("JSESSIONID", session)
|
||||
.exchange()
|
||||
.expectStatus().isFound
|
||||
.expectCookie()
|
||||
|
||||
}
|
||||
|
||||
// @Test
|
||||
// fun `OAuth2で権限read writeを持ったトークンでのログインができる`() {
|
||||
//// webTestClient.post().uri("/api/v1/apps")
|
||||
// }
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
hideout:
|
||||
url: "https://localhost:8080"
|
||||
use-mongodb: true
|
||||
security:
|
||||
jwt:
|
||||
generate: true
|
||||
key-id: a
|
||||
private-key: "MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQC7VJTUt9Us8cKjMzEfYyjiWA4R4/M2bS1GB4t7NXp98C3SC6dVMvDuictGeurT8jNbvJZHtCSuYEvuNMoSfm76oqFvAp8Gy0iz5sxjZmSnXyCdPEovGhLa0VzMaQ8s+CLOyS56YyCFGeJZqgtzJ6GR3eqoYSW9b9UMvkBpZODSctWSNGj3P7jRFDO5VoTwCQAWbFnOjDfH5Ulgp2PKSQnSJP3AJLQNFNe7br1XbrhV//eO+t51mIpGSDCUv3E0DDFcWDTH9cXDTTlRZVEiR2BwpZOOkE/Z0/BVnhZYL71oZV34bKfWjQIt6V/isSMahdsAASACp4ZTGtwiVuNd9tybAgMBAAECggEBAK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HskAjFTevO86Fsz1C2aSeRKSqGFoOQ0tmJzBEs1R6KqnHInicDTQrKhArgLXX4v3CddjfTRJkFWDbE/CkvKZNOrcf1nhaGCPspRJj2KUkj1Fhl9Cncdn/RsYEONbwQSjIfMPkvxF+8HQ=="
|
||||
public-key: "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAu1SU1LfVLPHCozMxH2Mo4lgOEePzNm0tRgeLezV6ffAt0gunVTLw7onLRnrq0/IzW7yWR7QkrmBL7jTKEn5u+qKhbwKfBstIs+bMY2Zkp18gnTxKLxoS2tFczGkPLPgizskuemMghRniWaoLcyehkd3qqGElvW/VDL5AaWTg0nLVkjRo9z+40RQzuVaE8AkAFmxZzow3x+VJYKdjykkJ0iT9wCS0DRTXu269V264Vf/3jvredZiKRkgwlL9xNAwxXFg0x/XFw005UWVRIkdgcKWTjpBP2dPwVZ4WWC+9aGVd+Gyn1o0CLelf4rEjGoXbAAEgAqeGUxrcIlbjXfbcmwIDAQAB"
|
||||
storage:
|
||||
use-s3: true
|
||||
endpoint: "http://localhost:8082/test-hideout"
|
||||
public-url: "http://localhost:8082/test-hideout"
|
||||
bucket: "test-hideout"
|
||||
region: "auto"
|
||||
access-key: ""
|
||||
secret-key: ""
|
||||
|
||||
spring:
|
||||
flyway:
|
||||
enabled: true
|
||||
clean-disabled: false
|
||||
datasource:
|
||||
driver-class-name: org.h2.Driver
|
||||
url: "jdbc:h2:mem:test;MODE=POSTGRESQL;DB_CLOSE_DELAY=-1;CASE_INSENSITIVE_IDENTIFIERS=true;TRACE_LEVEL_FILE=4;"
|
||||
username: ""
|
||||
password:
|
||||
data:
|
||||
mongodb:
|
||||
auto-index-creation: true
|
||||
host: localhost
|
||||
port: 27017
|
||||
database: hideout
|
||||
h2:
|
||||
console:
|
||||
enabled: true
|
||||
|
||||
# exposed:
|
||||
# generate-ddl: true
|
||||
# excluded-packages: dev.usbharu.hideout.core.infrastructure.kjobexposed
|
||||
server:
|
||||
port: 8080
|
|
@ -0,0 +1,11 @@
|
|||
<configuration>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{YYYY-MM-dd HH:mm:ss.SSS} [%thread] %-5level [%X{x-request-id}] %logger{36} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
<root level="TRACE">
|
||||
<appender-ref ref="STDOUT"/>
|
||||
</root>
|
||||
<logger name="org.springframework.security" level="TRACE"/>
|
||||
</configuration>
|
Loading…
Reference in New Issue