Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not throw NPE from BigQueryImpl.testIamPermissions #1596

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -1495,7 +1495,9 @@ public com.google.api.services.bigquery.model.TestIamPermissionsResponse call()
getOptions().getRetrySettings(),
EXCEPTION_HANDLER,
getOptions().getClock());
return ImmutableList.copyOf(response.getPermissions());
return response.getPermissions() == null
? ImmutableList.of()
: ImmutableList.copyOf(response.getPermissions());
} catch (RetryHelperException e) {
throw BigQueryException.translateAndThrow(e);
}
Expand Down
Expand Up @@ -2766,4 +2766,21 @@ public void testTestIamPermissions() {
assertEquals(perms, grantedPermissions);
verify(bigqueryRpcMock).testIamPermissions(resourceId, checkedPermissions, EMPTY_RPC_OPTIONS);
}

@Test
public void testTestIamPermissionsWhenNoPermissionsGranted() {
final String resourceId =
String.format("projects/%s/datasets/%s/tables/%s", PROJECT, DATASET, TABLE);
final List<String> checkedPermissions = ImmutableList.<String>of("foo", "bar", "baz");
// If caller has no permissions, TestIamPermissionsResponse.permissions will be null
final com.google.api.services.bigquery.model.TestIamPermissionsResponse response =
new com.google.api.services.bigquery.model.TestIamPermissionsResponse()
.setPermissions(null);
when(bigqueryRpcMock.testIamPermissions(resourceId, checkedPermissions, EMPTY_RPC_OPTIONS))
.thenReturn(response);
bigquery = options.getService();
List<String> perms = bigquery.testIamPermissions(TABLE_ID, checkedPermissions);
assertEquals(perms, ImmutableList.of());
verify(bigqueryRpcMock).testIamPermissions(resourceId, checkedPermissions, EMPTY_RPC_OPTIONS);
}
}