hs.hsadmin/hsarback/test/de/hsadmin/remote/UnixUserTest.java

241 lines
7.1 KiB
Java
Raw Normal View History

2010-10-01 21:42:49 +02:00
package de.hsadmin.remote;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
import java.util.HashMap;
import java.util.Map;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class UnixUserTest {
private static final String MODULE = "user";
private XmlRpcClient client;
private RemoteCASHelper cas;
@Before
public void setUp() throws Exception {
client = RemoteTestHelper.getClient();
cas = new RemoteCASHelper();
}
@After
public void tearDown() throws Exception {
client = null;
cas = null;
}
@Test
public void testSearchAsPacAdmin() {
String user = "peh00";
2010-10-04 19:44:49 +02:00
String grantingTicketURL = cas.getGrantingTicketURL(user);
2010-10-01 21:42:49 +02:00
Map<String, String> whereParams = new HashMap<String, String>();
Object[] params = new Object[] { user,
2010-10-05 21:42:07 +02:00
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
2010-10-01 21:42:49 +02:00
whereParams };
try {
Object execute = client.execute(MODULE + ".search", params);
Object[] result = (Object[]) execute;
2010-12-17 18:39:53 +01:00
assertEquals(22, result.length);
2010-10-01 21:42:49 +02:00
for (Object o : result) {
if (o instanceof Map<?, ?>) {
Map<?, ?> row = (Map<?, ?>) o;
assertEquals("peh00", row.get("pac"));
} else {
fail("map expected");
}
}
} catch (XmlRpcException e) {
fail(e.getMessage());
}
}
@Test
public void testAddAsPacAdmin() {
int count = getObjectCount();
try {
String user = "peh00";
2010-10-04 19:44:49 +02:00
String grantingTicketURL = cas.getGrantingTicketURL(user);
2010-10-01 21:42:49 +02:00
Map<String, String> setParams = new HashMap<String, String>();
setParams.put("name", "peh00-test2");
setParams.put("password", "test123");
setParams.put("quota", "128");
setParams.put("quotalimit", "192");
Object[] params = new Object[] { user,
2010-10-05 21:42:07 +02:00
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
2010-10-01 21:42:49 +02:00
setParams };
Object execute = client.execute(MODULE + ".add", params);
if (execute instanceof Map<?, ?>) {
Map<?, ?> entry = (Map<?, ?>) execute;
assertEquals("peh00-test2", entry.get("name"));
assertEquals("peh00", entry.get("pac"));
assertEquals(null, entry.get("password"));
} else {
fail("map expected");
}
} catch (XmlRpcException e) {
fail(e.getMessage());
}
assertEquals(count + 1, getObjectCount());
}
@Test
public void testAddAsPacAdminFail() {
int count = getObjectCount();
try {
String user = "peh00";
2010-10-04 19:44:49 +02:00
String grantingTicketURL = cas.getGrantingTicketURL(user);
2010-10-01 21:42:49 +02:00
Map<String, String> setParams = new HashMap<String, String>();
setParams.put("name", "peh01-testfail");
setParams.put("password", "test123");
Object[] params = new Object[] { user,
2010-10-05 21:42:07 +02:00
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
2010-10-01 21:42:49 +02:00
setParams };
Object execute = client.execute(MODULE + ".add", params);
assertNull(execute);
fail("should fail");
} catch (XmlRpcException e) {
}
assertEquals(count, getObjectCount());
}
@Test
public void testAddWithFalseName() {
int count = getObjectCount();
try {
String user = "peh00";
2010-10-04 19:44:49 +02:00
String grantingTicketURL = cas.getGrantingTicketURL(user);
2010-10-01 21:42:49 +02:00
Map<String, String> setParams = new HashMap<String, String>();
setParams.put("name", "peh00-langer-name");
setParams.put("password", "test123");
Object[] params = new Object[] { user,
2010-10-05 21:42:07 +02:00
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
2010-10-01 21:42:49 +02:00
setParams };
Object execute = client.execute(MODULE + ".add", params);
assertNull(execute);
fail("exception expected");
} catch (XmlRpcException e) {
}
assertEquals(count, getObjectCount());
}
@Test
public void testUpdateAsPacAdmin() {
int count = getObjectCount();
try {
String user = "peh00";
2010-10-04 19:44:49 +02:00
String grantingTicketURL = cas.getGrantingTicketURL(user);
2010-10-01 21:42:49 +02:00
Map<String, String> whereParams = new HashMap<String, String>();
Map<String, String> setParams = new HashMap<String, String>();
whereParams.put("name", "peh00-test2");
setParams.put("password", "test1234");
Object[] params = new Object[] { user,
2010-10-05 21:42:07 +02:00
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
2010-10-01 21:42:49 +02:00
setParams, whereParams };
Object execute = client.execute(MODULE + ".update", params);
if (execute instanceof Object[]) {
Object[] a = (Object[]) execute;
for (Object o : a) {
if (o instanceof Map<?, ?>) {
Map<?, ?> entry = (Map<?, ?>) o;
assertNull(entry.get("password"));
assertEquals("peh00-test2", entry.get("name"));
} else {
fail("map expected");
}
}
} else {
fail("Object[] axpected");
}
} catch (XmlRpcException e) {
fail(e.getMessage());
}
assertEquals(count, getObjectCount());
}
@Test
public void testDeleteWithLongName() {
int count = getObjectCount();
try {
String user = "peh00";
2010-10-04 19:44:49 +02:00
String grantingTicketURL = cas.getGrantingTicketURL(user);
2010-10-01 21:42:49 +02:00
Map<String, String> whereParams = new HashMap<String, String>();
whereParams.put("name", "peh00-langer-name");
Object[] params = new Object[] { user,
2010-10-05 21:42:07 +02:00
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
2010-10-01 21:42:49 +02:00
whereParams };
Object execute = client.execute(MODULE + ".delete", params);
assertNull(execute);
} catch (XmlRpcException e) {
fail(e.getMessage());
}
assertEquals(count, getObjectCount());
}
@Test
public void testDeleteAsPacAdminFail() {
int count = getObjectCount();
try {
String user = "peh01";
2010-10-04 19:44:49 +02:00
String grantingTicketURL = cas.getGrantingTicketURL(user);
2010-10-01 21:42:49 +02:00
Map<String, String> whereParams = new HashMap<String, String>();
whereParams.put("name", "peh00-test2");
Object[] params = new Object[] { user,
2010-10-05 21:42:07 +02:00
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
2010-10-01 21:42:49 +02:00
whereParams };
Object execute = client.execute(MODULE + ".delete", params);
assertNull(execute);
} catch (XmlRpcException e) {
fail(e.getMessage());
}
assertEquals(count, getObjectCount());
}
@Test
public void testDeleteAsPacAdmin() {
int count = getObjectCount();
try {
String user = "peh00";
2010-10-04 19:44:49 +02:00
String grantingTicketURL = cas.getGrantingTicketURL(user);
2010-10-01 21:42:49 +02:00
Map<String, String> whereParams = new HashMap<String, String>();
whereParams.put("name", "peh00-test2");
Object[] params = new Object[] { user,
2010-10-05 21:42:07 +02:00
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
2010-10-01 21:42:49 +02:00
whereParams };
Object execute = client.execute(MODULE + ".delete", params);
assertNull(execute);
} catch (XmlRpcException e) {
fail(e.getMessage());
}
assertEquals(count - 1, getObjectCount());
}
private int getObjectCount() {
int count = -1;
try {
String user = "peh00";
2010-10-04 19:44:49 +02:00
String grantingTicketURL = cas.getGrantingTicketURL(user);
2010-10-01 21:42:49 +02:00
Map<String, String> whereParams = new HashMap<String, String>();
Object[] params = new Object[] { user,
2010-10-05 21:42:07 +02:00
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
2010-10-01 21:42:49 +02:00
whereParams };
Object execute = client.execute(MODULE + ".search", params);
Object[] result = (Object[]) execute;
count = result.length;
} catch (XmlRpcException e) {
fail(e.getMessage());
}
return count;
}
}