Do not impose assumptions on ID format

Closes: #19814
This commit is contained in:
Hynek Mlnarik 2023-03-15 08:47:05 +01:00 committed by Hynek Mlnařík
parent 80ba42a0b4
commit d7d50634b3
9 changed files with 35 additions and 21 deletions

View file

@ -922,8 +922,9 @@ public class PartialImportTest extends AbstractAuthTest {
piRep.setRoles(roles);
Assert.assertEquals("default role should have been overwritten", 1, doImport().getOverwritten());
Assert.assertNotEquals("when overwriting, the ID of the role changes",
testRealmResource().toRepresentation().getDefaultRole().getId(), oldDefaultRole.getId());
// The following check is not valid anymore since file store does have the same ID
// Assert.assertNotEquals("when overwriting, the ID of the role changes",
// testRealmResource().toRepresentation().getDefaultRole().getId(), oldDefaultRole.getId());
}
}

View file

@ -627,9 +627,6 @@ public class RealmTest extends AbstractAdminTest {
}
public static void assertRealm(RealmRepresentation realm, RealmRepresentation storedRealm) {
if (realm.getId() != null) {
assertEquals(realm.getId(), storedRealm.getId());
}
if (realm.getRealm() != null) {
assertEquals(realm.getRealm(), storedRealm.getRealm());
}

View file

@ -1502,7 +1502,8 @@ public abstract class AbstractClientPoliciesTest extends AbstractKeycloakTest {
AccessToken token = oauth.verifyToken(res.getAccessToken());
String userId = findUserByUsername(adminClient.realm(REALM_NAME), userName).getId();
assertEquals(userId, token.getSubject());
Assert.assertNotEquals(userName, token.getSubject());
// The following check is not valid anymore since file store does have the same ID, and is redundant due to the previous line
// Assert.assertNotEquals(userName, token.getSubject());
assertEquals(sessionId, token.getSessionState());
assertEquals(clientId, token.getIssuedFor());

View file

@ -81,7 +81,8 @@ public class MultipleRealmsTest extends AbstractTestRealmKeycloakTest {
r1user1Atomic.set(r1user1);
Assert.assertEquals(r1user1.getUsername(), r2user1.getUsername());
Assert.assertNotEquals(r1user1.getId(), r2user1.getId());
// The following check is not valid anymore since file store does have the same ID, and is redundant due to the previous line
// Assert.assertNotEquals(r1user1.getId(), r2user1.getId());
// Test password
r1user1.credentialManager().updateCredential(UserCredentialModel.password("pass1"));

View file

@ -221,7 +221,8 @@ public class AccessTokenTest extends AbstractKeycloakTest {
AccessToken token = oauth.verifyToken(response.getAccessToken());
assertEquals(findUserByUsername(adminClient.realm("test"), "test-user@localhost").getId(), token.getSubject());
assertNotEquals("test-user@localhost", token.getSubject());
// The following check is not valid anymore since file store does have the same ID, and is redundant due to the previous line
// assertNotEquals("test-user@localhost", token.getSubject());
assertEquals(sessionId, token.getSessionState());
@ -1389,7 +1390,8 @@ public class AccessTokenTest extends AbstractKeycloakTest {
AccessToken token = oauth.verifyToken(response.getAccessToken());
assertEquals(findUserByUsername(adminClient.realm("test"), "test-user@localhost").getId(), token.getSubject());
assertNotEquals("test-user@localhost", token.getSubject());
// The following check is not valid anymore since file store does have the same ID, and is redundant due to the previous line
// assertNotEquals("test-user@localhost", token.getSubject());
assertEquals(sessionId, token.getSessionState());

View file

@ -445,7 +445,8 @@ public class OAuthProofKeyForCodeExchangeTest extends AbstractKeycloakTest {
AccessToken token = oauth.verifyToken(response.getAccessToken());
assertEquals(findUserByUsername(adminClient.realm("test"), "test-user@localhost").getId(), token.getSubject());
Assert.assertNotEquals("test-user@localhost", token.getSubject());
// The following check is not valid anymore since file store does have the same ID, and is redundant due to the previous line
// Assert.assertNotEquals("test-user@localhost", token.getSubject());
assertEquals(sessionId, token.getSessionState());
assertEquals(2, token.getRealmAccess().getRoles().size());
assertTrue(token.getRealmAccess().isUserInRole("user"));
@ -492,7 +493,8 @@ public class OAuthProofKeyForCodeExchangeTest extends AbstractKeycloakTest {
assertEquals("Bearer", refreshResponse.getTokenType());
assertEquals(findUserByUsername(adminClient.realm("test"), "test-user@localhost").getId(), refreshedToken.getSubject());
Assert.assertNotEquals("test-user@localhost", refreshedToken.getSubject());
// The following check is not valid anymore since file store does have the same ID, and is redundant due to the previous line
// Assert.assertNotEquals("test-user@localhost", refreshedToken.getSubject());
assertEquals(2, refreshedToken.getRealmAccess().getRoles().size());
Assert.assertTrue(refreshedToken.getRealmAccess().isUserInRole("user"));

View file

@ -264,7 +264,8 @@ public class RefreshTokenTest extends AbstractKeycloakTest {
assertEquals("Bearer", response.getTokenType());
assertEquals(findUserByUsername(adminClient.realm("test"), "test-user@localhost").getId(), refreshedToken.getSubject());
Assert.assertNotEquals("test-user@localhost", refreshedToken.getSubject());
// The following check is not valid anymore since file store does have the same ID, and is redundant due to the previous line
// Assert.assertNotEquals("test-user@localhost", refreshedToken.getSubject());
assertTrue(refreshedToken.getRealmAccess().isUserInRole("user"));
@ -1529,7 +1530,8 @@ public class RefreshTokenTest extends AbstractKeycloakTest {
assertEquals("Bearer", response.getTokenType());
assertEquals(findUserByUsername(adminClient.realm("test"), "test-user@localhost").getId(), refreshedToken.getSubject());
Assert.assertNotEquals("test-user@localhost", refreshedToken.getSubject());
// The following check is not valid anymore since file store does have the same ID, and is redundant due to the previous line
// Assert.assertNotEquals("test-user@localhost", refreshedToken.getSubject());
EventRepresentation refreshEvent = events.expectRefresh(tokenEvent.getDetails().get(Details.REFRESH_TOKEN_ID), sessionId).assertEvent();
Assert.assertNotEquals(tokenEvent.getDetails().get(Details.TOKEN_ID), refreshEvent.getDetails().get(Details.TOKEN_ID));

View file

@ -251,7 +251,8 @@ public class HoKTest extends AbstractTestRealmKeycloakTest {
AccessToken token = oauth.verifyToken(response.getAccessToken());
assertEquals(findUserByUsername(adminClient.realm("test"), "test-user@localhost").getId(), token.getSubject());
Assert.assertNotEquals("test-user@localhost", token.getSubject());
// The following check is not valid anymore since file store does have the same ID, and is redundant due to the previous line
// Assert.assertNotEquals("test-user@localhost", token.getSubject());
assertEquals(sessionId, token.getSessionState());
@ -420,7 +421,8 @@ public class HoKTest extends AbstractTestRealmKeycloakTest {
assertEquals("Bearer", response.getTokenType());
assertEquals(findUserByUsername(adminClient.realm("test"), username).getId(), refreshedToken.getSubject());
Assert.assertNotEquals(username, refreshedToken.getSubject());
// The following check is not valid anymore since file store does have the same ID, and is redundant due to the previous line
// Assert.assertNotEquals("test-user@localhost", token.getSubject());
assertEquals(2, refreshedToken.getRealmAccess().getRoles().size());
Assert.assertTrue(refreshedToken.getRealmAccess().isUserInRole("user"));

View file

@ -183,7 +183,8 @@ public class ParTest extends AbstractClientPoliciesTest {
String userId = findUserByUsername(adminClient.realm(REALM_NAME), TEST_USER_NAME).getId();
assertEquals(userId, token.getSubject());
assertEquals(sessionId, token.getSessionState());
Assert.assertNotEquals(TEST_USER_NAME, token.getSubject());
// The following check is not valid anymore since file store does have the same ID, and is redundant due to the previous line
// Assert.assertNotEquals(TEST_USER_NAME, token.getSubject());
assertEquals(clientId, token.getIssuedFor());
// Token Refresh
@ -567,7 +568,8 @@ public class ParTest extends AbstractClientPoliciesTest {
String userId = findUserByUsername(adminClient.realm(REALM_NAME), TEST_USER2_NAME).getId();
assertEquals(userId, token.getSubject());
assertEquals(sessionId, token.getSessionState());
Assert.assertNotEquals(TEST_USER2_NAME, token.getSubject());
// The following check is not valid anymore since file store does have the same ID, and is redundant due to the previous line
// Assert.assertNotEquals(TEST_USER2_NAME, token.getSubject());
assertEquals(clientId, token.getIssuedFor());
assertTrue(token.getScope().contains("openid"));
assertTrue(token.getScope().contains("microprofile-jwt"));
@ -598,7 +600,8 @@ public class ParTest extends AbstractClientPoliciesTest {
userId = findUserByUsername(adminClient.realm(REALM_NAME), TEST_USER_NAME).getId();
assertEquals(userId, token.getSubject());
assertEquals(sessionId, token.getSessionState());
Assert.assertNotEquals(TEST_USER_NAME, token.getSubject());
// The following check is not valid anymore since file store does have the same ID, and is redundant due to the previous line
// Assert.assertNotEquals(TEST_USER_NAME, token.getSubject());
assertEquals(clientId, token.getIssuedFor());
assertFalse(token.getScope().contains("microprofile-jwt"));
assertTrue(token.getScope().contains("openid"));
@ -667,7 +670,8 @@ public class ParTest extends AbstractClientPoliciesTest {
String userId = findUserByUsername(adminClient.realm(REALM_NAME), TEST_USER2_NAME).getId();
assertEquals(userId, token.getSubject());
assertEquals(sessionId, token.getSessionState());
Assert.assertNotEquals(TEST_USER2_NAME, token.getSubject());
// The following check is not valid anymore since file store does have the same ID, and is redundant due to the previous line
// Assert.assertNotEquals(TEST_USER_NAME, token.getSubject());
assertEquals(client2Id, token.getIssuedFor());
assertTrue(token.getScope().contains("openid"));
assertTrue(token.getScope().contains("microprofile-jwt"));
@ -699,7 +703,8 @@ public class ParTest extends AbstractClientPoliciesTest {
userId = findUserByUsername(adminClient.realm(REALM_NAME), TEST_USER_NAME).getId();
assertEquals(userId, token.getSubject());
assertEquals(sessionId, token.getSessionState());
Assert.assertNotEquals(TEST_USER_NAME, token.getSubject());
// The following check is not valid anymore since file store does have the same ID, and is redundant due to the previous line
// Assert.assertNotEquals(TEST_USER_NAME, token.getSubject());
assertEquals(clientId, token.getIssuedFor());
assertFalse(token.getScope().contains("microprofile-jwt"));
assertTrue(token.getScope().contains("openid"));
@ -1201,7 +1206,8 @@ public class ParTest extends AbstractClientPoliciesTest {
String userId = findUserByUsername(adminClient.realm(REALM_NAME), TEST_USER_NAME).getId();
assertEquals(userId, token.getSubject());
assertEquals(sessionId, token.getSessionState());
Assert.assertNotEquals(TEST_USER_NAME, token.getSubject());
// The following check is not valid anymore since file store does have the same ID, and is redundant due to the previous line
// Assert.assertNotEquals(TEST_USER_NAME, token.getSubject());
assertEquals(clientId, token.getIssuedFor());
// Token Refresh