Further progress on Exec Identity Store
This commit is contained in:
@@ -18,15 +18,15 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.kamax.mxisd.backend.exec;
|
||||
package io.kamax.mxisd.backend.exec.input;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class ExecAuthStoreArgsTest extends ExecAuthStoreTest {
|
||||
public class ArgsTest extends InputTest {
|
||||
|
||||
@Override
|
||||
protected void setValidCommand() {
|
||||
cfg.getAuth().setCommand("src/test/resources/store/exec/authArgsTest.sh");
|
||||
cfg.getAuth().setCommand("src/test/resources/store/exec/input/argsTest.sh");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -18,9 +18,11 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.kamax.mxisd.backend.exec;
|
||||
package io.kamax.mxisd.backend.exec.input;
|
||||
|
||||
public class ExecAuthStoreEnvTest extends ExecAuthStoreTest {
|
||||
import java.util.HashMap;
|
||||
|
||||
public class EnvTest extends InputTest {
|
||||
|
||||
private final String LocalpartEnv = "LOCALPART";
|
||||
private final String DomainEnv = "DOMAIN";
|
||||
@@ -28,11 +30,12 @@ public class ExecAuthStoreEnvTest extends ExecAuthStoreTest {
|
||||
|
||||
@Override
|
||||
protected void setValidCommand() {
|
||||
cfg.getAuth().setCommand("src/test/resources/store/exec/authEnvTest.sh");
|
||||
cfg.getAuth().setCommand("src/test/resources/store/exec/input/envTest.sh");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setValidEnv() {
|
||||
cfg.getAuth().setEnv(new HashMap<>());
|
||||
cfg.getAuth().addEnv(LocalpartEnv, LocalpartToken);
|
||||
cfg.getAuth().addEnv(DomainEnv, DomainToken);
|
||||
cfg.getAuth().addEnv(MxidEnv, MxidToken);
|
||||
@@ -18,13 +18,16 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.kamax.mxisd.backend.exec;
|
||||
package io.kamax.mxisd.backend.exec.input;
|
||||
|
||||
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;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -32,7 +35,7 @@ import java.util.Collections;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public abstract class ExecAuthStoreTest {
|
||||
public abstract class InputTest {
|
||||
|
||||
protected final ExecConfig cfg;
|
||||
protected final ExecAuthStore p;
|
||||
@@ -61,20 +64,23 @@ public abstract class ExecAuthStoreTest {
|
||||
// no-op
|
||||
}
|
||||
|
||||
protected void setValidInput() {
|
||||
// no-op
|
||||
}
|
||||
|
||||
protected void setValidExit() {
|
||||
cfg.getAuth().getExit().setSuccess(Collections.singletonList(0));
|
||||
cfg.getAuth().getExit().setFailure(Arrays.asList(1, 10, 11, 12, 20, 21, 22));
|
||||
}
|
||||
|
||||
protected void setValidConfig() {
|
||||
@Before
|
||||
public void setValidConfig() {
|
||||
setValidCommand();
|
||||
setValidEnv();
|
||||
setValidArgs();
|
||||
setValidInput();
|
||||
setValidExit();
|
||||
}
|
||||
|
||||
public ExecAuthStoreTest() {
|
||||
cfg = new ExecConfig();
|
||||
cfg.getAuth().addEnv("WITH_LOCALPART", "1");
|
||||
cfg.getAuth().addEnv("REQ_LOCALPART", uId.getLocalPart());
|
||||
cfg.getAuth().addEnv("WITH_DOMAIN", "1");
|
||||
@@ -82,9 +88,10 @@ public abstract class ExecAuthStoreTest {
|
||||
cfg.getAuth().addEnv("WITH_MXID", "1");
|
||||
cfg.getAuth().addEnv("REQ_MXID", uId.getId());
|
||||
cfg.getAuth().addEnv("REQ_PASS", requiredPass);
|
||||
}
|
||||
|
||||
setValidConfig();
|
||||
|
||||
public InputTest() {
|
||||
cfg = new ExecConfig();
|
||||
p = new ExecAuthStore(cfg);
|
||||
}
|
||||
|
||||
@@ -119,7 +126,7 @@ public abstract class ExecAuthStoreTest {
|
||||
protected abstract void setEmptyLocalpartConfig();
|
||||
|
||||
@Test
|
||||
public void doEmptyLocalpartConfig() {
|
||||
public void emptyLocalpartConfig() {
|
||||
setEmptyLocalpartConfig();
|
||||
|
||||
ExecAuthResult res = p.authenticate(uId, requiredPass);
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* 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.backend.exec.input;
|
||||
|
||||
import io.kamax.mxisd.backend.exec.ExecStore;
|
||||
|
||||
public class MultilinesTest extends InputTest {
|
||||
|
||||
@Override
|
||||
protected void setValidCommand() {
|
||||
cfg.getAuth().setCommand("src/test/resources/store/exec/input/multilinesTest.sh");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setValidInput() {
|
||||
cfg.getAuth().getInput().setType(ExecStore.MultilinesType);
|
||||
cfg.getAuth().getInput().setTemplate(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setEmptyLocalpartConfig() {
|
||||
cfg.getAuth().getInput().setTemplate("" + System.lineSeparator()
|
||||
+ DomainToken + System.lineSeparator()
|
||||
+ MxidToken + System.lineSeparator()
|
||||
+ PassToken + System.lineSeparator()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWrongLocalpartConfig() {
|
||||
cfg.getAuth().getInput().setTemplate(LocalpartInvalid + System.lineSeparator()
|
||||
+ DomainToken + System.lineSeparator()
|
||||
+ MxidToken + System.lineSeparator()
|
||||
+ PassToken + System.lineSeparator()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setEmptyDomainConfig() {
|
||||
cfg.getAuth().getInput().setTemplate(LocalpartToken + System.lineSeparator()
|
||||
+ "" + System.lineSeparator()
|
||||
+ MxidToken + System.lineSeparator()
|
||||
+ PassToken + System.lineSeparator()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWrongDomainConfig() {
|
||||
cfg.getAuth().getInput().setTemplate(LocalpartToken + System.lineSeparator()
|
||||
+ DomainInvalid + System.lineSeparator()
|
||||
+ MxidToken + System.lineSeparator()
|
||||
+ PassToken + System.lineSeparator()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setEmptyMxidConfig() {
|
||||
cfg.getAuth().getInput().setTemplate(LocalpartToken + System.lineSeparator()
|
||||
+ DomainToken + System.lineSeparator()
|
||||
+ "" + System.lineSeparator()
|
||||
+ PassToken + System.lineSeparator()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWrongMxidConfig() {
|
||||
cfg.getAuth().getInput().setTemplate(LocalpartToken + System.lineSeparator()
|
||||
+ DomainToken + System.lineSeparator()
|
||||
+ MxidInvalid + System.lineSeparator()
|
||||
+ PassToken + System.lineSeparator()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user