mirror of https://github.com/usbharu/Hideout.git
test: FollowAcceptTestを追加
This commit is contained in:
parent
8d4288247a
commit
aaa8bcdad8
|
@ -2,10 +2,20 @@ import dev.usbharu.hideout.core.infrastructure.exposedrepository.Users
|
|||
import org.jetbrains.exposed.sql.and
|
||||
import org.jetbrains.exposed.sql.select
|
||||
import org.jetbrains.exposed.sql.selectAll
|
||||
import java.net.MalformedURLException
|
||||
import java.net.URL
|
||||
|
||||
object AssertionUtil {
|
||||
|
||||
@JvmStatic
|
||||
fun assertUserExist(username: String, domain: String): Boolean {
|
||||
val s = try {
|
||||
val url = URL(domain)
|
||||
url.host + ":" + url.port.toString().takeIf { it != "-1" }.orEmpty()
|
||||
} catch (e: MalformedURLException) {
|
||||
domain
|
||||
}
|
||||
|
||||
val selectAll = Users.selectAll()
|
||||
println(selectAll.fetchSize)
|
||||
|
||||
|
@ -13,6 +23,6 @@ object AssertionUtil {
|
|||
|
||||
selectAll.map { "@${it[Users.name]}@${it[Users.domain]}" }.forEach { println(it) }
|
||||
|
||||
return Users.select { Users.name eq username and (Users.domain eq domain) }.empty().not()
|
||||
return Users.select { Users.name eq username and (Users.domain eq s) }.empty().not()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
package federation
|
||||
|
||||
import AssertionUtil
|
||||
import KarateUtil
|
||||
import com.intuit.karate.core.MockServer
|
||||
import com.intuit.karate.junit5.Karate
|
||||
import dev.usbharu.hideout.SpringApplication
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.flywaydb.core.Flyway
|
||||
import org.junit.jupiter.api.AfterAll
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.BeforeAll
|
||||
import org.junit.jupiter.api.TestFactory
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.context.SpringBootTest
|
||||
import org.springframework.boot.test.web.server.LocalServerPort
|
||||
import org.springframework.transaction.annotation.Transactional
|
||||
import java.net.MalformedURLException
|
||||
import java.net.URL
|
||||
|
||||
@SpringBootTest(
|
||||
classes = [SpringApplication::class],
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT
|
||||
)
|
||||
@Transactional
|
||||
class FollowAcceptTest {
|
||||
@LocalServerPort
|
||||
private var port = ""
|
||||
|
||||
@Karate.Test
|
||||
@TestFactory
|
||||
fun `FollowAcceptTest`(): Karate {
|
||||
return KarateUtil.e2eTest(
|
||||
"FollowAcceptTest", "Follow Accept Test",
|
||||
mapOf("karate.port" to port),
|
||||
javaClass
|
||||
)
|
||||
}
|
||||
|
||||
companion object {
|
||||
lateinit var server: MockServer
|
||||
|
||||
lateinit var _remotePort: String
|
||||
|
||||
@JvmStatic
|
||||
fun assertUserExist(username: String, domain: String) = runBlocking {
|
||||
val s = try {
|
||||
val url = URL(domain)
|
||||
url.host + ":" + url.port.toString().takeIf { it != "-1" }.orEmpty()
|
||||
} catch (e: MalformedURLException) {
|
||||
domain
|
||||
}
|
||||
|
||||
var check = false
|
||||
|
||||
repeat(10) {
|
||||
delay(1000)
|
||||
check = AssertionUtil.assertUserExist(username, s) or check
|
||||
if (check) {
|
||||
return@repeat
|
||||
}
|
||||
}
|
||||
|
||||
Assertions.assertTrue(check, "User @$username@$s not exist.")
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getRemotePort(): String = _remotePort
|
||||
|
||||
@BeforeAll
|
||||
@JvmStatic
|
||||
fun beforeAll(@Autowired flyway: Flyway) {
|
||||
server = MockServer.feature("classpath:federation/FollowAcceptMockServer.feature").http(0).build()
|
||||
_remotePort = server.port.toString()
|
||||
|
||||
flyway.clean()
|
||||
flyway.migrate()
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
@JvmStatic
|
||||
fun afterAll() {
|
||||
server.stop()
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,8 +16,6 @@ import org.springframework.beans.factory.annotation.Autowired
|
|||
import org.springframework.boot.test.context.SpringBootTest
|
||||
import org.springframework.boot.test.web.server.LocalServerPort
|
||||
import org.springframework.transaction.annotation.Transactional
|
||||
import java.net.MalformedURLException
|
||||
import java.net.URL
|
||||
|
||||
@SpringBootTest(
|
||||
classes = [SpringApplication::class],
|
||||
|
@ -96,24 +94,17 @@ class InboxCommonTest {
|
|||
|
||||
@JvmStatic
|
||||
fun assertUserExist(username: String, domain: String) = runBlocking {
|
||||
val s = try {
|
||||
val url = URL(domain)
|
||||
url.host + ":" + url.port.toString().takeIf { it != "-1" }.orEmpty()
|
||||
} catch (e: MalformedURLException) {
|
||||
domain
|
||||
}
|
||||
|
||||
var check = false
|
||||
|
||||
repeat(10) {
|
||||
delay(1000)
|
||||
check = AssertionUtil.assertUserExist(username, s) or check
|
||||
check = AssertionUtil.assertUserExist(username, domain) or check
|
||||
if (check) {
|
||||
return@repeat
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue(check, "User @$username@$s not exist.")
|
||||
assertTrue(check, "User @$username@$domain not exist.")
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
|
@ -128,6 +119,7 @@ class InboxCommonTest {
|
|||
flyway.clean()
|
||||
flyway.migrate()
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
@JvmStatic
|
||||
fun afterAll() {
|
||||
|
|
|
@ -0,0 +1,140 @@
|
|||
Feature: Follow Accept Mock Server
|
||||
|
||||
Background:
|
||||
* def assertInbox = Java.type(`federation.FollowAcceptTest`)
|
||||
* def req = {req: []}
|
||||
|
||||
Scenario: pathMatches('/users/test-follower') && methodIs('get')
|
||||
* def remoteUrl = 'http://localhost:' + assertInbox.getRemotePort()
|
||||
* def username = 'test-follower'
|
||||
* def userUrl = remoteUrl + '/users/' + username
|
||||
|
||||
|
||||
* def person =
|
||||
"""
|
||||
{
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://w3id.org/security/v1",
|
||||
{
|
||||
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
|
||||
"toot": "http://joinmastodon.org/ns#",
|
||||
"featured": {
|
||||
"@id": "toot:featured",
|
||||
"@type": "@id"
|
||||
},
|
||||
"featuredTags": {
|
||||
"@id": "toot:featuredTags",
|
||||
"@type": "@id"
|
||||
},
|
||||
"alsoKnownAs": {
|
||||
"@id": "as:alsoKnownAs",
|
||||
"@type": "@id"
|
||||
},
|
||||
"movedTo": {
|
||||
"@id": "as:movedTo",
|
||||
"@type": "@id"
|
||||
},
|
||||
"schema": "http://schema.org#",
|
||||
"PropertyValue": "schema:PropertyValue",
|
||||
"value": "schema:value",
|
||||
"discoverable": "toot:discoverable",
|
||||
"Device": "toot:Device",
|
||||
"Ed25519Signature": "toot:Ed25519Signature",
|
||||
"Ed25519Key": "toot:Ed25519Key",
|
||||
"Curve25519Key": "toot:Curve25519Key",
|
||||
"EncryptedMessage": "toot:EncryptedMessage",
|
||||
"publicKeyBase64": "toot:publicKeyBase64",
|
||||
"deviceId": "toot:deviceId",
|
||||
"claim": {
|
||||
"@type": "@id",
|
||||
"@id": "toot:claim"
|
||||
},
|
||||
"fingerprintKey": {
|
||||
"@type": "@id",
|
||||
"@id": "toot:fingerprintKey"
|
||||
},
|
||||
"identityKey": {
|
||||
"@type": "@id",
|
||||
"@id": "toot:identityKey"
|
||||
},
|
||||
"devices": {
|
||||
"@type": "@id",
|
||||
"@id": "toot:devices"
|
||||
},
|
||||
"messageFranking": "toot:messageFranking",
|
||||
"messageType": "toot:messageType",
|
||||
"cipherText": "toot:cipherText",
|
||||
"suspended": "toot:suspended",
|
||||
"focalPoint": {
|
||||
"@container": "@list",
|
||||
"@id": "toot:focalPoint"
|
||||
}
|
||||
}
|
||||
],
|
||||
"id": #(userUrl),
|
||||
"type": "Person",
|
||||
"following": #(userUrl + '/following'),
|
||||
"followers": #(userUrl + '/followers'),
|
||||
"inbox": #(userUrl + '/inbox'),
|
||||
"outbox": #(userUrl + '/outbox'),
|
||||
"featured": #(userUrl + '/collections/featured'),
|
||||
"featuredTags": #(userUrl + '/collections/tags'),
|
||||
"preferredUsername": #(username),
|
||||
"name": #(username),
|
||||
"summary": "E2E Test User Jaga/Cotlin/Winter Boot/Ktol\nYonTude: https://example.com\nY(Tvvitter): https://example.com\n",
|
||||
"url": #(userUrl + '/@' + username),
|
||||
"manuallyApprovesFollowers": false,
|
||||
"discoverable": true,
|
||||
"published": "2016-03-16T00:00:00Z",
|
||||
"devices": #(userUrl + '/collections/devices'),
|
||||
"alsoKnownAs": [
|
||||
#( 'https://example.com/users/' + username)
|
||||
],
|
||||
"publicKey": {
|
||||
"id": #(userUrl + '#main-key'),
|
||||
"owner": #(userUrl),
|
||||
"publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvmtKo0xYGXR4M0LQQhK4\nBkKpRvvUxrqGV6Ew4CBHSyzdnbFsiBqHUWz4JvRiQvAPqQ4jQFpxVZCPr9xx6lJp\nx7EAAKIdVTnBBV4CYfu7QPsRqtjbB5408q+mo5oUXNs8xg2tcC42p2SJ5CRJX/fr\nOgCZwo3LC9pOBdCQZ+tiiPmWNBTNby99JZn4D/xNcwuhV04qcPoHYD9OPuxxGyzc\naVJ2mqJmvi/lewQuR8qnUIbz+Gik+xvyG6LmyuDoa1H2LDQfQXYb62G70HsYdu7a\ndObvZovytp+kkjP/cUaIYkhhOAYqAA4zCwVRY4NHK0MAMq9sMoUfNJa8U+zR9NvD\noQIDAQAB\n-----END PUBLIC KEY-----\n"
|
||||
},
|
||||
"tag": [],
|
||||
"attachment": [
|
||||
{
|
||||
"type": "PropertyValue",
|
||||
"name": "Pixib Fan-Bridge",
|
||||
"value": "\u003ca href=\"https://example.com/hideout\" target=\"_blank\" rel=\"nofollow noopener noreferrer me\"\u003e\u003cspan class=\"invisible\"\u003ehttps://www.\u003c/span\u003e\u003cspan class=\"\"\u003eexample.com/hideout\u003c/span\u003e\u003cspan class=\"invisible\"\u003e\u003c/span\u003e\u003c/a\u003e"
|
||||
},
|
||||
{
|
||||
"type": "PropertyValue",
|
||||
"name": "GitHub",
|
||||
"value": "\u003ca href=\"https://github.com/usbharu/hideout\" target=\"_blank\" rel=\"nofollow noopener noreferrer me\"\u003e\u003cspan class=\"invisible\"\u003ehttps://\u003c/span\u003e\u003cspan class=\"\"\u003egithub.com/usbharu/hideout\u003c/span\u003e\u003cspan class=\"invisible\"\u003e\u003c/span\u003e\u003c/a\u003e"
|
||||
}
|
||||
],
|
||||
"endpoints": {
|
||||
"sharedInbox": #(remoteUrl + '/inbox')
|
||||
},
|
||||
"icon": {
|
||||
"type": "Image",
|
||||
"mediaType": "image/jpeg",
|
||||
"url": "https://upload.wikimedia.org/wikipedia/commons/thumb/3/30/Destroyer_Vozbuzhdenyy.jpg/320px-Destroyer_Vozbuzhdenyy.jpg"
|
||||
},
|
||||
"image": {
|
||||
"type": "Image",
|
||||
"mediaType": "image/jpeg",
|
||||
"url": "https://upload.wikimedia.org/wikipedia/commons/thumb/6/63/Views_of_Mount_Fuji_from_%C5%8Cwakudani_20211202.jpg/320px-Views_of_Mount_Fuji_from_%C5%8Cwakudani_20211202.jpg"
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
* set req.req[] = '/users/' + username
|
||||
* def response = person
|
||||
|
||||
Scenario: pathMatches('/inbox') && methodIs('post')
|
||||
* set req.req[] = '/inbox'
|
||||
* def responseStatus = 202
|
||||
|
||||
Scenario: pathMatches('/internal-assertion-api/requests') && methodIs('get')
|
||||
* def response = req
|
||||
|
||||
Scenario: pathMatches('/internal-assertion-api/requests/deleteAll') && methodIs('post')
|
||||
* set req.req = []
|
||||
* def responseStatus = 200
|
|
@ -0,0 +1,29 @@
|
|||
Feature: Follow Accept Test
|
||||
|
||||
Background:
|
||||
* url baseUrl
|
||||
* def assertionUtil = Java.type('AssertionUtil')
|
||||
|
||||
Scenario: Follow Accept Test
|
||||
|
||||
* def follow =
|
||||
"""
|
||||
{"type": "Follow","actor": #(remoteUrl + '/users/test-follower'),"object": #(baseUrl + '/users/test-user')}
|
||||
"""
|
||||
|
||||
Given path '/inbox'
|
||||
And header Signature = 'keyId="https://test-hideout.usbharu.dev/users/c#pubkey", algorithm="rsa-sha256", headers="x-request-id tpp-redirect-uri digest psu-id", signature="e/91pFiI5bRffP33EMrqoI5A0xjkg3Ar0kzRGHC/1RsLrDW0zV50dHly/qJJ5xrYHRlss3+vd0mznTLBs1X0hx0uXjpfvCvwclpSi8u+sqn+Y2bcQKzf7ah0vAONQd6zeTYW7e/1kDJreP43PsJyz29KZD16Yop8nM++YeEs6C5eWiyYXKoQozXnfmTOX3y6bhxfKKQWVcxA5aLOTmTZRYTsBsTy9zn8NjDQaRI/0gcyYPqpq+2g8j2DbyJu3Z6zP6VmwbGGlQU/s9Pa7G5LqUPH/sBMSlIeqh+Hvm2pL7B3/BMFvGtTD+e2mR60BFnLIxMYx+oX4o33J2XkFIODLQ=="'
|
||||
And request follow
|
||||
When method post
|
||||
Then status 202
|
||||
|
||||
And retry until assertionUtil.assertUserExist('test-follower',remoteUrl)
|
||||
|
||||
* url remoteUrl
|
||||
|
||||
Given path '/internal-assertion-api/requests'
|
||||
When method get
|
||||
Then status 200
|
||||
And match response.req contains ['/users/test-follower']
|
||||
|
||||
* url baseUrl
|
|
@ -110,7 +110,7 @@ Feature: InboxCommonMockServer
|
|||
}
|
||||
],
|
||||
"endpoints": {
|
||||
"sharedInbox": #(userUrl + 'inbox')
|
||||
"sharedInbox": #(remoteUrl + '/inbox')
|
||||
},
|
||||
"icon": {
|
||||
"type": "Image",
|
||||
|
|
Loading…
Reference in New Issue