1717import org .elasticsearch .common .settings .SecureString ;
1818import org .elasticsearch .common .settings .Settings ;
1919import org .elasticsearch .common .util .concurrent .ThreadContext ;
20+ import org .elasticsearch .core .Booleans ;
2021import org .elasticsearch .core .PathUtils ;
2122import org .elasticsearch .test .TestTrustStore ;
2223import org .elasticsearch .test .XContentTestUtils ;
2324import org .elasticsearch .test .cluster .ElasticsearchCluster ;
25+ import org .elasticsearch .test .cluster .local .LocalClusterSpecBuilder ;
2426import org .elasticsearch .test .cluster .local .model .User ;
2527import org .elasticsearch .test .cluster .util .resource .Resource ;
2628import org .elasticsearch .test .rest .ESRestTestCase ;
5153
5254public class MicrosoftGraphAuthzPluginIT extends ESRestTestCase {
5355
54- private static final String TENANT_ID = "tenant-id" ;
55- private static final String CLIENT_ID = "client_id" ;
56- private static final String CLIENT_SECRET = "client_secret" ;
57- private static final String USERNAME = "Thor" ;
58- private static final String EXPECTED_GROUP = "test_group" ;
56+ private static final String TENANT_ID = System .getProperty ("test.ms_graph.tenant_id" );
57+ private static final String CLIENT_ID = System .getProperty ("test.ms_graph.client_id" );
58+ private static final String CLIENT_SECRET = System .getProperty ("test.ms_graph.client_secret" );
59+ private static final String USERNAME = System .getProperty ("test.ms_graph.username" );
60+ private static final String EXPECTED_GROUP = System .getProperty ("test.ms_graph.group_id" );
61+ private static final Boolean USE_FIXTURE = Booleans .parseBoolean (System .getProperty ("test.ms_graph.fixture" ));
5962
6063 private static final List <MicrosoftGraphHttpFixture .TestUser > TEST_USERS = List .of (
6164 new MicrosoftGraphHttpFixture .TestUser (
@@ -90,12 +93,14 @@ public class MicrosoftGraphAuthzPluginIT extends ESRestTestCase {
9093 );
9194
9295 @ ClassRule
93- public static TestRule ruleChain = RuleChain .outerRule (graphFixture ).around (trustStore ).around (cluster );
96+ public static TestRule ruleChain = USE_FIXTURE
97+ ? RuleChain .outerRule (graphFixture ).around (trustStore ).around (cluster )
98+ : RuleChain .outerRule (cluster );
9499
95100 private static final String IDP_ENTITY_ID = "http://idp.example.org/" ;
96101
97102 private static ElasticsearchCluster initTestCluster () {
98- return ElasticsearchCluster .local ()
103+ final var clusterBuilder = ElasticsearchCluster .local ()
99104 .module ("analysis-common" )
100105 .setting ("xpack.security.enabled" , "true" )
101106 .setting ("xpack.license.self_generated.type" , "trial" )
@@ -117,16 +122,20 @@ private static ElasticsearchCluster initTestCluster() {
117122 .setting ("xpack.security.authc.realms.microsoft_graph.microsoft_graph1.order" , "2" )
118123 .setting ("xpack.security.authc.realms.microsoft_graph.microsoft_graph1.client_id" , CLIENT_ID )
119124 .keystore ("xpack.security.authc.realms.microsoft_graph.microsoft_graph1.client_secret" , CLIENT_SECRET )
120- .setting ("xpack.security.authc.realms.microsoft_graph.microsoft_graph1.tenant_id" , TENANT_ID )
121- .setting ("xpack.security.authc.realms.microsoft_graph.microsoft_graph1.graph_host" , () -> graphFixture .getBaseUrl () + "/v1.0" )
122- .setting ("xpack.security.authc.realms.microsoft_graph.microsoft_graph1.access_token_host" , graphFixture ::getBaseUrl )
123- .setting ("logger.org.elasticsearch.xpack.security.authz.microsoft" , "TRACE" )
124- .setting ("logger.com.microsoft" , "TRACE" )
125- .setting ("logger.com.azure" , "TRACE" )
126- .systemProperty ("javax.net.ssl.trustStore" , () -> trustStore .getTrustStorePath ().toString ())
127- .systemProperty ("javax.net.ssl.trustStoreType" , "jks" )
128- .systemProperty ("tests.azure.credentials.disable_instance_discovery" , "true" )
129- .build ();
125+ .setting ("xpack.security.authc.realms.microsoft_graph.microsoft_graph1.tenant_id" , TENANT_ID );
126+
127+ if (USE_FIXTURE ) {
128+ clusterBuilder .setting (
129+ "xpack.security.authc.realms.microsoft_graph.microsoft_graph1.graph_host" ,
130+ () -> graphFixture .getBaseUrl () + "/v1.0"
131+ )
132+ .setting ("xpack.security.authc.realms.microsoft_graph.microsoft_graph1.access_token_host" , graphFixture ::getBaseUrl )
133+ .systemProperty ("javax.net.ssl.trustStore" , () -> trustStore .getTrustStorePath ().toString ())
134+ .systemProperty ("javax.net.ssl.trustStoreType" , "jks" )
135+ .systemProperty ("tests.azure.credentials.disable_instance_discovery" , "true" );
136+ }
137+
138+ return clusterBuilder .build ();
130139 }
131140
132141 private static String getIDPMetadata () {
@@ -205,6 +214,7 @@ public void testAuthenticationSuccessful() throws Exception {
205214 }
206215
207216 public void testConcurrentAuthentication () throws Exception {
217+ assumeTrue ("This needs the test server as the real account only has one user configured" , USE_FIXTURE );
208218 final var concurrentLogins = 3 ;
209219
210220 final var resultsListener = new PlainActionFuture <Collection <Map <String , Object >>>();
0 commit comments