Skip to content

Instantly share code, notes, and snippets.

View with-heart's full-sized avatar
❤️‍🔥
growing love

with-heart with-heart

❤️‍🔥
growing love
View GitHub Profile
@with-heart
with-heart / SketchSystems.spec
Last active March 19, 2019 14:22
Traffic Light*
Traffic Light*
Green*
timer -> Yellow
Yellow
timer -> Red
Red
timer -> Green
@with-heart
with-heart / SketchSystems.spec
Last active March 19, 2019 13:14
Traffic Light*
Traffic Light*
Green*
timer -> Yellow
Yellow
timer -> Red
Red
timer -> Green

Keybase proof

I hereby claim:

To claim this, I am signing this object:

override fun run(): Any? {
val ctx = RequestContext.getCurrentContext()
val params = ctx.requestQueryParams
val encrypted = params["encryptedValue"]!![0]
val decrypted = encrypted.reversed()
params["encryptedValue"] = listOf(decrypted)
return null
}
@Test
fun `should replace encrypted string in query param with decrypted value`() {
val encrypted = "ABCDEFG123456"
val decrypted = encrypted.reversed()
val ctx = RequestContext.getCurrentContext()
ctx.requestQueryParams = mutableMapOf(
"encryptedValue" to listOf(encrypted)
)
filter.run()
override fun shouldFilter(): Boolean {
val ctx = RequestContext.getCurrentContext()
val params = ctx.requestQueryParams ?: return false
val encrypted = params["encryptedValue"] ?: return false
return encryptedStringRegex.matches(encrypted[0])
}
@Test
fun `should filter if encryptedValue param containing encrypted string`() {
val encrypted = "ABCDEFG123456"
val ctx = RequestContext.getCurrentContext()
ctx.requestQueryParams = mutableMapOf(
"encryptedValue" to listOf(encrypted)
)
assertEquals(true, filter.shouldFilter())
@Component
class QueryParamsDecryptionFilter : ZuulFilter() {
private val encryptedStringRegex =
Regex("(?=.*[A-Z]+)(?=.*\\d+)([A-Z0-9]){12,}")
override fun run(): Any? {
return null
}
override fun shouldFilter(): Boolean {
class QueryParamsDecryptionFilterTest {
private val filter = QueryParamsDecryptionFilter()
private val request = MockHttpServletRequest()
@Before
fun init() {
val ctx = RequestContext.getCurrentContext()
ctx.clear()
ctx.request = request
}
override fun run(): Any? {
val ctx = RequestContext.getCurrentContext()
val uri = ctx.request.requestURI
val encrypted = encryptedStringRegex.find(uri)!!.value
val decrypted = encrypted.reversed()
val newUri = encryptedStringRegex.replace(uri, decrypted)
val newRequest = object : HttpServletRequestWrapper(ctx.request) {
override fun getRequestURI() = newUri