17
17
import org .elasticsearch .common .settings .SecureString ;
18
18
import org .elasticsearch .common .settings .Settings ;
19
19
import org .elasticsearch .common .util .concurrent .ThreadContext ;
20
+ import org .elasticsearch .core .Booleans ;
20
21
import org .elasticsearch .core .PathUtils ;
21
22
import org .elasticsearch .test .TestTrustStore ;
22
23
import org .elasticsearch .test .XContentTestUtils ;
51
52
52
53
public class MicrosoftGraphAuthzPluginIT extends ESRestTestCase {
53
54
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" ));
59
61
60
62
private static final List <MicrosoftGraphHttpFixture .TestUser > TEST_USERS = List .of (
61
63
new MicrosoftGraphHttpFixture .TestUser (
@@ -90,12 +92,14 @@ public class MicrosoftGraphAuthzPluginIT extends ESRestTestCase {
90
92
);
91
93
92
94
@ 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 );
94
98
95
99
private static final String IDP_ENTITY_ID = "http://idp.example.org/" ;
96
100
97
101
private static ElasticsearchCluster initTestCluster () {
98
- return ElasticsearchCluster .local ()
102
+ final var clusterBuilder = ElasticsearchCluster .local ()
99
103
.module ("analysis-common" )
100
104
.setting ("xpack.security.enabled" , "true" )
101
105
.setting ("xpack.license.self_generated.type" , "trial" )
@@ -117,16 +121,20 @@ private static ElasticsearchCluster initTestCluster() {
117
121
.setting ("xpack.security.authc.realms.microsoft_graph.microsoft_graph1.order" , "2" )
118
122
.setting ("xpack.security.authc.realms.microsoft_graph.microsoft_graph1.client_id" , CLIENT_ID )
119
123
.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 ();
124
+ .setting ("xpack.security.authc.realms.microsoft_graph.microsoft_graph1.tenant_id" , TENANT_ID );
125
+
126
+ if (USE_FIXTURE ) {
127
+ clusterBuilder .setting (
128
+ "xpack.security.authc.realms.microsoft_graph.microsoft_graph1.graph_host" ,
129
+ () -> graphFixture .getBaseUrl () + "/v1.0"
130
+ )
131
+ .setting ("xpack.security.authc.realms.microsoft_graph.microsoft_graph1.access_token_host" , graphFixture ::getBaseUrl )
132
+ .systemProperty ("javax.net.ssl.trustStore" , () -> trustStore .getTrustStorePath ().toString ())
133
+ .systemProperty ("javax.net.ssl.trustStoreType" , "jks" )
134
+ .systemProperty ("tests.azure.credentials.disable_instance_discovery" , "true" );
135
+ }
136
+
137
+ return clusterBuilder .build ();
130
138
}
131
139
132
140
private static String getIDPMetadata () {
@@ -205,6 +213,7 @@ public void testAuthenticationSuccessful() throws Exception {
205
213
}
206
214
207
215
public void testConcurrentAuthentication () throws Exception {
216
+ assumeTrue ("This needs the test server as the real account only has one user configured" , USE_FIXTURE );
208
217
final var concurrentLogins = 3 ;
209
218
210
219
final var resultsListener = new PlainActionFuture <Collection <Map <String , Object >>>();
0 commit comments