From fd645543959f23682836d4d97d464aa6ef9f3320 Mon Sep 17 00:00:00 2001 From: anhefti Date: Tue, 8 Mar 2022 11:20:16 +0100 Subject: [PATCH] more tests --- .../ch/ethz/seb/sebserver/gbl/util/Tuple.java | 2 +- .../seb/sebserver/gbl/util/Tuple3Test.java | 37 ++++- .../integration/UseCasesIntegrationTest.java | 148 ++++++++++++++++++ src/test/resources/sebserver-test.cer | 20 +++ src/test/resources/testIdentity123.pfx | Bin 0 -> 3786 bytes 5 files changed, 205 insertions(+), 2 deletions(-) create mode 100644 src/test/resources/sebserver-test.cer create mode 100644 src/test/resources/testIdentity123.pfx diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/util/Tuple.java b/src/main/java/ch/ethz/seb/sebserver/gbl/util/Tuple.java index 21de222f..6af9d20d 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/util/Tuple.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/util/Tuple.java @@ -36,7 +36,7 @@ public class Tuple { return (TT) this; } - return null; + throw new IllegalArgumentException("Type mismatch: " + this.getClass() + " to " + type); } @Override diff --git a/src/test/java/ch/ethz/seb/sebserver/gbl/util/Tuple3Test.java b/src/test/java/ch/ethz/seb/sebserver/gbl/util/Tuple3Test.java index 24528ece..4225bf65 100644 --- a/src/test/java/ch/ethz/seb/sebserver/gbl/util/Tuple3Test.java +++ b/src/test/java/ch/ethz/seb/sebserver/gbl/util/Tuple3Test.java @@ -9,18 +9,53 @@ package ch.ethz.seb.sebserver.gbl.util; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.jupiter.api.Assertions.fail; import org.junit.Test; public class Tuple3Test { @Test - public void test() { + public void test3() { final Tuple3 candidate = new Tuple3<>("1", "2", "3"); assertEquals("(1, 2, 3)", candidate.toString()); assertEquals("1", candidate.get_1()); assertEquals("2", candidate.get_2()); assertEquals("3", candidate.get_3()); + + final Tuple3 candidate1 = new Tuple3<>("1", "2", "3"); + final Tuple3 candidate2 = new Tuple3<>("4", "5", "6"); + assertEquals(candidate, candidate1); + assertNotEquals(candidate1, candidate2); + + try { + @SuppressWarnings("unchecked") + final Tuple tuple = candidate.adaptTo(Tuple.class); + fail("Should fail here"); + } catch (final Exception e) { + assertEquals( + "Type mismatch: class ch.ethz.seb.sebserver.gbl.util.Tuple3 to class ch.ethz.seb.sebserver.gbl.util.Tuple", + e.getMessage()); + } + } + + @Test + public void test2() { + final Tuple candidate = new Tuple<>("1", "2"); + assertEquals("(1, 2)", candidate.toString()); + assertEquals("1", candidate.get_1()); + assertEquals("2", candidate.get_2()); + + final Tuple candidate1 = new Tuple<>("1", "2"); + final Tuple candidate2 = new Tuple3<>("4", "5", "6"); + assertEquals(candidate, candidate1); + assertNotEquals(candidate1, candidate2); + + @SuppressWarnings("unchecked") + final Tuple3 tuple = candidate2.adaptTo(Tuple3.class); + assertEquals("(4, 5, 6)", tuple.toString()); + } } diff --git a/src/test/java/ch/ethz/seb/sebserver/gui/integration/UseCasesIntegrationTest.java b/src/test/java/ch/ethz/seb/sebserver/gui/integration/UseCasesIntegrationTest.java index 148164fa..fe651cd7 100644 --- a/src/test/java/ch/ethz/seb/sebserver/gui/integration/UseCasesIntegrationTest.java +++ b/src/test/java/ch/ethz/seb/sebserver/gui/integration/UseCasesIntegrationTest.java @@ -72,6 +72,8 @@ import ch.ethz.seb.sebserver.gbl.model.institution.Institution; import ch.ethz.seb.sebserver.gbl.model.institution.LmsSetup; import ch.ethz.seb.sebserver.gbl.model.institution.LmsSetup.LmsType; import ch.ethz.seb.sebserver.gbl.model.institution.LmsSetupTestResult; +import ch.ethz.seb.sebserver.gbl.model.sebconfig.CertificateInfo; +import ch.ethz.seb.sebserver.gbl.model.sebconfig.CertificateInfo.CertificateType; import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigCreationInfo; import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigKey; import ch.ethz.seb.sebserver.gbl.model.sebconfig.Configuration; @@ -152,6 +154,11 @@ import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.logs.GetUserLogPa import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.quiz.GetQuizData; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.quiz.GetQuizPage; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.quiz.ImportAsExam; +import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.cert.AddCertificate; +import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.cert.GetCertificate; +import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.cert.GetCertificateNames; +import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.cert.GetCertificatePage; +import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.cert.RemoveCertificate; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.clientconfig.ActivateClientConfig; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.clientconfig.DeactivateClientConfig; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.clientconfig.ExportClientConfig; @@ -2950,4 +2957,145 @@ public class UseCasesIntegrationTest extends GuiIntegrationTest { } + @Test + @Order(23) + // ************************************* + // Use Case 23: Certificates + // - check certificates (list) is empty + // - upload test certificate + // - check certificates + // - upload identity certificate + // - check certificates + // - create new connection config with identity certigficate encryption + // - donwload connection config with identity certigficate encryption + // - remove certificate + public void testUsecase23_Certificates() throws Exception { + final RestServiceImpl restService = createRestServiceForUser( + "TestInstAdmin", + "987654321", + new GetCertificate(), + new GetCertificateNames(), + new GetCertificatePage(), + new RemoveCertificate(), + new AddCertificate(), + new NewClientConfig(), + new SaveClientConfig(), + new ActivateClientConfig(), + new DeactivateClientConfig(), + new ExportClientConfig()); + + // - check certificates (list) is empty + Page certificates = restService + .getBuilder(GetCertificatePage.class) + .call() + .getOrThrow(); + + assertNotNull(certificates); + assertTrue(certificates.content.isEmpty()); + + // - upload test certificate + InputStream inputStream = new ClassPathResource("sebserver-test.cer").getInputStream(); + final CertificateInfo newCert = restService + .getBuilder(AddCertificate.class) + .withBody(inputStream) + .withHeader(API.IMPORT_FILE_ATTR_NAME, "sebserver-test.cer") + .call() + .getOrThrow(); + + assertNotNull(newCert); + assertEquals("test.anhefti.sebserver", newCert.alias); + assertTrue(newCert.types.contains(CertificateType.DIGITAL_SIGNATURE)); + assertTrue(newCert.types.contains(CertificateType.DATA_ENCIPHERMENT)); + + // - check certificates + certificates = restService + .getBuilder(GetCertificatePage.class) + .call() + .getOrThrow(); + + assertNotNull(certificates); + assertFalse(certificates.content.isEmpty()); + + final CertificateInfo certificateInfo = certificates.content.get(0); + assertEquals("test.anhefti.sebserver", certificateInfo.alias); + + // - upload identity certificate + inputStream = new ClassPathResource("testIdentity123.pfx").getInputStream(); + final CertificateInfo newCert1 = restService + .getBuilder(AddCertificate.class) + .withBody(inputStream) + .withHeader(API.IMPORT_FILE_ATTR_NAME, "testIdentity123.pfx") + .withHeader(API.IMPORT_PASSWORD_ATTR_NAME, "123") + .call() + .getOrThrow(); + + assertNotNull(newCert1); + assertEquals("*.2mdn.net", newCert1.alias); + assertTrue(newCert1.types.contains(CertificateType.DATA_ENCIPHERMENT_PRIVATE_KEY)); + + // - check certificates + certificates = restService + .getBuilder(GetCertificatePage.class) + .call() + .getOrThrow(); + + assertNotNull(certificates); + assertFalse(certificates.content.isEmpty()); + assertTrue(certificates.content.size() == 2); + + // - create new connection config with identity certigficate encryption + final SEBClientConfig newConfig = restService + .getBuilder(NewClientConfig.class) + .withFormParam(Domain.SEB_CLIENT_CONFIGURATION.ATTR_NAME, "Connection Config with Cert") + .withFormParam(SEBClientConfig.ATTR_ENCRYPT_CERTIFICATE_ALIAS, "*.2mdn.net") + .withFormParam(SEBClientConfig.ATTR_CONFIG_PURPOSE, SEBClientConfig.ConfigPurpose.START_EXAM.name()) + .call() + .getOrThrow(); + + assertNotNull(newConfig); + assertEquals("*.2mdn.net", newConfig.encryptCertificateAlias); + + // - donwload connection config with identity certigficate encryption + final Result exportResponse = restService + .getBuilder(ExportClientConfig.class) + .withURIVariable(API.PARAM_MODEL_ID, newConfig.getModelId()) + .withResponseExtractor(response -> { + final InputStream input = response.getBody(); + final List readLines = IOUtils.readLines(input, "UTF-8"); + assertNotNull(readLines); + assertFalse(readLines.isEmpty()); + return true; + }) + .call(); + + assertNotNull(exportResponse); + assertTrue(exportResponse.get()); + + // - remmove certificate + final CertificateInfo cert = restService + .getBuilder(GetCertificate.class) + .withURIVariable(API.CERTIFICATE_ALIAS, "test.anhefti.sebserver") + //.withURIVariable(API.PARAM_MODEL_ID, newCert.getModelId()) + .call() + .getOrThrow(); + + assertNotNull(cert); + assertEquals("test.anhefti.sebserver", cert.alias); + + final Result> removeCert = restService + .getBuilder(RemoveCertificate.class) + .withFormParam(API.CERTIFICATE_ALIAS, "test.anhefti.sebserver") + .call(); + + assertNotNull(removeCert); + assertFalse(removeCert.hasError()); + final Collection collection = removeCert.get(); + assertFalse(collection.isEmpty()); + final EntityKey next = collection.iterator().next(); + assertEquals( + "EntityKey [modelId=test.anhefti.sebserver, entityType=CERTIFICATE]", + next.toString()); + + } + } diff --git a/src/test/resources/sebserver-test.cer b/src/test/resources/sebserver-test.cer new file mode 100644 index 00000000..c291bc16 --- /dev/null +++ b/src/test/resources/sebserver-test.cer @@ -0,0 +1,20 @@ +-----BEGIN CERTIFICATE----- +MIIDPzCCAiegAwIBAgIQUQvCtw+rLZBG+inNAge2ojANBgkqhkiG9w0BAQsFADAh +MR8wHQYDVQQDDBZ0ZXN0LmFuaGVmdGkuc2Vic2VydmVyMB4XDTIxMDUwNjEyMjEw +MVoXDTIyMDUwNjEyNDEwMVowITEfMB0GA1UEAwwWdGVzdC5hbmhlZnRpLnNlYnNl +cnZlcjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAOnoI00+x4AO4glp +/n6H6KoOKAsPwJhwa2im5Xe6hU1EODzGxCSjklnzwj0Qa2a5nBkutoek3sAaKHY5 +6EaoijjjglckmsxopYygbHho0K1dgnO0Ip2lT1Yq3IZ21hbPbzQXpPkmkjsgA1qD +/WGtLfSz6AC0rv3/4ODQzjTnMpBge/nI0E2+SVxAe25tzCMiAclrAVDYzAIbNo4F +5efZ30RTXMd4GSxNP7YHn+TIYdX+W36eyGEisAuOJWzQfLbXgiOkISGRv/Nvmla7 +YXRmCcXOkWCr5QwZshHulD6Zx3m0rM1eNqNuiV7Lxpz5XtDV9m+GJ+ucE+8DGu2Q +AlSZ260CAwEAAaNzMHEwDgYDVR0PAQH/BAQDAgWgMB0GA1UdJQQWMBQGCCsGAQUF +BwMCBggrBgEFBQcDATAhBgNVHREEGjAYghZ0ZXN0LmFuaGVmdGkuc2Vic2VydmVy +MB0GA1UdDgQWBBQ3mdxUQV1Fh9dNOQFz6xnAeC/LfjANBgkqhkiG9w0BAQsFAAOC +AQEAOlh0Nq5ysBNniUFNnvHidayWcI6V1MMg31EOc43rzzBdrssPflFFXm6AfX6M +yFOyeHfU8FRxp3IAiRi/jc+w0GUnIpm803SoxIbalI/lVEV8GhVhKEEe1l9QWs07 +oKS1Wu5u3XKF/AwjNs1jhtNobo4jvAVylgRc/fxsXM7SwyFfkMMiwml0rBDzokrM +y6obH2UdK8sRGL7xTGAmOBMRVlI+EiNd8Cc42wARuMMamIF/SEOSzgfR4kMTzSzB +GTM2CnNQsE2Jfg2Uz+fD8wT5roqFBFux1AY8ZW2VjLppupUuZMRx3OWAR77Bh/01 +2iZ4+3rMmgqErbkgCB6fDLGh9g== +-----END CERTIFICATE----- diff --git a/src/test/resources/testIdentity123.pfx b/src/test/resources/testIdentity123.pfx new file mode 100644 index 0000000000000000000000000000000000000000..41f2d9c8b1ec77a274b7d1de3ae60bbe9aa5aec4 GIT binary patch literal 3786 zcmc&%dpuNm8$WX~?!%a2v@W@%&25~S#{Ck5$^8fOJ>TaUkb}Ml zhao@?nu8M7NVG}hi^BwAg&cG^l7kL~;G-Z1h5p+ufej=_U=8F5@S$T7CHehyQ7s){mawF5GVo7POXU&yJLa$y`y;0Sx z>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