-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
118 additions
and
53 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
19 changes: 19 additions & 0 deletions
19
gateway-service/src/main/kotlin/com/michibaum/gatewayservice/FilterConfig.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,19 @@ | ||
package com.michibaum.gatewayservice | ||
|
||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
|
||
@Configuration | ||
class FilterConfig { | ||
|
||
@Bean | ||
fun authenticationFilter(): AuthenticationFilter { | ||
return AuthenticationFilter() | ||
} | ||
|
||
@Bean | ||
fun authorizationPreFilter(): AuthorizationPreFilter { | ||
return AuthorizationPreFilter() | ||
} | ||
|
||
} |
17 changes: 0 additions & 17 deletions
17
gateway-service/src/main/kotlin/com/michibaum/gatewayservice/RequestLog.kt
This file was deleted.
Oops, something went wrong.
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
70 changes: 70 additions & 0 deletions
70
gateway-service/src/test/kotlin/com/michibaum/gatewayservice/AuthenticationFilterUT.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,70 @@ | ||
package com.michibaum.gatewayservice | ||
|
||
import com.michibaum.authentication_library.AuthenticationClient | ||
import io.mockk.* | ||
import org.junit.jupiter.api.Assertions.* | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import org.mockito.junit.jupiter.MockitoExtension | ||
import org.springframework.cloud.gateway.filter.GatewayFilterChain | ||
import org.springframework.http.HttpStatus | ||
import org.springframework.http.server.reactive.ServerHttpResponse | ||
import org.springframework.web.server.ServerWebExchange | ||
import reactor.core.publisher.Mono | ||
|
||
@ExtendWith(MockitoExtension::class) | ||
class AuthenticationFilterUT{ | ||
|
||
private val authenticationClient: AuthenticationClient = mockk() | ||
|
||
@BeforeEach | ||
|
||
@Test | ||
fun `exchange null returns error`(){ | ||
// GIVEN | ||
val authenticationFilter = AuthenticationFilter() | ||
authenticationFilter.authenticationClient = this.authenticationClient | ||
|
||
val gatewayFilterChain: GatewayFilterChain = mockk() | ||
|
||
// WHEN | ||
val result = authenticationFilter.filter(null, gatewayFilterChain) | ||
|
||
//THEN | ||
assertThrows( | ||
Exception::class.java, | ||
result::block, | ||
"ServerWebExchange is null" | ||
) | ||
} | ||
|
||
@Test | ||
fun `authorization header does not exist`(){ | ||
// GIVEN | ||
val authenticationFilter = AuthenticationFilter() | ||
authenticationFilter.authenticationClient = this.authenticationClient | ||
|
||
val gatewayFilterChain: GatewayFilterChain = mockk() | ||
val httpResponse: ServerHttpResponse = mockk { | ||
every { setStatusCode(any()) } returns true | ||
every { setComplete() } returns Mono.empty() | ||
} | ||
val serverWebExchange: ServerWebExchange = mockk{ | ||
every { response } returns httpResponse | ||
every { request } returns mockk { | ||
every { headers } returns mockk { | ||
every { headers["Authorization"] } returns null | ||
} | ||
} | ||
} | ||
|
||
// WHEN | ||
authenticationFilter.filter(serverWebExchange, gatewayFilterChain) | ||
|
||
//THEN | ||
verify (exactly = 1) { httpResponse.setStatusCode(HttpStatus.FORBIDDEN) } | ||
|
||
} | ||
|
||
} |
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