mirror of
https://github.com/datahub-project/datahub.git
synced 2025-12-25 08:58:26 +00:00
Allow dashes in user urn (#1564)
* Fix: allow user/group urns to contain dashes CorpUser urns containing dashes are valid entries. When adding that user as an owner, the MAE job validates the owner's urn using a regex filter that only accepts alphanumeric characters and underscore (\w). That means any ownership changes where the user urn contains an underscore are rejected. This change extends the regex filter to allow dashes in the name. It includes unit tests that verify the change works for multiple dashes and underscores. There are other cases to consider: 1. Should any other characters be allowed? 2. Should the filter check the urn starts and ends with alphanumeric characters? CLOSES: User urn does not handle dashes consistently #1554 BREAKING CHANGE: None. This change relaxes a restriction so existing code is ok. * Added tests for group members and fixed assertion
This commit is contained in:
parent
eab97f7c7b
commit
d09cedca28
@ -8,7 +8,7 @@ public final class CorpGroupUrn extends Urn {
|
||||
|
||||
public static final String ENTITY_TYPE = "corpGroup";
|
||||
|
||||
private static final Pattern URN_PATTERN = Pattern.compile("^" + URN_PREFIX + ENTITY_TYPE + ":(\\w+)$");
|
||||
private static final Pattern URN_PATTERN = Pattern.compile("^" + URN_PREFIX + ENTITY_TYPE + ":([\\-\\w]+)$");
|
||||
|
||||
private final String groupNameEntity;
|
||||
|
||||
|
||||
@ -4,11 +4,12 @@ import java.net.URISyntaxException;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
||||
public final class CorpuserUrn extends Urn {
|
||||
|
||||
public static final String ENTITY_TYPE = "corpuser";
|
||||
|
||||
private static final Pattern URN_PATTERN = Pattern.compile("^" + URN_PREFIX + ENTITY_TYPE + ":(\\w+)$");
|
||||
private static final Pattern URN_PATTERN = Pattern.compile("^" + URN_PREFIX + ENTITY_TYPE + ":([\\-\\w]+)$");
|
||||
|
||||
private final String usernameEntity;
|
||||
|
||||
|
||||
@ -24,9 +24,13 @@ public class BuilderUtilsTest {
|
||||
Owner owner1 = new Owner().setOwner(new CorpuserUrn("t1"));
|
||||
Owner owner2 = new Owner().setOwner(new CorpuserUrn("t2"));
|
||||
Owner owner3 = new Owner().setOwner(new CorpGroupUrn("t3"));
|
||||
List<Owner> owners = Arrays.asList(owner1, owner2, owner3);
|
||||
Owner owner4 = new Owner().setOwner(new CorpuserUrn("t-4-t"));
|
||||
Owner owner5 = new Owner().setOwner(new CorpuserUrn("t_5_t"));
|
||||
Owner owner6 = new Owner().setOwner(new CorpGroupUrn("t-6-t_group"));
|
||||
Owner owner7 = new Owner().setOwner(new CorpGroupUrn("t_7_t_group"));
|
||||
List<Owner> owners = Arrays.asList(owner1, owner2, owner3, owner4, owner5, owner6, owner7);
|
||||
ownership.setOwners(new OwnerArray(owners));
|
||||
assertEquals(BuilderUtils.getCorpUserOwners(ownership), Arrays.asList("t1", "t2"));
|
||||
assertEquals(BuilderUtils.getCorpUserOwners(ownership), Arrays.asList("t1", "t2", "t-4-t", "t_5_t"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user