|
@@ -19,13 +19,18 @@
|
|
|
package org.apache.hadoop.lib.wsrs;
|
|
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
+import static org.junit.Assert.assertNotNull;
|
|
|
import static org.junit.Assert.assertNull;
|
|
|
|
|
|
import java.security.Principal;
|
|
|
|
|
|
import javax.ws.rs.core.MultivaluedMap;
|
|
|
|
|
|
+import org.apache.hadoop.test.TestException;
|
|
|
+import org.apache.hadoop.test.TestExceptionHelper;
|
|
|
+import org.junit.Rule;
|
|
|
import org.junit.Test;
|
|
|
+import org.junit.rules.MethodRule;
|
|
|
import org.mockito.Mockito;
|
|
|
import org.slf4j.MDC;
|
|
|
|
|
@@ -35,6 +40,9 @@ import com.sun.jersey.core.spi.component.ComponentScope;
|
|
|
|
|
|
public class TestUserProvider {
|
|
|
|
|
|
+ @Rule
|
|
|
+ public MethodRule exceptionHelper = new TestExceptionHelper();
|
|
|
+
|
|
|
@Test
|
|
|
@SuppressWarnings("unchecked")
|
|
|
public void noUser() {
|
|
@@ -92,4 +100,51 @@ public class TestUserProvider {
|
|
|
assertEquals(up.getInjectable(null, null, Principal.class), up);
|
|
|
assertNull(up.getInjectable(null, null, String.class));
|
|
|
}
|
|
|
+
|
|
|
+ @Test
|
|
|
+ @TestException(exception = IllegalArgumentException.class)
|
|
|
+ public void userNameEmpty() {
|
|
|
+ UserProvider.UserParam userParam = new UserProvider.UserParam("username");
|
|
|
+ userParam.parseParam("");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ @TestException(exception = IllegalArgumentException.class)
|
|
|
+ public void userNameTooLong() {
|
|
|
+ UserProvider.UserParam userParam = new UserProvider.UserParam("username");
|
|
|
+ userParam.parseParam("a123456789012345678901234567890x");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ @TestException(exception = IllegalArgumentException.class)
|
|
|
+ public void userNameInvalidStart() {
|
|
|
+ UserProvider.UserParam userParam = new UserProvider.UserParam("username");
|
|
|
+ userParam.parseParam("1x");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ @TestException(exception = IllegalArgumentException.class)
|
|
|
+ public void userNameInvalidDollarSign() {
|
|
|
+ UserProvider.UserParam userParam = new UserProvider.UserParam("username");
|
|
|
+ userParam.parseParam("1$x");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void userNameMinLength() {
|
|
|
+ UserProvider.UserParam userParam = new UserProvider.UserParam("username");
|
|
|
+ assertNotNull(userParam.parseParam("a"));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void userNameMaxLength() {
|
|
|
+ UserProvider.UserParam userParam = new UserProvider.UserParam("username");
|
|
|
+ assertNotNull(userParam.parseParam("a123456789012345678901234567890"));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void userNameValidDollarSign() {
|
|
|
+ UserProvider.UserParam userParam = new UserProvider.UserParam("username");
|
|
|
+ assertNotNull(userParam.parseParam("a$"));
|
|
|
+ }
|
|
|
+
|
|
|
}
|