diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b34a4721..07f8b7ad0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## [3.10.3] - 2022-04-16 +### Fixes +* Potential exception when `set_ugi` has immutable list or null-value groups argument. + ## [3.10.2] - 2022-04-19 ### Changed * Caching `set_ugi` call in clients to prevent unnecessary calls to metastores. diff --git a/waggle-dance-core/src/main/java/com/hotels/bdp/waggledance/client/HiveUgiArgs.java b/waggle-dance-core/src/main/java/com/hotels/bdp/waggledance/client/HiveUgiArgs.java index 4e7bffcc5..e891e5af8 100644 --- a/waggle-dance-core/src/main/java/com/hotels/bdp/waggledance/client/HiveUgiArgs.java +++ b/waggle-dance-core/src/main/java/com/hotels/bdp/waggledance/client/HiveUgiArgs.java @@ -15,19 +15,23 @@ */ package com.hotels.bdp.waggledance.client; -import java.util.Collections; +import java.util.ArrayList; import java.util.List; public class HiveUgiArgs { - public static final HiveUgiArgs WAGGLE_DANCE_DEFAULT = new HiveUgiArgs("waggledance", Collections.emptyList()); + public static final HiveUgiArgs WAGGLE_DANCE_DEFAULT = new HiveUgiArgs("waggledance", null); private final String user; private final List groups; public HiveUgiArgs(String user, List groups) { this.user = user; - this.groups = groups; + if (groups == null) { + this.groups = new ArrayList<>(); + } else { + this.groups = new ArrayList<>(groups); + } } public String getUser() { diff --git a/waggle-dance-core/src/test/java/com/hotels/bdp/waggledance/client/HiveUgiArgsTest.java b/waggle-dance-core/src/test/java/com/hotels/bdp/waggledance/client/HiveUgiArgsTest.java new file mode 100644 index 000000000..93ea3c750 --- /dev/null +++ b/waggle-dance-core/src/test/java/com/hotels/bdp/waggledance/client/HiveUgiArgsTest.java @@ -0,0 +1,49 @@ +package com.hotels.bdp.waggledance.client; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Collections; + +import org.junit.Test; + +public class HiveUgiArgsTest { + + @Test + public void groups() throws Exception { + HiveUgiArgs args = new HiveUgiArgs("user", new ArrayList<>()); + assertThat("user", is(args.getUser())); + asssertThatListIsMutatable(args); + } + + private void asssertThatListIsMutatable(HiveUgiArgs args) { + assertThat(args.getGroups().size(), is(0)); + // List should be mutable, Hive code potentially mutates it. + args.getGroups().add("user"); + assertThat(args.getGroups().size(), is(1)); + } + + @Test + public void groupDefaults() throws Exception { + HiveUgiArgs args = HiveUgiArgs.WAGGLE_DANCE_DEFAULT; + assertThat("waggledance", is(args.getUser())); + asssertThatListIsMutatable(args); + } + + @Test + public void groupsImmutable() throws Exception { + HiveUgiArgs args = new HiveUgiArgs("user", Collections.emptyList()); + assertThat("user", is(args.getUser())); + asssertThatListIsMutatable(args); + } + + @Test + public void groupsNull() throws Exception { + HiveUgiArgs args = new HiveUgiArgs("user", null); + assertThat("user", is(args.getUser())); + assertTrue(args.getGroups().isEmpty()); + } + +}