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: handle malformed backend responses for PolicyTag messages #522

Merged
merged 1 commit into from Jul 10, 2020
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 @@ -60,6 +60,10 @@ com.google.api.services.bigquery.model.TableFieldSchema.PolicyTags toPb() {

static PolicyTags fromPb(
com.google.api.services.bigquery.model.TableFieldSchema.PolicyTags tagPb) {
return newBuilder().setNames(tagPb.getNames()).build();
// Treat a PolicyTag message without a Names subfield as invalid.
if (tagPb.getNames() != null) {
return newBuilder().setNames(tagPb.getNames()).build();
}
return null;
}
}
Expand Up @@ -18,6 +18,7 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNull;

import com.google.common.collect.ImmutableList;
import java.util.List;
Expand Down Expand Up @@ -46,6 +47,13 @@ public void testBuilder() {
assertNotEquals(POLICY_TAGS, POLICIES);
}

@Test
public void testWithoutNames() {
com.google.api.services.bigquery.model.TableFieldSchema.PolicyTags PARTIALTAG =
new com.google.api.services.bigquery.model.TableFieldSchema.PolicyTags();
assertNull(PolicyTags.fromPb(PARTIALTAG));
}

@Test
public void testFromAndPb() {
assertEquals(POLICY_TAGS, PolicyTags.fromPb(POLICY_TAGS.toPb()));
Expand Down