Skip to content

Commit c50a10f

Browse files
committed
Add unit test for STS request/response.
1 parent 5633cc1 commit c50a10f

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

oauth2_http/javatests/com/google/auth/oauth2/MockStsTransport.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,14 @@ public final class MockStsTransport extends MockHttpTransport {
6565
private static final String ACCESS_TOKEN = "accessToken";
6666
private static final String TOKEN_TYPE = "Bearer";
6767
private static final Long EXPIRES_IN = 3600L;
68+
private static final String ACCESS_BOUNDARY_SESSION_KEY = "accessBoundarySessionKey";
6869

6970
private final Queue<IOException> responseErrorSequence = new ArrayDeque<>();
7071
private final Queue<List<String>> scopeSequence = new ArrayDeque<>();
7172
private final Queue<String> refreshTokenSequence = new ArrayDeque<>();
7273

7374
private boolean returnExpiresIn = true;
75+
private boolean returnAccessBoundarySessionKey = false;
7476
private MockLowLevelHttpRequest request;
7577

7678
public void addResponseErrorSequence(IOException... errors) {
@@ -133,6 +135,11 @@ public LowLevelHttpResponse execute() throws IOException {
133135
response.put("refresh_token", refreshTokenSequence.poll());
134136
}
135137
}
138+
139+
if (returnAccessBoundarySessionKey) {
140+
response.put("access_boundary_session_key", ACCESS_BOUNDARY_SESSION_KEY);
141+
}
142+
136143
return new MockLowLevelHttpResponse()
137144
.setContentType(Json.MEDIA_TYPE)
138145
.setContent(response.toPrettyString());
@@ -169,7 +176,15 @@ public Long getExpiresIn() {
169176
return EXPIRES_IN;
170177
}
171178

179+
public String getAccessBoundarySessionKey() {
180+
return ACCESS_BOUNDARY_SESSION_KEY;
181+
}
182+
172183
public void setReturnExpiresIn(boolean returnExpiresIn) {
173184
this.returnExpiresIn = returnExpiresIn;
174185
}
186+
187+
public void setReturnAccessBoundarySessionKey(boolean returnAccessBoundarySessionKey) {
188+
this.returnAccessBoundarySessionKey = returnAccessBoundarySessionKey;
189+
}
175190
}

oauth2_http/javatests/com/google/auth/oauth2/StsRequestHandlerTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,4 +275,23 @@ public void exchangeToken_noExpiresInReturned() throws IOException {
275275
assertEquals(transport.getIssuedTokenType(), response.getIssuedTokenType());
276276
assertNull(response.getExpiresInSeconds());
277277
}
278+
279+
@Test
280+
public void exchangeToken_withAccessBoundarySessionKey() throws IOException {
281+
transport.setReturnAccessBoundarySessionKey(/* returnAccessBoundarySessionKey= */ true);
282+
283+
StsTokenExchangeRequest stsTokenExchangeRequest =
284+
StsTokenExchangeRequest.newBuilder("credential", "subjectTokenType")
285+
.build();
286+
287+
StsRequestHandler requestHandler =
288+
StsRequestHandler.newBuilder(
289+
TOKEN_URL, stsTokenExchangeRequest, transport.createRequestFactory())
290+
.build();
291+
292+
StsTokenExchangeResponse response = requestHandler.exchangeToken();
293+
294+
// Validate response.
295+
assertEquals(transport.getAccessBoundarySessionKey(), response.getAccessBoundarySessionKey());
296+
}
278297
}

0 commit comments

Comments
 (0)