-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Token based authentication to connect to Cluster Api Co-authored-by: muralibasani <muralidahr.basani@aiven.io>
- Loading branch information
1 parent
92ee5ed
commit 22b9783
Showing
6 changed files
with
115 additions
and
62 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
25 changes: 23 additions & 2 deletions
25
src/test/java/io/aiven/klaw/service/ServerConfigServiceTest.java
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 |
---|---|---|
@@ -1,35 +1,56 @@ | ||
package io.aiven.klaw.service; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.when; | ||
|
||
import io.aiven.klaw.model.ServerConfigProperties; | ||
import java.util.List; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.springframework.context.annotation.AnnotationConfigApplicationContext; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.core.context.SecurityContext; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.security.core.userdetails.UserDetails; | ||
import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
|
||
@ExtendWith(SpringExtension.class) | ||
public class ServerConfigServiceTest { | ||
|
||
@Mock private CommonUtilsService commonUtilsService; | ||
ServerConfigService serverConfigService; | ||
|
||
@Mock private UserDetails userDetails; | ||
|
||
private Environment env; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); | ||
this.env = context.getEnvironment(); | ||
loginMock(); | ||
|
||
serverConfigService = new ServerConfigService(env); | ||
serverConfigService = new ServerConfigService(env, commonUtilsService); | ||
} | ||
|
||
@Test | ||
public void getAllProps() { | ||
when(commonUtilsService.isNotAuthorizedUser(any(), any())).thenReturn(false); | ||
serverConfigService.getAllProperties(); | ||
List<ServerConfigProperties> list = serverConfigService.getAllProps(); | ||
assertThat(list).isNotEmpty(); | ||
assertThat(list).isEmpty(); // filtering for spring. and klaw. | ||
} | ||
|
||
private void loginMock() { | ||
Authentication authentication = Mockito.mock(Authentication.class); | ||
SecurityContext securityContext = Mockito.mock(SecurityContext.class); | ||
when(securityContext.getAuthentication()).thenReturn(authentication); | ||
when(authentication.getPrincipal()).thenReturn(userDetails); | ||
SecurityContextHolder.setContext(securityContext); | ||
} | ||
} |