From d56ec95029b1f1c8af027ce3ee9ad1731f631056 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Wed, 29 Nov 2023 15:17:52 +0900 Subject: [PATCH] =?UTF-8?q?test:=20=E3=83=A1=E3=83=87=E3=82=A3=E3=82=A2?= =?UTF-8?q?=E3=82=A2=E3=83=83=E3=83=97=E3=83=AD=E3=83=BC=E3=83=89=E3=81=AE?= =?UTF-8?q?=E3=82=B9=E3=82=B3=E3=83=BC=E3=83=97=E3=81=AE=E3=83=86=E3=82=B9?= =?UTF-8?q?=E3=83=88=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/intTest/kotlin/mastodon/MediaTest.kt | 42 ++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/intTest/kotlin/mastodon/MediaTest.kt b/src/intTest/kotlin/mastodon/MediaTest.kt index 1a170c81..d3e54e88 100644 --- a/src/intTest/kotlin/mastodon/MediaTest.kt +++ b/src/intTest/kotlin/mastodon/MediaTest.kt @@ -68,4 +68,46 @@ class MediaTest { .asyncDispatch() .andExpect { status { isOk() } } } + + @Test + fun write_mediaスコープでメディアをアップロードできる() = runTest { + whenever(mediaDataStore.save(any())).doReturn(SuccessSavedMedia("", "", "")) + + mockMvc + .multipart("/api/v1/media") { + + file( + MockMultipartFile( + "file", + "400x400.png", + "image/png", + String.javaClass.classLoader.getResourceAsStream("media/400x400.png") + ) + ) + with(jwt().jwt { it.claim("uid", "1") }.authorities(SimpleGrantedAuthority("SCOPE_write:media"))) + } + .asyncDispatch() + .andExpect { status { isOk() } } + } + + @Test + fun 権限がないと403() = runTest { + whenever(mediaDataStore.save(any())).doReturn(SuccessSavedMedia("", "", "")) + + mockMvc + .multipart("/api/v1/media") { + + file( + MockMultipartFile( + "file", + "400x400.png", + "image/png", + String.javaClass.classLoader.getResourceAsStream("media/400x400.png") + ) + ) + with(jwt().jwt { it.claim("uid", "1") }.authorities(SimpleGrantedAuthority("SCOPE_read"))) + } + .andExpect { status { isForbidden() } } + } + }