-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ANCHOR-618] Fix auth header not configurable for callback API and pl…
…atform API (#1302) ### Description [ANCHOR-618] Fix auth header not configurable for callback API and platform API ### Context Bug fixes. ### Testing - `./gradlew test` ### Documentation N/A ### Known limitations N/A [ANCHOR-618]: https://stellarorg.atlassian.net/browse/ANCHOR-618?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
- Loading branch information
Showing
15 changed files
with
179 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
core/src/test/kotlin/org/stellar/anchor/filter/AbstractJwtFilterTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package org.stellar.anchor.filter | ||
|
||
import io.mockk.Called | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import io.mockk.verify | ||
import javax.servlet.FilterChain | ||
import javax.servlet.ServletResponse | ||
import javax.servlet.http.HttpServletRequest | ||
import javax.servlet.http.HttpServletResponse | ||
import org.apache.http.HttpStatus | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.params.ParameterizedTest | ||
import org.junit.jupiter.params.provider.ValueSource | ||
import org.stellar.anchor.auth.JwtService | ||
import org.stellar.anchor.config.CustodySecretConfig | ||
import org.stellar.anchor.config.SecretConfig | ||
|
||
class AbstractJwtFilterTest { | ||
private lateinit var jwtService: JwtService | ||
|
||
@BeforeEach | ||
fun setup() { | ||
val secretConfig = mockk<SecretConfig>(relaxed = true) | ||
val custodySecretConfig = mockk<CustodySecretConfig>(relaxed = true) | ||
every { secretConfig.sep10JwtSecretKey } returns "secret" | ||
this.jwtService = JwtService(secretConfig, custodySecretConfig) | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(strings = ["GET", "PUT", "POST", "DELETE"]) | ||
fun `make sure FORBIDDEN is returned when the filter requires header names other than Authorization`( | ||
method: String | ||
) { | ||
val request = mockk<HttpServletRequest>(relaxed = true) | ||
val response = mockk<HttpServletResponse>(relaxed = true) | ||
val filterChain = mockk<FilterChain>(relaxed = true) | ||
|
||
every { request.method } returns method | ||
every { request.getHeader("Authorization") } returns "Authorization_Header_Value" | ||
val filter = | ||
object : AbstractJwtFilter(jwtService, "Authorization-custom") { | ||
@Throws(Exception::class) | ||
override fun check( | ||
jwtCipher: String?, | ||
request: HttpServletRequest, | ||
servletResponse: ServletResponse?, | ||
) {} | ||
} | ||
|
||
filter.doFilter(request, response, filterChain) | ||
verify(exactly = 1) { | ||
response.setStatus(HttpStatus.SC_FORBIDDEN) | ||
response.contentType = Sep10JwtFilter.APPLICATION_JSON_VALUE | ||
} | ||
verify { filterChain wasNot Called } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.