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