-
-
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
12 changed files
with
127 additions
and
23 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
54 changes: 54 additions & 0 deletions
54
...st/java/com/michibaum/authentication_service/authentication/AuthenticationControllerUT.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,54 @@ | ||
package com.michibaum.authentication_service.authentication | ||
|
||
import com.michibaum.authentication_service.config.UsermanagementClient | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Assertions.assertNotNull | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import org.mockito.junit.jupiter.MockitoExtension | ||
import org.springframework.http.HttpHeaders | ||
import org.springframework.http.HttpStatus | ||
|
||
@ExtendWith(MockitoExtension::class) | ||
class AuthenticationControllerUT { | ||
|
||
private val authenticationService: AuthenticationService = mockk() | ||
private val usermanagementClient: UsermanagementClient = mockk() | ||
|
||
private val authenticationController: AuthenticationController = AuthenticationController(authenticationService, usermanagementClient) | ||
|
||
@Test | ||
fun `Authentication successful`(){ | ||
// GIVEN | ||
every { usermanagementClient.checkPassword(any()) } returns true | ||
|
||
val jws = "1234qwer" | ||
val authenticationDto = AuthenticationDto("UName", "Passwört") | ||
every { authenticationService.generateJWS(authenticationDto.username) } returns jws | ||
|
||
// WHEN | ||
val result = authenticationController.authenticate(authenticationDto) | ||
|
||
// THEN | ||
assertEquals(HttpStatus.OK, result.statusCode) | ||
assertNotNull(result.headers) | ||
assertEquals(jws, result.headers[HttpHeaders.AUTHORIZATION]?.get(0) ?: "") | ||
} | ||
|
||
@Test | ||
fun `Bad credentials`(){ | ||
// GIVEN | ||
every { usermanagementClient.checkPassword(any()) } returns false | ||
val authenticationDto = AuthenticationDto("UName", "Passwört") | ||
|
||
// WHEN | ||
val result = authenticationController.authenticate(authenticationDto) | ||
|
||
// THEN | ||
assertEquals(HttpStatus.UNAUTHORIZED, result.statusCode) | ||
assertEquals(0, result.headers.size) | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export interface Authentication { | ||
username: string; | ||
password: string; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const environment = { | ||
url: 'http:michibaum.ch' | ||
}; |
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,3 @@ | ||
export const environment = { | ||
url: 'http:michibaum.ch' | ||
}; |