Skip to content

Commit b0afc5d

Browse files
authored
Merge pull request #964 from AzureAD/avdunn/status-code-constants
Consistently use constants for HTTP status codes
2 parents 1894fed + 0869edb commit b0afc5d

22 files changed

+94
-109
lines changed

msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AadInstanceDiscoveryProvider.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,8 @@ static AadInstanceDiscoveryResponse sendInstanceDiscoveryRequest(URL authorityUr
235235

236236
AadInstanceDiscoveryResponse response = JsonHelper.convertJsonStringToJsonSerializableObject(httpResponse.body(), AadInstanceDiscoveryResponse::fromJson);
237237

238-
if (httpResponse.statusCode() != HttpHelper.HTTP_STATUS_200) {
239-
if (httpResponse.statusCode() == HttpHelper.HTTP_STATUS_400 && response.error().equals("invalid_instance")) {
238+
if (httpResponse.statusCode() != HttpStatus.HTTP_OK) {
239+
if (httpResponse.statusCode() == HttpStatus.HTTP_BAD_REQUEST && response.error().equals("invalid_instance")) {
240240
// instance discovery failed due to an invalid authority, throw an exception.
241241
throw MsalServiceExceptionFactory.fromHttpResponse(httpResponse);
242242
}
@@ -310,7 +310,7 @@ static String discoverRegion(MsalRequest msalRequest, ServiceBundle serviceBundl
310310
log.info("Starting call to IMDS endpoint.");
311311
IHttpResponse httpResponse = future.get(IMDS_TIMEOUT, IMDS_TIMEOUT_UNIT);
312312
//If call to IMDS endpoint was successful, return region from response body
313-
if (httpResponse.statusCode() == HttpHelper.HTTP_STATUS_200 && !httpResponse.body().isEmpty()) {
313+
if (httpResponse.statusCode() == HttpStatus.HTTP_OK && !httpResponse.body().isEmpty()) {
314314
log.info(String.format("Region retrieved from IMDS endpoint: %s", httpResponse.body()));
315315
currentRequest.regionSource(RegionTelemetry.REGION_SOURCE_IMDS.telemetryValue);
316316

msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AuthorizationResponseHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class AuthorizationResponseHandler implements HttpHandler {
4141
public void handle(HttpExchange httpExchange) throws IOException {
4242
try {
4343
if (!httpExchange.getRequestURI().getPath().equalsIgnoreCase("/")) {
44-
httpExchange.sendResponseHeaders(200, 0);
44+
httpExchange.sendResponseHeaders(HttpStatus.HTTP_OK, 0);
4545
return;
4646
}
4747
String responseBody = new BufferedReader(new InputStreamReader(
@@ -92,13 +92,13 @@ private void sendErrorResponse(HttpExchange httpExchange, String response) throw
9292
private void send302Response(HttpExchange httpExchange, String redirectUri) throws IOException {
9393
Headers responseHeaders = httpExchange.getResponseHeaders();
9494
responseHeaders.set("Location", redirectUri);
95-
httpExchange.sendResponseHeaders(302, 0);
95+
httpExchange.sendResponseHeaders(HttpStatus.HTTP_FOUND, 0);
9696
}
9797

9898
private void send200Response(HttpExchange httpExchange, String response) throws IOException {
9999
byte[] responseBytes = response.getBytes("UTF-8");
100100
httpExchange.getResponseHeaders().set("Content-Type", "text/html; charset=UTF-8");
101-
httpExchange.sendResponseHeaders(200, responseBytes.length);
101+
httpExchange.sendResponseHeaders(HttpStatus.HTTP_OK, responseBytes.length);
102102
OutputStream os = httpExchange.getResponseBody();
103103
os.write(responseBytes);
104104
os.close();

msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/DeviceCodeFlowRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ DeviceCode acquireDeviceCode(String url,
4646
this.requestContext(),
4747
serviceBundle);
4848

49-
if (response.statusCode() != HttpHelper.HTTP_STATUS_200) {
49+
if (response.statusCode() != HttpStatus.HTTP_OK) {
5050
throw MsalServiceExceptionFactory.fromHttpResponse(response);
5151
}
5252

msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/HttpHelper.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ class HttpHelper implements IHttpHelper {
1919
private static final Logger log = LoggerFactory.getLogger(HttpHelper.class);
2020
public static final String RETRY_AFTER_HEADER = "Retry-After";
2121

22-
public static final int HTTP_STATUS_200 = 200;
23-
public static final int HTTP_STATUS_400 = 400;
24-
public static final int HTTP_STATUS_429 = 429;
25-
public static final int HTTP_STATUS_500 = 500;
26-
2722
private IHttpClient httpClient;
2823
private IRetryPolicy retryPolicy;
2924

@@ -179,8 +174,8 @@ private void processThrottlingInstructions(IHttpResponse httpResponse, RequestCo
179174
Integer retryAfterHeaderVal = getRetryAfterHeader(httpResponse);
180175
if (retryAfterHeaderVal != null) {
181176
expirationTimestamp = System.currentTimeMillis() + retryAfterHeaderVal * 1000;
182-
} else if (httpResponse.statusCode() == HTTP_STATUS_429 ||
183-
(httpResponse.statusCode() >= HTTP_STATUS_500)) {
177+
} else if (httpResponse.statusCode() == HttpStatus.HTTP_TOO_MANY_REQUESTS ||
178+
(httpResponse.statusCode() >= HttpStatus.HTTP_INTERNAL_ERROR)) {
184179

185180
expirationTimestamp = System.currentTimeMillis() + ThrottlingCache.DEFAULT_THROTTLING_TIME_SEC * 1000;
186181
}

msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/HttpStatus.java

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,26 @@
33

44
package com.microsoft.aad.msal4j;
55

6-
enum HttpStatus {
7-
OK(200, "OK"),
8-
FOUND(302, "Found"),
9-
BAD_REQUEST(400, "Bad Request"),
10-
NOT_FOUND(404, "Not Found"),
11-
REQUEST_TIMEOUT(408, "Request Timeout"),
12-
GONE(410, "Gone"),
13-
TOO_MANY_REQUESTS(429, "Too Many Requests"),
14-
INTERNAL_SERVER_ERROR(500, "Internal Server Error"),
15-
SERVICE_UNAVAILABLE(503, "Service Unavailable"),
16-
GATEWAY_TIMEOUT(504, "Gateway Timeout");
6+
class HttpStatus {
177

18-
private final int code;
19-
private final String description;
8+
static final int HTTP_OK = 200;
9+
static final int HTTP_FOUND = 302;
10+
static final int HTTP_BAD_REQUEST = 400;
11+
static final int HTTP_UNAUTHORIZED = 401;
12+
static final int HTTP_NOT_FOUND = 404;
13+
static final int HTTP_REQUEST_TIMEOUT = 408;
14+
static final int HTTP_GONE = 410;
15+
static final int HTTP_TOO_MANY_REQUESTS = 429;
16+
static final int HTTP_INTERNAL_ERROR = 500;
17+
static final int HTTP_UNAVAILABLE = 503;
18+
static final int HTTP_GATEWAY_TIMEOUT = 504;
2019

21-
HttpStatus(int code, String description) {
22-
this.code = code;
23-
this.description = description;
24-
}
25-
26-
int getCode() {
27-
return code;
28-
}
29-
30-
String getDescription() {
31-
return description;
32-
}
33-
34-
//All 5xx errors
20+
/**
21+
* Determines if the status code represents a server error (5xx).
22+
*
23+
* @param code The HTTP status code
24+
* @return true if the status code is between 500 and 599, inclusive
25+
*/
3526
static boolean isServerError(int code) {
3627
return code >= 500 && code < 600;
3728
}

msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/IMDSRetryPolicy.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ class IMDSRetryPolicy extends ManagedIdentityRetryPolicy {
2323

2424
private static final Set<Integer> RETRYABLE_STATUS_CODES = Collections.unmodifiableSet(
2525
new HashSet<>(Arrays.asList(
26-
HttpStatus.NOT_FOUND.getCode(),
27-
HttpStatus.REQUEST_TIMEOUT.getCode(),
28-
HttpStatus.GONE.getCode(),
29-
HttpStatus.TOO_MANY_REQUESTS.getCode()
26+
HttpStatus.HTTP_NOT_FOUND,
27+
HttpStatus.HTTP_REQUEST_TIMEOUT,
28+
HttpStatus.HTTP_GONE,
29+
HttpStatus.HTTP_TOO_MANY_REQUESTS
3030
))
3131
);
3232

@@ -40,13 +40,13 @@ public boolean isRetryable(IHttpResponse httpResponse) {
4040

4141
@Override
4242
public int getMaxRetryCount(IHttpResponse httpResponse) {
43-
return (httpResponse.statusCode() == HttpStatus.GONE.getCode()) ? LINEAR_RETRY_NUM : EXPONENTIAL_RETRY_NUM;
43+
return (httpResponse.statusCode() == HttpStatus.HTTP_GONE) ? LINEAR_RETRY_NUM : EXPONENTIAL_RETRY_NUM;
4444
}
4545

4646
@Override
4747
public int getRetryDelayMs(IHttpResponse httpResponse) {
4848
// Use exponential backoff for non-410 status codes
49-
if (lastStatusCode == HttpStatus.GONE.getCode()) {
49+
if (lastStatusCode == HttpStatus.HTTP_GONE) {
5050
return currentLinearRetryDelayMs;
5151
} else {
5252
return (int) (Math.pow(2, currentRetryCount) * exponentialLinearRetryDelayMs);

msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/ManagedIdentityRetryPolicy.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ class ManagedIdentityRetryPolicy implements IRetryPolicy {
1919

2020
private static final Set<Integer> RETRYABLE_STATUS_CODES = Collections.unmodifiableSet(
2121
new HashSet<>(Arrays.asList(
22-
HttpStatus.NOT_FOUND.getCode(),
23-
HttpStatus.REQUEST_TIMEOUT.getCode(),
24-
HttpStatus.TOO_MANY_REQUESTS.getCode(),
25-
HttpStatus.INTERNAL_SERVER_ERROR.getCode(),
26-
HttpStatus.SERVICE_UNAVAILABLE.getCode(),
27-
HttpStatus.GATEWAY_TIMEOUT.getCode()
22+
HttpStatus.HTTP_NOT_FOUND,
23+
HttpStatus.HTTP_REQUEST_TIMEOUT,
24+
HttpStatus.HTTP_TOO_MANY_REQUESTS,
25+
HttpStatus.HTTP_INTERNAL_ERROR,
26+
HttpStatus.HTTP_UNAVAILABLE,
27+
HttpStatus.HTTP_GATEWAY_TIMEOUT
2828
))
2929
);
3030

msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/OidcDiscoveryProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ static OidcDiscoveryResponse performOidcDiscovery(OidcAuthority authority, Abstr
1414

1515
OidcDiscoveryResponse response = JsonHelper.convertJsonStringToJsonSerializableObject(httpResponse.body(), OidcDiscoveryResponse::fromJson);
1616

17-
if (httpResponse.statusCode() != HttpHelper.HTTP_STATUS_200) {
17+
if (httpResponse.statusCode() != HttpStatus.HTTP_OK) {
1818
throw MsalServiceExceptionFactory.fromHttpResponse(httpResponse);
1919
}
2020

msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/TokenRequestExecutor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ private AuthenticationResult createAuthenticationResultFromOauthHttpResponse(
167167

168168
} else {
169169
// http codes indicating that STS did not log request
170-
if (oauthHttpResponse.getStatusCode() == HttpHelper.HTTP_STATUS_429 || oauthHttpResponse.getStatusCode() >= HttpHelper.HTTP_STATUS_500) {
170+
if (oauthHttpResponse.getStatusCode() == HttpStatus.HTTP_TOO_MANY_REQUESTS || oauthHttpResponse.getStatusCode() >= HttpStatus.HTTP_INTERNAL_ERROR) {
171171
serviceBundle.getServerSideTelemetry().previousRequests.putAll(
172172
serviceBundle.getServerSideTelemetry().previousRequestInProgress);
173173
}

msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/UserDiscoveryRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static UserDiscoveryResponse execute(
2929
HttpRequest httpRequest = new HttpRequest(HttpMethod.GET, uri, headers);
3030
IHttpResponse response = serviceBundle.getHttpHelper().executeHttpRequest(httpRequest, requestContext, serviceBundle);
3131

32-
if (response.statusCode() != HttpHelper.HTTP_STATUS_200) {
32+
if (response.statusCode() != HttpStatus.HTTP_OK) {
3333
throw MsalServiceExceptionFactory.fromHttpResponse(response);
3434
}
3535

msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/WSTrustRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static WSTrustResponse execute(String url,
5959
HttpRequest httpRequest = new HttpRequest(HttpMethod.GET, url);
6060
IHttpResponse mexResponse = serviceBundle.getHttpHelper().executeHttpRequest(httpRequest, requestContext, serviceBundle);
6161

62-
if (mexResponse.statusCode() != HttpHelper.HTTP_STATUS_200 || StringHelper.isBlank(mexResponse.body())) {
62+
if (mexResponse.statusCode() != HttpStatus.HTTP_OK || StringHelper.isBlank(mexResponse.body())) {
6363
throw MsalServiceExceptionFactory.fromHttpResponse(mexResponse);
6464
}
6565

msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/AcquireTokenSilentlyTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ void testTokenRefreshReasons() throws Exception {
137137
responseParameters.put("access_token", "expiredToken");
138138
responseParameters.put("id_token", TestHelper.createIdToken(new HashMap<>()));
139139
responseParameters.put("expires_in", "0");
140-
TestHelper.createTokenRequestMock(httpClientMock, TestHelper.getSuccessfulTokenResponse(responseParameters), 200);
140+
TestHelper.createTokenRequestMock(httpClientMock, TestHelper.getSuccessfulTokenResponse(responseParameters), HttpStatus.HTTP_OK);
141141

142142
OnBehalfOfParameters parameters = OnBehalfOfParameters.builder(Collections.singleton("someScopes"), new UserAssertion(TestHelper.signedAssertion)).build();
143143
IAuthenticationResult result = cca.acquireToken(parameters).get();
@@ -149,7 +149,7 @@ void testTokenRefreshReasons() throws Exception {
149149
// In this test, it will be replaced with a token that expires in 1 minute
150150
responseParameters.put("access_token", "nearlyExpiredToken");
151151
responseParameters.put("expires_in", "60");
152-
TestHelper.createTokenRequestMock(httpClientMock, TestHelper.getSuccessfulTokenResponse(responseParameters), 200);
152+
TestHelper.createTokenRequestMock(httpClientMock, TestHelper.getSuccessfulTokenResponse(responseParameters), HttpStatus.HTTP_OK);
153153

154154
SilentParameters silentParameters = SilentParameters.builder(Collections.singleton("someScopes"), result.account()).build();
155155
result = cca.acquireTokenSilently(silentParameters).get();
@@ -162,7 +162,7 @@ void testTokenRefreshReasons() throws Exception {
162162
responseParameters.put("access_token", "refreshInToken");
163163
responseParameters.put("expires_in", "3600");
164164
responseParameters.put("refresh_in", "1");
165-
TestHelper.createTokenRequestMock(httpClientMock, TestHelper.getSuccessfulTokenResponse(responseParameters), 200);
165+
TestHelper.createTokenRequestMock(httpClientMock, TestHelper.getSuccessfulTokenResponse(responseParameters), HttpStatus.HTTP_OK);
166166

167167
silentParameters = SilentParameters.builder(Collections.singleton("someScopes"), result.account()).build();
168168
result = cca.acquireTokenSilently(silentParameters).get();
@@ -174,7 +174,7 @@ void testTokenRefreshReasons() throws Exception {
174174
responseParameters.put("access_token", "normalToken");
175175
responseParameters.put("expires_in", "3600");
176176
responseParameters.put("refresh_in", "0");
177-
TestHelper.createTokenRequestMock(httpClientMock, TestHelper.getSuccessfulTokenResponse(responseParameters), 200);
177+
TestHelper.createTokenRequestMock(httpClientMock, TestHelper.getSuccessfulTokenResponse(responseParameters), HttpStatus.HTTP_OK);
178178

179179
//refresh_in values are in seconds, so we must wait to guarantee it is past the proactive refresh time
180180
TimeUnit.SECONDS.sleep(2);
@@ -186,7 +186,7 @@ void testTokenRefreshReasons() throws Exception {
186186

187187
//Force the token to be refreshed
188188
responseParameters.put("access_token", "forcedRefreshToken");
189-
TestHelper.createTokenRequestMock(httpClientMock, TestHelper.getSuccessfulTokenResponse(responseParameters), 200);
189+
TestHelper.createTokenRequestMock(httpClientMock, TestHelper.getSuccessfulTokenResponse(responseParameters), HttpStatus.HTTP_OK);
190190

191191
silentParameters = SilentParameters.builder(Collections.singleton("someScopes"), result.account()).forceRefresh(true).build();
192192
result = cca.acquireTokenSilently(silentParameters).get();
@@ -195,7 +195,7 @@ void testTokenRefreshReasons() throws Exception {
195195

196196
//Finally, force a refresh by setting claims
197197
responseParameters.put("access_token", "claimsToken");
198-
TestHelper.createTokenRequestMock(httpClientMock, TestHelper.getSuccessfulTokenResponse(responseParameters), 200);
198+
TestHelper.createTokenRequestMock(httpClientMock, TestHelper.getSuccessfulTokenResponse(responseParameters), HttpStatus.HTTP_OK);
199199

200200
silentParameters = SilentParameters.builder(Collections.singleton("someScopes"), result.account()).claims(new ClaimsRequest()).build();
201201
result = cca.acquireTokenSilently(silentParameters).get();

msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/CacheFormatTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public void tokenCacheEntitiesFormatTest(String folder) throws URISyntaxExceptio
158158

159159
doReturn(msalOAuthHttpRequest).when(request).createOauthHttpRequest();
160160
doReturn(httpResponse).when(msalOAuthHttpRequest).send();
161-
doReturn(200).when(httpResponse).getStatusCode();
161+
doReturn(HttpStatus.HTTP_OK).when(httpResponse).getStatusCode();
162162
doReturn(JSONObjectUtils.parse(tokenResponse)).when(httpResponse).getContentAsJSONObject();
163163

164164
final AuthenticationResult result = request.executeTokenRequest();

msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/CacheTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void cacheLookup_MixAccountBasedAndAssertionBasedSilentFlows() throws Exception
3535
responseParameters.put("access_token", "accessTokenNoAccount");
3636

3737
ClientCredentialParameters clientCredentialParameters = ClientCredentialParameters.builder(Collections.singleton("someScopes")).build();
38-
when(httpClientMock.send(any(HttpRequest.class))).thenReturn(TestHelper.expectedResponse(200, TestHelper.getSuccessfulTokenResponse(responseParameters)));
38+
when(httpClientMock.send(any(HttpRequest.class))).thenReturn(TestHelper.expectedResponse(HttpStatus.HTTP_OK, TestHelper.getSuccessfulTokenResponse(responseParameters)));
3939
IAuthenticationResult resultNoAccount = cca.acquireToken(clientCredentialParameters).get();
4040

4141
//Ensure there is one token in the cache, and the result had no account
@@ -47,7 +47,7 @@ void cacheLookup_MixAccountBasedAndAssertionBasedSilentFlows() throws Exception
4747
responseParameters.put("access_token", "accessTokenWithAccount");
4848
responseParameters.put("id_token", TestHelper.createIdToken(new HashMap<>()));
4949

50-
when(httpClientMock.send(any(HttpRequest.class))).thenReturn(TestHelper.expectedResponse(200, TestHelper.getSuccessfulTokenResponse(responseParameters)));
50+
when(httpClientMock.send(any(HttpRequest.class))).thenReturn(TestHelper.expectedResponse(HttpStatus.HTTP_OK, TestHelper.getSuccessfulTokenResponse(responseParameters)));
5151
OnBehalfOfParameters onBehalfOfParametersarameters = OnBehalfOfParameters.builder(Collections.singleton("someOtherScopes"), new UserAssertion(TestHelper.signedAssertion)).build();
5252
IAuthenticationResult resultWithAccount = cca.acquireToken(onBehalfOfParametersarameters).get();
5353

msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/ClientCertificateTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ void testIClientCertificateInterface_CredentialFactoryUsesSha256() throws Except
7676
if (request.body().contains(((PrivateKeyJWT) cca.clientAuthentication()).getClientAssertion().serialize())
7777
&& headerParams.contains("x5t#S256")) {
7878

79-
return TestHelper.expectedResponse(200, TestHelper.getSuccessfulTokenResponse(tokenResponseValues));
79+
return TestHelper.expectedResponse(HttpStatus.HTTP_OK, TestHelper.getSuccessfulTokenResponse(tokenResponseValues));
8080
}
8181
return null;
8282
});

msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/ClientCredentialTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void testSecretNullAndEmpty() {
4747
void OnBehalfOf_InternalCacheLookup_Success() throws Exception {
4848
DefaultHttpClient httpClientMock = mock(DefaultHttpClient.class);
4949

50-
when(httpClientMock.send(any(HttpRequest.class))).thenReturn(TestHelper.expectedResponse(200, TestHelper.getSuccessfulTokenResponse(new HashMap<>())));
50+
when(httpClientMock.send(any(HttpRequest.class))).thenReturn(TestHelper.expectedResponse(HttpStatus.HTTP_OK, TestHelper.getSuccessfulTokenResponse(new HashMap<>())));
5151

5252
ConfidentialClientApplication cca =
5353
ConfidentialClientApplication.builder("clientId", ClientCredentialFactory.createFromSecret("password"))
@@ -82,7 +82,7 @@ void OnBehalfOf_TenantOverride() throws Exception {
8282
HashMap<String, String> tokenResponseValues = new HashMap<>();
8383
tokenResponseValues.put("access_token", "accessTokenFirstCall");
8484

85-
when(httpClientMock.send(any(HttpRequest.class))).thenReturn(TestHelper.expectedResponse(200, TestHelper.getSuccessfulTokenResponse(tokenResponseValues)));
85+
when(httpClientMock.send(any(HttpRequest.class))).thenReturn(TestHelper.expectedResponse(HttpStatus.HTTP_OK, TestHelper.getSuccessfulTokenResponse(tokenResponseValues)));
8686
ClientCredentialParameters parameters = ClientCredentialParameters.builder(Collections.singleton("scopes")).build();
8787

8888
//The two acquireToken calls have the same parameters...
@@ -95,7 +95,7 @@ void OnBehalfOf_TenantOverride() throws Exception {
9595

9696
tokenResponseValues.put("access_token", "accessTokenSecondCall");
9797

98-
when(httpClientMock.send(any(HttpRequest.class))).thenReturn(TestHelper.expectedResponse(200, TestHelper.getSuccessfulTokenResponse(tokenResponseValues)));
98+
when(httpClientMock.send(any(HttpRequest.class))).thenReturn(TestHelper.expectedResponse(HttpStatus.HTTP_OK, TestHelper.getSuccessfulTokenResponse(tokenResponseValues)));
9999
parameters = ClientCredentialParameters.builder(Collections.singleton("scopes")).tenant("otherTenant").build();
100100

101101
//Overriding the tenant parameter in the request should lead to a new token call being made...

0 commit comments

Comments
 (0)