KEYCLOAK-15849 : auth-remote-server exclude -> removed duplicated annotation, fixed @Test(timeout) bug -> replaced by lambda expression.
This commit is contained in:
parent
63b19389c1
commit
4a2830bc2e
5 changed files with 167 additions and 133 deletions
|
@ -27,6 +27,7 @@ import org.jboss.logging.Logger;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.junit.runners.model.TestTimedOutException;
|
||||||
import org.keycloak.admin.client.Keycloak;
|
import org.keycloak.admin.client.Keycloak;
|
||||||
import org.keycloak.admin.client.resource.AuthenticationManagementResource;
|
import org.keycloak.admin.client.resource.AuthenticationManagementResource;
|
||||||
import org.keycloak.admin.client.resource.RealmsResource;
|
import org.keycloak.admin.client.resource.RealmsResource;
|
||||||
|
@ -78,6 +79,7 @@ import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
import java.util.concurrent.*;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
@ -403,6 +405,34 @@ public abstract class AbstractKeycloakTest {
|
||||||
.replace("8180", "8543");
|
.replace("8180", "8543");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected interface ExecutableTestMethod {
|
||||||
|
void execute() throws Exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void runTestWithTimeout(long timeout, ExecutableTestMethod executableTestMethod) throws Exception {
|
||||||
|
ExecutorService service = Executors.newSingleThreadExecutor();
|
||||||
|
Callable<Object> callable = new Callable<Object>() {
|
||||||
|
public Object call() throws Exception {
|
||||||
|
executableTestMethod.execute();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Future<Object> result = service.submit(callable);
|
||||||
|
service.shutdown();
|
||||||
|
try {
|
||||||
|
boolean terminated = service.awaitTermination(timeout,
|
||||||
|
TimeUnit.MILLISECONDS);
|
||||||
|
if (!terminated) {
|
||||||
|
service.shutdownNow();
|
||||||
|
}
|
||||||
|
result.get(0, TimeUnit.MILLISECONDS); // throws the exception if one occurred during the invocation
|
||||||
|
} catch (TimeoutException e) {
|
||||||
|
throw new TestTimedOutException(timeout, TimeUnit.MILLISECONDS);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new Exception(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Return <code>true</code> if you wish to automatically post-process realm and replace
|
* @return Return <code>true</code> if you wish to automatically post-process realm and replace
|
||||||
* all http values with https (and correct ports).
|
* all http values with https (and correct ports).
|
||||||
|
|
|
@ -132,9 +132,9 @@ public class ClientStorageTest extends AbstractTestRealmKeycloakTest {
|
||||||
oauth.clientId("hardcoded-client");
|
oauth.clientId("hardcoded-client");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeout = 4000)
|
@Test
|
||||||
@AuthServerContainerExclude(AuthServer.REMOTE) // testingClient doesn't work with remote
|
public void testSearchTimeout() throws Exception{
|
||||||
public void testSearchTimeout() {
|
runTestWithTimeout(4000, () -> {
|
||||||
String hardcodedClient = HardcodedClientStorageProviderFactory.PROVIDER_ID;
|
String hardcodedClient = HardcodedClientStorageProviderFactory.PROVIDER_ID;
|
||||||
String delayedSearch = HardcodedClientStorageProviderFactory.DELAYED_SEARCH;
|
String delayedSearch = HardcodedClientStorageProviderFactory.DELAYED_SEARCH;
|
||||||
String providerId = this.providerId;
|
String providerId = this.providerId;
|
||||||
|
@ -168,6 +168,7 @@ public class ClientStorageTest extends AbstractTestRealmKeycloakTest {
|
||||||
hasItem("root-url-client")
|
hasItem("root-url-client")
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -86,9 +86,9 @@ public class GroupStorageTest extends AbstractTestRealmKeycloakTest {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeout = 4000)
|
@Test
|
||||||
@AuthServerContainerExclude(AuthServer.REMOTE) // testingClient doesn't work with remote
|
public void testSearchTimeout() throws Exception{
|
||||||
public void testSearchTimeout() {
|
runTestWithTimeout(4000, () -> {
|
||||||
String hardcodedGroup = HardcodedGroupStorageProviderFactory.PROVIDER_ID;
|
String hardcodedGroup = HardcodedGroupStorageProviderFactory.PROVIDER_ID;
|
||||||
String delayedSearch = HardcodedGroupStorageProviderFactory.DELAYED_SEARCH;
|
String delayedSearch = HardcodedGroupStorageProviderFactory.DELAYED_SEARCH;
|
||||||
String providerId = this.providerId;
|
String providerId = this.providerId;
|
||||||
|
@ -122,6 +122,7 @@ public class GroupStorageTest extends AbstractTestRealmKeycloakTest {
|
||||||
hasItem("sample-realm-group")
|
hasItem("sample-realm-group")
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -93,9 +93,9 @@ public class RoleStorageTest extends AbstractTestRealmKeycloakTest {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeout = 4000)
|
@Test
|
||||||
@AuthServerContainerExclude(AuthServer.REMOTE) // testingClient doesn't work with remote
|
public void testSearchTimeout() throws Exception{
|
||||||
public void testSearchTimeout() {
|
runTestWithTimeout(4000, () -> {
|
||||||
String hardcodedRole = HardcodedRoleStorageProviderFactory.PROVIDER_ID;
|
String hardcodedRole = HardcodedRoleStorageProviderFactory.PROVIDER_ID;
|
||||||
String delayedSearch = HardcodedRoleStorageProviderFactory.DELAYED_SEARCH;
|
String delayedSearch = HardcodedRoleStorageProviderFactory.DELAYED_SEARCH;
|
||||||
String providerId = this.providerId;
|
String providerId = this.providerId;
|
||||||
|
@ -129,6 +129,7 @@ public class RoleStorageTest extends AbstractTestRealmKeycloakTest {
|
||||||
hasItem("sample-realm-role")
|
hasItem("sample-realm-role")
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -43,9 +43,9 @@ import static org.keycloak.testsuite.util.Matchers.statusCodeIsHC;
|
||||||
@AppServerContainer(ContainerConstants.APP_SERVER_TOMCAT9)
|
@AppServerContainer(ContainerConstants.APP_SERVER_TOMCAT9)
|
||||||
public class SamlXMLAttacksTest extends AbstractSamlTest {
|
public class SamlXMLAttacksTest extends AbstractSamlTest {
|
||||||
|
|
||||||
@Test(timeout = 4000)
|
@Test
|
||||||
public void testXMLBombAttackResistance() throws Exception {
|
public void testXMLBombAttackResistance() throws Exception {
|
||||||
|
runTestWithTimeout(4000, () -> {
|
||||||
String bombDoctype = "<!DOCTYPE AuthnRequest [" +
|
String bombDoctype = "<!DOCTYPE AuthnRequest [" +
|
||||||
" <!ENTITY lol \"lol\">" +
|
" <!ENTITY lol \"lol\">" +
|
||||||
"<!ELEMENT AuthnRequest (#PCDATA)>" +
|
"<!ELEMENT AuthnRequest (#PCDATA)>" +
|
||||||
|
@ -84,6 +84,7 @@ public class SamlXMLAttacksTest extends AbstractSamlTest {
|
||||||
assertThat(response, bodyHC(containsString("Invalid Request")));
|
assertThat(response, bodyHC(containsString("Invalid Request")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deployment(name = "DTD")
|
@Deployment(name = "DTD")
|
||||||
|
|
Loading…
Reference in a new issue