You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by fm...@apache.org on 2009/02/27 10:27:08 UTC

svn commit: r748459 - /incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/

Author: fmeschbe
Date: Fri Feb 27 09:27:07 2009
New Revision: 748459

URL: http://svn.apache.org/viewvc?rev=748459&view=rev
Log:
SLING-875 integration tests for jackrabbit user management

Added:
    incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/
    incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/AbstractUserManagerTest.java   (with props)
    incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/CreateGroupTest.java   (with props)
    incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/CreateUserTest.java   (with props)
    incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/RemoveAuthorizablesTest.java   (with props)
    incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/UpdateGroupTest.java   (with props)
    incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/UpdateUserTest.java   (with props)

Added: incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/AbstractUserManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/AbstractUserManagerTest.java?rev=748459&view=auto
==============================================================================
--- incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/AbstractUserManagerTest.java (added)
+++ incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/AbstractUserManagerTest.java Fri Feb 27 09:27:07 2009
@@ -0,0 +1,184 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.launchpad.webapp.integrationtest.userManager;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.httpclient.Credentials;
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.NameValuePair;
+import org.apache.commons.httpclient.UsernamePasswordCredentials;
+import org.apache.commons.httpclient.auth.AuthScope;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.sling.commons.testing.integration.HttpTestBase;
+
+/**
+ * Base class for UserManager tests.
+ */
+public abstract class AbstractUserManagerTest extends HttpTestBase {
+	
+    /** Execute a POST request and check status */
+    protected void assertAuthenticatedAdminPostStatus(String url, int expectedStatusCode, List<NameValuePair> postParams, String assertMessage)
+    throws IOException {
+        Credentials defaultcreds = new UsernamePasswordCredentials("admin", "admin");
+        assertAuthenticatedPostStatus(defaultcreds, url, expectedStatusCode, postParams, assertMessage);
+    }
+
+    /** Execute a POST request and check status */
+    protected void assertAuthenticatedPostStatus(Credentials creds, String url, int expectedStatusCode, List<NameValuePair> postParams, String assertMessage)
+    throws IOException {
+        final PostMethod post = new PostMethod(url);
+        post.setFollowRedirects(false);
+        
+        URL baseUrl = new URL(HTTP_BASE_URL);
+        AuthScope authScope = new AuthScope(baseUrl.getHost(), baseUrl.getPort(), AuthScope.ANY_REALM);
+        post.setDoAuthentication(true);
+        try {
+			httpClient.getState().setCredentials(authScope, creds);
+	        
+	        if(postParams!=null) {
+	            final NameValuePair [] nvp = {};
+	            post.setRequestBody(postParams.toArray(nvp));
+	        }
+	
+	        final int status = httpClient.executeMethod(post);
+	        if(assertMessage == null) {
+	            assertEquals(expectedStatusCode, status);
+	        } else {
+	            assertEquals(assertMessage, expectedStatusCode, status);
+	        }
+        } finally {
+        	httpClient.getState().setCredentials(authScope, null);
+        }
+    }
+
+    /** Verify that given URL returns expectedStatusCode
+     * @throws IOException */
+    protected void assertAuthenticatedHttpStatus(Credentials creds, String urlString, int expectedStatusCode, String assertMessage) throws IOException {
+        URL baseUrl = new URL(HTTP_BASE_URL);
+        AuthScope authScope = new AuthScope(baseUrl.getHost(), baseUrl.getPort(), AuthScope.ANY_REALM);
+        GetMethod getMethod = new GetMethod(urlString);
+        getMethod.setDoAuthentication(true);
+    	try {
+			httpClient.getState().setCredentials(authScope, creds);
+
+			final int status = httpClient.executeMethod(getMethod);
+            if(assertMessage == null) {
+                assertEquals(urlString,expectedStatusCode, status);
+            } else {
+                assertEquals(assertMessage, expectedStatusCode, status);
+            }
+    	} finally {
+        	httpClient.getState().setCredentials(authScope, null);
+    	}
+    }
+
+    
+    /** retrieve the contents of given URL and assert its content type
+     * @param expectedContentType use CONTENT_TYPE_DONTCARE if must not be checked 
+     * @throws IOException
+     * @throws HttpException */
+    protected String getAuthenticatedContent(Credentials creds, String url, String expectedContentType, List<NameValuePair> params, int expectedStatusCode) throws IOException {
+        final GetMethod get = new GetMethod(url);
+
+        URL baseUrl = new URL(HTTP_BASE_URL);
+        AuthScope authScope = new AuthScope(baseUrl.getHost(), baseUrl.getPort(), AuthScope.ANY_REALM);
+        get.setDoAuthentication(true);
+    	try {
+			httpClient.getState().setCredentials(authScope, creds);
+			
+	        if(params != null) {
+	            final NameValuePair [] nvp = new NameValuePair[0];
+	            get.setQueryString(params.toArray(nvp));
+	        }
+	        final int status = httpClient.executeMethod(get);
+	        final InputStream is = get.getResponseBodyAsStream();
+	        final StringBuffer content = new StringBuffer();
+	        final String charset = get.getResponseCharSet();
+	        final byte [] buffer = new byte[16384];
+	        int n = 0;
+	        while( (n = is.read(buffer, 0, buffer.length)) > 0) {
+	            content.append(new String(buffer, 0, n, charset));
+	        }
+	        assertEquals("Expected status " + expectedStatusCode + " for " + url + " (content=" + content + ")",
+	                expectedStatusCode,status);
+	        final Header h = get.getResponseHeader("Content-Type");
+	        if(expectedContentType == null) {
+	            if(h!=null) {
+	                fail("Expected null Content-Type, got " + h.getValue());
+	            }
+	        } else if(CONTENT_TYPE_DONTCARE.equals(expectedContentType)) {
+	            // no check
+	        } else if(h==null) {
+	            fail(
+	                    "Expected Content-Type that starts with '" + expectedContentType
+	                    +" but got no Content-Type header at " + url
+	            );
+	        } else {
+	            assertTrue(
+	                "Expected Content-Type that starts with '" + expectedContentType
+	                + "' for " + url + ", got '" + h.getValue() + "'",
+	                h.getValue().startsWith(expectedContentType)
+	            );
+	        }
+	        return content.toString();
+			
+    	} finally {
+        	httpClient.getState().setCredentials(authScope, null);
+    	}
+    }
+    
+    
+    protected static int counter = 1;
+    
+	protected String createTestUser() throws IOException {
+        String postUrl = HTTP_BASE_URL + "/system/userManager/user/";
+
+		String testUserId = "testUser" + (counter++);
+		List<NameValuePair> postParams = new ArrayList<NameValuePair>();
+		postParams.add(new NameValuePair(":operation", "createUser"));
+		postParams.add(new NameValuePair(":name", testUserId));
+		postParams.add(new NameValuePair("pwd", "testPwd"));
+		postParams.add(new NameValuePair("pwdConfirm", "testPwd"));
+		assertPostStatus(postUrl, HttpServletResponse.SC_OK, postParams, null);
+		
+		return testUserId;
+	}
+    
+	protected String createTestGroup() throws IOException {
+        String postUrl = HTTP_BASE_URL + "/system/userManager/group/";
+
+		String testGroupId = "testGroup" + (counter++);
+		List<NameValuePair> postParams = new ArrayList<NameValuePair>();
+		postParams.add(new NameValuePair(":operation", "createGroup"));
+		postParams.add(new NameValuePair(":name", testGroupId));
+		
+		//success would be a redirect to the welcome page of the webapp
+		assertAuthenticatedAdminPostStatus(postUrl, HttpServletResponse.SC_OK, postParams, null);
+		
+		return testGroupId;
+	}
+	
+}

