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 {
/**
* Creates a new LDAP POSIX group.
*
* @param cn the group's common name
* @param gidNumber the group's gid number
* @param description the group's description
* @param userPassword the group's user password
* @param group the {@link PosixGroup} to create
* @return the created {@link PosixGroup}
*
*/
public PosixGroup createPosixGroup(String cn, int gidNumber, String description,
String userPassword) {
PosixGroup group = new PosixGroup();
group.setCommonName(cn);
group.setGidNumber(gidNumber);
group.setDescription(description);
if (userPassword != null) {
group.setUserPassword(userPassword.getBytes());
}
public PosixGroup createPosixGroup(PosixGroup 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;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import edu.kit.scc.test.http.HttpClientTest;
import edu.kit.scc.test.ldap.LdapClientTest;
@RunWith(Suite.class)
@Suite.SuiteClasses({LdapClientTest.class})
@Suite.SuiteClasses({HttpClientTest.class, LdapClientTest.class})
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;
import static org.junit.Assert.assertNotNull;
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.Test;
import org.junit.runner.RunWith;
......@@ -22,10 +28,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import edu.kit.scc.Application;
import edu.kit.scc.dto.PosixGroup;
import edu.kit.scc.dto.PosixUser;
import edu.kit.scc.ldap.LdapClient;
import java.util.List;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
......@@ -37,30 +40,56 @@ public class LdapClientTest {
@Autowired
private LdapClient ldapClient;
@Test
public void a_createLdapGroupTest() {
ldapClient.createPosixGroup("newGroup", 3333, null, null);
}
protected static PosixGroup posixGroup;
protected static PosixUser posixUser;
@Test
public void b_createLdapUserTest() {
String cn = "newUser";
String sn = "newUser";
@BeforeClass
public static void setUpBeforeClass() {
String userCn = "newUser";
String userSn = "newUser";
String description = "new posix user";
String homeDirectory = "/home/newUser";
String uid = "newUser";
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;
// ldapClient.createIndigoUser(uid, cn, sn, uid, uidNumber, gidNumber,
// homeDirectory, description, null, null,
// null);
posixGroup = new PosixGroup();
posixGroup.setCommonName(groupCn);
posixGroup.setGidNumber(gidNumber);
}
@Test
public void c_getLdapUserTest() {
PosixUser user = ldapClient.getPosixUser("newUser");
public void a_createLdapGroupTest() {
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);
log.debug(user.toString());
......@@ -68,27 +97,26 @@ public class LdapClientTest {
@Test
public void d_updateUserTest() {
String cn = "newUser";
String sn = "newUser";
String description = "new posix user (update)";
String homeDirectory = "/home/newUser";
String uid = "newUser";
int uidNumber = 6001;
int gidNumber = 3333;
posixUser.setDescription("new posix user (update)");
PosixUser user = ldapClient.updatePosixUser(posixUser);
assertNotNull(user);
// ldapClient.updateIndigoUser(uid, cn, sn, uid, uidNumber, gidNumber,
// homeDirectory, description, null, null,
// null);
log.debug(user.toString());
}
@Test
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
public void f_getLdapGroupTest() {
PosixGroup group = ldapClient.getPosixGroup("newGroup");
PosixGroup group = ldapClient.getPosixGroup(posixGroup.getCommonName());
assertNotNull(group);
......@@ -96,35 +124,37 @@ public class LdapClientTest {
}
@Test
public void g_deleteLdapUserTest() {
ldapClient.deleteUser("newUser");
public void g_groupEqualityTest() {
assertTrue(ldapClient.equalGroups(ldapClient.getPosixGroup(posixGroup.getGidNumber()),
ldapClient.getPosixGroup(posixGroup.getCommonName())));
}
@Test
public void h_deleteLdapGroupTest() {
ldapClient.deleteGroup("newGroup");
public void h_deleteLdapUserTest() {
ldapClient.deleteUser(posixUser.getUid());
}
@Test
public void getLdapGroupsTest() {
ldapClient.getPosixGroups();
public void i_deleteLdapGroupTest() {
ldapClient.deleteGroup(posixGroup.getCommonName());
}
@Test
public void getLdapUsersTest() {
public void j_getLdapGroupsTest() {
List<PosixGroup> groups = ldapClient.getPosixGroups();
assertNotNull(groups);
}
@Test
public void getNewGidNumber() {
log.debug("{}", ldapClient.generateGroupIdNumber());
public void k_getLdapUsersTest() {
List<PosixUser> users = ldapClient.getPosixUsers();
assertNotNull(users);
}
@Test
public void groupEqualityTest() {
assertTrue(
ldapClient.equalGroups(ldapClient.getPosixGroup(2001), ldapClient.getPosixGroup("user")));
public void getNewGidNumber() {
assertNotNull(ldapClient.generateGroupIdNumber());
}
}
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