-
Notifications
You must be signed in to change notification settings - Fork 159
Expand file tree
/
Copy pathDeviceCodeIT.java
More file actions
66 lines (53 loc) · 2.38 KB
/
DeviceCodeIT.java
File metadata and controls
66 lines (53 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.microsoft.aad.msal4j;
import com.microsoft.aad.msal4j.labapi.*;
import static com.microsoft.aad.msal4j.labapi.KeyVaultSecrets.*;
import infrastructure.SeleniumExtensions;
import org.openqa.selenium.WebDriver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.AfterAll;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.util.Collections;
import java.util.function.Consumer;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class DeviceCodeIT {
private static final Logger LOG = LoggerFactory.getLogger(DeviceCodeIT.class);
private WebDriver seleniumDriver;
@BeforeAll
void setUp() {
seleniumDriver = SeleniumExtensions.createDefaultWebDriver();
}
//Temporarily disabling: timeout occuring after 15 minutes, likely either a server-side issue or a UI change
//Needs investigation, tracked in https://github.com/AzureAD/microsoft-authentication-library-for-java/issues/1023
//@Test
void DeviceCodeFlowADTest() throws Exception {
AppConfig app = LabResponseHelper.getAppConfig(APP_PCACLIENT);
UserConfig user = LabResponseHelper.getUserConfig(USER_PUBLIC_CLOUD);
PublicClientApplication pca = IntegrationTestHelper.createPublicApp(app.getAppId(), TestConstants.MICROSOFT_AUTHORITY_HOST + user.getTenantId());
Consumer<DeviceCode> deviceCodeConsumer = (DeviceCode deviceCode) -> runAutomatedDeviceCodeFlow(deviceCode, user);
IAuthenticationResult result = pca.acquireToken(DeviceCodeFlowParameters
.builder(Collections.singleton(TestConstants.GRAPH_DEFAULT_SCOPE),
deviceCodeConsumer)
.build())
.get();
IntegrationTestHelper.assertAccessAndIdTokensNotNull(result);
}
private void runAutomatedDeviceCodeFlow(DeviceCode deviceCode, UserConfig user) {
SeleniumExtensions.performDeviceCodeLogin(
seleniumDriver,
deviceCode.verificationUri(),
deviceCode.userCode(),
user);
}
@AfterAll
void cleanUp() {
if (seleniumDriver != null) {
seleniumDriver.close();
}
}
}