Updated client registration (store client secret hashcode).
Change-Id: Ifa14f1439b617be2b1c37c31a8c40298efcc6314
diff --git a/full/src/test/java/de/ids_mannheim/korap/config/ConfigTest.java b/full/src/test/java/de/ids_mannheim/korap/config/ConfigTest.java
index 8fd00ef..ac3a131 100644
--- a/full/src/test/java/de/ids_mannheim/korap/config/ConfigTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/config/ConfigTest.java
@@ -3,17 +3,12 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.security.NoSuchAlgorithmException;
import java.util.Map;
import java.util.Properties;
-import org.codehaus.plexus.util.IOUtil;
import org.junit.Ignore;
import org.junit.Test;
@@ -43,22 +38,6 @@
assertNotNull(p);
}
-
- @Test
- public void testAdminHash () throws IOException, KustvaktException,
- NoSuchAlgorithmException {
- AdminSetup setup = AdminSetup.getInstance();
- String hash = setup.getHash();
- File f = new File("./admin_token");
- FileInputStream stream = new FileInputStream(f);
- String token = IOUtil.toString(stream);
- assertNotEquals("", hash);
- assertNotEquals("", token);
- EncryptionIface crypto = helper().getContext().getEncryption();
- assertTrue(crypto.checkHash(token, hash));
- }
-
-
@Test
public void testServiceInfo () {
String version = ServiceInfo.getInfo().getVersion();
@@ -89,16 +68,6 @@
}
@Test
- @Ignore
- public void testKustvaktValueValidation() {
- Map m = KustvaktConfiguration.KUSTVAKT_USER;
- EncryptionIface crypto = helper().getContext().getEncryption();
-
-
- }
-
-
- @Test
public void testBootConfigDependencyOrder () {
// todo:
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/OAuth2HandlerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/OAuth2HandlerTest.java
index a8742fa..24d468f 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/OAuth2HandlerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/OAuth2HandlerTest.java
@@ -11,6 +11,7 @@
import de.ids_mannheim.korap.config.BeanConfigTest;
import de.ids_mannheim.korap.config.ClientInfo;
import de.ids_mannheim.korap.config.ContextHolder;
+import de.ids_mannheim.korap.encryption.KustvaktEncryption;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.handlers.OAuth2Handler;
import de.ids_mannheim.korap.interfaces.EncryptionIface;
@@ -23,6 +24,7 @@
* @date 13/05/2015
*/
@Ignore
+@Deprecated
public class OAuth2HandlerTest extends BeanConfigTest {
private static ClientInfo info;
@@ -33,14 +35,20 @@
@Test
public void testStoreAuthorizationCodeThrowsNoException ()
throws KustvaktException {
- String auth_code = helper().getContext().getEncryption().createToken();
- AuthCodeInfo codeInfo = new AuthCodeInfo(info.getClient_id(), auth_code);
+
+ EncryptionIface crypto = new KustvaktEncryption(
+ helper().getContext().getConfiguration());
+
+ String auth_code = crypto.createToken();
+ AuthCodeInfo codeInfo =
+ new AuthCodeInfo(info.getClient_id(), auth_code);
codeInfo.setScopes(SCOPES);
- OAuth2Handler handler = new OAuth2Handler(helper().getContext()
- .getPersistenceClient());
+ OAuth2Handler handler =
+ new OAuth2Handler(helper().getContext().getPersistenceClient());
handler.authorize(codeInfo, helper().getUser());
- assertTrue("couldn't find entry in cache", handler.hasCacheEntry(codeInfo.getCode()));
+ assertTrue("couldn't find entry in cache",
+ handler.hasCacheEntry(codeInfo.getCode()));
codeInfo = handler.getAuthorization(auth_code);
assertNotNull("client is null!", codeInfo);
}
@@ -49,15 +57,19 @@
@Test
public void testAuthorizationCodeRemoveThrowsNoException ()
throws KustvaktException {
- String auth_code = helper().getContext().getEncryption().createToken();
- AuthCodeInfo codeInfo = new AuthCodeInfo(info.getClient_id(), auth_code);
+ EncryptionIface crypto = new KustvaktEncryption(
+ helper().getContext().getConfiguration());
+
+ String auth_code = crypto.createToken();
+ AuthCodeInfo codeInfo =
+ new AuthCodeInfo(info.getClient_id(), auth_code);
codeInfo.setScopes(SCOPES);
- OAuth2Handler handler = new OAuth2Handler(helper().getContext()
- .getPersistenceClient());
+ OAuth2Handler handler =
+ new OAuth2Handler(helper().getContext().getPersistenceClient());
handler.authorize(codeInfo, helper().getUser());
- String t = helper().getContext().getEncryption().createToken();
- String refresh = helper().getContext().getEncryption().createToken();
+ String t = crypto.createToken();
+ String refresh = crypto.createToken();
handler.addToken(codeInfo.getCode(), t, refresh, 7200);
TokenContext ctx = handler.getPersistenceHandler().getContext(t);
@@ -76,8 +88,11 @@
@Test
public void testStoreAccessCodeViaAuthCodeThrowsNoException () {
- String auth_code = helper().getContext().getEncryption().createToken();
- AuthCodeInfo codeInfo = new AuthCodeInfo(info.getClient_id(), auth_code);
+ String auth_code =
+ new KustvaktEncryption(helper().getContext().getConfiguration())
+ .createToken();
+ AuthCodeInfo codeInfo =
+ new AuthCodeInfo(info.getClient_id(), auth_code);
codeInfo.setScopes(SCOPES);
}
@@ -112,14 +127,17 @@
public void initMethod () throws KustvaktException {
helper().setupAccount();
- EncryptionIface crypto = helper().getContext().getEncryption();
- info = new ClientInfo(crypto.createRandomNumber(), crypto.createToken());
+ EncryptionIface crypto = new KustvaktEncryption(
+ helper().getContext().getConfiguration());
+ info = new ClientInfo(crypto.createRandomNumber(),
+ crypto.createToken());
info.setConfidential(true);
//todo: support for subdomains?!
info.setUrl("http://localhost:8080/api/v0.1");
info.setRedirect_uri("testwebsite/login");
PersistenceClient cl = helper().getBean(ContextHolder.KUSTVAKT_DB);
OAuth2Handler handler = new OAuth2Handler(cl);
- handler.getPersistenceHandler().registerClient(info, helper().getUser());
+ handler.getPersistenceHandler().registerClient(info,
+ helper().getUser());
}
}
diff --git a/full/src/test/resources/test-config.xml b/full/src/test/resources/test-config.xml
index ffd8c9e..562c3bb 100644
--- a/full/src/test/resources/test-config.xml
+++ b/full/src/test/resources/test-config.xml
@@ -195,7 +195,7 @@
</bean>
<bean name="kustvakt_encryption"
- class="de.ids_mannheim.korap.interfaces.defaults.KustvaktEncryption">
+ class="de.ids_mannheim.korap.encryption.KustvaktEncryption">
<constructor-arg ref="kustvakt_config" />
</bean>