Skip to content
Snippets Groups Projects
Commit 8ef9fff1 authored by uhensler's avatar uhensler
Browse files

OO-3065: Prevent auto-booking if no identifier value is delivered

parent 193870f0
No related branches found
No related tags found
No related merge requests found
......@@ -19,6 +19,7 @@
*/
package org.olat.resource.accesscontrol.provider.auto.manager;
import org.olat.core.util.StringHelper;
import org.olat.resource.accesscontrol.provider.auto.AdvanceOrderInput;
import org.springframework.stereotype.Component;
......@@ -40,7 +41,7 @@ class InputValidator {
} else {
isValid &= notNull(input.getIdentity());
isValid &= notNull(input.getMethodClass());
isValid &= notNull(input.getRawValues());
isValid &= StringHelper.containsNonWhitespace(input.getRawValues());
if (input.getKeys() == null) {
isValid &= false;
......
......@@ -23,6 +23,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import org.olat.core.util.StringHelper;
import org.springframework.stereotype.Component;
......@@ -44,7 +45,7 @@ public class SemicolonSplitter implements IdentifierValueSplitter {
@Override
public Collection<String> split(String rawValue) {
if (rawValue == null) return new ArrayList<>();
if (!StringHelper.containsNonWhitespace(rawValue)) return new ArrayList<>();
return Arrays.asList(rawValue.split(";"));
}
......
......@@ -25,6 +25,7 @@ import java.util.Map;
import javax.annotation.PostConstruct;
import org.olat.core.util.StringHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
......@@ -51,7 +52,7 @@ public class SplitterFactory {
public IdentifierValueSplitter getSplitter(String type) {
IdentifierValueSplitter splitter = cache.get(type);
if (splitter == null) {
if (!StringHelper.containsNonWhitespace(type)) {
splitter = cache.get(SemicolonSplitter.TYPE);
}
return splitter;
......
......@@ -110,6 +110,16 @@ public class InputValidatorTest {
assertThat(isValid).isFalse();
}
@Test
public void shouldNotBeValidIfRawValuesIsEmptyString() {
when(inputMock.getRawValues()).thenReturn("");
boolean isValid = sut.isValid(inputMock);
assertThat(isValid).isFalse();
}
@Test
public void shouldNotBeValidIfMethodDoesNotExist() {
when(inputMock.getIdentity()).thenReturn(null);
......
......@@ -67,6 +67,12 @@ public class SemicolonSplitterTest {
public void shouldReturnEmptyCollectionIfNullInput() {
Collection<String> values = sut.split(null);
assertThat(values).hasSize(0);
}
@Test
public void shouldReturnEmptyCollectionIfEmptyStringInput() {
Collection<String> values = sut.split("");
assertThat(values).hasSize(0);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment