Be consistent about testing package
This commit is contained in:
@@ -18,11 +18,13 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.kamax.mxisd.backend.exec;
|
||||
package io.kamax.mxisd.test.backend.exec;
|
||||
|
||||
import io.kamax.matrix.MatrixID;
|
||||
import io.kamax.matrix._MatrixID;
|
||||
import io.kamax.mxisd.UserIdType;
|
||||
import io.kamax.mxisd.backend.exec.ExecAuthResult;
|
||||
import io.kamax.mxisd.backend.exec.ExecAuthStore;
|
||||
import io.kamax.mxisd.config.ExecConfig;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.junit.Before;
|
@@ -18,10 +18,12 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.kamax.mxisd.backend.exec;
|
||||
package io.kamax.mxisd.test.backend.exec;
|
||||
|
||||
import io.kamax.matrix.MatrixID;
|
||||
import io.kamax.matrix.json.GsonUtil;
|
||||
import io.kamax.mxisd.backend.exec.ExecDirectoryStore;
|
||||
import io.kamax.mxisd.backend.exec.ExecStore;
|
||||
import io.kamax.mxisd.config.ExecConfig;
|
||||
import io.kamax.mxisd.exception.InternalServerError;
|
||||
import io.kamax.mxisd.http.io.UserDirectorySearchResult;
|
@@ -18,7 +18,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.kamax.mxisd.backend.exec;
|
||||
package io.kamax.mxisd.test.backend.exec;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import io.kamax.matrix.MatrixID;
|
||||
@@ -26,6 +26,8 @@ import io.kamax.matrix.ThreePidMedium;
|
||||
import io.kamax.matrix.json.GsonUtil;
|
||||
import io.kamax.mxisd.UserID;
|
||||
import io.kamax.mxisd.UserIdType;
|
||||
import io.kamax.mxisd.backend.exec.ExecIdentityStore;
|
||||
import io.kamax.mxisd.backend.exec.ExecStore;
|
||||
import io.kamax.mxisd.backend.rest.LookupSingleResponseJson;
|
||||
import io.kamax.mxisd.config.ExecConfig;
|
||||
import io.kamax.mxisd.exception.InternalServerError;
|
@@ -18,7 +18,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.kamax.mxisd.backend.exec;
|
||||
package io.kamax.mxisd.test.backend.exec;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import io.kamax.matrix.MatrixID;
|
||||
@@ -27,6 +27,8 @@ import io.kamax.matrix.ThreePidMedium;
|
||||
import io.kamax.matrix._ThreePid;
|
||||
import io.kamax.matrix.json.GsonUtil;
|
||||
import io.kamax.mxisd.UserIdType;
|
||||
import io.kamax.mxisd.backend.exec.ExecProfileStore;
|
||||
import io.kamax.mxisd.backend.exec.ExecStore;
|
||||
import io.kamax.mxisd.config.ExecConfig;
|
||||
import io.kamax.mxisd.profile.JsonProfileResult;
|
||||
import org.junit.Test;
|
@@ -18,7 +18,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.kamax.mxisd.backend.exec;
|
||||
package io.kamax.mxisd.test.backend.exec;
|
||||
|
||||
import io.kamax.matrix.MatrixID;
|
||||
import io.kamax.matrix._MatrixID;
|
@@ -18,9 +18,9 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.kamax.mxisd.backend.exec.auth.input;
|
||||
package io.kamax.mxisd.test.backend.exec.auth.input;
|
||||
|
||||
import io.kamax.mxisd.backend.exec.ExecAuthStoreTest;
|
||||
import io.kamax.mxisd.test.backend.exec.ExecAuthStoreTest;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
@@ -18,9 +18,9 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.kamax.mxisd.backend.exec.auth.input;
|
||||
package io.kamax.mxisd.test.backend.exec.auth.input;
|
||||
|
||||
import io.kamax.mxisd.backend.exec.ExecAuthStoreTest;
|
||||
import io.kamax.mxisd.test.backend.exec.ExecAuthStoreTest;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
@@ -18,10 +18,10 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.kamax.mxisd.backend.exec.auth.input;
|
||||
package io.kamax.mxisd.test.backend.exec.auth.input;
|
||||
|
||||
import io.kamax.mxisd.backend.exec.ExecAuthStoreTest;
|
||||
import io.kamax.mxisd.backend.exec.ExecStore;
|
||||
import io.kamax.mxisd.test.backend.exec.ExecAuthStoreTest;
|
||||
|
||||
public class ExecAuthInputMultilinesTest extends ExecAuthStoreTest {
|
||||
|
@@ -43,16 +43,25 @@ public class LdapAuthTest {
|
||||
private static InMemoryDirectoryServer ds;
|
||||
private static ArrayList<String> dnList = new ArrayList<>();
|
||||
|
||||
private static String domain = "example.org";
|
||||
private static String host = "localhost";
|
||||
private static String mxisdCn = "cn=mxisd";
|
||||
private static String mxisdPw = "mxisd";
|
||||
private static String idType = "uid";
|
||||
private static String idAttribute = "saMAccountName";
|
||||
private static String userId = "john";
|
||||
private static String userPw = "doe";
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws LDAPException {
|
||||
dnList.add("dc=1,dc=mxisd,dc=example,dc=org");
|
||||
dnList.add("dc=2,dc=mxisd,dc=example,dc=org");
|
||||
dnList.add("dc=3,dc=mxisd,dc=example,dc=org");
|
||||
|
||||
InMemoryListenerConfig lCfg = InMemoryListenerConfig.createLDAPConfig("localhost", 65001);
|
||||
InMemoryListenerConfig lCfg = InMemoryListenerConfig.createLDAPConfig(host, 65001);
|
||||
InMemoryDirectoryServerConfig config =
|
||||
new InMemoryDirectoryServerConfig(dnList.get(0), dnList.get(1), dnList.get(2));
|
||||
config.addAdditionalBindCredentials("cn=mxisd", "mxisd");
|
||||
config.addAdditionalBindCredentials(mxisdCn, mxisdPw);
|
||||
config.setListenerConfigs(lCfg);
|
||||
|
||||
ds = new InMemoryDirectoryServer(config);
|
||||
@@ -67,48 +76,48 @@ public class LdapAuthTest {
|
||||
@Test
|
||||
public void singleDn() {
|
||||
MatrixConfig mxCfg = new MatrixConfig();
|
||||
mxCfg.setDomain("example.org");
|
||||
mxCfg.setDomain(domain);
|
||||
mxCfg.build();
|
||||
|
||||
LdapConfig cfg = new GenericLdapConfig();
|
||||
cfg.getConnection().setHost("localhost");
|
||||
cfg.getConnection().setHost(host);
|
||||
cfg.getConnection().setPort(65001);
|
||||
cfg.getConnection().setBaseDn(dnList.get(0));
|
||||
cfg.getConnection().setBindDn("cn=mxisd");
|
||||
cfg.getConnection().setBindPassword("mxisd");
|
||||
cfg.getConnection().setBindDn(mxisdCn);
|
||||
cfg.getConnection().setBindPassword(mxisdPw);
|
||||
|
||||
LdapConfig.UID uid = new LdapConfig.UID();
|
||||
uid.setType("uid");
|
||||
uid.setValue("saMAccountName");
|
||||
uid.setType(idType);
|
||||
uid.setValue(idAttribute);
|
||||
cfg.getAttribute().setUid(uid);
|
||||
cfg.build();
|
||||
|
||||
LdapAuthProvider p = new LdapAuthProvider(cfg, mxCfg);
|
||||
BackendAuthResult result = p.authenticate(MatrixID.from("john", "example.org").valid(), "doe");
|
||||
BackendAuthResult result = p.authenticate(MatrixID.from(userId, domain).valid(), userPw);
|
||||
assertFalse(result.isSuccess());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multiDNs() {
|
||||
MatrixConfig mxCfg = new MatrixConfig();
|
||||
mxCfg.setDomain("example.org");
|
||||
mxCfg.setDomain(domain);
|
||||
mxCfg.build();
|
||||
|
||||
LdapConfig cfg = new GenericLdapConfig();
|
||||
cfg.getConnection().setHost("localhost");
|
||||
cfg.getConnection().setHost(host);
|
||||
cfg.getConnection().setPort(65001);
|
||||
cfg.getConnection().setBaseDNs(dnList);
|
||||
cfg.getConnection().setBindDn("cn=mxisd");
|
||||
cfg.getConnection().setBindPassword("mxisd");
|
||||
cfg.getConnection().setBindDn(mxisdCn);
|
||||
cfg.getConnection().setBindPassword(mxisdPw);
|
||||
|
||||
LdapConfig.UID uid = new LdapConfig.UID();
|
||||
uid.setType("uid");
|
||||
uid.setValue("saMAccountName");
|
||||
uid.setType(idType);
|
||||
uid.setValue(idAttribute);
|
||||
cfg.getAttribute().setUid(uid);
|
||||
cfg.build();
|
||||
|
||||
LdapAuthProvider p = new LdapAuthProvider(cfg, mxCfg);
|
||||
BackendAuthResult result = p.authenticate(MatrixID.from("john", "example.org").valid(), "doe");
|
||||
BackendAuthResult result = p.authenticate(MatrixID.from(userId, domain).valid(), userPw);
|
||||
assertFalse(result.isSuccess());
|
||||
}
|
||||
|
||||
|
@@ -18,14 +18,16 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.kamax.mxisd.backend.rest;
|
||||
package io.kamax.mxisd.test.backend.rest;
|
||||
|
||||
import com.github.tomakehurst.wiremock.junit.WireMockRule;
|
||||
import io.kamax.matrix.MatrixID;
|
||||
import io.kamax.mxisd.backend.rest.RestDirectoryProvider;
|
||||
import io.kamax.mxisd.config.MatrixConfig;
|
||||
import io.kamax.mxisd.config.rest.RestBackendConfig;
|
||||
import io.kamax.mxisd.http.io.UserDirectorySearchResult;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
@@ -81,7 +83,7 @@ public class RestDirectoryProviderTest {
|
||||
public void byNameFound() {
|
||||
stubFor(post(urlEqualTo(endpoint))
|
||||
.willReturn(aResponse()
|
||||
.withHeader("Content-Type", "application/json")
|
||||
.withHeader("Content-Type", ContentType.APPLICATION_JSON.getMimeType())
|
||||
.withBody(byNameResponse)
|
||||
)
|
||||
);
|
||||
@@ -96,7 +98,7 @@ public class RestDirectoryProviderTest {
|
||||
assertTrue(StringUtils.equals(MatrixID.asAcceptable(byNameId, domain).getId(), entry.getUserId()));
|
||||
|
||||
verify(postRequestedFor(urlMatching(endpoint))
|
||||
.withHeader("Content-Type", containing("application/json"))
|
||||
.withHeader("Content-Type", containing(ContentType.APPLICATION_JSON.getMimeType()))
|
||||
.withRequestBody(equalTo(byNameRequest))
|
||||
);
|
||||
}
|
||||
@@ -105,7 +107,7 @@ public class RestDirectoryProviderTest {
|
||||
public void byNameNotFound() {
|
||||
stubFor(post(urlEqualTo(endpoint))
|
||||
.willReturn(aResponse()
|
||||
.withHeader("Content-Type", "application/json")
|
||||
.withHeader("Content-Type", ContentType.APPLICATION_JSON.getMimeType())
|
||||
.withBody(byNameEmptyResponse)
|
||||
)
|
||||
);
|
||||
@@ -115,7 +117,7 @@ public class RestDirectoryProviderTest {
|
||||
assertTrue(result.getResults().isEmpty());
|
||||
|
||||
verify(postRequestedFor(urlMatching(endpoint))
|
||||
.withHeader("Content-Type", containing("application/json"))
|
||||
.withHeader("Content-Type", containing(ContentType.APPLICATION_JSON.getMimeType()))
|
||||
.withRequestBody(equalTo(byNameRequest))
|
||||
);
|
||||
}
|
||||
@@ -124,7 +126,7 @@ public class RestDirectoryProviderTest {
|
||||
public void byThreepidFound() {
|
||||
stubFor(post(urlEqualTo(endpoint))
|
||||
.willReturn(aResponse()
|
||||
.withHeader("Content-Type", "application/json")
|
||||
.withHeader("Content-Type", ContentType.APPLICATION_JSON.getMimeType())
|
||||
.withBody(new String(byThreepidResponse.getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8))
|
||||
)
|
||||
);
|
||||
@@ -139,7 +141,7 @@ public class RestDirectoryProviderTest {
|
||||
assertTrue(StringUtils.equals(MatrixID.asAcceptable(byThreepidId, domain).getId(), entry.getUserId()));
|
||||
|
||||
verify(postRequestedFor(urlMatching(endpoint))
|
||||
.withHeader("Content-Type", containing("application/json"))
|
||||
.withHeader("Content-Type", containing(ContentType.APPLICATION_JSON.getMimeType()))
|
||||
.withRequestBody(equalTo(byThreepidRequest))
|
||||
);
|
||||
}
|
||||
@@ -148,7 +150,7 @@ public class RestDirectoryProviderTest {
|
||||
public void byThreepidNotFound() {
|
||||
stubFor(post(urlEqualTo(endpoint))
|
||||
.willReturn(aResponse()
|
||||
.withHeader("Content-Type", "application/json")
|
||||
.withHeader("Content-Type", ContentType.APPLICATION_JSON.getMimeType())
|
||||
.withBody(byThreepidEmptyResponse)
|
||||
)
|
||||
);
|
||||
@@ -158,7 +160,7 @@ public class RestDirectoryProviderTest {
|
||||
assertTrue(result.getResults().isEmpty());
|
||||
|
||||
verify(postRequestedFor(urlMatching(endpoint))
|
||||
.withHeader("Content-Type", containing("application/json"))
|
||||
.withHeader("Content-Type", containing(ContentType.APPLICATION_JSON.getMimeType()))
|
||||
.withRequestBody(equalTo(byThreepidRequest))
|
||||
);
|
||||
}
|
@@ -18,12 +18,13 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.kamax.mxisd.backend.rest;
|
||||
package io.kamax.mxisd.test.backend.rest;
|
||||
|
||||
import com.github.tomakehurst.wiremock.junit.WireMockRule;
|
||||
import io.kamax.matrix.MatrixID;
|
||||
import io.kamax.matrix._MatrixID;
|
||||
import io.kamax.matrix.json.GsonUtil;
|
||||
import io.kamax.mxisd.backend.rest.RestProfileProvider;
|
||||
import io.kamax.mxisd.config.rest.RestBackendConfig;
|
||||
import io.kamax.mxisd.exception.InternalServerError;
|
||||
import io.kamax.mxisd.profile.JsonProfileRequest;
|
@@ -1,13 +1,15 @@
|
||||
package io.kamax.mxisd.backend.rest;
|
||||
package io.kamax.mxisd.test.backend.rest;
|
||||
|
||||
import com.github.tomakehurst.wiremock.junit.WireMockRule;
|
||||
import io.kamax.matrix.ThreePidMedium;
|
||||
import io.kamax.mxisd.backend.rest.RestThreePidProvider;
|
||||
import io.kamax.mxisd.config.MatrixConfig;
|
||||
import io.kamax.mxisd.config.rest.RestBackendConfig;
|
||||
import io.kamax.mxisd.lookup.SingleLookupReply;
|
||||
import io.kamax.mxisd.lookup.SingleLookupRequest;
|
||||
import io.kamax.mxisd.lookup.ThreePidMapping;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
@@ -17,6 +19,7 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.*;
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@@ -78,7 +81,7 @@ public class RestThreePidProviderTest {
|
||||
public void lookupSingleFound() {
|
||||
stubFor(post(urlEqualTo(lookupSinglePath))
|
||||
.willReturn(aResponse()
|
||||
.withHeader("Content-Type", "application/json")
|
||||
.withHeader("Content-Type", ContentType.APPLICATION_JSON.getMimeType())
|
||||
.withBody(lookupSingleFoundBody)
|
||||
)
|
||||
);
|
||||
@@ -91,7 +94,7 @@ public class RestThreePidProviderTest {
|
||||
});
|
||||
|
||||
verify(postRequestedFor(urlMatching("/lookup/single"))
|
||||
.withHeader("Content-Type", containing("application/json"))
|
||||
.withHeader("Content-Type", containing(ContentType.APPLICATION_JSON.getMimeType()))
|
||||
.withRequestBody(equalTo(lookupSingleRequestBody))
|
||||
);
|
||||
}
|
||||
@@ -100,7 +103,7 @@ public class RestThreePidProviderTest {
|
||||
public void lookupSingleNotFound() {
|
||||
stubFor(post(urlEqualTo(lookupSinglePath))
|
||||
.willReturn(aResponse()
|
||||
.withHeader("Content-Type", "application/json")
|
||||
.withHeader("Content-Type", ContentType.APPLICATION_JSON.getMimeType())
|
||||
.withBody(lookupSingleNotFoundBody)
|
||||
)
|
||||
);
|
||||
@@ -109,7 +112,7 @@ public class RestThreePidProviderTest {
|
||||
assertTrue(!rep.isPresent());
|
||||
|
||||
verify(postRequestedFor(urlMatching("/lookup/single"))
|
||||
.withHeader("Content-Type", containing("application/json"))
|
||||
.withHeader("Content-Type", containing(ContentType.APPLICATION_JSON.getMimeType()))
|
||||
.withRequestBody(equalTo(lookupSingleRequestBody))
|
||||
);
|
||||
}
|
||||
@@ -118,14 +121,14 @@ public class RestThreePidProviderTest {
|
||||
public void lookupBulkFound() {
|
||||
stubFor(post(urlEqualTo(lookupBulkPath))
|
||||
.willReturn(aResponse()
|
||||
.withHeader("Content-Type", "application/json")
|
||||
.withHeader("Content-Type", ContentType.APPLICATION_JSON.getMimeType())
|
||||
.withBody(lookupBulkFoundBody)
|
||||
)
|
||||
);
|
||||
|
||||
List<ThreePidMapping> mappings = p.populate(lookupBulkList);
|
||||
assertNotNull(mappings);
|
||||
assertTrue(mappings.size() == 2);
|
||||
assertEquals(2, mappings.size());
|
||||
assertTrue(StringUtils.equals(mappings.get(0).getMxid(), "@john:example.org"));
|
||||
assertTrue(StringUtils.equals(mappings.get(1).getMxid(), "@jane:example.org"));
|
||||
}
|
||||
@@ -134,14 +137,14 @@ public class RestThreePidProviderTest {
|
||||
public void lookupBulkNotFound() {
|
||||
stubFor(post(urlEqualTo(lookupBulkPath))
|
||||
.willReturn(aResponse()
|
||||
.withHeader("Content-Type", "application/json")
|
||||
.withHeader("Content-Type", ContentType.APPLICATION_JSON.getMimeType())
|
||||
.withBody(lookupBulkNotFoundBody)
|
||||
)
|
||||
);
|
||||
|
||||
List<ThreePidMapping> mappings = p.populate(lookupBulkList);
|
||||
assertNotNull(mappings);
|
||||
assertTrue(mappings.size() == 0);
|
||||
assertEquals(0, mappings.size());
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user