mirror of https://github.com/usbharu/Hideout.git
test: WebFingerの統合テストを追加
This commit is contained in:
parent
f2fea24fce
commit
3a0d91de79
|
@ -200,6 +200,8 @@ dependencies {
|
||||||
implementation("org.drewcarlson:kjob-mongo:0.6.0")
|
implementation("org.drewcarlson:kjob-mongo:0.6.0")
|
||||||
|
|
||||||
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.23.1")
|
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.23.1")
|
||||||
|
|
||||||
|
intTestImplementation("org.springframework.boot:spring-boot-starter-test")
|
||||||
}
|
}
|
||||||
|
|
||||||
detekt {
|
detekt {
|
||||||
|
|
|
@ -0,0 +1,83 @@
|
||||||
|
package activitypub.webfinger
|
||||||
|
|
||||||
|
import dev.usbharu.hideout.SpringApplication
|
||||||
|
import dev.usbharu.hideout.application.external.Transaction
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
|
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest
|
||||||
|
import org.springframework.boot.test.context.TestConfiguration
|
||||||
|
import org.springframework.context.annotation.Bean
|
||||||
|
import org.springframework.test.context.jdbc.Sql
|
||||||
|
import org.springframework.test.web.servlet.MockMvc
|
||||||
|
import org.springframework.test.web.servlet.get
|
||||||
|
import org.springframework.transaction.annotation.Transactional
|
||||||
|
import util.TestTransaction
|
||||||
|
import java.net.URL
|
||||||
|
|
||||||
|
@SpringBootTest(classes = [SpringApplication::class])
|
||||||
|
@AutoConfigureMockMvc
|
||||||
|
@Transactional
|
||||||
|
class WebFingerTest {
|
||||||
|
@Autowired
|
||||||
|
private lateinit var mockMvc: MockMvc
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Sql("/sql/test-user.sql")
|
||||||
|
fun `webfinger 存在するユーザーを取得`() {
|
||||||
|
mockMvc
|
||||||
|
.get("/.well-known/webfinger?resource=acct:test-user@example.com")
|
||||||
|
.andExpect { status { isOk() } }
|
||||||
|
.andExpect { header { string("Content-Type", "application/json") } }
|
||||||
|
.andExpect {
|
||||||
|
jsonPath("\$.subject") {
|
||||||
|
value("acct:test-user@example.com")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.andExpect {
|
||||||
|
jsonPath("\$.links[0].rel") {
|
||||||
|
value("self")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.andExpect {
|
||||||
|
jsonPath("\$.links[0].href") { value("https://example.com/users/test-user") }
|
||||||
|
}
|
||||||
|
.andExpect {
|
||||||
|
jsonPath("\$.links[0].type") {
|
||||||
|
value("application/activity+json")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `webfinger 存在しないユーザーに404`() {
|
||||||
|
mockMvc
|
||||||
|
.get("/.well-known/webfinger?resource=acct:test-user@example.com")
|
||||||
|
.andExpect { status { isNotFound() } }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `webfinger 不正なリクエストは400`() {
|
||||||
|
mockMvc
|
||||||
|
.get("/.well-known/webfinger?res=acct:test")
|
||||||
|
.andExpect { status { isBadRequest() } }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `webfinger acctのパースが出来なくても400`() {
|
||||||
|
mockMvc
|
||||||
|
.get("/.well-known/webfinger?resource=acct:@a@b@c@d")
|
||||||
|
.andExpect { status { isBadRequest() } }
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestConfiguration
|
||||||
|
class Configuration {
|
||||||
|
@Bean
|
||||||
|
fun url(): URL {
|
||||||
|
return URL("https://example.com")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
fun testTransaction(): Transaction = TestTransaction
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
package util
|
||||||
|
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
abstract class SpringApplicationTestBase
|
|
@ -0,0 +1,9 @@
|
||||||
|
package util
|
||||||
|
|
||||||
|
import dev.usbharu.hideout.application.external.Transaction
|
||||||
|
|
||||||
|
object TestTransaction : Transaction {
|
||||||
|
override suspend fun <T> transaction(block: suspend () -> T): T = block()
|
||||||
|
|
||||||
|
override suspend fun <T> transaction(transactionLevel: Int, block: suspend () -> T): T = block()
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
hideout:
|
||||||
|
url: "https://localhost:8080"
|
||||||
|
use-mongodb: true
|
||||||
|
security:
|
||||||
|
jwt:
|
||||||
|
generate: true
|
||||||
|
key-id: a
|
||||||
|
private-key: "MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQC7VJTUt9Us8cKjMzEfYyjiWA4R4/M2bS1GB4t7NXp98C3SC6dVMvDuictGeurT8jNbvJZHtCSuYEvuNMoSfm76oqFvAp8Gy0iz5sxjZmSnXyCdPEovGhLa0VzMaQ8s+CLOyS56YyCFGeJZqgtzJ6GR3eqoYSW9b9UMvkBpZODSctWSNGj3P7jRFDO5VoTwCQAWbFnOjDfH5Ulgp2PKSQnSJP3AJLQNFNe7br1XbrhV//eO+t51mIpGSDCUv3E0DDFcWDTH9cXDTTlRZVEiR2BwpZOOkE/Z0/BVnhZYL71oZV34bKfWjQIt6V/isSMahdsAASACp4ZTGtwiVuNd9tybAgMBAAECggEBAKTmjaS6tkK8BlPXClTQ2vpz/N6uxDeS35mXpqasqskVlaAidgg/sWqpjXDbXr93otIMLlWsM+X0CqMDgSXKejLS2jx4GDjI1ZTXg++0AMJ8sJ74pWzVDOfmCEQ/7wXs3+cbnXhKriO8Z036q92Qc1+N87SI38nkGa0ABH9CN83HmQqt4fB7UdHzuIRe/me2PGhIq5ZBzj6h3BpoPGzEP+x3l9YmK8t/1cN0pqI+dQwYdgfGjackLu/2qH80MCF7IyQaseZUOJyKrCLtSD/Iixv/hzDEU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TKEn5u+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:
|
||||||
|
datasource:
|
||||||
|
driver-class-name: org.h2.Driver
|
||||||
|
url: "jdbc:h2:mem:test;MODE=POSTGRESQL;DB_CLOSE_DELAY=-1"
|
||||||
|
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,9 @@
|
||||||
|
insert into "USERS" (ID, NAME, DOMAIN, SCREEN_NAME, DESCRIPTION, PASSWORD, INBOX, OUTBOX, URL, PUBLIC_KEY, PRIVATE_KEY,
|
||||||
|
CREATED_AT, KEY_ID, FOLLOWING, FOLLOWERS)
|
||||||
|
VALUES (1, 'test-user', 'example.com', 'Im test user.', 'THis account is test user.',
|
||||||
|
'5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8', 'https://example.com/users/test-user/inbox',
|
||||||
|
'https://example.com/users/test-user/outbox', 'https://example.com/users/test-user',
|
||||||
|
'-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----',
|
||||||
|
'-----BEGIN PRIVATE KEY-----...-----END PRIVATE KEY-----', 12345678,
|
||||||
|
'https://example.com/users/test-user#pubkey', 'https://example.com/users/test-user/following',
|
||||||
|
'https://example.com/users/test-users/followers');
|
Loading…
Reference in New Issue