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 server: MockServer
|
||||||
|
|
||||||
lateinit var _remotePort: String
|
lateinit var _remotePort: String
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
|
@ -81,7 +107,6 @@ class InboxCommonTest {
|
||||||
flyway.clean()
|
flyway.clean()
|
||||||
flyway.migrate()
|
flyway.migrate()
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterAll
|
@AfterAll
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun afterAll() {
|
fun afterAll() {
|
||||||
|
|
|
@ -5,6 +5,14 @@ Feature: Inbox Common Test
|
||||||
|
|
||||||
Scenario: inboxにHTTP Signature付きのリクエストがあったらリモートに取得しに行く
|
Scenario: inboxにHTTP Signature付きのリクエストがあったらリモートに取得しに行く
|
||||||
|
|
||||||
|
* url remoteUrl
|
||||||
|
|
||||||
|
Given path '/internal-assertion-api/requests/deleteAll'
|
||||||
|
When method post
|
||||||
|
Then status 200
|
||||||
|
|
||||||
|
* url baseUrl
|
||||||
|
|
||||||
* def inbox =
|
* def inbox =
|
||||||
"""
|
"""
|
||||||
{ "type": "Follow" }
|
{ "type": "Follow" }
|
||||||
|
@ -20,3 +28,66 @@ Feature: Inbox Common Test
|
||||||
* def assertInbox = Java.type(`federation.InboxCommonTest`)
|
* def assertInbox = Java.type(`federation.InboxCommonTest`)
|
||||||
|
|
||||||
And assertInbox.assertUserExist('test-user',remoteUrl)
|
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:
|
Background:
|
||||||
* def assertInbox = Java.type(`federation.InboxCommonTest`)
|
* 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 remoteUrl = 'http://localhost:' + assertInbox.getRemotePort()
|
||||||
* def userUrl = remoteUrl + '/users/test-user'
|
* def username = pathParams.username
|
||||||
|
* def userUrl = remoteUrl + '/users/' + username
|
||||||
|
|
||||||
|
|
||||||
* def person =
|
* def person =
|
||||||
"""
|
"""
|
||||||
|
@ -77,16 +80,16 @@ Feature: InboxCommonMockServer
|
||||||
"outbox": #(userUrl + '/outbox'),
|
"outbox": #(userUrl + '/outbox'),
|
||||||
"featured": #(userUrl + '/collections/featured'),
|
"featured": #(userUrl + '/collections/featured'),
|
||||||
"featuredTags": #(userUrl + '/collections/tags'),
|
"featuredTags": #(userUrl + '/collections/tags'),
|
||||||
"preferredUsername": "test-user",
|
"preferredUsername": #(username),
|
||||||
"name": "test-user",
|
"name": #(username),
|
||||||
"summary": "E2E Test User Jaga/Cotlin/Winter Boot/Ktol\nYonTude: https://example.com\nY(Tvvitter): https://example.com\n",
|
"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,
|
"manuallyApprovesFollowers": false,
|
||||||
"discoverable": true,
|
"discoverable": true,
|
||||||
"published": "2016-03-16T00:00:00Z",
|
"published": "2016-03-16T00:00:00Z",
|
||||||
"devices": #(userUrl + '/collections/devices'),
|
"devices": #(userUrl + '/collections/devices'),
|
||||||
"alsoKnownAs": [
|
"alsoKnownAs": [
|
||||||
"https://example.com/users/test-users"
|
#( 'https://example.com/users/' + username)
|
||||||
],
|
],
|
||||||
"publicKey": {
|
"publicKey": {
|
||||||
"id": #(userUrl + '#main-key'),
|
"id": #(userUrl + '#main-key'),
|
||||||
|
@ -122,5 +125,12 @@ Feature: InboxCommonMockServer
|
||||||
}
|
}
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
* set req.req[] = '/users/' + username
|
||||||
* def response = person
|
* 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 -> {
|
else -> {
|
||||||
TODO()
|
throw IllegalStateException("Unknown nodeinfo versions: $key url: $value")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,6 +60,7 @@ class UserServiceImpl(
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
override suspend fun createRemoteUser(user: RemoteUserCreateDto): User {
|
override suspend fun createRemoteUser(user: RemoteUserCreateDto): User {
|
||||||
|
logger.info("START Create New remote user. name: {} url: {}", user.name, user.url)
|
||||||
@Suppress("TooGenericExceptionCaught")
|
@Suppress("TooGenericExceptionCaught")
|
||||||
val instance = try {
|
val instance = try {
|
||||||
instanceService.fetchInstance(user.url, user.sharedInbox)
|
instanceService.fetchInstance(user.url, user.sharedInbox)
|
||||||
|
@ -86,8 +87,11 @@ class UserServiceImpl(
|
||||||
instance = instance?.id
|
instance = instance?.id
|
||||||
)
|
)
|
||||||
return try {
|
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) {
|
} catch (_: ExposedSQLException) {
|
||||||
|
logger.warn("FAILED User already exists. name: {} url: {}", user.name, user.url)
|
||||||
userQueryService.findByUrl(user.url)
|
userQueryService.findByUrl(user.url)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue