diff --git a/acrarium/src/main/kotlin/com/faendir/acra/rest/RestReportInterface.kt b/acrarium/src/main/kotlin/com/faendir/acra/rest/RestReportInterface.kt index 26bcd01e..f3765cca 100644 --- a/acrarium/src/main/kotlin/com/faendir/acra/rest/RestReportInterface.kt +++ b/acrarium/src/main/kotlin/com/faendir/acra/rest/RestReportInterface.kt @@ -60,31 +60,7 @@ class RestReportInterface(private val dataService: DataService) { return ResponseEntity.ok().build() } - @PreAuthorize("hasRole(T(com.faendir.acra.model.User\$Role).USER)") - @RequestMapping(value = [EXPORT_PATH], produces = [MediaType.APPLICATION_JSON_VALUE], method = [RequestMethod.GET]) - fun export(@RequestParam(name = PARAM_APP) appId: String, @RequestParam(name = PARAM_ID, required = false) id: String?, - @RequestParam(name = PARAM_MAIL, required = false) mail: String?): ResponseEntity { - val app = dataService.findApp(appId) ?: return ResponseEntity.notFound().build() - var where: BooleanExpression? = null - var name = "" - if (mail != null && mail.isNotEmpty()) { - where = QReport.report.userEmail.eq(mail) - name += "_$mail" - } - if (id != null && id.isNotEmpty()) { - where = QReport.report.installationId.eq(id).and(where) - name += "_$id" - } - if (name.isEmpty()) { - return ResponseEntity.badRequest().build() - } - val headers = HttpHeaders() - headers.setContentDispositionFormData("attachment", "reports$name.json") - return ResponseEntity.ok().headers(headers).body(dataService.getFromReports(app, where, QReport.report.content).joinToString(", ", "[", "]")) - } - companion object { - const val EXPORT_PATH = "export" const val PARAM_APP = "app_id" const val PARAM_ID = "id" const val PARAM_MAIL = "mail" diff --git a/acrarium/src/test/kotlin/com/faendir/acra/rest/RestReportInterfaceTest.kt b/acrarium/src/test/kotlin/com/faendir/acra/rest/RestReportInterfaceTest.kt index 14387ca6..07322ec2 100644 --- a/acrarium/src/test/kotlin/com/faendir/acra/rest/RestReportInterfaceTest.kt +++ b/acrarium/src/test/kotlin/com/faendir/acra/rest/RestReportInterfaceTest.kt @@ -17,23 +17,16 @@ package com.faendir.acra.rest import com.faendir.acra.model.App import com.faendir.acra.rest.RestReportInterface.Companion.ATTACHMENT -import com.faendir.acra.rest.RestReportInterface.Companion.EXPORT_PATH -import com.faendir.acra.rest.RestReportInterface.Companion.PARAM_APP -import com.faendir.acra.rest.RestReportInterface.Companion.PARAM_ID -import com.faendir.acra.rest.RestReportInterface.Companion.PARAM_MAIL import com.faendir.acra.rest.RestReportInterface.Companion.REPORT import com.faendir.acra.rest.RestReportInterface.Companion.REPORT_PATH import com.faendir.acra.service.DataService import com.faendir.acra.service.UserService import com.ninjasquad.springmockk.MockkBean -import com.querydsl.core.types.Expression import io.mockk.every import io.mockk.just import io.mockk.mockk import io.mockk.runs import io.mockk.verify -import org.json.JSONArray -import org.json.JSONObject import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.springframework.beans.factory.annotation.Autowired @@ -47,13 +40,9 @@ import org.springframework.mock.web.MockMultipartFile import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity import org.springframework.security.test.context.support.WithMockUser import org.springframework.test.web.servlet.MockMvc -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status -import strikt.api.expectThat -import strikt.assertions.isA -import strikt.assertions.isEqualTo /** * @author lukas @@ -79,7 +68,6 @@ class RestReportInterfaceTest { fun setUp() { val app = mockk() every { dataService.findApp(TEST_STRING) } returns app - every { dataService.getFromReports(any(), any(), any>()) } returns listOf("{\"name\":\"a\"}", "{\"name\":\"b\"}") every { dataService.createNewReport(any(), any(), any()) } just runs } @@ -97,35 +85,6 @@ class RestReportInterfaceTest { verify(exactly = 1) { dataService.createNewReport(any(), any(), any()) } } - @Test - fun exportWithId() { - mvc.perform(get("/$EXPORT_PATH").param(PARAM_APP, TEST_STRING).param(PARAM_ID, TEST_STRING)).andExpect(status().isOk).andExpect { - val array = JSONArray(it.response.contentAsString) - expectThat(array) { - get(JSONArray::length).isEqualTo(2) - get { get(0) }.isA() - } - } - } - - @Test - fun exportWithMail() { - mvc.perform(get("/$EXPORT_PATH").param(PARAM_APP, TEST_STRING).param(PARAM_MAIL, TEST_STRING)).andExpect(status().isOk).andExpect { - expectThat(JSONArray(it.response.contentAsString)) { - get(JSONArray::length).isEqualTo(2) - get { get(0) }.isA() - } - } - } - - @Test - fun exportInvalid() { - mvc.perform(get("/$EXPORT_PATH").param(PARAM_APP, TEST_STRING)).andExpect(status().is4xxClientError) - mvc.perform(get("/$EXPORT_PATH").param(PARAM_ID, TEST_STRING)).andExpect(status().is4xxClientError) - mvc.perform(get("/$EXPORT_PATH").param(PARAM_MAIL, TEST_STRING)).andExpect(status().is4xxClientError) - mvc.perform(get("/$EXPORT_PATH")).andExpect(status().is4xxClientError) - } - companion object { private const val TEST_STRING = "TEST" }