From 5591323259856fe1bf4b089e8f3884e9d08b5f74 Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Thu, 23 Nov 2017 15:48:30 +0100 Subject: [PATCH] allow '-' in email aliases --- .../src/de/hsadmin/mods/email/EMailAlias.java | 2 +- .../validate/EMailAliasValidationTest.java | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 hsarback/test/de/hsadmin/validate/EMailAliasValidationTest.java diff --git a/hsarback/src/de/hsadmin/mods/email/EMailAlias.java b/hsarback/src/de/hsadmin/mods/email/EMailAlias.java index ba274c3..f7c3fef 100644 --- a/hsarback/src/de/hsadmin/mods/email/EMailAlias.java +++ b/hsarback/src/de/hsadmin/mods/email/EMailAlias.java @@ -48,7 +48,7 @@ public class EMailAlias extends AbstractEntity implements Serializable { @AnnFieldIO(validation="[a-z0-9]*", rw=ReadWriteAccess.READONLY) private Pac pac; - @AnnFieldIO(validation="[a-z0-9]{5}(-[a-z0-9\\.\\_]{1,})?", rw=ReadWriteAccess.WRITEONCE) + @AnnFieldIO(validation="[a-z0-9]{5}(-[a-z0-9\\.\\_\\-]{1,})?", rw=ReadWriteAccess.WRITEONCE) @Column(updatable=false) private String name; diff --git a/hsarback/test/de/hsadmin/validate/EMailAliasValidationTest.java b/hsarback/test/de/hsadmin/validate/EMailAliasValidationTest.java new file mode 100644 index 0000000..34489e0 --- /dev/null +++ b/hsarback/test/de/hsadmin/validate/EMailAliasValidationTest.java @@ -0,0 +1,32 @@ +package de.hsadmin.validate; + +import java.util.regex.Pattern; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class EMailAliasValidationTest { + + private Pattern pattern; + + @Before + public void setUp() throws Exception { + pattern = Pattern.compile("[a-z0-9]{5}(-[a-z0-9\\.\\_\\-]{1,})?"); + } + + @Test + public void test() { + Assert.assertTrue("xyz00-a.b", pattern.matcher("xyz00-a.b").matches()); + Assert.assertTrue("xyz00-a-b", pattern.matcher("xyz00-a-b").matches()); + Assert.assertTrue("xyz00--b", pattern.matcher("xyz00-a-b").matches()); + Assert.assertTrue("xyz00-a-", pattern.matcher("xyz00-a-b").matches()); + Assert.assertFalse("xyz00-a.B", pattern.matcher("xyz00-a.B").matches()); + Assert.assertFalse("xyz00-", pattern.matcher("xyz00-").matches()); + Assert.assertTrue("xyz00", pattern.matcher("xyz00").matches()); + Assert.assertFalse("xyz0", pattern.matcher("xyz0").matches()); + Assert.assertFalse("xyz00_a", pattern.matcher("xyz00_a").matches()); + Assert.assertFalse("xyz00-a.b:c", pattern.matcher("xyz00-a.b:c").matches()); + } + +}