-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(jans-auth-server): added device secret generation
- Loading branch information
Showing
9 changed files
with
179 additions
and
21 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
95 changes: 95 additions & 0 deletions
95
...erver/server/src/test/java/io/jans/as/server/authorize/ws/rs/AuthzRequestServiceTest.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 |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package io.jans.as.server.authorize.ws.rs; | ||
|
||
import io.jans.as.common.model.session.SessionId; | ||
import io.jans.as.common.util.RedirectUri; | ||
import io.jans.as.model.config.WebKeysConfiguration; | ||
import io.jans.as.model.configuration.AppConfiguration; | ||
import io.jans.as.model.crypto.AbstractCryptoProvider; | ||
import io.jans.as.model.error.ErrorResponseFactory; | ||
import io.jans.as.server.model.authorize.ScopeChecker; | ||
import io.jans.as.server.par.ws.rs.ParService; | ||
import io.jans.as.server.service.ClientService; | ||
import io.jans.as.server.service.RedirectUriResponse; | ||
import io.jans.as.server.service.RedirectionUriService; | ||
import io.jans.as.server.service.RequestParameterService; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import org.apache.commons.lang.StringUtils; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.testng.MockitoTestNGListener; | ||
import org.slf4j.Logger; | ||
import org.testng.annotations.Listeners; | ||
import org.testng.annotations.Test; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.testng.Assert.assertEquals; | ||
import static org.testng.Assert.assertTrue; | ||
|
||
/** | ||
* @author Yuriy Z | ||
*/ | ||
@Listeners(MockitoTestNGListener.class) | ||
public class AuthzRequestServiceTest { | ||
|
||
@InjectMocks | ||
private AuthzRequestService authzRequestService; | ||
|
||
@Mock | ||
private Logger log; | ||
|
||
@Mock | ||
private AppConfiguration appConfiguration; | ||
|
||
@Mock | ||
private ErrorResponseFactory errorResponseFactory; | ||
|
||
@Mock | ||
private AuthorizeRestWebServiceValidator authorizeRestWebServiceValidator; | ||
|
||
@Mock | ||
private ParService parService; | ||
|
||
@Mock | ||
private AbstractCryptoProvider cryptoProvider; | ||
|
||
@Mock | ||
private ScopeChecker scopeChecker; | ||
|
||
@Mock | ||
private RequestParameterService requestParameterService; | ||
|
||
@Mock | ||
private WebKeysConfiguration webKeysConfiguration; | ||
|
||
@Mock | ||
private ClientService clientService; | ||
|
||
@Mock | ||
private RedirectionUriService redirectionUriService; | ||
|
||
@Test | ||
public void addDeviceSecretToSession_withoutDeviceSsoScope_shouldNotGenerateDeviceSecret() { | ||
AuthzRequest authzRequest = new AuthzRequest(); | ||
authzRequest.setScope("openid"); | ||
authzRequest.setRedirectUriResponse(new RedirectUriResponse(mock(RedirectUri.class), "", mock(HttpServletRequest.class), mock(ErrorResponseFactory.class))); | ||
|
||
SessionId sessionId = new SessionId(); | ||
|
||
authzRequestService.addDeviceSecretToSession(authzRequest, sessionId); | ||
assertTrue(sessionId.getDeviceSecrets().isEmpty()); | ||
} | ||
|
||
@Test | ||
public void addDeviceSecretToSession_withDeviceSsoScope_shouldGenerateDeviceSecret() { | ||
AuthzRequest authzRequest = new AuthzRequest(); | ||
authzRequest.setRedirectUriResponse(new RedirectUriResponse(mock(RedirectUri.class), "", mock(HttpServletRequest.class), mock(ErrorResponseFactory.class))); | ||
authzRequest.setScope("openid device_sso"); | ||
|
||
SessionId sessionId = new SessionId(); | ||
|
||
assertTrue(sessionId.getDeviceSecrets().isEmpty()); | ||
authzRequestService.addDeviceSecretToSession(authzRequest, sessionId); | ||
assertEquals(1, sessionId.getDeviceSecrets().size()); | ||
assertTrue(StringUtils.isNotBlank(sessionId.getDeviceSecrets().get(0))); | ||
} | ||
} |
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