Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
strehle committed Jul 6, 2023
1 parent dfa37c3 commit 119c206
Showing 1 changed file with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.cloudfoundry.identity.uaa.util;

import org.cloudfoundry.identity.uaa.oauth.token.ClaimConstants;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.OAuth2Request;

import java.util.HashMap;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

class UaaSecurityContextUtilsTest {

private OAuth2Request auth2Request;

@BeforeEach
void setUp() {
OAuth2Authentication authentication = mock(OAuth2Authentication.class);
SecurityContextHolder.getContext().setAuthentication(authentication);
auth2Request = mock(OAuth2Request.class);
when(auth2Request.getExtensions()).thenReturn(new HashMap<>());
when(authentication.getOAuth2Request()).thenReturn(auth2Request);
}

@Test
void getNoClientAuthenticationMethod() {
assertNull(UaaSecurityContextUtils.getClientAuthenticationMethod());
}

@Test
void getNullClientAuthenticationMethod() {
SecurityContextHolder.getContext().setAuthentication(null);
assertNull(UaaSecurityContextUtils.getClientAuthenticationMethod());
}

@Test
void getClientAuthenticationMethod() {
when(auth2Request.getExtensions()).thenReturn(Map.of(ClaimConstants.CLIENT_AUTH_METHOD, "none"));
assertEquals("none", UaaSecurityContextUtils.getClientAuthenticationMethod());
}
}

0 comments on commit 119c206

Please sign in to comment.