Search in sources :

Example 1 with InvalidAccessTokenException

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);
    }
}
Also used : HttpRequestor(com.dropbox.core.http.HttpRequestor) Matchers.anyString(org.mockito.Matchers.anyString) DbxClientV2(com.dropbox.core.v2.DbxClientV2) InvalidAccessTokenException(com.dropbox.core.InvalidAccessTokenException) DbxRequestConfig(com.dropbox.core.DbxRequestConfig) ByteArrayInputStream(java.io.ByteArrayInputStream) List(java.util.List) Test(org.testng.annotations.Test)

Aggregations

DbxRequestConfig (com.dropbox.core.DbxRequestConfig)1 InvalidAccessTokenException (com.dropbox.core.InvalidAccessTokenException)1 HttpRequestor (com.dropbox.core.http.HttpRequestor)1 DbxClientV2 (com.dropbox.core.v2.DbxClientV2)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 List (java.util.List)1 Matchers.anyString (org.mockito.Matchers.anyString)1 Test (org.testng.annotations.Test)1