Skip to content
Open
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 @@ -22,6 +22,7 @@
import org.elasticsearch.test.junit.RunnableTestRuleAdapter;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.rules.RuleChain;
Expand Down Expand Up @@ -52,10 +53,7 @@ public class SamlRestTestCase extends ESRestTestCase {
private static Path caPath;

@ClassRule
public static TestRule ruleChain = RuleChain.outerRule(new RunnableTestRuleAdapter(SamlRestTestCase::initWebserver))
.around(cluster)
// during the startup, the metadata remains unavailable to prevent caching. After cluster init, make metadata available.
.around(new RunnableTestRuleAdapter(() -> makeMetadataAvailable(1, 2, 3)));
public static TestRule ruleChain = RuleChain.outerRule(new RunnableTestRuleAdapter(SamlRestTestCase::initWebserver)).around(cluster);

private static void initWebserver() {
try {
Expand Down Expand Up @@ -159,7 +157,7 @@ protected static InetSocketAddress getIdpHttpsAddress() {
}

private static void configureMetadataResource(int realmNumber) throws CertificateException, IOException, URISyntaxException {
metadataAvailable.putIfAbsent(realmNumber, false);
metadataAvailable.put(realmNumber, false);

var signingCert = getDataResource(SAML_SIGNING_CRT);
var metadataBody = new SamlIdpMetadataBuilder().entityId(getIdpEntityId(realmNumber)).sign(signingCert).asString();
Expand Down Expand Up @@ -194,6 +192,22 @@ public static void loadCertificateAuthority() throws Exception {
caPath = PathUtils.get(resource.toURI());
}

/**
* Make metadata available by default before each test, but make this behaviour controllable by subclasses.
*/
@Before
public void initMetadata() {
if (isMetadataAvailable()) {
makeMetadataAvailable(1, 2, 3);
} else {
makeAllMetadataUnavailable();
}
}

protected boolean isMetadataAvailable() {
return true;
}

@Override
protected String getTestRestCluster() {
return cluster.getHttpAddresses();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,16 @@

public class SamlServiceProviderMetadataIT extends SamlRestTestCase {

/**
* Within this class we the metadata not to be enabled at the start of each test
*/
@Override
protected boolean isMetadataAvailable() {
return false;
}

public void testAuthenticationWhenMetadataIsUnreliable() throws Exception {
// Start with no metadata available
makeAllMetadataUnavailable();
// initially, metadata in unavailable for all realms

final String username = randomAlphaOfLengthBetween(4, 12);
for (int realmNumber : shuffledList(List.of(1, 2, 3))) {
Expand Down