use of com.dropbox.core.InvalidAccessTokenException in project dropbox-sdk-java by dropbox.
the class DbxRefreshTest method testMissingScope.
@Test
public void testMissingScope() throws Exception {
Long now = System.currentTimeMillis();
ByteArrayInputStream responseStream = new ByteArrayInputStream(("{" + "\"error_summary\":\"missing_scope/.\" ,\"error\":{\".tag\": \"missing_scope\", \"required_scope\": \"account.info.read\"}" + "}").getBytes("UTF-8"));
HttpRequestor.Response finishResponse = new HttpRequestor.Response(401, responseStream, new HashMap<String, List<String>>());
// Mock requester and uploader
HttpRequestor.Uploader mockUploader = mock(HttpRequestor.Uploader.class);
DbxRequestConfig mockConfig = setupMockRequestConfig(finishResponse, mockUploader);
DbxCredential credential = new DbxCredential(NEW_TOKEN, now + 2 * DbxCredential.EXPIRE_MARGIN, REFRESH_TOKEN, APP.getKey(), APP.getSecret());
DbxClientV2 client = new DbxClientV2(mockConfig, credential);
try {
client.users().getCurrentAccount();
fail("Should raise exception before reaching here");
} catch (InvalidAccessTokenException ex) {
assertThat(ex.getAuthError().isMissingScope()).isTrue();
String missingScope = ex.getAuthError().getMissingScopeValue().getRequiredScope();
assertWithMessage("expect account.info.read, get " + missingScope).that("account.info.read").isEqualTo(missingScope);
}
}
Aggregations