Commit 6291efc1 authored by benjamin.ertl's avatar benjamin.ertl
Browse files

update

parent e0f41ab6
Pipeline #3357 skipped
...@@ -212,25 +212,25 @@ public class LdapClient { ...@@ -212,25 +212,25 @@ public class LdapClient {
/** /**
* Creates a new LDAP POSIX group. * Creates a new LDAP POSIX group.
* *
* @param cn the group's common name * @param group the {@link PosixGroup} to create
* @param gidNumber the group's gid number
* @param description the group's description
* @param userPassword the group's user password
* @return the created {@link PosixGroup} * @return the created {@link PosixGroup}
* *
*/ */
public PosixGroup createPosixGroup(String cn, int gidNumber, String description, public PosixGroup createPosixGroup(PosixGroup group) {
String userPassword) {
PosixGroup group = new PosixGroup();
group.setCommonName(cn);
group.setGidNumber(gidNumber);
group.setDescription(description);
if (userPassword != null) {
group.setUserPassword(userPassword.getBytes());
}
ldapPosixGroup.insertGroup(group); ldapPosixGroup.insertGroup(group);
return getPosixGroup(group.getCommonName());
}
return getPosixGroup(cn); /**
* Creates a new LDAP POSIX user.
*
* @param user the {@link PosixUser} to create
* @return the created {@link PosixUser}
*/
public PosixUser createPosixUser(PosixUser user) {
ldapPosixUser.insertUser(user);
return getPosixUser(user.getUid());
} }
/** /**
......
# LOGGING
logging.level.edu.kit.scc=DEBUG
logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
# EMBEDDED SERVER CONFIGURATION (ServerProperties)
server.address=0.0.0.0
server.port=8443
server.ssl.enabled=true
server.ssl.key-alias=testserver
server.ssl.key-password=changeit
server.ssl.key-store=privateKey.store
server.ssl.key-store-password=changeit
#server.ssl.trust-store=src/main/resources/publicKey.store
#server.ssl.trust-store-password=supersecret
# LDAP
ldap.url = ldap://ldap/
ldap.searchBase = dc=example,dc=com
ldap.userBase = ou=users
ldap.groupBase = ou=groups
ldap.bindDn = uid=admin,ou=system
ldap.bindPassword = admin
# REST API
rest.serviceUsername = restadmin
rest.servicePassword = restadmin
...@@ -12,10 +12,11 @@ package edu.kit.scc.test; ...@@ -12,10 +12,11 @@ package edu.kit.scc.test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.Suite; import org.junit.runners.Suite;
import edu.kit.scc.test.http.HttpClientTest;
import edu.kit.scc.test.ldap.LdapClientTest; import edu.kit.scc.test.ldap.LdapClientTest;
@RunWith(Suite.class) @RunWith(Suite.class)
@Suite.SuiteClasses({LdapClientTest.class}) @Suite.SuiteClasses({HttpClientTest.class, LdapClientTest.class})
public class TestSuite { public class TestSuite {
} }
/*
* Copyright 2016 Karlsruhe Institute of Technology (KIT)
*
* Licensed 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
*/
package edu.kit.scc.test.http;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import edu.kit.scc.Application;
import edu.kit.scc.http.HttpClient;
import edu.kit.scc.http.HttpResponse;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
public class HttpClientTest {
private static final Logger log = LoggerFactory.getLogger(HttpClientTest.class);
@Autowired
private HttpClient httpClient;
protected static String httpUrl = "http://api.rottentomatoes.com/api/public/v1.0";
protected static String httpsUrl = "https://launchlibrary.net/1.2/agency/NASA";
@Test
public void makeHttpPostRequestTest() {
HttpResponse httpResponse = httpClient.makeHttpPostRequest("hello", httpUrl);
assertNull(httpResponse);
}
@Test
public void makeHttpGetRequestTest() {
HttpResponse httpResponse = httpClient.makeHttpGetRequest(httpUrl);
assertNotNull(httpResponse);
log.debug(httpResponse.toString());
}
@Test
public void makeHttpsPostRequestTest() {
HttpResponse httpResponse = httpClient.makeHttpsPostRequest("hello", httpsUrl);
assertNull(httpResponse);
}
@Test
public void makeHttpsGetRequestTest() {
HttpResponse httpResponse = httpClient.makeHttpsGetRequest(httpsUrl);
assertNotNull(httpResponse);
log.debug(httpResponse.toString());
}
}
...@@ -12,6 +12,12 @@ package edu.kit.scc.test.ldap; ...@@ -12,6 +12,12 @@ package edu.kit.scc.test.ldap;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import edu.kit.scc.Application;
import edu.kit.scc.dto.PosixGroup;
import edu.kit.scc.dto.PosixUser;
import edu.kit.scc.ldap.LdapClient;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder; import org.junit.FixMethodOrder;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
...@@ -22,10 +28,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -22,10 +28,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import edu.kit.scc.Application; import java.util.List;
import edu.kit.scc.dto.PosixGroup;
import edu.kit.scc.dto.PosixUser;
import edu.kit.scc.ldap.LdapClient;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class) @SpringApplicationConfiguration(classes = Application.class)
...@@ -37,30 +40,56 @@ public class LdapClientTest { ...@@ -37,30 +40,56 @@ public class LdapClientTest {
@Autowired @Autowired
private LdapClient ldapClient; private LdapClient ldapClient;
@Test protected static PosixGroup posixGroup;
public void a_createLdapGroupTest() { protected static PosixUser posixUser;
ldapClient.createPosixGroup("newGroup", 3333, null, null);
}
@Test @BeforeClass
public void b_createLdapUserTest() { public static void setUpBeforeClass() {
String cn = "newUser"; String userCn = "newUser";
String sn = "newUser"; String userSn = "newUser";
String description = "new posix user"; String description = "new posix user";
String homeDirectory = "/home/newUser"; String homeDirectory = "/home/newUser";
String uid = "newUser"; String uid = "newUser";
int uidNumber = 6001; int uidNumber = 6001;
int userGidNumber = 3333;
posixUser = new PosixUser();
posixUser.setCommonName(userCn);
posixUser.setSurName(userSn);
posixUser.setHomeDirectory(homeDirectory);
posixUser.setDescription(description);
posixUser.setUid(uid);
posixUser.setUidNumber(uidNumber);
posixUser.setGidNumber(userGidNumber);
String groupCn = "newGroup";
int gidNumber = 3333; int gidNumber = 3333;
// ldapClient.createIndigoUser(uid, cn, sn, uid, uidNumber, gidNumber, posixGroup = new PosixGroup();
// homeDirectory, description, null, null, posixGroup.setCommonName(groupCn);
// null); posixGroup.setGidNumber(gidNumber);
} }
@Test @Test
public void c_getLdapUserTest() { public void a_createLdapGroupTest() {
PosixUser user = ldapClient.getPosixUser("newUser"); PosixGroup group = ldapClient.createPosixGroup(posixGroup);
assertNotNull(group);
log.debug(group.toString());
}
@Test
public void b_createLdapUserTest() {
PosixUser user = ldapClient.createPosixUser(posixUser);
assertNotNull(user);
log.debug(user.toString());
}
@Test
public void c_getLdapUserTest() {
PosixUser user = ldapClient.getPosixUser(posixUser.getUid());
assertNotNull(user); assertNotNull(user);
log.debug(user.toString()); log.debug(user.toString());
...@@ -68,27 +97,26 @@ public class LdapClientTest { ...@@ -68,27 +97,26 @@ public class LdapClientTest {
@Test @Test
public void d_updateUserTest() { public void d_updateUserTest() {
String cn = "newUser"; posixUser.setDescription("new posix user (update)");
String sn = "newUser"; PosixUser user = ldapClient.updatePosixUser(posixUser);
String description = "new posix user (update)"; assertNotNull(user);
String homeDirectory = "/home/newUser";
String uid = "newUser";
int uidNumber = 6001;
int gidNumber = 3333;
// ldapClient.updateIndigoUser(uid, cn, sn, uid, uidNumber, gidNumber, log.debug(user.toString());
// homeDirectory, description, null, null,
// null);
} }
@Test @Test
public void e_addUserToGroupTest() { public void e_addUserToGroupTest() {
ldapClient.addGroupMember("newGroup", "newUser"); ldapClient.addGroupMember(posixGroup.getCommonName(), posixUser.getUid());
}
@Test
public void f_removeUserFromGroupTest() {
ldapClient.removeGroupMember(posixGroup.getCommonName(), posixUser.getUid());
} }
@Test @Test
public void f_getLdapGroupTest() { public void f_getLdapGroupTest() {
PosixGroup group = ldapClient.getPosixGroup("newGroup"); PosixGroup group = ldapClient.getPosixGroup(posixGroup.getCommonName());
assertNotNull(group); assertNotNull(group);
...@@ -96,35 +124,37 @@ public class LdapClientTest { ...@@ -96,35 +124,37 @@ public class LdapClientTest {
} }
@Test @Test
public void g_deleteLdapUserTest() { public void g_groupEqualityTest() {
ldapClient.deleteUser("newUser");
assertTrue(ldapClient.equalGroups(ldapClient.getPosixGroup(posixGroup.getGidNumber()),
ldapClient.getPosixGroup(posixGroup.getCommonName())));
} }
@Test @Test
public void h_deleteLdapGroupTest() { public void h_deleteLdapUserTest() {
ldapClient.deleteGroup("newGroup"); ldapClient.deleteUser(posixUser.getUid());
} }
@Test @Test
public void getLdapGroupsTest() { public void i_deleteLdapGroupTest() {
ldapClient.getPosixGroups(); ldapClient.deleteGroup(posixGroup.getCommonName());
} }
@Test @Test
public void getLdapUsersTest() { public void j_getLdapGroupsTest() {
List<PosixGroup> groups = ldapClient.getPosixGroups();
assertNotNull(groups);
} }
@Test @Test
public void getNewGidNumber() { public void k_getLdapUsersTest() {
log.debug("{}", ldapClient.generateGroupIdNumber()); List<PosixUser> users = ldapClient.getPosixUsers();
assertNotNull(users);
} }
@Test @Test
public void groupEqualityTest() { public void getNewGidNumber() {
assertNotNull(ldapClient.generateGroupIdNumber());
assertTrue(
ldapClient.equalGroups(ldapClient.getPosixGroup(2001), ldapClient.getPosixGroup("user")));
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment