mirror of https://github.com/usbharu/Hideout.git
test: user-inboxのテストを追加
This commit is contained in:
parent
14034cd1b9
commit
5a77b9e669
|
@ -42,9 +42,35 @@ class InboxCommonTest {
|
|||
)
|
||||
}
|
||||
|
||||
companion object {
|
||||
@Karate.Test
|
||||
@TestFactory
|
||||
fun `user-inboxにHTTP Signature付きのリクエストがあったらリモートに取得しに行く`(): Karate {
|
||||
return KarateUtil.e2eTest(
|
||||
"InboxCommonTest",
|
||||
"user-inboxにHTTP Signature付きのリクエストがあったらリモートに取得しに行く",
|
||||
mapOf(
|
||||
"karate.port" to port,
|
||||
"karate.remotePort" to _remotePort
|
||||
),
|
||||
javaClass
|
||||
)
|
||||
}
|
||||
|
||||
@Karate.Test
|
||||
@TestFactory
|
||||
fun `inboxにHTTP Signatureがないリクエストがきたら401を返す`(): Karate {
|
||||
return KarateUtil.e2eTest(
|
||||
"InboxCommonTest",
|
||||
"inboxにHTTP Signatureがないリクエストがきたら401を返す",
|
||||
mapOf("karate.port" to port),
|
||||
javaClass
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
companion object {
|
||||
lateinit var server: MockServer
|
||||
|
||||
lateinit var _remotePort: String
|
||||
|
||||
@JvmStatic
|
||||
|
@ -81,7 +107,6 @@ class InboxCommonTest {
|
|||
flyway.clean()
|
||||
flyway.migrate()
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
@JvmStatic
|
||||
fun afterAll() {
|
||||
|
|
|
@ -5,6 +5,14 @@ Feature: Inbox Common Test
|
|||
|
||||
Scenario: inboxにHTTP Signature付きのリクエストがあったらリモートに取得しに行く
|
||||
|
||||
* url remoteUrl
|
||||
|
||||
Given path '/internal-assertion-api/requests/deleteAll'
|
||||
When method post
|
||||
Then status 200
|
||||
|
||||
* url baseUrl
|
||||
|
||||
* def inbox =
|
||||
"""
|
||||
{ "type": "Follow" }
|
||||
|
@ -20,3 +28,66 @@ Feature: Inbox Common Test
|
|||
* def assertInbox = Java.type(`federation.InboxCommonTest`)
|
||||
|
||||
And assertInbox.assertUserExist('test-user',remoteUrl)
|
||||
|
||||
* url remoteUrl
|
||||
|
||||
Given path '/internal-assertion-api/requests'
|
||||
When method get
|
||||
Then status 200
|
||||
|
||||
* url baseUrl
|
||||
|
||||
* print response
|
||||
Then match response.req == ['/users/test-user']
|
||||
|
||||
|
||||
Scenario: inboxにHTTP Signatureがないリクエストがきたら401を返す
|
||||
|
||||
* def inbox =
|
||||
"""
|
||||
{"type": "Follow"}
|
||||
"""
|
||||
|
||||
Given path '/inbox'
|
||||
And request inbox
|
||||
When method post
|
||||
Then status 401
|
||||
|
||||
|
||||
Scenario: user-inboxにHTTP Signature付きのリクエストがあったらリモートに取得しに行く
|
||||
|
||||
* url remoteUrl
|
||||
|
||||
Given path '/internal-assertion-api/requests/deleteAll'
|
||||
When method post
|
||||
Then status 200
|
||||
|
||||
* url baseUrl
|
||||
|
||||
* def inbox =
|
||||
"""
|
||||
{ "type": "Follow" }
|
||||
"""
|
||||
|
||||
Given path `/inbox`
|
||||
And request inbox
|
||||
# And header Signature = 'keyId="'+ remoteUrl +'/users/test-user#pubkey", algorithm="rsa-sha256", headers="(request-target)", signature="a"'
|
||||
And header Signature = 'keyId="'+ remoteUrl +'/users/test-user2#pubkey", algorithm="rsa-sha256", headers="(request-target) date host digest", signature="FfpkmBogW70FMo94yovGpl15L/m4bDjVIFb9mSZUstPE3H00nHiqNsjAq671qFMJsGOO1uWfLEExcdvzwTiC3wuHShzingvxQUbTgcgRTRZcHbtrOZxT8hYHGndpCXGv/NOLkfXDtZO9v5u0fnA2yJFokzyPHOPJ1cJliWlXP38Bl/pO4H5rBLQBZKpM2jYIjMyI78G2rDXNHEeGrGiyfB5SKb3H6zFQL+X9QpXUI4n0f07VsnwaDyp63oUopmzNUyBEuSqB+8va/lbfcWwrxpZnKGzQRZ+VBcV7jDoKGNOP9/O1xEI2CwB8sh+h6KVHdX3EQEvO1slaaLzcwRRqrQ=="'
|
||||
When method post
|
||||
Then status 202
|
||||
|
||||
* def assertInbox = Java.type(`federation.InboxCommonTest`)
|
||||
|
||||
And assertInbox.assertUserExist('test-user2',remoteUrl)
|
||||
|
||||
|
||||
* url remoteUrl
|
||||
|
||||
Given path '/internal-assertion-api/requests'
|
||||
When method get
|
||||
Then status 200
|
||||
|
||||
* url baseUrl
|
||||
|
||||
* print response
|
||||
Then match response.req == ['/users/test-user2']
|
||||
|
|
|
@ -2,10 +2,13 @@ Feature: InboxCommonMockServer
|
|||
|
||||
Background:
|
||||
* def assertInbox = Java.type(`federation.InboxCommonTest`)
|
||||
* def req = {req: []}
|
||||
|
||||
Scenario: pathMatches('/users/test-user') && methodIs('get')
|
||||
Scenario: pathMatches('/users/{username}') && methodIs('get')
|
||||
* def remoteUrl = 'http://localhost:' + assertInbox.getRemotePort()
|
||||
* def userUrl = remoteUrl + '/users/test-user'
|
||||
* def username = pathParams.username
|
||||
* def userUrl = remoteUrl + '/users/' + username
|
||||
|
||||
|
||||
* def person =
|
||||
"""
|
||||
|
@ -77,16 +80,16 @@ Feature: InboxCommonMockServer
|
|||
"outbox": #(userUrl + '/outbox'),
|
||||
"featured": #(userUrl + '/collections/featured'),
|
||||
"featuredTags": #(userUrl + '/collections/tags'),
|
||||
"preferredUsername": "test-user",
|
||||
"name": "test-user",
|
||||
"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 + '/@test-user'),
|
||||
"url": #(userUrl + '/@' + username),
|
||||
"manuallyApprovesFollowers": false,
|
||||
"discoverable": true,
|
||||
"published": "2016-03-16T00:00:00Z",
|
||||
"devices": #(userUrl + '/collections/devices'),
|
||||
"alsoKnownAs": [
|
||||
"https://example.com/users/test-users"
|
||||
#( 'https://example.com/users/' + username)
|
||||
],
|
||||
"publicKey": {
|
||||
"id": #(userUrl + '#main-key'),
|
||||
|
@ -122,5 +125,12 @@ Feature: InboxCommonMockServer
|
|||
}
|
||||
|
||||
"""
|
||||
|
||||
* set req.req[] = '/users/' + username
|
||||
* def response = person
|
||||
|
||||
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
|
||||
|
|
|
@ -81,7 +81,7 @@ class InstanceServiceImpl(
|
|||
}
|
||||
|
||||
else -> {
|
||||
TODO()
|
||||
throw IllegalStateException("Unknown nodeinfo versions: $key url: $value")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,6 +60,7 @@ class UserServiceImpl(
|
|||
|
||||
@Transactional
|
||||
override suspend fun createRemoteUser(user: RemoteUserCreateDto): User {
|
||||
logger.info("START Create New remote user. name: {} url: {}", user.name, user.url)
|
||||
@Suppress("TooGenericExceptionCaught")
|
||||
val instance = try {
|
||||
instanceService.fetchInstance(user.url, user.sharedInbox)
|
||||
|
@ -86,8 +87,11 @@ class UserServiceImpl(
|
|||
instance = instance?.id
|
||||
)
|
||||
return try {
|
||||
userRepository.save(userEntity)
|
||||
val save = userRepository.save(userEntity)
|
||||
logger.warn("SUCCESS Create New remote user. id: {} name: {} url: {}", userEntity.id, user.name, user.url)
|
||||
save
|
||||
} catch (_: ExposedSQLException) {
|
||||
logger.warn("FAILED User already exists. name: {} url: {}", user.name, user.url)
|
||||
userQueryService.findByUrl(user.url)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue