mirror of
https://github.com/usbharu/Hideout.git
synced 2026-09-26 06:51:09 +00:00
test: テストを修正
This commit is contained in:
@@ -17,11 +17,13 @@
|
||||
package activitypub.inbox
|
||||
|
||||
import dev.usbharu.hideout.SpringApplication
|
||||
import dev.usbharu.hideout.util.Base64Util
|
||||
import org.flywaydb.core.Flyway
|
||||
import org.junit.jupiter.api.AfterAll
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.beans.factory.annotation.Qualifier
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
|
||||
import org.springframework.boot.test.context.SpringBootTest
|
||||
import org.springframework.boot.test.context.TestConfiguration
|
||||
@@ -37,17 +39,25 @@ import org.springframework.transaction.annotation.Transactional
|
||||
import org.springframework.web.context.WebApplicationContext
|
||||
import util.TestTransaction
|
||||
import util.WithMockHttpSignature
|
||||
import java.security.MessageDigest
|
||||
import java.time.ZonedDateTime
|
||||
import java.time.format.DateTimeFormatter
|
||||
|
||||
@SpringBootTest(classes = [SpringApplication::class])
|
||||
@AutoConfigureMockMvc
|
||||
@Transactional
|
||||
class InboxTest {
|
||||
|
||||
@Autowired
|
||||
@Qualifier("http")
|
||||
private lateinit var dateTimeFormatter: DateTimeFormatter
|
||||
|
||||
@Autowired
|
||||
private lateinit var context: WebApplicationContext
|
||||
|
||||
private lateinit var mockMvc: MockMvc
|
||||
|
||||
|
||||
@BeforeEach
|
||||
fun setUp() {
|
||||
mockMvc = MockMvcBuilders.webAppContextSetup(context)
|
||||
@@ -62,6 +72,12 @@ class InboxTest {
|
||||
.post("/inbox") {
|
||||
content = "{}"
|
||||
contentType = MediaType.APPLICATION_JSON
|
||||
header("Host", "example.com")
|
||||
header("Date", ZonedDateTime.now().format(dateTimeFormatter))
|
||||
header(
|
||||
"Digest",
|
||||
"SHA-256=" + Base64Util.encode(MessageDigest.getInstance("SHA-256").digest("{}".toByteArray()))
|
||||
)
|
||||
}
|
||||
.asyncDispatch()
|
||||
.andExpect { status { isUnauthorized() } }
|
||||
@@ -74,7 +90,13 @@ class InboxTest {
|
||||
.post("/inbox") {
|
||||
content = "{}"
|
||||
contentType = MediaType.APPLICATION_JSON
|
||||
header("Signature", "")
|
||||
header("Signature", "a")
|
||||
header("Host", "example.com")
|
||||
header("Date", ZonedDateTime.now().format(dateTimeFormatter))
|
||||
header(
|
||||
"Digest",
|
||||
"SHA-256=" + Base64Util.encode(MessageDigest.getInstance("SHA-256").digest("{}".toByteArray()))
|
||||
)
|
||||
}
|
||||
.asyncDispatch()
|
||||
.andExpect { status { isAccepted() } }
|
||||
@@ -87,8 +109,15 @@ class InboxTest {
|
||||
.post("/users/hoge/inbox") {
|
||||
content = "{}"
|
||||
contentType = MediaType.APPLICATION_JSON
|
||||
header("Host", "example.com")
|
||||
header("Date", ZonedDateTime.now().format(dateTimeFormatter))
|
||||
header(
|
||||
"Digest",
|
||||
"SHA-256=" + Base64Util.encode(MessageDigest.getInstance("SHA-256").digest("{}".toByteArray()))
|
||||
)
|
||||
}
|
||||
.asyncDispatch()
|
||||
.andDo { print() }
|
||||
.andExpect { status { isUnauthorized() } }
|
||||
}
|
||||
|
||||
@@ -99,9 +128,16 @@ class InboxTest {
|
||||
.post("/users/hoge/inbox") {
|
||||
content = "{}"
|
||||
contentType = MediaType.APPLICATION_JSON
|
||||
header("Signature", "")
|
||||
header("Signature", "a")
|
||||
header("Host", "example.com")
|
||||
header("Date", ZonedDateTime.now().format(dateTimeFormatter))
|
||||
header(
|
||||
"Digest",
|
||||
"SHA-256=" + Base64Util.encode(MessageDigest.getInstance("SHA-256").digest("{}".toByteArray()))
|
||||
)
|
||||
}
|
||||
.asyncDispatch()
|
||||
.andDo { print() }
|
||||
.andExpect { status { isAccepted() } }
|
||||
}
|
||||
|
||||
|
||||
+12
-12
@@ -90,7 +90,7 @@ class InboxControllerImplTest {
|
||||
header("Signature", "a")
|
||||
header("Host", "example.com")
|
||||
header("Date", ZonedDateTime.now().format(dateTimeFormatter))
|
||||
header("Digest", digest)
|
||||
header("Digest", "SHA-256=" + digest)
|
||||
}.asyncDispatch().andExpect {
|
||||
status { isAccepted() }
|
||||
}
|
||||
@@ -110,7 +110,7 @@ class InboxControllerImplTest {
|
||||
header("Signature", "a")
|
||||
header("Host", "example.com")
|
||||
header("Date", ZonedDateTime.now().format(dateTimeFormatter))
|
||||
header("Digest", digest)
|
||||
header("Digest", "SHA-256=$digest")
|
||||
}.asyncDispatch().andExpect {
|
||||
status { isAccepted() }
|
||||
}
|
||||
@@ -135,7 +135,7 @@ class InboxControllerImplTest {
|
||||
header("Signature", "a")
|
||||
header("Host", "example.com")
|
||||
header("Date", ZonedDateTime.now().format(dateTimeFormatter))
|
||||
header("Digest", digest)
|
||||
header("Digest", "SHA-256=$digest")
|
||||
}.asyncDispatch().andExpect {
|
||||
status { isAccepted() }
|
||||
}
|
||||
@@ -165,7 +165,7 @@ class InboxControllerImplTest {
|
||||
header("Signature", "a")
|
||||
header("Host", "example.com")
|
||||
header("Date", ZonedDateTime.now().format(dateTimeFormatter))
|
||||
header("Digest", digest)
|
||||
header("Digest", "SHA-256=$digest")
|
||||
}.asyncDispatch().andExpect {
|
||||
status { isAccepted() }
|
||||
}
|
||||
@@ -185,7 +185,7 @@ class InboxControllerImplTest {
|
||||
header("Signature", "a")
|
||||
header("Host", "example.com")
|
||||
header("Date", ZonedDateTime.now().format(dateTimeFormatter))
|
||||
header("Digest", digest)
|
||||
header("Digest", "SHA-256=$digest")
|
||||
}.asyncDispatch().andExpect {
|
||||
status { isAccepted() }
|
||||
}
|
||||
@@ -210,7 +210,7 @@ class InboxControllerImplTest {
|
||||
header("Signature", "a")
|
||||
header("Host", "example.com")
|
||||
header("Date", ZonedDateTime.now().format(dateTimeFormatter))
|
||||
header("Digest", digest)
|
||||
header("Digest", "SHA-256=$digest")
|
||||
}.asyncDispatch().andExpect {
|
||||
status { isAccepted() }
|
||||
}
|
||||
@@ -427,7 +427,7 @@ class InboxControllerImplTest {
|
||||
header("Signature", "")
|
||||
header("Host", "example.com")
|
||||
header("Date", ZonedDateTime.now().format(dateTimeFormatter))
|
||||
header("Digest", digest)
|
||||
header("Digest", "SHA-256=$digest")
|
||||
}
|
||||
.asyncDispatch()
|
||||
.andExpect {
|
||||
@@ -470,7 +470,7 @@ class InboxControllerImplTest {
|
||||
header("Signature", "")
|
||||
header("Host", "example.com")
|
||||
header("Date", ZonedDateTime.now().format(dateTimeFormatter))
|
||||
header("Digest", digest)
|
||||
header("Digest", "SHA-256=$digest")
|
||||
}
|
||||
.asyncDispatch()
|
||||
.andExpect {
|
||||
@@ -493,7 +493,7 @@ class InboxControllerImplTest {
|
||||
contentType = MediaType.APPLICATION_JSON
|
||||
header("Host", "example.com")
|
||||
header("Date", ZonedDateTime.now().format(dateTimeFormatter))
|
||||
header("Digest", digest)
|
||||
header("Digest", "SHA-256=$digest")
|
||||
}
|
||||
.asyncDispatch()
|
||||
.andExpect {
|
||||
@@ -516,7 +516,7 @@ class InboxControllerImplTest {
|
||||
header("Signature", "")
|
||||
header("Host", "example.com")
|
||||
header("Date", ZonedDateTime.now().format(dateTimeFormatter))
|
||||
header("Digest", digest)
|
||||
header("Digest", "SHA-256=$digest")
|
||||
}
|
||||
.asyncDispatch()
|
||||
.andExpect {
|
||||
@@ -537,7 +537,7 @@ class InboxControllerImplTest {
|
||||
contentType = MediaType.APPLICATION_JSON
|
||||
header("Host", "example.com")
|
||||
header("Date", ZonedDateTime.now().format(dateTimeFormatter))
|
||||
header("Digest", digest)
|
||||
header("Digest", "SHA-256=$digest")
|
||||
}
|
||||
.asyncDispatch()
|
||||
.andExpect {
|
||||
@@ -560,7 +560,7 @@ class InboxControllerImplTest {
|
||||
header("Signature", "")
|
||||
header("Host", "example.com")
|
||||
header("Date", ZonedDateTime.now().format(dateTimeFormatter))
|
||||
header("Digest", digest)
|
||||
header("Digest", "SHA-256=$digest")
|
||||
}
|
||||
.asyncDispatch()
|
||||
.andExpect {
|
||||
|
||||
+1
-1
@@ -87,7 +87,7 @@ class HttpSignatureHeaderCheckerTest {
|
||||
val digest = Base64Util.encode(sha256.digest(requestBody.toByteArray()))
|
||||
|
||||
assertDoesNotThrow {
|
||||
httpSignatureHeaderChecker.checkDigest(requestBody.toByteArray(), digest)
|
||||
httpSignatureHeaderChecker.checkDigest(requestBody.toByteArray(), "SHA-256=" + digest)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user