Propchange: incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/AbstractUserManagerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/AbstractUserManagerTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev Url

Added: incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/CreateGroupTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/CreateGroupTest.java?rev=748459&view=auto
==============================================================================
--- incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/CreateGroupTest.java (added)
+++ incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/CreateGroupTest.java Fri Feb 27 09:27:07 2009
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.launchpad.webapp.integrationtest.userManager;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.httpclient.Credentials;
+import org.apache.commons.httpclient.NameValuePair;
+import org.apache.commons.httpclient.UsernamePasswordCredentials;
+import org.apache.sling.commons.json.JSONException;
+import org.apache.sling.commons.json.JSONObject;
+
+/**
+ * Tests for the 'createGroup' Sling Post Operation
+ */
+public class CreateGroupTest extends AbstractUserManagerTest {
+
+	String testGroupId = null;
+	
+	@Override
+	protected void tearDown() throws Exception {
+		if (testGroupId != null) {
+			//remove the test group if it exists.
+			String postUrl = HTTP_BASE_URL + "/system/userManager/group/" + testGroupId;
+			List<NameValuePair> postParams = new ArrayList<NameValuePair>();
+			postParams.add(new NameValuePair(":operation", "deleteAuthorizable"));
+			assertAuthenticatedAdminPostStatus(postUrl, HttpServletResponse.SC_OK, postParams, null);
+		}
+
+		super.tearDown();
+	}
+
+	public void testCreateGroup() throws IOException, JSONException {
+        String postUrl = HTTP_BASE_URL + "/system/userManager/group/";
+
+		testGroupId = "testGroup" + (counter++);
+		List<NameValuePair> postParams = new ArrayList<NameValuePair>();
+		postParams.add(new NameValuePair(":operation", "createGroup"));
+		postParams.add(new NameValuePair(":name", testGroupId));
+		assertAuthenticatedAdminPostStatus(postUrl, HttpServletResponse.SC_OK, postParams, null);
+		
+		//fetch the group profile json to verify the settings
+		String getUrl = HTTP_BASE_URL + "/system/userManager/group/" + testGroupId + ".json";
+		Credentials creds = new UsernamePasswordCredentials("admin", "admin");
+		String json = getAuthenticatedContent(creds, getUrl, CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
+		assertNotNull(json);
+		JSONObject jsonObj = new JSONObject(json);
+		assertEquals(testGroupId, jsonObj.getString("rep:principalName"));
+	}
+
+	public void testCreateGroupMissingGroupId() throws IOException {
+        String postUrl = HTTP_BASE_URL + "/system/userManager/group/";
+
+		List<NameValuePair> postParams = new ArrayList<NameValuePair>();
+		postParams.add(new NameValuePair(":operation", "createGroup"));
+		assertAuthenticatedAdminPostStatus(postUrl, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, postParams, null);
+	}
+
+	public void testCreateGroupAlreadyExists() throws IOException {
+        String postUrl = HTTP_BASE_URL + "/system/userManager/group/";
+
+		testGroupId = "testGroup" + (counter++);
+		List<NameValuePair> postParams = new ArrayList<NameValuePair>();
+		postParams.add(new NameValuePair(":operation", "createGroup"));
+		postParams.add(new NameValuePair(":name", testGroupId));
+		assertAuthenticatedAdminPostStatus(postUrl, HttpServletResponse.SC_OK, postParams, null);
+		
+		//post the same info again, should fail
+		assertAuthenticatedAdminPostStatus(postUrl, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, postParams, null);
+	}
+	
+	public void testCreateGroupWithExtraProperties() throws IOException, JSONException {
+        String postUrl = HTTP_BASE_URL + "/system/userManager/group/";
+
+		testGroupId = "testGroup" + (counter++);
+		List<NameValuePair> postParams = new ArrayList<NameValuePair>();
+		postParams.add(new NameValuePair(":operation", "createGroup"));
+		postParams.add(new NameValuePair(":name", testGroupId));
+		postParams.add(new NameValuePair("displayName", "My Test Group"));
+		postParams.add(new NameValuePair("url", "http://www.apache.org"));
+		assertAuthenticatedAdminPostStatus(postUrl, HttpServletResponse.SC_OK, postParams, null);
+
+		//fetch the group profile json to verify the settings
+		String getUrl = HTTP_BASE_URL + "/system/userManager/group/" + testGroupId + ".json";
+		Credentials creds = new UsernamePasswordCredentials("admin", "admin");
+		String json = getAuthenticatedContent(creds, getUrl, CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
+		assertNotNull(json);
+		JSONObject jsonObj = new JSONObject(json);
+		assertEquals(testGroupId, jsonObj.getString("rep:principalName"));
+		assertEquals("My Test Group", jsonObj.getString("displayName"));
+		assertEquals("http://www.apache.org", jsonObj.getString("url"));
+	}		
+}

Propchange: incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/CreateGroupTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/CreateGroupTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev Url

Added: incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/CreateUserTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/CreateUserTest.java?rev=748459&view=auto
==============================================================================
--- incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/CreateUserTest.java (added)
+++ incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/CreateUserTest.java Fri Feb 27 09:27:07 2009
@@ -0,0 +1,166 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.launchpad.webapp.integrationtest.userManager;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.httpclient.Credentials;
+import org.apache.commons.httpclient.NameValuePair;
+import org.apache.commons.httpclient.UsernamePasswordCredentials;
+import org.apache.sling.commons.json.JSONException;
+import org.apache.sling.commons.json.JSONObject;
+
+/**
+ * Tests for the 'createUser' Sling Post Operation
+ */
+public class CreateUserTest extends AbstractUserManagerTest {
+
+	String testUserId = null;
+	
+	@Override
+	protected void tearDown() throws Exception {
+		if (testUserId != null) {
+			//remove the test user if it exists.
+			String postUrl = HTTP_BASE_URL + "/system/userManager/user/" + testUserId;
+			List<NameValuePair> postParams = new ArrayList<NameValuePair>();
+			postParams.add(new NameValuePair(":operation", "deleteAuthorizable"));
+			assertAuthenticatedAdminPostStatus(postUrl, HttpServletResponse.SC_OK, postParams, null);
+		}
+		super.tearDown();
+	}
+
+	/*
+		<form action="/system/userManager/createUser.html" method="POST">
+			<input type="hidden" name=":operation" value="creteUser" />
+		   <div>Name: <input type="text" name=":name" value="testUser" /></div>
+		   <div>Password: <input type="text" name="pwd" value="testUser" /></div>
+		   <div>Password Confirm: <input type="text" name="pwdConfirm" value="testUser" /></div>
+		   <input type="submit" value="Submit" />
+		</form>
+	 */
+	public void testCreateUser() throws IOException, JSONException {
+        String postUrl = HTTP_BASE_URL + "/system/userManager/user/";
+        
+		testUserId = "testUser" + (counter++);
+		List<NameValuePair> postParams = new ArrayList<NameValuePair>();
+		postParams.add(new NameValuePair(":operation", "createUser"));
+		postParams.add(new NameValuePair(":name", testUserId));
+		postParams.add(new NameValuePair("pwd", "testPwd"));
+		postParams.add(new NameValuePair("pwdConfirm", "testPwd"));
+		assertPostStatus(postUrl, HttpServletResponse.SC_OK, postParams, null);
+		
+		//fetch the user profile json to verify the settings
+		String getUrl = HTTP_BASE_URL + "/system/userManager/user/" + testUserId + ".json";
+		Credentials creds = new UsernamePasswordCredentials("admin", "admin");
+		String json = getAuthenticatedContent(creds, getUrl, CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
+		assertNotNull(json);
+		JSONObject jsonObj = new JSONObject(json);
+		assertEquals(testUserId, jsonObj.getString("rep:principalName"));
+		assertFalse(jsonObj.has(":name"));
+		assertFalse(jsonObj.has("pwd"));
+		assertFalse(jsonObj.has("pwdConfirm"));
+		assertFalse(jsonObj.has(":operation"));
+	}
+
+	public void testCreateUserMissingUserId() throws IOException {
+        String postUrl = HTTP_BASE_URL + "/system/userManager/user/";
+
+		List<NameValuePair> postParams = new ArrayList<NameValuePair>();
+		postParams.add(new NameValuePair(":operation", "createUser"));
+		assertPostStatus(postUrl, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, postParams, null);
+	}
+
+	public void testCreateUserMissingPwd() throws IOException {
+        String postUrl = HTTP_BASE_URL + "/system/userManager/user/";
+
+        String userId = "testUser" + (counter++);
+		List<NameValuePair> postParams = new ArrayList<NameValuePair>();
+		postParams.add(new NameValuePair(":operation", "createUser"));
+		postParams.add(new NameValuePair(":name", userId));
+		assertPostStatus(postUrl, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, postParams, null);
+	}
+
+	public void testCreateUserWrongConfirmPwd() throws IOException {
+        String postUrl = HTTP_BASE_URL + "/system/userManager/user/";
+
+        String userId = "testUser" + (counter++);
+		List<NameValuePair> postParams = new ArrayList<NameValuePair>();
+		postParams.add(new NameValuePair(":operation", "createUser"));
+		postParams.add(new NameValuePair(":name", userId));
+		postParams.add(new NameValuePair("pwd", "testPwd"));
+		postParams.add(new NameValuePair("pwdConfirm", "testPwd2"));
+		assertPostStatus(postUrl, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, postParams, null);
+	}
+
+	public void testCreateUserUserAlreadyExists() throws IOException {
+        String postUrl = HTTP_BASE_URL + "/system/userManager/user/";
+
+		testUserId = "testUser" + (counter++);
+		List<NameValuePair> postParams = new ArrayList<NameValuePair>();
+		postParams.add(new NameValuePair(":operation", "createUser"));
+		postParams.add(new NameValuePair(":name", testUserId));
+		postParams.add(new NameValuePair("pwd", "testPwd"));
+		postParams.add(new NameValuePair("pwdConfirm", "testPwd"));
+		assertPostStatus(postUrl, HttpServletResponse.SC_OK, postParams, null);
+		
+		//post the same info again, should fail
+		assertPostStatus(postUrl, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, postParams, null);
+	}
+	
+	/*
+	<form action="/system/userManager/createUser.html" method="POST">
+	    <input type="hidden" name=":operation" value="creteUser" />
+	   <div>Name: <input type="text" name=":name" value="testUser" /></div>
+	   <div>Password: <input type="text" name="pwd" value="testUser" /></div>
+	   <div>Password Confirm: <input type="text" name="pwdConfirm" value="testUser" /></div>
+	   <div>Extra Property #1: <input type="text" name="displayName" value="My Test User" /></div>
+	   <div>Extra Property #2: <input type="text" name="url" value="http://www.apache.org" /></div>
+	   <input type="submit" value="Submit" />
+	</form>
+	*/
+	public void testCreateUserWithExtraProperties() throws IOException, JSONException {
+        String postUrl = HTTP_BASE_URL + "/system/userManager/user/";
+
+		testUserId = "testUser" + (counter++);
+		List<NameValuePair> postParams = new ArrayList<NameValuePair>();
+		postParams.add(new NameValuePair(":operation", "createUser"));
+		postParams.add(new NameValuePair(":name", testUserId));
+		postParams.add(new NameValuePair("pwd", "testPwd"));
+		postParams.add(new NameValuePair("pwdConfirm", "testPwd"));
+		postParams.add(new NameValuePair("displayName", "My Test User"));
+		postParams.add(new NameValuePair("url", "http://www.apache.org"));
+		assertPostStatus(postUrl, HttpServletResponse.SC_OK, postParams, null);
+
+		//fetch the user profile json to verify the settings
+		String getUrl = HTTP_BASE_URL + "/system/userManager/user/" + testUserId + ".json";
+		Credentials creds = new UsernamePasswordCredentials("admin", "admin");
+		String json = getAuthenticatedContent(creds, getUrl, CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
+		assertNotNull(json);
+		JSONObject jsonObj = new JSONObject(json);
+		assertEquals(testUserId, jsonObj.getString("rep:principalName"));
+		assertEquals("My Test User", jsonObj.getString("displayName"));
+		assertEquals("http://www.apache.org", jsonObj.getString("url"));
+		assertFalse(jsonObj.has(":name"));
+		assertFalse(jsonObj.has("pwd"));
+		assertFalse(jsonObj.has("pwdConfirm"));
+		assertFalse(jsonObj.has(":operation"));
+	}		
+}

Propchange: incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/CreateUserTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/CreateUserTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev Url

Added: incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/RemoveAuthorizablesTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/RemoveAuthorizablesTest.java?rev=748459&view=auto
==============================================================================
--- incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/RemoveAuthorizablesTest.java (added)
+++ incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/RemoveAuthorizablesTest.java Fri Feb 27 09:27:07 2009
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.launchpad.webapp.integrationtest.userManager;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.httpclient.Credentials;
+import org.apache.commons.httpclient.NameValuePair;
+import org.apache.commons.httpclient.UsernamePasswordCredentials;
+
+/**
+ * Tests for the 'removeAuthorizable' Sling Post Operation
+ */
+public class RemoveAuthorizablesTest extends AbstractUserManagerTest {
+
+	public void testRemoveUser() throws IOException {
+		String userId = createTestUser();
+		
+        Credentials creds = new UsernamePasswordCredentials("admin", "admin");
+
+		String getUrl = HTTP_BASE_URL + "/system/userManager/user/" + userId + ".json";
+		assertAuthenticatedHttpStatus(creds, getUrl, HttpServletResponse.SC_OK, null); //make sure the profile request returns some data
+
+		String postUrl = HTTP_BASE_URL + "/system/userManager/user/" + userId;
+		List<NameValuePair> postParams = new ArrayList<NameValuePair>();
+		postParams.add(new NameValuePair(":operation", "deleteAuthorizable"));
+		assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
+		
+		getUrl = HTTP_BASE_URL + "/system/userManager/user/" + userId + ".json";
+		assertAuthenticatedHttpStatus(creds, getUrl, HttpServletResponse.SC_NOT_FOUND, null); //make sure the profile request returns some data
+	}
+	
+	public void testRemoveGroup() throws IOException {
+		String groupId = createTestGroup();
+		
+        Credentials creds = new UsernamePasswordCredentials("admin", "admin");
+
+		String getUrl = HTTP_BASE_URL + "/system/userManager/group/" + groupId + ".json";
+		assertAuthenticatedHttpStatus(creds, getUrl, HttpServletResponse.SC_OK, null); //make sure the profile request returns some data
+
+		String postUrl = HTTP_BASE_URL + "/system/userManager/group/" + groupId;
+		List<NameValuePair> postParams = new ArrayList<NameValuePair>();
+		postParams.add(new NameValuePair(":operation", "deleteAuthorizable"));
+		assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
+		
+		getUrl = HTTP_BASE_URL + "/system/userManager/group/" + groupId + ".json";
+		assertAuthenticatedHttpStatus(creds, getUrl, HttpServletResponse.SC_NOT_FOUND, null); //make sure the profile request returns some data
+	}
+
+	public void testRemoveAuthorizables() throws IOException {
+		String userId = createTestUser();
+		String groupId = createTestGroup();
+		
+        Credentials creds = new UsernamePasswordCredentials("admin", "admin");
+
+		String getUrl = HTTP_BASE_URL + "/system/userManager/user/" + userId + ".json";
+		assertAuthenticatedHttpStatus(creds, getUrl, HttpServletResponse.SC_OK, null); //make sure the profile request returns some data
+
+		getUrl = HTTP_BASE_URL + "/system/userManager/group/" + groupId + ".json";
+		assertAuthenticatedHttpStatus(creds, getUrl, HttpServletResponse.SC_OK, null); //make sure the profile request returns some data
+		
+		String postUrl = HTTP_BASE_URL + "/system/userManager";
+		List<NameValuePair> postParams = new ArrayList<NameValuePair>();
+		postParams.add(new NameValuePair(":operation", "deleteAuthorizable"));
+		postParams.add(new NameValuePair(":applyTo", "group/" + groupId));
+		postParams.add(new NameValuePair(":applyTo", "user/" + userId));
+		assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
+		
+		getUrl = HTTP_BASE_URL + "/system/userManager/user/" + userId + ".json";
+		assertAuthenticatedHttpStatus(creds, getUrl, HttpServletResponse.SC_NOT_FOUND, null); //make sure the profile request returns some data
+
+		getUrl = HTTP_BASE_URL + "/system/userManager/group/" + groupId + ".json";
+		assertAuthenticatedHttpStatus(creds, getUrl, HttpServletResponse.SC_NOT_FOUND, null); //make sure the profile request returns some data
+	}
+}

Propchange: incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/RemoveAuthorizablesTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/RemoveAuthorizablesTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev Url

Added: incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/UpdateGroupTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/UpdateGroupTest.java?rev=748459&view=auto
==============================================================================
--- incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/UpdateGroupTest.java (added)
+++ incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/UpdateGroupTest.java Fri Feb 27 09:27:07 2009
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.launchpad.webapp.integrationtest.userManager;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.httpclient.Credentials;
+import org.apache.commons.httpclient.NameValuePair;
+import org.apache.commons.httpclient.UsernamePasswordCredentials;
+import org.apache.sling.commons.json.JSONException;
+import org.apache.sling.commons.json.JSONObject;
+
+/**
+ * Tests for the 'updateAuthorizable' Sling Post Operation on
+ * a group resource.
+ */
+public class UpdateGroupTest extends AbstractUserManagerTest {
+
+	String testGroupId = null;
+	
+	@Override
+	protected void tearDown() throws Exception {
+		if (testGroupId != null) {
+			//remove the test user if it exists.
+			String postUrl = HTTP_BASE_URL + "/system/userManager/group/" + testGroupId;
+			List<NameValuePair> postParams = new ArrayList<NameValuePair>();
+			postParams.add(new NameValuePair(":operation", "deleteAuthorizable"));
+			assertAuthenticatedAdminPostStatus(postUrl, HttpServletResponse.SC_OK, postParams, null);
+		}
+
+		super.tearDown();
+	}
+
+	public void testUpdateGroup() throws IOException, JSONException {
+		testGroupId = createTestGroup();
+		
+        String postUrl = HTTP_BASE_URL + "/system/userManager/group/" + testGroupId;
+
+		List<NameValuePair> postParams = new ArrayList<NameValuePair>();
+		postParams.add(new NameValuePair(":operation", "updateAuthorizable"));
+		postParams.add(new NameValuePair("displayName", "My Updated Test Group"));
+		postParams.add(new NameValuePair("url", "http://www.apache.org/updated"));
+		
+		Credentials creds = new UsernamePasswordCredentials("admin", "admin");
+		assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
+		
+		//fetch the user profile json to verify the settings
+		String getUrl = HTTP_BASE_URL + "/system/userManager/group/" + testGroupId + ".json";
+		assertAuthenticatedHttpStatus(creds, getUrl, HttpServletResponse.SC_OK, null); //make sure the profile request returns some data
+		String json = getAuthenticatedContent(creds, getUrl, CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
+		assertNotNull(json);
+		JSONObject jsonObj = new JSONObject(json);
+		assertEquals("My Updated Test Group", jsonObj.getString("displayName"));
+		assertEquals("http://www.apache.org/updated", jsonObj.getString("url"));
+		assertFalse(jsonObj.has(":operation"));
+	}
+	
+	public void testUpdateGroupMembers() throws IOException, JSONException {
+		testGroupId = createTestGroup();
+		
+        String postUrl = HTTP_BASE_URL + "/system/userManager/group/" + testGroupId;
+
+        //TODO: verify this works....
+		List<NameValuePair> postParams = new ArrayList<NameValuePair>();
+		postParams.add(new NameValuePair(":operation", "updateAuthorizable"));
+		postParams.add(new NameValuePair(":member", "../user/testUser"));
+		postParams.add(new NameValuePair(":member@Delete", "testGroup"));
+		
+		Credentials creds = new UsernamePasswordCredentials("admin", "admin");
+		assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
+		
+        //TODO: verify the group membership is correct....
+	}
+	
+}
+

Propchange: incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/UpdateGroupTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/UpdateGroupTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev Url

Added: incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/UpdateUserTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/UpdateUserTest.java?rev=748459&view=auto
==============================================================================
--- incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/UpdateUserTest.java (added)
+++ incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/UpdateUserTest.java Fri Feb 27 09:27:07 2009
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.launchpad.webapp.integrationtest.userManager;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.httpclient.Credentials;
+import org.apache.commons.httpclient.NameValuePair;
+import org.apache.commons.httpclient.UsernamePasswordCredentials;
+import org.apache.sling.commons.json.JSONException;
+import org.apache.sling.commons.json.JSONObject;
+
+/**
+ * Tests for the 'updateAuthorizable' and 'changePassword' Sling Post 
+ * Operations on a user resource.
+ */
+public class UpdateUserTest extends AbstractUserManagerTest {
+
+	String testUserId = null;
+	
+	@Override
+	protected void tearDown() throws Exception {
+		if (testUserId != null) {
+			//remove the test user if it exists.
+			String postUrl = HTTP_BASE_URL + "/system/userManager/user/" + testUserId;
+			List<NameValuePair> postParams = new ArrayList<NameValuePair>();
+			postParams.add(new NameValuePair(":operation", "updateAuthorizable"));
+			assertAuthenticatedAdminPostStatus(postUrl, HttpServletResponse.SC_OK, postParams, null);
+		}
+
+		super.tearDown();
+	}
+
+	public void testUpdateUser() throws IOException, JSONException {
+		testUserId = createTestUser();
+		
+        String postUrl = HTTP_BASE_URL + "/system/userManager/user/" + testUserId;
+
+		List<NameValuePair> postParams = new ArrayList<NameValuePair>();
+		postParams.add(new NameValuePair(":operation", "updateAuthorizable"));
+		postParams.add(new NameValuePair("displayName", "My Updated Test User"));
+		postParams.add(new NameValuePair("url", "http://www.apache.org/updated"));
+		Credentials creds = new UsernamePasswordCredentials(testUserId, "testPwd");
+		assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
+		
+		//fetch the user profile json to verify the settings
+		String getUrl = HTTP_BASE_URL + "/system/userManager/user/" + testUserId + ".json";
+		assertAuthenticatedHttpStatus(creds, getUrl, HttpServletResponse.SC_OK, null); //make sure the profile request returns some data
+		String json = getAuthenticatedContent(creds, getUrl, CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
+		assertNotNull(json);
+		JSONObject jsonObj = new JSONObject(json);
+		assertEquals("My Updated Test User", jsonObj.getString("displayName"));
+		assertEquals("http://www.apache.org/updated", jsonObj.getString("url"));
+		assertFalse(jsonObj.has(":operation"));
+	}
+	
+	public void testChangeUserPassword() throws IOException {
+		testUserId = createTestUser();
+		
+        String postUrl = HTTP_BASE_URL + "/system/userManager/user/" + testUserId;
+
+		List<NameValuePair> postParams = new ArrayList<NameValuePair>();
+		postParams.add(new NameValuePair(":operation", "changePassword"));
+		postParams.add(new NameValuePair("oldPwd", "testPwd"));
+		postParams.add(new NameValuePair("newPwd", "testNewPwd"));
+		postParams.add(new NameValuePair("newPwdConfirm", "testNewPwd"));
+
+		Credentials creds = new UsernamePasswordCredentials(testUserId, "testPwd");
+		assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
+	}
+	
+	public void testChangeUserPasswordWrongOldPwd() throws IOException {
+		testUserId = createTestUser();
+		
+        String postUrl = HTTP_BASE_URL + "/system/userManager/user/" + testUserId;
+
+		List<NameValuePair> postParams = new ArrayList<NameValuePair>();
+		postParams.add(new NameValuePair(":operation", "changePassword"));
+		postParams.add(new NameValuePair("oldPwd", "wrongTestPwd"));
+		postParams.add(new NameValuePair("newPwd", "testNewPwd"));
+		postParams.add(new NameValuePair("newPwdConfirm", "testNewPwd"));
+		
+		//Credentials creds = new UsernamePasswordCredentials(testUserId, "testPwd");
+		Credentials creds = new UsernamePasswordCredentials("admin", "admin");
+		assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, postParams, null);
+	}
+
+	public void testChangeUserPasswordWrongConfirmPwd() throws IOException {
+		testUserId = createTestUser();
+		
+        String postUrl = HTTP_BASE_URL + "/system/userManager/user/" + testUserId;
+
+		List<NameValuePair> postParams = new ArrayList<NameValuePair>();
+		postParams.add(new NameValuePair(":operation", "changePassword"));
+		postParams.add(new NameValuePair("oldPwd", "testPwd"));
+		postParams.add(new NameValuePair("newPwd", "testNewPwd"));
+		postParams.add(new NameValuePair("newPwdConfirm", "wrongTestNewPwd"));
+		
+		//Credentials creds = new UsernamePasswordCredentials(testUserId, "testPwd");
+		Credentials creds = new UsernamePasswordCredentials("admin", "admin");
+		assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, postParams, null);
+	}
+	
+}

Propchange: incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/UpdateUserTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/UpdateUserTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev Url