8000 Revise Client Policies Codes - ClientPoliciesConditionTest by tnorimat · Pull Request #39892 · keycloak/keycloak · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Revise Client Policies Codes - ClientPoliciesConditionTest #39892

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

Merged
merged 1 commit into from
May 26, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
import org.keycloak.testsuite.arquillian.annotation.EnableFeature;
import org.keycloak.testsuite.pages.ErrorPage;
import org.keycloak.testsuite.pages.LogoutConfirmPage;
import org.keycloak.testsuite.pages.OAuth2DeviceVerificationPage;
import org.keycloak.testsuite.pages.OAuthGrantPage;
import org.keycloak.testsuite.services.clientpolicy.executor.TestRaiseExceptionExecutorFactory;
import org.keycloak.testsuite.util.ClientBuilder;
Expand All @@ -93,9 +92,6 @@
@EnableFeature(value = Profile.Feature.CLIENT_SECRET_ROTATION)
public class ClientPoliciesConditionTest extends AbstractClientPoliciesTest {

@Page
protected OAuth2DeviceVerificationPage verificationPage;

@Page
protected OAuthGrantPage grantPage;

Expand Down Expand Up @@ -130,7 +126,7 @@ public void addTestRealms(List<RealmRepresentation> testRealms) {
user.setUsername("create-clients");
user.setCredentials(credentials);
user.setClientRoles(Collections.singletonMap(Constants.REALM_MANAGEMENT_CLIENT_ID, Collections.singletonList(AdminRoles.CREATE_CLIENT)));
user.setGroups(Arrays.asList("topGroup")); // defined in testrealm.json
user.setGroups(List.of("topGroup")); // defined in testrealm.json

users.add(user);

Expand Down Expand Up @@ -189,14 +185,12 @@ public void testAnyClientCondition() throws Exception {
String clientAlphaId = generateSuffixedName("Alpha-App");
String clientAlphaSecret = "secretAlpha";
createClientByAdmin(clientAlphaId, (ClientRepresentation clientRep) -> {
clientRep.setDefaultRoles((String[]) Arrays.asList("sample-client-role-alpha").toArray(new String[1]));
clientRep.setDefaultRoles(List.of("sample-client-role-alpha").toArray(new String[1]));
clientRep.setSecret(clientAlphaSecret);
});

String clientBetaId = generateSuffixedName("Beta-App");
createClientByAdmin(clientBetaId, (ClientRepresentation clientRep) -> {
clientRep.setSecret("secretBeta");
});
createClientByAdmin(clientBetaId, (ClientRepresentation clientRep) -> clientRep.setSecret("secretBeta"));

try {
failLoginWithoutSecureSessionParameter(clientBetaId, ERR_MSG_MISSING_NONCE);
Expand Down Expand Up @@ -233,9 +227,7 @@ public void testClientUpdateSourceHostsCondition() throws Exception {
String clientId = generateSuffixedName(CLIENT_NAME);
String clientSecret = "secret";
try {
createClientByAdmin(clientId, (ClientRepresentation clientRep) -> {
clientRep.setSecret(clientSecret);
});
createClientByAdmin(clientId, (ClientRepresentation clientRep) -> clientRep.setSecret(clientSecret));
fail();
} catch (ClientPolicyException e) {
assertEquals(OAuthErrorException.INVALID_CLIENT_METADATA, e.getMessage());
Expand All @@ -245,16 +237,14 @@ public void testClientUpdateSourceHostsCondition() throws Exception {
json = (new ClientPoliciesBuilder()).addPolicy(
(new ClientPolicyBuilder()).createPolicy(POLICY_NAME, "Aktualizovana Prvni Politika", Boolean.TRUE)
.addCondition(ClientUpdaterSourceHostsConditionFactory.PROVIDER_ID,
createClientUpdateSourceHostsConditionConfig(Arrays.asList("example.com")))
createClientUpdateSourceHostsConditionConfig(List.of("example.com")))
.addProfile(PROFILE_NAME)
.toRepresentation()
).toString();
updatePolicies(json);

try {
createClientByAdmin(clientId, (ClientRepresentation clientRep) -> {
clientRep.setSecret(clientSecret);
});
createClientByAdmin(clientId, (ClientRepresentation clientRep) -> clientRep.setSecret(clientSecret));
} catch (Exception e) {
fail();
}
Expand All @@ -267,7 +257,7 @@ public void testClientUpdateSourceGroupsCondition() throws Exception {
(new ClientProfileBuilder()).createProfile(PROFILE_NAME, "Den Forste Profil")
.addExecutor(SecureClientAuthenticatorExecutorFactory.PROVIDER_ID,
createSecureClientAuthenticatorExecutorConfig(
Arrays.asList(JWTClientAuthenticator.PROVIDER_ID),
List.of(JWTClientAuthenticator.PROVIDER_ID),
null)
)
.toRepresentation()
Expand All @@ -278,7 +268,7 @@ public void testClientUpdateSourceGroupsCondition() throws Exception {
json = (new ClientPoliciesBuilder()).addPolicy(
(new ClientPolicyBuilder()).createPolicy(POLICY_NAME, "Den Forste Politik", Boolean.TRUE)
.addCondition(ClientUpdaterSourceGroupsConditionFactory.PROVIDER_ID,
createClientUpdateSourceGroupsConditionConfig(Arrays.asList("topGroup")))
createClientUpdateSourceGroupsConditionConfig(List.of("topGroup")))
.addProfile(PROFILE_NAME)
.toRepresentation()
).toString();
Expand Down Expand Up @@ -308,7 +298,7 @@ public void testClientUpdateSourceRolesCondition() throws Exception {
(new ClientProfileBuilder()).createProfile(PROFILE_NAME, "Il Primo Profilo")
.addExecutor(SecureClientAuthenticatorExecutorFactory.PROVIDER_ID,
createSecureClientAuthenticatorExecutorConfig(
Arrays.asList(JWTClientSecretAuthenticator.PROVIDER_ID),
List.of(JWTClientSecretAuthenticator.PROVIDER_ID),
null)
)
.toRepresentation()
Expand All @@ -319,7 +309,7 @@ public void testClientUpdateSourceRolesCondition() throws Exception {
json = (new ClientPoliciesBuilder()).addPolicy(
(new ClientPolicyBuilder()).createPolicy(POLICY_NAME, "La Prima Politica", Boolean.TRUE)
.addCondition(ClientUpdaterSourceRolesConditionFactory.PROVIDER_ID,
createClientUpdateSourceRolesConditionConfig(Arrays.asList(Constants.REALM_MANAGEMENT_CLIENT_ID + "." + AdminRoles.CREATE_CLIENT)))
createClientUpdateSourceRolesConditionConfig(List.of(Constants.REALM_MANAGEMENT_CLIENT_ID + "." + AdminRoles.CREATE_CLIENT)))
.addProfile(PROFILE_NAME)
.toRepresentation()
).toString();
Expand Down Expand Up @@ -365,9 +355,7 @@ public void testClientScopesOptionalCondition() throws Exception {

String clientId = generateSuffixedName(CLIENT_NAME);
String clientSecret = "secret";
createClientByAdmin(clientId, (ClientRepresentation clientRep) -> {
clientRep.setSecret(clientSecret);
});
createClientByAdmin(clientId, (ClientRepresentation clientRep) -> clientRep.setSecret(clientSecret));

try {
oauth.scope("address" + " " + "phone");
Expand Down Expand Up @@ -408,9 +396,7 @@ public void testClientScopesAnyCondition() throws Exception {

String clientId = generateSuffixedName(CLIENT_NAME);
String clientSecret = "secret";
String id = createClientByAdmin(clientId, (ClientRepresentation clientRep) -> {
clientRep.setSecret(clientSecret);
});
String id = createClientByAdmin(clientId, (ClientRepresentation clientRep) -> clientRep.setSecret(clientSecret));


String emailClientScopeId = adminClient.realm(REALM_NAME)
Expand Down Expand Up @@ -459,7 +445,7 @@ public void testClientAttributesCondition() throws Exception {
json = (new ClientPoliciesBuilder()).addPolicy(
(new ClientPolicyBuilder()).createPolicy(POLICY_NAME, "Het Eerste Beleid", Boolean.TRUE)
.addCondition(ClientAttributesConditionFactory.PROVIDER_ID,
createClientAttributesConditionConfig(new MultivaluedHashMap<String, String>() {
createClientAttributesConditionConfig(new MultivaluedHashMap<>() {
{
putSingle("attr1", "Apple");
putSingle("attr2", "Orange");
Expand All @@ -474,7 +460,7 @@ public void testClientAttributesCondition() throws Exception {
String clientSecret = "secret";
createClientByAdmin(clientAlphaId, (ClientRepresentation clientRep) -> {
clientRep.setSecret(clientSecret);
clientRep.setAttributes(new HashMap<String, String>() {
clientRep.setAttributes(new HashMap<>() {
{
put("attr1", "Apple");
put("attr2", "Orange");
Expand All @@ -486,7 +472,7 @@ public void testClientAttributesCondition() throws Exception {
String clientBetaId = generateSuffixedName("Beta-App");
createClientByAdmin(clientBetaId, (ClientRepresentation clientRep) -> {
clientRep.setSecret(clientSecret);
clientRep.setAttributes(new HashMap<String, String>() {
clientRep.setAttributes(new HashMap<>() {
{
put("attr1", "Apple");
put("attr2", "Peach"); // attr2 is not "Orange"
Expand Down Expand Up @@ -523,7 +509,7 @@ public void testClientAccessTypeCondition() throws Exception {
json = (new ClientPoliciesBuilder()).addPolicy(
(new ClientPolicyBuilder()).createPolicy(POLICY_NAME, "La Primera Plitica", Boolean.TRUE)
.addCondition(ClientAccessTypeConditionFactory.PROVIDER_ID,
createClientAccessTypeConditionConfig(Arrays.asList(ClientAccessTypeConditionFactory.TYPE_CONFIDENTIAL)))
createClientAccessTypeConditionConfig(List.of(ClientAccessTypeConditionFactory.TYPE_CONFIDENTIAL)))
.addProfile(PROFILE_NAME)
.toRepresentation()
).toString();
Expand Down Expand Up @@ -578,9 +564,7 @@ public void testClientAccessTypeCondition() throws Exception {
updateProfiles(json);

authCreateClients();
String clientGammaId = createClientDynamically(generateSuffixedName("Gamma-App"), (OIDCClientRepresentation clientRep) -> {
clientRep.setClientSecret("secretGamma");
});
String clientGammaId = createClientDynamically(generateSuffixedName("Gamma-App"), (OIDCClientRepresentation clientRep) -> clientRep.setClientSecret("secretGamma"));

ClientRepresentation clientRep = getClientByAdmin(clientGammaId);
assertEquals(OAuth2Constants.PKCE_METHOD_S256, OIDCAdvancedConfigWrapper.fromClientRepresentation(clientRep).getPkceCodeChallengeMethod());
Expand Down Expand Up @@ -625,7 +609,7 @@ public void testClientPolicyTriggeredForServiceAccountRequest() throws Exception
String json = (new ClientProfilesBuilder()).addProfile(
(new ClientProfileBuilder()).createProfile(PROFILE_NAME, "Den Forste Profilen")
.addExecutor(TestRaiseExceptionExecutorFactory.PROVIDER_ID,
createTestRaiseExeptionExecutorConfig(Arrays.asList(ClientPolicyEvent.SERVICE_ACCOUNT_TOKEN_REQUEST)))
createTestRaiseExeptionExecutorConfig(List.of(ClientPolicyEvent.SERVICE_ACCOUNT_TOKEN_REQUEST)))
.toRepresentation()
).toString();
updateProfiles(json);
Expand All @@ -647,7 +631,7 @@ public void testClientPolicyTriggeredForServiceAccountRequest() throws Exception
assertEquals(ClientPolicyEvent.SERVICE_ACCOUNT_TOKEN_REQUEST.toString(), response.getError());
assertEquals("Exception thrown intentionally", response.getErrorDescription());
} finally {
oauth.clientId(origClientId);
oauth.client(origClientId);
}
}
}
Loading
0