From b5c9057589c2fa0f6dc65eeb9658a41c647c4477 Mon Sep 17 00:00:00 2001 From: anhefti Date: Tue, 14 Jan 2020 14:24:19 +0100 Subject: [PATCH] more unit tests --- .../seb/examconfig/DeactivateExamConfig.java | 40 - ....java => GetConfigurationTableValues.java} | 18 +- .../examconfig/GetFollowupConfiguration.java | 4 +- .../sebconfig/AttributeValueConverter.java | 2 +- .../converter/ArrayOfStringConverter.java | 4 +- .../impl/converter/BooleanConverter.java | 2 +- .../impl/converter/InlineTableConverter.java | 2 +- .../impl/converter/IntegerConverter.java | 2 +- .../impl/converter/StringConverter.java | 4 +- .../impl/converter/TableConverter.java | 4 +- .../api/ConfigurationValueController.java | 2 +- .../integration/UseCasesIntegrationTest.java | 256 ++++- .../gui/integration/UsecaseTestUtils.java | 132 +++ src/test/resources/importTest.seb | 973 ++++++++++++++++++ src/test/resources/importTest_123.seb | Bin 0 -> 3693 bytes 15 files changed, 1362 insertions(+), 83 deletions(-) delete mode 100644 src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/seb/examconfig/DeactivateExamConfig.java rename src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/seb/examconfig/{ActivateExamConfig.java => GetConfigurationTableValues.java} (61%) create mode 100644 src/test/java/ch/ethz/seb/sebserver/gui/integration/UsecaseTestUtils.java create mode 100644 src/test/resources/importTest.seb create mode 100644 src/test/resources/importTest_123.seb diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/seb/examconfig/DeactivateExamConfig.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/seb/examconfig/DeactivateExamConfig.java deleted file mode 100644 index c3fa9848..00000000 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/seb/examconfig/DeactivateExamConfig.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2019 ETH Zürich, Educational Development and Technology (LET) - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -package ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig; - -import org.springframework.context.annotation.Lazy; -import org.springframework.http.HttpMethod; -import org.springframework.http.MediaType; -import org.springframework.stereotype.Component; - -import com.fasterxml.jackson.core.type.TypeReference; - -import ch.ethz.seb.sebserver.gbl.api.API; -import ch.ethz.seb.sebserver.gbl.api.EntityType; -import ch.ethz.seb.sebserver.gbl.model.EntityProcessingReport; -import ch.ethz.seb.sebserver.gbl.profile.GuiProfile; -import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestCall; - -@Lazy -@Component -@GuiProfile -public class DeactivateExamConfig extends RestCall { - - public DeactivateExamConfig() { - super(new TypeKey<>( - CallType.ACTIVATION_DEACTIVATE, - EntityType.CONFIGURATION_NODE, - new TypeReference() { - }), - HttpMethod.POST, - MediaType.APPLICATION_FORM_URLENCODED, - API.CONFIGURATION_NODE_ENDPOINT + API.PATH_VAR_INACTIVE); - } - -} diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/seb/examconfig/ActivateExamConfig.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/seb/examconfig/GetConfigurationTableValues.java similarity index 61% rename from src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/seb/examconfig/ActivateExamConfig.java rename to src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/seb/examconfig/GetConfigurationTableValues.java index d7268ca5..7d8f260c 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/seb/examconfig/ActivateExamConfig.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/seb/examconfig/GetConfigurationTableValues.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 ETH Zürich, Educational Development and Technology (LET) + * Copyright (c) 2020 ETH Zürich, Educational Development and Technology (LET) * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this @@ -17,24 +17,24 @@ import com.fasterxml.jackson.core.type.TypeReference; import ch.ethz.seb.sebserver.gbl.api.API; import ch.ethz.seb.sebserver.gbl.api.EntityType; -import ch.ethz.seb.sebserver.gbl.model.EntityProcessingReport; +import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationTableValues; import ch.ethz.seb.sebserver.gbl.profile.GuiProfile; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestCall; @Lazy @Component @GuiProfile -public class ActivateExamConfig extends RestCall { +public class GetConfigurationTableValues extends RestCall { - public ActivateExamConfig() { + public GetConfigurationTableValues() { super(new TypeKey<>( - CallType.ACTIVATION_ACTIVATE, - EntityType.CONFIGURATION_NODE, - new TypeReference() { + CallType.GET_SINGLE, + EntityType.CONFIGURATION_VALUE, + new TypeReference() { }), - HttpMethod.POST, + HttpMethod.GET, MediaType.APPLICATION_FORM_URLENCODED, - API.CONFIGURATION_NODE_ENDPOINT + API.PATH_VAR_ACTIVE); + API.CONFIGURATION_VALUE_ENDPOINT + API.CONFIGURATION_TABLE_VALUE_PATH_SEGMENT); } } diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/seb/examconfig/GetFollowupConfiguration.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/seb/examconfig/GetFollowupConfiguration.java index b3b43e15..ed93ac99 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/seb/examconfig/GetFollowupConfiguration.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/seb/examconfig/GetFollowupConfiguration.java @@ -34,7 +34,9 @@ public class GetFollowupConfiguration extends RestCall { }), HttpMethod.GET, MediaType.APPLICATION_FORM_URLENCODED, - API.MODEL_ID_VAR_PATH_SEGMENT + API.CONFIGURATION_FOLLOWUP_PATH_SEGMENT); + API.CONFIGURATION_NODE_ENDPOINT + + API.MODEL_ID_VAR_PATH_SEGMENT + + API.CONFIGURATION_FOLLOWUP_PATH_SEGMENT); } } diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/AttributeValueConverter.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/AttributeValueConverter.java index 9980d3d7..6326681e 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/AttributeValueConverter.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/AttributeValueConverter.java @@ -72,7 +72,7 @@ public interface AttributeValueConverter { * * @param attribute * @return the SEB configuration attribute name */ - default String extractName(final ConfigurationAttribute attribute) { + static String extractName(final ConfigurationAttribute attribute) { final int lastIndexOf = attribute.name.lastIndexOf('.'); if (lastIndexOf > 0) { return attribute.name.substring(lastIndexOf + 1, attribute.name.length()); diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/converter/ArrayOfStringConverter.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/converter/ArrayOfStringConverter.java index 8fb8e083..8d874d02 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/converter/ArrayOfStringConverter.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/converter/ArrayOfStringConverter.java @@ -91,7 +91,7 @@ public class ArrayOfStringConverter implements AttributeValueConverter { final StringBuilder sb = new StringBuilder(); sb.append(String.format( (xml) ? XML_TEMPLATE : JSON_TEMPLATE, - extractName(attribute))); + AttributeValueConverter.extractName(attribute))); for (final String v : values) { sb.append(String.format( @@ -112,7 +112,7 @@ public class ArrayOfStringConverter implements AttributeValueConverter { } else { out.write(Utils.toByteArray(String.format( (xml) ? XML_TEMPLATE_EMPTY : JSON_TEMPLATE_EMPTY, - extractName(attribute)))); + AttributeValueConverter.extractName(attribute)))); } } diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/converter/BooleanConverter.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/converter/BooleanConverter.java index 2c5c8e06..5930f6d7 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/converter/BooleanConverter.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/converter/BooleanConverter.java @@ -77,7 +77,7 @@ public class BooleanConverter implements AttributeValueConverter { out.write(Utils.toByteArray( String.format( template, - extractName(attribute), + AttributeValueConverter.extractName(attribute), (value != null && value.value != null) ? value.value : defaultValue))); } diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/converter/InlineTableConverter.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/converter/InlineTableConverter.java index 40293814..dd67a367 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/converter/InlineTableConverter.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/converter/InlineTableConverter.java @@ -89,7 +89,7 @@ public class InlineTableConverter implements AttributeValueConverter { out.write(Utils.toByteArray(String.format( (xml) ? XML_KEY_TEMPLATE : JSON_KEY_TEMPLATE, - extractName(attribute)))); + AttributeValueConverter.extractName(attribute)))); if (StringUtils.isBlank(value.value)) { out.write((xml) ? XML_EMPTY_ARRAY : JSON_EMPTY_ARRAY); diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/converter/IntegerConverter.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/converter/IntegerConverter.java index 1848ba28..35536045 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/converter/IntegerConverter.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/converter/IntegerConverter.java @@ -93,7 +93,7 @@ public class IntegerConverter implements AttributeValueConverter { out.write(Utils.toByteArray(String.format( template, - extractName(attribute), + AttributeValueConverter.extractName(attribute), intVal))); } diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/converter/StringConverter.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/converter/StringConverter.java index 17647d6a..1430f521 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/converter/StringConverter.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/converter/StringConverter.java @@ -88,12 +88,12 @@ public class StringConverter implements AttributeValueConverter { if (StringUtils.isNotBlank(val)) { out.write(Utils.toByteArray(String.format( template, - extractName(attribute), + AttributeValueConverter.extractName(attribute), val))); } else { out.write(Utils.toByteArray(String.format( emptyTemplate, - extractName(attribute)))); + AttributeValueConverter.extractName(attribute)))); } } diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/converter/TableConverter.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/converter/TableConverter.java index f6fd5928..e1a74c06 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/converter/TableConverter.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/converter/TableConverter.java @@ -121,7 +121,7 @@ public class TableConverter implements AttributeValueConverter { out.write(Utils.toByteArray(String.format( (xml) ? XML_KEY_TEMPLATE : JSON_KEY_TEMPLATE, - extractName(attribute)))); + AttributeValueConverter.extractName(attribute)))); if (noValues) { out.write((xml) ? XML_EMPTY_ARRAY : JSON_EMPTY_ARRAY); @@ -136,7 +136,7 @@ public class TableConverter implements AttributeValueConverter { } else { out.write(Utils.toByteArray(String.format( (xml) ? XML_KEY_TEMPLATE : JSON_KEY_TEMPLATE, - extractName(attribute)))); + AttributeValueConverter.extractName(attribute)))); } } diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ConfigurationValueController.java b/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ConfigurationValueController.java index 2cfbe385..30740bd3 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ConfigurationValueController.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ConfigurationValueController.java @@ -96,7 +96,7 @@ public class ConfigurationValueController extends EntityController values = valuesResponse.get(); assertFalse(values.isEmpty()); + UsecaseTestUtils.testProhibitedProcessesInit( + followup.getModelId(), + restService); + UsecaseTestUtils.testPermittedProcessesInit( + followup.getModelId(), + restService); + // update a value -- grab first final ConfigurationValue value = values.get(0); ConfigurationValue newValue = new ConfigurationValue( @@ -1170,29 +1187,22 @@ public class UseCasesIntegrationTest extends GuiIntegrationTest { @Test @Order(11) // ************************************* - // Use Case 11: Login as examAdmin2 and create a new SEB Exam Configuration - // - table value add, delete, modify - // - export + // Use Case 11: Login as examAdmin2 and get newly created exam configuration + // - get permitted processes table values + // - modify permitted processes table values + // - save permitted processes table values + // - check save OK public void testUsecase11() throws IOException { final RestServiceImpl restService = createRestServiceForUser( "examAdmin2", "examAdmin2", - new NewExamConfig(), - new GetExamConfigNode(), + new GetConfigAttributes(), new GetExamConfigNodePage(), - new GetConfigurationPage(), new GetConfigurations(), + new GetConfigurationPage(), new SaveExamConfigHistory(), - new ExportExamConfig(), - new GetFollowupConfiguration(), - new SebExamConfigUndo(), - new SaveExamConfigValue(), - new SaveExamConfigTableValues(), - new GetConfigurationValuePage(), - new GetConfigurationValues(), - new ActivateExamConfig(), - new DeactivateExamConfig(), - new GetUserAccountNames()); + new GetConfigurationTableValues(), + new SaveExamConfigTableValues()); // get configuration page final Result> pageResponse = restService @@ -1206,6 +1216,208 @@ public class UseCasesIntegrationTest extends GuiIntegrationTest { final ConfigurationNode configurationNode = page.content.get(0); assertEquals("New Exam Config", configurationNode.name); + + // get follow-up configuration + final Result> configHistoryResponse = restService + .getBuilder(GetConfigurations.class) + .withQueryParam(Configuration.FILTER_ATTR_CONFIGURATION_NODE_ID, configurationNode.getModelId()) + .call(); + + final List configHistory = configHistoryResponse.get(); + final Configuration followup = configHistory + .stream() + .filter(config -> BooleanUtils.isTrue(config.followup)) + .findFirst() + .orElseThrow(() -> new RuntimeException("Followup Node not found")); + + final ConfigurationTableValues permittedProcessValues = UsecaseTestUtils.getTableValues( + "73", + followup.getModelId(), + restService); + + assertNotNull(permittedProcessValues); + assertFalse(permittedProcessValues.values.isEmpty()); + + // get all configuration attributes + final Map attributes = restService + .getBuilder(GetConfigAttributes.class) + .call() + .getOrThrow() + .stream() + .collect(Collectors.toMap(attr -> attr.id, Function.identity())); + + // create new row by copy the values + final List newTableValues = permittedProcessValues.values + .stream() + .map(attr -> new TableValue(attr.attributeId, 1, attributes.get(attr.attributeId).defaultValue)) + .collect(Collectors.toList()); + newTableValues.addAll(permittedProcessValues.values); + + // test institutional integrity violation + try { + final ConfigurationTableValues newTableValue = new ConfigurationTableValues( + 1000L, + followup.id, + 73L, + newTableValues); + + restService.getBuilder(SaveExamConfigTableValues.class) + .withBody(newTableValue) + .call() + .getOrThrow(); + + fail("Exception expected here"); + } catch (final Exception e) { + assertEquals("Unexpected error while rest call", e.getMessage()); + } + + // test follow-up integrity violation + try { + final ConfigurationTableValues newTableValue = new ConfigurationTableValues( + configHistory.get(0).id, + followup.id, + 73L, + newTableValues); + + restService.getBuilder(SaveExamConfigTableValues.class) + .withBody(newTableValue) + .call() + .getOrThrow(); + + fail("Exception expected here"); + } catch (final Exception e) { + assertEquals("Unexpected error while rest call", e.getMessage()); + } + + final ConfigurationTableValues newTableValue = new ConfigurationTableValues( + followup.institutionId, + followup.id, + 73L, + newTableValues); + + final ConfigurationTableValues savedValues = restService.getBuilder(SaveExamConfigTableValues.class) + .withBody(newTableValue) + .call() + .getOrThrow(); + + assertNotNull(savedValues); + assertFalse(savedValues.values.isEmpty()); + assertTrue(savedValues.values.size() == newTableValues.size()); + } + + @Test + @Order(12) + // ************************************* + // Use Case 12: Login as examAdmin2 and use newly created configuration + // - get follow-up configuration by API + // - import + // - export + public void testUsecase12() throws IOException { + final RestServiceImpl restService = createRestServiceForUser( + "examAdmin2", + "examAdmin2", + new GetConfigAttributes(), + new GetExamConfigNodePage(), + new SaveExamConfigHistory(), + new ExportExamConfig(), + new ImportNewExamConfig(), + new ImportExamConfigOnExistingConfig(), + new ExportPlainXML(), + new GetFollowupConfiguration()); + + // get all configuration attributes + final Collection attributes = restService + .getBuilder(GetConfigAttributes.class) + .call() + .getOrThrow() + .stream() + .collect(Collectors.toList()); + + // get configuration page + final Result> pageResponse = restService + .getBuilder(GetExamConfigNodePage.class) + .call(); + + assertNotNull(pageResponse); + assertFalse(pageResponse.hasError()); + final Page page = pageResponse.get(); + assertFalse(page.content.isEmpty()); + + final ConfigurationNode configurationNode = page.content.get(0); + assertEquals("New Exam Config", configurationNode.name); + + final Configuration followup = restService + .getBuilder(GetFollowupConfiguration.class) + .withURIVariable(API.PARAM_MODEL_ID, configurationNode.getModelId()) + .call() + .getOrThrow(); + + assertNotNull(followup); + assertTrue(followup.followup); + + // export1 + final InputStream input = restService + .getBuilder(ExportPlainXML.class) + .withURIVariable(API.PARAM_MODEL_ID, configurationNode.getModelId()) + .call() + .getOrThrow(); + + final String xmlString = StreamUtils.copyToString(input, Charsets.UTF_8); + assertNotNull(xmlString); + for (final ConfigurationAttribute attribute : attributes) { + if (attribute.name.contains(".") || attribute.name.equals("kioskMode")) { + continue; + } + if (!xmlString.contains(attribute.name)) { + fail("missing attribute: " + attribute.name); + } + } + + // import plain config + InputStream inputStream = new ClassPathResource("importTest.seb").getInputStream(); + Configuration importedConfig = restService + .getBuilder(ImportNewExamConfig.class) + .withBody(inputStream) + .withHeader(Domain.CONFIGURATION_NODE.ATTR_NAME, "Imported Test Configuration") + .call() + .getOrThrow(); + + assertNotNull(importedConfig); + + // import with the same name should cause an exception + try { + restService + .getBuilder(ImportNewExamConfig.class) + .withBody(inputStream) + .withHeader(Domain.CONFIGURATION_NODE.ATTR_NAME, "Imported Test Configuration") + .withHeader(API.IMPORT_PASSWORD_ATTR_NAME, "123") + .call() + .getOrThrow(); + fail("Expecting an exception here"); + } catch (final Exception e) { + + } + + // import encrypted config with password encryption + inputStream = new ClassPathResource("importTest_123.seb").getInputStream(); + importedConfig = restService + .getBuilder(ImportNewExamConfig.class) + .withBody(inputStream) + .withHeader(Domain.CONFIGURATION_NODE.ATTR_NAME, "Imported Encrypted Test Configuration") + .withHeader(API.IMPORT_PASSWORD_ATTR_NAME, "123") + .call() + .getOrThrow(); + + assertNotNull(importedConfig); + + // import config within existing configuration + inputStream = new ClassPathResource("importTest.seb").getInputStream(); + importedConfig = restService + .getBuilder(ImportExamConfigOnExistingConfig.class) + .withBody(inputStream) + .withURIVariable(API.PARAM_MODEL_ID, String.valueOf(importedConfig.getConfigurationNodeId())) + .call() + .getOrThrow(); } } diff --git a/src/test/java/ch/ethz/seb/sebserver/gui/integration/UsecaseTestUtils.java b/src/test/java/ch/ethz/seb/sebserver/gui/integration/UsecaseTestUtils.java new file mode 100644 index 00000000..e25d63ef --- /dev/null +++ b/src/test/java/ch/ethz/seb/sebserver/gui/integration/UsecaseTestUtils.java @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2020 ETH Zürich, Educational Development and Technology (LET) + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +package ch.ethz.seb.sebserver.gui.integration; + +import static org.junit.Assert.*; + +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; + +import org.apache.tomcat.util.buf.StringUtils; + +import ch.ethz.seb.sebserver.gbl.Constants; +import ch.ethz.seb.sebserver.gbl.model.Domain; +import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationAttribute; +import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationTableValues; +import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestServiceImpl; +import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.GetConfigAttributes; +import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.GetConfigurationTableValues; +import ch.ethz.seb.sebserver.webservice.servicelayer.sebconfig.impl.init.XMLAttributeLoader; + +public abstract class UsecaseTestUtils { + + static ConfigurationTableValues testProhibitedProcessesInit( + final String configId, + final RestServiceImpl restService) { + + final ConfigurationTableValues tableValues = getTableValues("93", configId, restService); + + assertNotNull(tableValues); + assertFalse(tableValues.values.isEmpty()); + final String names = StringUtils.join( + tableValues.values + .stream() + .filter(attr -> attr.attributeId == 98) + .map(attr -> attr.value) + .sorted() + .collect(Collectors.toList()), + Constants.LIST_SEPARATOR_CHAR); + + // get all configuration attributes + final Map attributes = restService + .getBuilder(GetConfigAttributes.class) + .call() + .getOrThrow() + .stream() + .collect(Collectors.toMap(attr -> attr.name, Function.identity())); + + final XMLAttributeLoader xmlAttributeLoader = new XMLAttributeLoader(); + final String configuraedNames = StringUtils.join(xmlAttributeLoader.loadFromXML( + 1L, + Long.parseLong(configId), + attrName -> attributes.get(attrName), + "config/initialProhibitedProcesses.xml") + .stream() + .filter(attr -> attr.attributeId == 98) + .map(attr -> attr.value) + .sorted() + .collect(Collectors.toList()), + Constants.LIST_SEPARATOR_CHAR); + + assertEquals(configuraedNames, names); + + return tableValues; + } + + static ConfigurationTableValues getTableValues( + final String attributeId, + final String configId, + final RestServiceImpl restService) { + final ConfigurationTableValues tableValues = restService.getBuilder(GetConfigurationTableValues.class) + .withQueryParam( + Domain.CONFIGURATION_VALUE.ATTR_CONFIGURATION_ATTRIBUTE_ID, + attributeId) + .withQueryParam( + Domain.CONFIGURATION_VALUE.ATTR_CONFIGURATION_ID, + configId) + .call() + .getOrThrow(); + return tableValues; + } + + static ConfigurationTableValues testPermittedProcessesInit( + final String configId, + final RestServiceImpl restService) { + + final ConfigurationTableValues tableValues = getTableValues("73", configId, restService); + + assertNotNull(tableValues); + assertFalse(tableValues.values.isEmpty()); + final String names = StringUtils.join( + tableValues.values + .stream() + .filter(attr -> attr.attributeId == 76) + .map(attr -> attr.value) + .sorted() + .collect(Collectors.toList()), + Constants.LIST_SEPARATOR_CHAR); + + // get all configuration attributes + final Map attributes = restService + .getBuilder(GetConfigAttributes.class) + .call() + .getOrThrow() + .stream() + .collect(Collectors.toMap(attr -> attr.name, Function.identity())); + + final XMLAttributeLoader xmlAttributeLoader = new XMLAttributeLoader(); + final String configuraedNames = StringUtils.join(xmlAttributeLoader.loadFromXML( + 1L, + Long.parseLong(configId), + attrName -> attributes.get(attrName), + "config/initialPermittedProcesses.xml") + .stream() + .filter(attr -> attr.attributeId == 76) + .map(attr -> attr.value) + .sorted() + .collect(Collectors.toList()), + Constants.LIST_SEPARATOR_CHAR); + + assertEquals(configuraedNames, names); + + return tableValues; + } + +} diff --git a/src/test/resources/importTest.seb b/src/test/resources/importTest.seb new file mode 100644 index 00000000..383389a2 --- /dev/null +++ b/src/test/resources/importTest.seb @@ -0,0 +1,973 @@ + + + + + URLFilterEnable + + URLFilterEnableContentFilter + + URLFilterIgnoreList + + URLFilterMessage + 0 + URLFilterRules + + + active + + regex + + expression + jrtjrtzj + action + 0 + + + active + + regex + + expression + rtjrtj + action + 1 + + + allowBrowsingBackForward + + allowDictation + + allowDictionaryLookup + + allowDisplayMirroring + + allowDownUploads + + allowFlashFullscreen + + allowPDFPlugIn + + allowPreferencesWindow + + allowQuit + + allowScreenSharing + + allowSiri + + allowSpellCheck + + allowSwitchToApplications + + allowUserSwitching + + allowVideoCapture + + allowVirtualMachine + + allowWLAN + + allowedDisplayBuiltin + + allowedDisplaysMaxNumber + 3 + allowiOSBetaVersionNumber + 12 + allowiOSVersionNumberMajor + 9 + allowiOSVersionNumberMinor + 0 + allowiOSVersionNumberPatch + 0 + blacklistURLFilter + jrtjrtzj + blockPopUpWindows + + browserExamKey + + browserMessagingPingTime + 120000 + browserMessagingSocket + ws:\localhost:8706 + browserScreenKeyboard + + browserURLSalt + + browserUserAgent + + browserUserAgentMac + 0 + browserUserAgentMacCustom + + browserUserAgentWinDesktopMode + 0 + browserUserAgentWinDesktopModeCustom + + browserUserAgentWinTouchMode + 0 + browserUserAgentWinTouchModeCustom + + browserUserAgentWinTouchModeIPad + Mozilla/5.0 (iPad; CPU OS 11_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.0 Mobile/15E148 Safari/604.1 + browserUserAgentiOS + 0 + browserUserAgentiOSCustom + + browserViewMode + 0 + browserWindowAllowReload + + browserWindowShowURL + 1 + chooseFileToUploadPolicy + 0 + createNewDesktop + + downloadAndOpenSebConfig + + downloadDirectoryOSX + /var/mobile/Containers/Data/Application/DE2E302B-36C4-48B7-A29E-804F8B27C2F6/Downloads + downloadDirectoryWin + Desktop + downloadPDFFiles + + embeddedCertificates + + enableAltEsc + + enableAltF4 + + enableAltMouseWheel + + enableAltTab + + enableAppSwitcherCheck + + enableBrowserWindowToolbar + + enableCtrlEsc + + enableDrawingEditor + + enableEsc + + enableF1 + + enableF10 + + enableF11 + + enableF12 + + enableF2 + + enableF3 + + enableF4 + + enableF5 + + enableF6 + + enableF7 + + enableF8 + + enableF9 + + enableJava + + enableJavaScript + + enableLogging + + enablePlugIns + + enablePrintScreen + + enablePrivateClipboard + + enableRightMouse + + enableSebBrowser + + enableStartMenu + + enableTouchExit + + enableURLContentFilter + + enableURLFilter + + enableZoomPage + + enableZoomText + + examConfigKeyContainedKeys + + examKeySalt + sq3GTYYzHLg6MT9b+SAi9vEA3TuMIHDxus8hzwe2KNA= + exitKey1 + 2 + exitKey2 + 10 + exitKey3 + 5 + forceAppFolderInstall + + hashedAdminPassword + + hashedQuitPassword + + hideBrowserWindowToolbar + + hookKeys + + ignoreExitKeys + + ignoreQuitPassword + + insideSebEnableChangeAPassword + + insideSebEnableEaseOfAccess + + insideSebEnableLockThisComputer + + insideSebEnableLogOff + + insideSebEnableShutDown + + insideSebEnableStartTaskManager + + insideSebEnableSwitchUser + + insideSebEnableVmWareClientShade + + killExplorerShell + + logDirectoryOSX + + logDirectoryWin + + logLevel + 3 + mainBrowserWindowHeight + 100% + mainBrowserWindowPositioning + 1 + mainBrowserWindowWidth + 100% + minMacOSVersion + 0 + mobileAllowGuidedAccess + + mobileAllowQRCodeConfig + + mobileAllowSingleAppMode + + mobileEnableASAM + + mobileEnableGuidedAccessLinkTransform + + mobilePreventAutoLock + + mobileShowSettings + + mobileStatusBarAppearance + 1 + mobileStatusBarAppearanceExtended + 1 + mobileSupportedFormFactorsCompact + + mobileSupportedFormFactorsNonTelephonyCompact + + mobileSupportedFormFactorsRegular + + mobileSupportedScreenOrientationsCompactLandscapeLeft + + mobileSupportedScreenOrientationsCompactLandscapeRight + + mobileSupportedScreenOrientationsCompactPortrait + + mobileSupportedScreenOrientationsCompactPortraitUpsideDown + + mobileSupportedScreenOrientationsRegularLandscapeLeft + + mobileSupportedScreenOrientationsRegularLandscapeRight + + mobileSupportedScreenOrientationsRegularPortrait + + mobileSupportedScreenOrientationsRegularPortraitUpsideDown + + monitorProcesses + + newBrowserWindowAllowReload + + newBrowserWindowByLinkBlockForeign + + newBrowserWindowByLinkHeight + 100% + newBrowserWindowByLinkPolicy + 2 + newBrowserWindowByLinkPositioning + 2 + newBrowserWindowByLinkWidth + 1000 + newBrowserWindowByScriptBlockForeign + + newBrowserWindowByScriptPolicy + 2 + newBrowserWindowNavigation + + newBrowserWindowShowReloadWarning + + newBrowserWindowShowURL + 2 + openDownloads + + originatorVersion + SEB_iOS_2.1.12_11838 + oskBehavior + 2 + outsideSebEnableChangeAPassword + + outsideSebEnableEaseOfAccess + + outsideSebEnableLockThisComputer + + outsideSebEnableLogOff + + outsideSebEnableShutDown + + outsideSebEnableStartTaskManager + + outsideSebEnableSwitchUser + + outsideSebEnableVmWareClientShade + + permittedProcesses + + + active + + allowUserToChooseApp + + allowedExecutables + + arguments + + autostart + + description + + executable + firefox.exe + iconInTaskbar + + identifier + Firefox + os + 1 + path + ../xulrunner/ + runInBackground + + strongKill + + title + SEB + windowHandlingProcess + + originalName + firefox.exe + + + active + + autostart + + iconInTaskbar + + runInBackground + + allowUserToChooseApp + + strongKill + + os + 0 + title + eheth + description + etheth + executable + tzjtzjtzj + originalName + eh + windowHandlingProcess + rh + path + rh + identifier + rehreh + arguments + + + active + + argument + erherh + + + active + + argument + eherh + + + active + + argument + rtherhe + + + + + pinEmbeddedCertificates + + prohibitedProcesses + + + active + + currentUser + + strongKill + + os + 1 + executable + join.me + originalName + join.me + description + + identifier + + windowHandlingProcess + + user + + + + active + + currentUser + + strongKill + + os + 1 + executable + RPCSuite + originalName + RPCSuite + description + + identifier + + windowHandlingProcess + + user + + + + active + + currentUser + + strongKill + + os + 1 + executable + RPCService + originalName + RPCService + description + + identifier + + windowHandlingProcess + + user + + + + active + + currentUser + + strongKill + + os + 1 + executable + RemotePCDesktop + originalName + RemotePCDesktop + description + + identifier + + windowHandlingProcess + + user + + + + active + + currentUser + + strongKill + + os + 1 + executable + beamyourscreen-host + originalName + beamyourscreen-host + description + + identifier + + windowHandlingProcess + + user + + + + active + + currentUser + + strongKill + + os + 1 + executable + AeroAdmin + originalName + AeroAdmin + description + + identifier + + windowHandlingProcess + + user + + + + active + + currentUser + + strongKill + + os + 1 + executable + Mikogo-host + originalName + Mikogo-host + description + + identifier + + windowHandlingProcess + + user + + + + active + + currentUser + + strongKill + + os + 1 + executable + chromoting + originalName + chromoting + description + + identifier + + windowHandlingProcess + + user + + + + active + + currentUser + + strongKill + + os + 1 + executable + vncserverui + originalName + vncserverui + description + + identifier + + windowHandlingProcess + + user + + + + active + + currentUser + + strongKill + + os + 1 + executable + vncviewer + originalName + vncviewer + description + + identifier + + windowHandlingProcess + + user + + + + active + + currentUser + + strongKill + + os + 1 + executable + vncserver + originalName + vncserver + description + + identifier + + windowHandlingProcess + + user + + + + active + + currentUser + + strongKill + + os + 1 + executable + TeamViewer + originalName + TeamViewer + description + + identifier + + windowHandlingProcess + + user + + + + active + + currentUser + + strongKill + + os + 1 + executable + GotoMeetingWinStore + originalName + GotoMeetingWinStore + description + + identifier + + windowHandlingProcess + + user + + + + active + + currentUser + + strongKill + + os + 1 + executable + g2mcomm.exe + originalName + g2mcomm.exe + description + + identifier + + windowHandlingProcess + + user + + + + active + + currentUser + + strongKill + + os + 1 + executable + SkypeHost + originalName + SkypeHost + description + + identifier + + windowHandlingProcess + + user + + + + active + + currentUser + + strongKill + + os + 1 + executable + Skype + originalName + Skype + description + + identifier + + windowHandlingProcess + + user + + + + proxies + + AutoConfigurationEnabled + + AutoConfigurationJavaScript + + AutoConfigurationURL + + AutoDiscoveryEnabled + + ExceptionsList + + ExcludeSimpleHostnames + + FTPEnable + + FTPPassive + + FTPPassword + + FTPPort + 21 + FTPProxy + + FTPRequiresPassword + + FTPUsername + + HTTPEnable + + HTTPPassword + + HTTPPort + 80 + HTTPProxy + + HTTPRequiresPassword + + HTTPSEnable + + HTTPSPassword + zul,.lli + HTTPSPort + 443 + HTTPSProxy + zilzklz + HTTPSRequiresPassword + + HTTPSUsername + luzulz + HTTPUsername + + RTSPEnable + + RTSPPassword + + RTSPPort + 554 + RTSPProxy + + RTSPRequiresPassword + + RTSPUsername + + SOCKSEnable + + SOCKSPassword + + SOCKSPort + 1080 + SOCKSProxy + + SOCKSRequiresPassword + + SOCKSUsername + + + proxySettingsPolicy + 0 + quitURL + + quitURLConfirm + + removeBrowserProfile + + removeLocalStorage + + restartExamPasswordProtected + + restartExamText + + restartExamURL + + restartExamUseStartURL + + sebConfigPurpose + 0 + sebMode + 0 + sebServerFallback + + sebServerURL + + sebServicePolicy + 2 + sendBrowserExamKey + + showBackToStartButton + + showInputLanguage + + showMenuBar + + showNavigationButtons + + showReloadButton + + showReloadWarning + + showScanQRCodeButton + + showSettingsInApp + + showTaskBar + + showTime + + startURL + https://demo.safeexambrowser.org/exams + startURLAllowDeepLink + + startURLAppendQueryParameter + + taskBarHeight + 40 + touchOptimized + + urlFilterRegex + + urlFilterTrustedContent + + whitelistURLFilter + ^.*?:\/\/((((rtjrtj)|(.*?\.rtjrtj)))|(((rtjrtj)|(.*?\.rtjrtj))\/.*?))(()|(\?.*?))$ + zoomMode + 0 + startResource + + useAsymmetricOnlyEncryption + + allowSpellCheckDictionary + + additionalDictionaries + + audioControlEnabled + + audioMute + + audioVolumeLevel + 100 + audioSetVolumeLevel + + allowAudioCapture + + browserWindowTitleSuffix + + backgroundOpenSEBConfig + + additionalResources + + allowWlan + + lockOnMessageSocketClose + + allowUserAppFolderInstall + + detectStoppedProcess + + insideSebEnableEnableNetworkConnectionSelector + + + \ No newline at end of file diff --git a/src/test/resources/importTest_123.seb b/src/test/resources/importTest_123.seb new file mode 100644 index 0000000000000000000000000000000000000000..ee6a472657da0aa13378c30bb8c5fe0040170419 GIT binary patch literal 3693 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