Skip to content

Commit f7f85f3

Browse files
authored
HTTPClient default timeouts (#264)
* Add default timeouts for DefaultHttpClient * Handle 'stay signed in' confirmation page in DeviceCodeIT tests * Small best-practices changes
1 parent cf659cd commit f7f85f3

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

src/integrationtest/java/com.microsoft.aad.msal4j/DeviceCodeIT.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void DeviceCodeFlowADTest(String environment) throws Exception {
4646
build();
4747

4848
Consumer<DeviceCode> deviceCodeConsumer = (DeviceCode deviceCode) -> {
49-
runAutomatedDeviceCodeFlow(deviceCode, user);
49+
runAutomatedDeviceCodeFlow(deviceCode, user, environment);
5050
};
5151

5252
IAuthenticationResult result = pca.acquireToken(DeviceCodeFlowParameters
@@ -70,7 +70,7 @@ public void DeviceCodeFlowADFSv2019Test(String environment) throws Exception {
7070
build();
7171

7272
Consumer<DeviceCode> deviceCodeConsumer = (DeviceCode deviceCode) -> {
73-
runAutomatedDeviceCodeFlow(deviceCode, user);
73+
runAutomatedDeviceCodeFlow(deviceCode, user, environment);
7474
};
7575

7676
IAuthenticationResult result = pca.acquireToken(DeviceCodeFlowParameters
@@ -83,7 +83,7 @@ public void DeviceCodeFlowADFSv2019Test(String environment) throws Exception {
8383
Assert.assertFalse(Strings.isNullOrEmpty(result.accessToken()));
8484
}
8585

86-
private void runAutomatedDeviceCodeFlow(DeviceCode deviceCode, User user){
86+
private void runAutomatedDeviceCodeFlow(DeviceCode deviceCode, User user, String environment){
8787
boolean isRunningLocally = true;//!Strings.isNullOrEmpty(
8888
//System.getenv(TestConstants.LOCAL_FLAG_ENV_VAR));
8989

@@ -123,6 +123,15 @@ private void runAutomatedDeviceCodeFlow(DeviceCode deviceCode, User user){
123123
} else {
124124
SeleniumExtensions.performADLogin(seleniumDriver, user);
125125
}
126+
127+
if (environment.equals(AzureEnvironment.AZURE) && !isADFS2019) {
128+
//Login flow for azurecloud environment has an extra "Stay signed in?" page after authentication
129+
continueBtn = SeleniumExtensions.waitForElementToBeVisibleAndEnable(
130+
seleniumDriver,
131+
new By.ById(continueButtonId));
132+
continueBtn.click();
133+
}
134+
126135
} catch(Exception e){
127136
if(!isRunningLocally){
128137
SeleniumExtensions.takeScreenShot(seleniumDriver);

src/main/java/com/microsoft/aad/msal4j/DefaultHttpClient.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class DefaultHttpClient implements IHttpClient {
1515

1616
private final Proxy proxy;
1717
private final SSLSocketFactory sslSocketFactory;
18+
public int DEFAULTCONNECTIONTIMEOUT = 3000;
19+
public int DEFAULTREADTIMEOUT = 5000;
1820

1921
DefaultHttpClient(Proxy proxy, SSLSocketFactory sslSocketFactory){
2022
this.proxy = proxy;
@@ -76,6 +78,9 @@ private HttpsURLConnection openConnection(final URL finalURL)
7678
connection.setSSLSocketFactory(sslSocketFactory);
7779
}
7880

81+
connection.setConnectTimeout(DEFAULTCONNECTIONTIMEOUT);
82+
connection.setReadTimeout(DEFAULTREADTIMEOUT);
83+
7984
return connection;
8085
}
8186

src/test/java/com/microsoft/aad/msal4j/DefaultHttpClientTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ public void ValidNotOkHttpResponse() throws Exception {
4444

4545
EasyMock.expect(mockCon.getHeaderFields()).andReturn(expectedHeaders).times(1);
4646

47+
mockCon.setReadTimeout(0);
48+
mockCon.setConnectTimeout(0);
49+
4750
DefaultHttpClient httpClient =
4851
PowerMock.createPartialMock(DefaultHttpClient.class, "openConnection");
4952

0 commit comments

Comments
 (0)