Continue structural port from Spring Boot to Undertow

This commit is contained in:
Max Dor
2018-12-30 05:28:05 +01:00
parent 6a376db322
commit 7ad985fead
85 changed files with 1019 additions and 367 deletions

View File

@@ -0,0 +1,51 @@
/*
* mxisd - Matrix Identity Server Daemon
* Copyright (C) 2018 Kamax Sarl
*
* https://www.kamax.io/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.kamax.mxisd.test;
import io.kamax.matrix.ThreePidMedium;
import io.kamax.mxisd.Mxisd;
import io.kamax.mxisd.config.MxisdConfig;
import org.junit.Test;
import static junit.framework.TestCase.*;
public class MxisdDefaultTest {
private final String domain = "localhost";
@Test
public void defaultConfig() {
MxisdConfig cfg = new MxisdConfig();
cfg.getMatrix().setDomain(domain);
cfg.getKey().setPath(":memory:");
cfg.getStorage().getProvider().getSqlite().setDatabase(":memory:");
Mxisd m = new Mxisd(cfg);
m.start();
assertNotNull(m.getConfig());
assertEquals(domain, m.getConfig().getMatrix().getDomain());
assertTrue(m.getNotif().isMediumSupported(ThreePidMedium.Email.getId()));
assertTrue(m.getNotif().isMediumSupported(ThreePidMedium.PhoneNumber.getId()));
}
}

View File

@@ -0,0 +1,78 @@
/*
* mxisd - Matrix Identity Server Daemon
* Copyright (C) 2018 Kamax Sarl
*
* https://www.kamax.io/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.kamax.mxisd.test;
import io.kamax.mxisd.Mxisd;
import io.kamax.mxisd.config.MxisdConfig;
import io.kamax.mxisd.config.memory.MemoryIdentityConfig;
import io.kamax.mxisd.config.memory.MemoryThreePid;
import io.kamax.mxisd.lookup.SingleLookupReply;
import io.kamax.mxisd.lookup.SingleLookupRequest;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.Optional;
import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertEquals;
public class MxisdTest {
private Mxisd m;
@Before
public void before() {
MxisdConfig cfg = new MxisdConfig();
cfg.getMatrix().setDomain("localhost");
cfg.getKey().setPath(":memory:");
cfg.getStorage().getProvider().getSqlite().setDatabase(":memory:");
MemoryThreePid mem3pid = new MemoryThreePid();
mem3pid.setMedium("email");
mem3pid.setAddress("john@localhost");
MemoryIdentityConfig memCfg = new MemoryIdentityConfig();
memCfg.setUsername("john");
memCfg.getThreepids().add(mem3pid);
cfg.getMemory().setEnabled(true);
cfg.getMemory().getIdentities().add(memCfg);
m = new Mxisd(cfg);
m.start();
}
@After
public void after() {
m.stop();
}
@Test
public void singleLookup() {
SingleLookupRequest req = new SingleLookupRequest();
req.setRecursive(false);
req.setType("email");
req.setThreePid("john@localhost");
Optional<SingleLookupReply> reply = m.getIdentity().find(req);
assertTrue(reply.isPresent());
assertEquals("@john:localhost", reply.get().getMxid().getId());
}
}

View File

@@ -68,7 +68,6 @@ public class ExecDirectoryStoreTest extends ExecStoreTest {
private ExecDirectoryStore getStore(ExecConfig.Directory cfg) {
ExecDirectoryStore store = new ExecDirectoryStore(cfg, getMatrixCfg());
store.setExecutorSupplier(this::build);
assertTrue(store.isEnabled());
return store;
}

View File

@@ -75,7 +75,7 @@ public class ExecIdentityStoreTest extends ExecStoreTest {
private ExecIdentityStore getStore(ExecConfig.Identity cfg) {
ExecIdentityStore store = new ExecIdentityStore(cfg, getMatrixCfg());
store.setExecutorSupplier(this::build);
assertTrue(store.isEnabled());
assertTrue(store.isLocal());
return store;
}

View File

@@ -84,7 +84,6 @@ public class ExecProfileStoreTest extends ExecStoreTest {
private ExecProfileStore getStore(ExecConfig.Profile cfg) {
ExecProfileStore store = new ExecProfileStore(cfg);
store.setExecutorSupplier(this::build);
assertTrue(store.isEnabled());
return store;
}

View File

@@ -75,22 +75,22 @@ public class LdapAuthTest {
@Test
public void singleDn() {
MatrixConfig mxCfg = new MatrixConfig();
mxCfg.setDomain(domain);
mxCfg.build();
LdapConfig cfg = new GenericLdapConfig();
cfg.getConnection().setHost(host);
cfg.getConnection().setPort(65001);
cfg.getConnection().setBaseDn(dnList.get(0));
cfg.getConnection().setBindDn(mxisdCn);
cfg.getConnection().setBindPassword(mxisdPw);
cfg.build();
LdapConfig.UID uid = new LdapConfig.UID();
uid.setType(idType);
uid.setValue(idAttribute);
cfg.getAttribute().setUid(uid);
cfg.build();
MatrixConfig mxCfg = new MatrixConfig();
mxCfg.setDomain(domain);
mxCfg.build();
LdapAuthProvider p = new LdapAuthProvider(cfg, mxCfg);
BackendAuthResult result = p.authenticate(MatrixID.from(userId, domain).valid(), userPw);