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 ;
5152
5253public class MicrosoftGraphAuthzPluginIT extends ESRestTestCase {
5354
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" ;
55+ private static final String TENANT_ID = System .getProperty ("test.ms_graph.tenant_id" );
56+ private static final String CLIENT_ID = System .getProperty ("test.ms_graph.client_id" );
57+ private static final String CLIENT_SECRET = System .getProperty ("test.ms_graph.client_secret" );
58+ private static final String USERNAME = System .getProperty ("test.ms_graph.username" );
59+ private static final String EXPECTED_GROUP = System .getProperty ("test.ms_graph.group_id" );
60+ private static final Boolean USE_FIXTURE = Booleans .parseBoolean (System .getProperty ("test.ms_graph.fixture" ));
5961
6062 private static final List <MicrosoftGraphHttpFixture .TestUser > TEST_USERS = List .of (
6163 new MicrosoftGraphHttpFixture .TestUser (
@@ -90,12 +92,14 @@ public class MicrosoftGraphAuthzPluginIT extends ESRestTestCase {
9092 );
9193
9294 @ ClassRule
93- public static TestRule ruleChain = RuleChain .outerRule (graphFixture ).around (trustStore ).around (cluster );
95+ public static TestRule ruleChain = USE_FIXTURE
96+ ? RuleChain .outerRule (graphFixture ).around (trustStore ).around (cluster )
97+ : RuleChain .outerRule (cluster );
9498
9599 private static final String IDP_ENTITY_ID = "http://idp.example.org/" ;
96100
97101 private static ElasticsearchCluster initTestCluster () {
98- return ElasticsearchCluster .local ()
102+ final var clusterBuilder = ElasticsearchCluster .local ()
99103 .module ("analysis-common" )
100104 .setting ("xpack.security.enabled" , "true" )
101105 .setting ("xpack.license.self_generated.type" , "trial" )
@@ -118,15 +122,22 @@ private static ElasticsearchCluster initTestCluster() {
118122 .setting ("xpack.security.authc.realms.microsoft_graph.microsoft_graph1.client_id" , CLIENT_ID )
119123 .keystore ("xpack.security.authc.realms.microsoft_graph.microsoft_graph1.client_secret" , CLIENT_SECRET )
120124 .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 )
123125 .setting ("logger.org.elasticsearch.xpack.security.authz.microsoft" , "TRACE" )
124126 .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 ();
127+ .setting ("logger.com.azure" , "TRACE" );
128+
129+ if (USE_FIXTURE ) {
130+ clusterBuilder .setting (
131+ "xpack.security.authc.realms.microsoft_graph.microsoft_graph1.graph_host" ,
132+ () -> graphFixture .getBaseUrl () + "/v1.0"
133+ )
134+ .setting ("xpack.security.authc.realms.microsoft_graph.microsoft_graph1.access_token_host" , graphFixture ::getBaseUrl )
135+ .systemProperty ("javax.net.ssl.trustStore" , () -> trustStore .getTrustStorePath ().toString ())
136+ .systemProperty ("javax.net.ssl.trustStoreType" , "jks" )
137+ .systemProperty ("tests.azure.credentials.disable_instance_discovery" , "true" );
138+ }
139+
140+ return clusterBuilder .build ();
130141 }
131142
132143 private static String getIDPMetadata () {
@@ -210,6 +221,7 @@ public void testAuthenticationSuccessful() throws Exception {
210221 }
211222
212223 public void testConcurrentAuthentication () throws Exception {
224+ assumeTrue ("This needs the test server as the real account only has one user configured" , USE_FIXTURE );
213225 final var concurrentLogins = 3 ;
214226
215227 final var resultsListener = new PlainActionFuture <Collection <Map <String , Object >>>();
0 commit comments