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;
|
|
|
|
}
|
|
|
|
|
2014-03-21 15:20:25 +01:00
|
|
|
public void doTests() {
|
|
|
|
testSearchAsPacAdmin();
|
|
|
|
testAddAsPacAdmin();
|
|
|
|
testAddAsPacAdminFail();
|
|
|
|
testAddWithFalseName();
|
|
|
|
testUpdateAsPacAdmin();
|
|
|
|
testDeleteWithLongName();
|
|
|
|
testDeleteAsPacAdminFail();
|
|
|
|
testDeleteAsPacAdmin();
|
|
|
|
}
|
|
|
|
|
2010-10-01 21:42:49 +02:00
|
|
|
@Test
|
|
|
|
public void testSearchAsPacAdmin() {
|
2011-03-30 18:26:43 +02:00
|
|
|
String user = "aaa00";
|
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;
|
2012-01-02 14:58:07 +01:00
|
|
|
assertEquals(3, result.length);
|
2010-10-01 21:42:49 +02:00
|
|
|
for (Object o : result) {
|
|
|
|
if (o instanceof Map<?, ?>) {
|
|
|
|
Map<?, ?> row = (Map<?, ?>) o;
|
2011-03-30 18:26:43 +02:00
|
|
|
assertEquals("aaa00", row.get("pac"));
|
2010-10-01 21:42:49 +02:00
|
|
|
} else {
|
|
|
|
fail("map expected");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (XmlRpcException e) {
|
|
|
|
fail(e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testAddAsPacAdmin() {
|
|
|
|
int count = getObjectCount();
|
|
|
|
try {
|
2011-03-30 18:26:43 +02:00
|
|
|
String user = "aaa00";
|
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>();
|
2014-03-21 15:20:25 +01:00
|
|
|
setParams.put("name", "aaa00-test3a");
|
2010-10-01 21:42:49 +02:00
|
|
|
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;
|
2014-03-21 15:20:25 +01:00
|
|
|
assertEquals("aaa00-test3a", entry.get("name"));
|
2011-03-30 18:26:43 +02:00
|
|
|
assertEquals("aaa00", entry.get("pac"));
|
2010-10-01 21:42:49 +02:00
|
|
|
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 {
|
2011-03-30 18:26:43 +02:00
|
|
|
String user = "aaa00";
|
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>();
|
2011-05-06 13:10:41 +02:00
|
|
|
setParams.put("name", "aaa01-testfail");
|
2010-10-01 21:42:49 +02:00
|
|
|
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 {
|
2011-03-30 18:26:43 +02:00
|
|
|
String user = "aaa00";
|
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>();
|
2011-03-30 18:26:43 +02:00
|
|
|
setParams.put("name", "aaa00-langer-name");
|
2010-10-01 21:42:49 +02:00
|
|
|
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 {
|
2011-03-30 18:26:43 +02:00
|
|
|
String user = "aaa00";
|
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>();
|
2011-05-06 16:54:43 +02:00
|
|
|
whereParams.put("name", "aaa00-test3");
|
2010-10-01 21:42:49 +02:00
|
|
|
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"));
|
2011-05-06 13:10:41 +02:00
|
|
|
assertEquals("aaa00-test3", entry.get("name"));
|
2010-10-01 21:42:49 +02:00
|
|
|
} 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 {
|
2011-03-30 18:26:43 +02:00
|
|
|
String user = "aaa00";
|
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>();
|
2011-03-30 18:26:43 +02:00
|
|
|
whereParams.put("name", "aaa00-langer-name");
|
2010-10-01 21:42:49 +02:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
2012-01-02 14:18:57 +01:00
|
|
|
@Test
|
|
|
|
public void testDeleteAsPacAdminFail() {
|
|
|
|
int count = getObjectCount();
|
|
|
|
try {
|
|
|
|
String user = "aaa01";
|
|
|
|
String grantingTicketURL = cas.getGrantingTicketURL(user);
|
|
|
|
Map<String, String> whereParams = new HashMap<String, String>();
|
|
|
|
whereParams.put("name", "aaa00-test2");
|
|
|
|
Object[] params = new Object[] { user,
|
|
|
|
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
|
|
|
|
whereParams };
|
|
|
|
Object execute = client.execute(MODULE + ".delete", params);
|
|
|
|
assertNull(execute);
|
|
|
|
} catch (XmlRpcException e) {
|
|
|
|
fail(e.getMessage());
|
|
|
|
}
|
|
|
|
assertEquals(count, getObjectCount());
|
|
|
|
}
|
2010-10-01 21:42:49 +02:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testDeleteAsPacAdmin() {
|
2014-03-21 15:20:25 +01:00
|
|
|
int count = 0;
|
2010-10-01 21:42:49 +02:00
|
|
|
try {
|
2011-03-30 18:26:43 +02:00
|
|
|
String user = "aaa00";
|
2010-10-04 19:44:49 +02:00
|
|
|
String grantingTicketURL = cas.getGrantingTicketURL(user);
|
2014-03-21 15:20:25 +01:00
|
|
|
Map<String, String> setParams = new HashMap<String, String>();
|
|
|
|
setParams.put("name", "aaa00-test3");
|
|
|
|
setParams.put("password", "test123");
|
|
|
|
setParams.put("quota", "128");
|
|
|
|
setParams.put("quotalimit", "192");
|
|
|
|
Object[] params = new Object[] { user,
|
|
|
|
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
|
|
|
|
setParams };
|
|
|
|
Object execute = client.execute(MODULE + ".add", params);
|
|
|
|
count = getObjectCount();
|
|
|
|
grantingTicketURL = cas.getGrantingTicketURL(user);
|
2010-10-01 21:42:49 +02:00
|
|
|
Map<String, String> whereParams = new HashMap<String, String>();
|
2011-05-06 17:10:27 +02:00
|
|
|
whereParams.put("name", "aaa00-test3");
|
2014-03-21 15:20:25 +01:00
|
|
|
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 };
|
2014-03-21 15:20:25 +01:00
|
|
|
execute = client.execute(MODULE + ".delete", params);
|
2010-10-01 21:42:49 +02:00
|
|
|
assertNull(execute);
|
|
|
|
} catch (XmlRpcException e) {
|
|
|
|
fail(e.getMessage());
|
|
|
|
}
|
|
|
|
assertEquals(count - 1, getObjectCount());
|
|
|
|
}
|
|
|
|
|
|
|
|
private int getObjectCount() {
|
|
|
|
int count = -1;
|
|
|
|
try {
|
2011-03-30 18:26:43 +02:00
|
|
|
String user = "aaa00";
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|