8000 Migrate the AccountRestServiceTest by gaoyikeshuer · Pull Request #49296 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
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 @@ -613,6 +613,11 @@ public RealmBuilder addClientScopeClientRoleMapping(String clientName, String cl
return this;
}

public RealmBuilder accountTheme(String accountTheme) {
rep.setAccountTheme(accountTheme);
return this;
}

/**
* Best practice is to use other convenience methods when configuring a realm, but while the framework is under
* active development there may not be a way to perform all updates required. In these cases this method allows
Expand Down

Large diffs are not rendered by default.

8000
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

@KeycloakIntegrationTest(config = AccountConsoleDisabledTest.ServerConfig.class)
public class AccountConsoleDisabledTest {

Expand All @@ -31,7 +30,7 @@ public void accountConsoleReturns404WhenDisabled() throws IOException {
HttpGet request = new HttpGet(realm.getBaseUrl() + "/account/");

try (CloseableHttpResponse response = httpClient.execute(request)) {
assertEquals(404, response.getStatusLine().getStatusCode(),
Assertions.assertEquals(404, response.getStatusLine().getStatusCode(),
"Account console should return 404 when ACCOUNT_V3 feature is disabled");
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.keycloak.tests.account;

import org.keycloak.http.simple.SimpleHttpResponse;
import org.keycloak.testframework.annotations.KeycloakIntegrationTest;
import org.keycloak.tests.common.CustomProvidersServerConfig;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

/**
*
* @author rmartinc
*/
@KeycloakIntegrationTest(config = CustomProvidersServerConfig.class)
public class AccountRestServiceCustomThemeTest extends AbstractRestServiceTest {

@Test
public void testCustomAccountResourceTheme() throws Exception {
managedRealm.updateWithCleanup(r -> r.accountTheme("custom-account-provider"));

try (SimpleHttpResponse response = simpleHttp.doGet(getAccountUrl(null))
.header("Accept", "text/html")
.asResponse()) {
Assertions.assertEquals(200, response.getStatus());

String html = response.asString();
Assertions.assertTrue(html.contains("Custom Account Console"));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright 2024 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.keycloak.tests.account;

import org.keycloak.services.clientpolicy.condition.AnyClientConditionFactory;
import org.keycloak.services.clientpolicy.executor.UseLightweightAccessTokenExecutorFactory;
import org.keycloak.testframework.annotations.InjectRealm;
import org.keycloak.testframework.annotations.KeycloakIntegrationTest;
import org.keycloak.testframework.realm.ClientPolicyBuilder;
import org.keycloak.testframework.realm.ClientProfileBuilder;
import org.keycloak.testframework.realm.ManagedRealm;
import org.keycloak.testframework.realm.RealmBuilder;

/**
*
* @author rmartinc
*/
@KeycloakIntegrationTest
public class AccountRestServiceLightweightTokenTest extends AccountRestServiceTest {

private static final String POLICY_NAME = "enable lightweight tokens";

@InjectRealm(config = LightweightTokenRealmConfig.class)
protected ManagedRealm managedRealm;

public static class LightweightTokenRealmConfig extends AccountRestRealmConfig {

@Override
public RealmBuilder configure(RealmBuilder realm) {
super.configure(realm);

realm.clientProfile(ClientProfileBuilder.create()
.name(POLICY_NAME)
.description("Profile Lightweight Tokens")
.executor(UseLightweightAccessTokenExecutorFactory.PROVIDER_ID, null)
.build());

realm.clientPolicy(ClientPolicyBuilder.create()
.name(POLICY_NAME)
.description("Policy Lightweight Tokens")
.condition(AnyClientConditionFactory.PROVIDER_ID, null)
.profile(POLICY_NAME)
.build());

return realm;
}
}
}
Loading
Loading
0