Repository navigation
#10227: RelayState max length not respected (fix) #10231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,74 @@ | ||||||||
| package org.keycloak.broker.provider.util; | ||||||||
|
|
||||||||
| import org.junit.Test; | ||||||||
| import org.keycloak.authorization.identity.Identity; | ||||||||
|
|
||||||||
| import static org.junit.Assert.assertEquals; | ||||||||
| import static org.junit.Assert.assertTrue; | ||||||||
|
|
||||||||
| public class IdentityBrokerStateTest { | ||||||||
| private static final int RELAY_STATE_MAX_LENGTH = 80; | ||||||||
|
|
||||||||
| @Test | ||||||||
| public void decoded_withinBounds_preservesClientId() { | ||||||||
| // Arrange | ||||||||
| // The length of the concatenated strings is below 80 characters, the RelayState limit as per the SAML specification. | ||||||||
| String state = "gNrGamIDGKpKSI9yOrcFzYTKoFGH779_WNCacAelkhk"; | ||||||||
| String tabId = "vpISZLVDAc0"; | ||||||||
| String clientId = "foo"; | ||||||||
|
|
||||||||
| // Act | ||||||||
| IdentityBrokerState ibs = IdentityBrokerState.decoded(state, clientId, tabId); | ||||||||
|
|
||||||||
| // Assert | ||||||||
| assertEquals(clientId, ibs.getClientId()); | ||||||||
| assertTrue(ibs.getEncoded().length() < RELAY_STATE_MAX_LENGTH); | ||||||||
| } | ||||||||
|
|
||||||||
| @Test | ||||||||
| public void decoded_outOfBounds_compressesClientId() { | ||||||||
| // Arrange | ||||||||
| // The length of the concatenated strings is above 80 characters, the RelayState limit as per the SAML specification. | ||||||||
| String state = "gNrGamIDGKpKSI9yOrcFzYTKoFGH779_WNCacAelkhk"; | ||||||||
| String tabId = "vpISZLVDAc0"; | ||||||||
| String clientId = "https://login.blablabla.com/auth/realms/broker"; | ||||||||
|
|
||||||||
| // Act | ||||||||
| IdentityBrokerState ibs = IdentityBrokerState.decoded(state, clientId, tabId); | ||||||||
|
|
||||||||
| // Assert | ||||||||
| assertTrue(ibs.getClientId().length() < clientId.length()); | ||||||||
| assertTrue(ibs.getEncoded().length() < RELAY_STATE_MAX_LENGTH); | ||||||||
| } | ||||||||
|
|
||||||||
| @Test | ||||||||
| public void encoded_compressedClientId_decompressesClientId() { | ||||||||
| // Arrange | ||||||||
| String state = "gNrGamIDGKpKSI9yOrcFzYTKoFGH779_WNCacAelkhk"; | ||||||||
| String tabId = "vpISZLVDAc0"; | ||||||||
| String clientId = "https://login.blablabla.com/auth/realms/broker"; | ||||||||
| String encodedState = IdentityBrokerState.decoded(state, clientId, tabId).getEncoded(); | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As the "arrange" part is calling IdentityBrokerState, thereby depending on the tested class. There is also no test to verify the output of encodedState.
Suggested change
|
||||||||
|
|
||||||||
| // Act | ||||||||
| IdentityBrokerState ibs = IdentityBrokerState.encoded(encodedState); | ||||||||
|
|
||||||||
| // Assert | ||||||||
| assertEquals(clientId, ibs.getClientId()); | ||||||||
| } | ||||||||
|
|
||||||||
| @Test | ||||||||
| public void encoded_uncompressedClientId_preservesClientId() { | ||||||||
| // Arrange | ||||||||
| String state = "gNrGamIDGKpKSI9yOrcFzYTKoFGH779_WNCacAelkhk"; | ||||||||
| String tabId = "vpISZLVDAc0"; | ||||||||
| String clientId = "foo"; | ||||||||
| String encodedState = IdentityBrokerState.decoded(state, clientId, tabId).getEncoded(); | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above.
Suggested change
|
||||||||
|
|
||||||||
| // Act | ||||||||
| IdentityBrokerState ibs = IdentityBrokerState.encoded(encodedState); | ||||||||
|
|
||||||||
| // Assert | ||||||||
| assertEquals(clientId, ibs.getClientId()); | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused import, please remove the unused import.