Skip to content

Instantly share code, notes, and snippets.

@ltsallas
Created October 8, 2023 21:27
Show Gist options
  • Save ltsallas/9903343b6b7a90013cdd155bfcd670ce to your computer and use it in GitHub Desktop.
Save ltsallas/9903343b6b7a90013cdd155bfcd670ce to your computer and use it in GitHub Desktop.
package com.example.demo
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RestController
import java.util.*
@RestController
class DemoController {
@GetMapping("test-uuid/{id}")
fun getByUUID(@PathVariable id: UUID) {
}
}
package com.example.demo
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.web.servlet.MockMvc
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
import java.util.*
@SpringBootTest
@AutoConfigureMockMvc
class DemoControllerTest(@Autowired val mockMvc: MockMvc) {
//success it is a 200
@Test
fun `testGetByUUID randomUUID`() {
val id: UUID = UUID.randomUUID()
mockMvc.perform(get("/test-uuid/$id"))
.andExpect(status().isOk())
}
//success it is a 400
@Test
fun `testGetByUUID integer`() {
mockMvc.perform(get("/test-uuid/1"))
.andExpect(status().is4xxClientError())
}
//success it is a 400
@Test
fun `testGetByUUID u002f`() {
mockMvc.perform(get("/test-uuid/\u002F"))
.andExpect(status().is4xxClientError())
}
//fails with 500 error(MissingPathVariableException). Should be a 400
@Test
fun `testGetByUUID u001F`() {
mockMvc.perform(get("/test-uuid/\u001F"))
.andExpect(status().is4xxClientError())
}
//fails with 500 error(MissingPathVariableException). Should be again a 400
@Test
fun `testGetByUUID 000D`() {
mockMvc.perform(get("/test-uuid/\u000D"))
.andExpect(status().is4xxClientError())
}
}
@quaff
Copy link

quaff commented Oct 25, 2023

I'm curious why \u002F would behavior differently to \u001F, could you explain? @ltsallas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment