SEBSERV-420 and unit tests
This commit is contained in:
parent
ab9d1f7dcc
commit
eb4f758328
5 changed files with 675 additions and 52 deletions
|
@ -19,20 +19,34 @@ public class AllowedSEBVersion {
|
|||
public static final String OS_WINDOWS_IDENTIFIER = "Win";
|
||||
public static final String OS_MAC_IDENTIFIER = "Mac";
|
||||
public static final String OS_IOS_IDENTIFIER = "iOS";
|
||||
public static final String ALIANCE_EDITION_IDENTIFIER = "AE";
|
||||
public static final String ALLIANCE_EDITION_IDENTIFIER = "AE";
|
||||
public static final String ALLIANCE_EDITION_IDENTIFIER_FULL1 = "Alliance Edition";
|
||||
public static final String ALLIANCE_EDITION_IDENTIFIER_FULL2 = "Alliance";
|
||||
public static final String MINIMAL_IDENTIFIER = "min";
|
||||
public static final String MINIMAL_IDENTIFIER_FULL = "minimal";
|
||||
|
||||
public final String wholeVersionString;
|
||||
//public final String wholeVersionString;
|
||||
public final String osTypeString;
|
||||
public final int major;
|
||||
public final int minor;
|
||||
public final int patch;
|
||||
public boolean alianceEdition;
|
||||
public boolean allianceEdition;
|
||||
public boolean minimal;
|
||||
public final boolean isValidFormat;
|
||||
|
||||
public AllowedSEBVersion(final String wholeVersionString) {
|
||||
this.wholeVersionString = wholeVersionString;
|
||||
//this.wholeVersionString = wholeVersionString;
|
||||
|
||||
if (StringUtils.isBlank(wholeVersionString)) {
|
||||
this.isValidFormat = false;
|
||||
this.osTypeString = null;
|
||||
this.major = 0;
|
||||
this.minor = 0;
|
||||
this.patch = 0;
|
||||
this.allianceEdition = false;
|
||||
this.minimal = false;
|
||||
return;
|
||||
}
|
||||
|
||||
boolean valid = true;
|
||||
final String[] split = StringUtils.split(wholeVersionString, Constants.DOT);
|
||||
|
@ -61,14 +75,15 @@ public class AllowedSEBVersion {
|
|||
valid = false;
|
||||
}
|
||||
this.minor = num;
|
||||
|
||||
if (split.length > 3) {
|
||||
try {
|
||||
num = Integer.valueOf(split[3]);
|
||||
} catch (final Exception e) {
|
||||
num = 0;
|
||||
if (split[3].equals(ALIANCE_EDITION_IDENTIFIER)) {
|
||||
this.alianceEdition = true;
|
||||
} else if (split[3].equals(MINIMAL_IDENTIFIER)) {
|
||||
if (split[3].equals(ALLIANCE_EDITION_IDENTIFIER)) {
|
||||
this.allianceEdition = true;
|
||||
} else if (isMinimal(split[3])) {
|
||||
this.minimal = true;
|
||||
} else {
|
||||
valid = false;
|
||||
|
@ -80,9 +95,9 @@ public class AllowedSEBVersion {
|
|||
this.patch = num;
|
||||
|
||||
if (valid && split.length > 4) {
|
||||
if (!this.alianceEdition && split[4].equals(ALIANCE_EDITION_IDENTIFIER)) {
|
||||
this.alianceEdition = true;
|
||||
} else if (!this.minimal && split[4].equals(MINIMAL_IDENTIFIER)) {
|
||||
if (!this.allianceEdition && split[4].equals(ALLIANCE_EDITION_IDENTIFIER)) {
|
||||
this.allianceEdition = true;
|
||||
} else if (!this.minimal && isMinimal(split[4])) {
|
||||
this.minimal = true;
|
||||
} else {
|
||||
valid = false;
|
||||
|
@ -90,9 +105,9 @@ public class AllowedSEBVersion {
|
|||
}
|
||||
|
||||
if (valid && split.length > 5) {
|
||||
if (!this.alianceEdition && split[5].equals(ALIANCE_EDITION_IDENTIFIER)) {
|
||||
this.alianceEdition = true;
|
||||
} else if (!this.minimal && split[5].equals(MINIMAL_IDENTIFIER)) {
|
||||
if (!this.allianceEdition && split[5].equals(ALLIANCE_EDITION_IDENTIFIER)) {
|
||||
this.allianceEdition = true;
|
||||
} else if (!this.minimal && isMinimal(split[5])) {
|
||||
this.minimal = true;
|
||||
} else {
|
||||
valid = false;
|
||||
|
@ -102,6 +117,15 @@ public class AllowedSEBVersion {
|
|||
}
|
||||
|
||||
public boolean match(final ClientVersion clientVersion) {
|
||||
|
||||
if (clientVersion == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.allianceEdition != clientVersion.isAllianceEdition) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Objects.equals(this.osTypeString, clientVersion.osTypeString)) {
|
||||
if (this.minimal) {
|
||||
// check greater or equals minimum version
|
||||
|
@ -118,21 +142,51 @@ public class AllowedSEBVersion {
|
|||
this.patch == clientVersion.patch;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isMinimal(final String tag) {
|
||||
return MINIMAL_IDENTIFIER.equalsIgnoreCase(tag) || MINIMAL_IDENTIFIER_FULL.equalsIgnoreCase(tag);
|
||||
}
|
||||
|
||||
public static final class ClientVersion {
|
||||
|
||||
public String osTypeString;
|
||||
public final int major;
|
||||
public final int minor;
|
||||
public final int patch;
|
||||
public final boolean isAllianceEdition;
|
||||
|
||||
public ClientVersion(
|
||||
final String osTypeString,
|
||||
final int major,
|
||||
final int minor,
|
||||
final int patch,
|
||||
final boolean isAlianceVersion) {
|
||||
|
||||
public ClientVersion(final String osTypeString, final int major, final int minor, final int patch) {
|
||||
this.osTypeString = osTypeString;
|
||||
this.major = major;
|
||||
this.minor = minor;
|
||||
this.patch = patch;
|
||||
this.isAllianceEdition = isAlianceVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
builder.append("ClientVersion [osTypeString=");
|
||||
builder.append(this.osTypeString);
|
||||
builder.append(", major=");
|
||||
builder.append(this.major);
|
||||
builder.append(", minor=");
|
||||
builder.append(this.minor);
|
||||
builder.append(", patch=");
|
||||
builder.append(this.patch);
|
||||
builder.append(", isAllianceVersion=");
|
||||
builder.append(this.isAllianceEdition);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ public class SEBClientVersionServiceImpl implements SEBClientVersionService {
|
|||
@Value("${ebserver.webservice.config.knownWindowsOSTags:Win,Windows}") final String knownWindowsOSTags,
|
||||
@Value("${ebserver.webservice.config.knownMacOSTags:macOS}") final String knownMacOSTags,
|
||||
@Value("${ebserver.webservice.config.knownIOSTags:iOS,iPad,iPadOS}") final String knownIOSTags,
|
||||
@Value("${ebserver.webservice.config.knownRestrictedVersions:BETA,rc,1.0.0.0}") final String knownRestrictedVersions) {
|
||||
@Value("${ebserver.webservice.config.knownRestrictedVersions:1.0.0.0,BETA}") final String knownRestrictedVersions) {
|
||||
|
||||
this.clientConnectionDAO = clientConnectionDAO;
|
||||
this.examSessionCacheService = examSessionCacheService;
|
||||
|
@ -73,45 +73,16 @@ public class SEBClientVersionServiceImpl implements SEBClientVersionService {
|
|||
final String clientVersion,
|
||||
final List<AllowedSEBVersion> allowedSEBVersions) {
|
||||
|
||||
// first check if this is a known restricted version
|
||||
if (this.knownRestrictedVersions.stream().filter(clientVersion::contains).findFirst().isPresent()) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Found default restricted SEB client version: {}", clientVersion);
|
||||
}
|
||||
final ClientVersion version = extractClientVersion(clientOSName, clientVersion);
|
||||
if (version == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final String osType = verifyOSType(clientOSName, clientVersion);
|
||||
|
||||
if (StringUtils.isBlank(osType)) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("No SEB client OS type tag found in : {} {}", clientOSName, clientVersion);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
final String[] versionSplit = StringUtils.split(clientVersion, Constants.SPACE);
|
||||
final String versioNumber = versionSplit[0];
|
||||
final String[] versionNumberSplit = StringUtils.split(versioNumber, Constants.DOT);
|
||||
|
||||
final int major = extractVersionNumber(versionNumberSplit[0]);
|
||||
final int minor = (versionNumberSplit.length > 1) ? extractVersionNumber(versionNumberSplit[1]) : 0;
|
||||
final int patch = (versionNumberSplit.length > 2) ? extractVersionNumber(versionNumberSplit[2]) : 0;
|
||||
|
||||
final ClientVersion version = new ClientVersion(osType, major, minor, patch);
|
||||
return allowedSEBVersions
|
||||
.stream()
|
||||
.filter(v -> v.match(version))
|
||||
.findFirst()
|
||||
.isPresent();
|
||||
} catch (final Exception e) {
|
||||
log.warn(
|
||||
"Invalid SEB version number in: {} {}",
|
||||
clientOSName,
|
||||
clientVersion);
|
||||
return false;
|
||||
}
|
||||
return allowedSEBVersions
|
||||
.stream()
|
||||
.filter(v -> v.match(version))
|
||||
.findFirst()
|
||||
.isPresent();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -134,6 +105,49 @@ public class SEBClientVersionServiceImpl implements SEBClientVersionService {
|
|||
}
|
||||
}
|
||||
|
||||
protected ClientVersion extractClientVersion(final String clientOSName, final String clientVersion) {
|
||||
try {
|
||||
// first check if this is a known restricted version
|
||||
if (this.knownRestrictedVersions.stream().filter(clientVersion::contains).findFirst().isPresent()) {
|
||||
log.warn("Found default restricted SEB client version: {}", clientVersion);
|
||||
return null;
|
||||
}
|
||||
|
||||
final String osType = verifyOSType(clientOSName, clientVersion);
|
||||
|
||||
if (StringUtils.isBlank(osType)) {
|
||||
log.warn("No SEB client OS type tag found in : {} {}", clientOSName, clientVersion);
|
||||
return null;
|
||||
}
|
||||
|
||||
final String[] versionSplit = StringUtils.split(clientVersion, Constants.SPACE);
|
||||
final String versioNumber = versionSplit[0];
|
||||
final String[] versionNumberSplit = StringUtils.split(versioNumber, Constants.DOT);
|
||||
|
||||
if (versionNumberSplit.length > 3) {
|
||||
log.warn("Invalid SEB version in : {}", clientVersion);
|
||||
return null;
|
||||
}
|
||||
|
||||
final int major = extractVersionNumber(versionNumberSplit[0]);
|
||||
final int minor = (versionNumberSplit.length > 1) ? extractVersionNumber(versionNumberSplit[1]) : 0;
|
||||
final int patch = (versionNumberSplit.length > 2) ? extractVersionNumber(versionNumberSplit[2]) : 0;
|
||||
|
||||
final boolean isAllianceEdition = clientVersion.contains(AllowedSEBVersion.ALLIANCE_EDITION_IDENTIFIER) ||
|
||||
clientVersion.contains(AllowedSEBVersion.ALLIANCE_EDITION_IDENTIFIER_FULL1) ||
|
||||
clientVersion.contains(AllowedSEBVersion.ALLIANCE_EDITION_IDENTIFIER_FULL2);
|
||||
|
||||
return new ClientVersion(osType, major, minor, patch, isAllianceEdition);
|
||||
|
||||
} catch (final Exception e) {
|
||||
log.warn(
|
||||
"Invalid SEB version number in: {} {}",
|
||||
clientOSName,
|
||||
clientVersion);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private String verifyOSType(final String clientOSName, final String clientVersion) {
|
||||
final char c = clientVersion.charAt(0);
|
||||
final String osVersionText = (c >= 'A' && c <= 'Z') ? clientVersion : clientOSName;
|
||||
|
|
|
@ -1854,7 +1854,7 @@ sebserver.examconfig.props.label.terminateProcesses.tooltip=SEB will attempt to
|
|||
sebserver.examconfig.props.label.prohibitedProcesses.ignoreInAAC=Ignore in AAC
|
||||
sebserver.examconfig.props.label.prohibitedProcesses.ignoreInAAC.tooltip=When using the AAC kiosk mode (which prevents network and screen access for other processes), ignore this prohibited process
|
||||
sebserver.examconfig.props.label.sebAllowedVersions=Allowed SEB Versions
|
||||
sebserver.examconfig.props.label.sebAllowedVersions.tooltip=List of text inputs which represent either a specific or a minimal SEB version which is allowed to access the (exam) session using current settings.<br/>The version string has the following format: [OS.mayor.minor.patch(.AE)(.minimal)], OS and mayor version are mandatory,<br/>OS is either "Win", "Mac" or "iOS", "minimal" indicates if version shall be interpreted as minimal version this and all above are valid. AE indicates a Alliance Edition version.
|
||||
sebserver.examconfig.props.label.sebAllowedVersions.tooltip=List of text inputs which represent either a specific or a minimal SEB version which is allowed to access the (exam) session using current settings.<br/>The version string has the following format: [OS.mayor.minor(.patch)(.AE)(.min)], OS and mayor version are mandatory,<br/>OS is either "Win", "Mac" or "iOS", "min" indicates if version shall be interpreted as minimal version this and all above are valid. AE indicates a Alliance Edition version.
|
||||
sebserver.examconfig.props.label.sebAllowedVersions.addAction=Add new allowed SEB version
|
||||
sebserver.examconfig.props.label.sebAllowedVersions.deleteAction=Delete allowed SEB version
|
||||
sebserver.examconfig.props.validation.SEBVersionValidator=At least one SEB Version has wrong format
|
||||
|
|
|
@ -0,0 +1,107 @@
|
|||
/*
|
||||
* Copyright (c) 2023 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.gbl.model.exam;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class AllowedSEBVersionTest {
|
||||
|
||||
@Test
|
||||
public void testInvalidVersions() {
|
||||
assertFalse(new AllowedSEBVersion("").isValidFormat);
|
||||
assertFalse(new AllowedSEBVersion("1").isValidFormat);
|
||||
assertFalse(new AllowedSEBVersion("a").isValidFormat);
|
||||
assertFalse(new AllowedSEBVersion("A").isValidFormat);
|
||||
assertFalse(new AllowedSEBVersion("WIN.1.").isValidFormat);
|
||||
assertFalse(new AllowedSEBVersion("WIN.1.1A").isValidFormat);
|
||||
assertFalse(new AllowedSEBVersion("WIN.1.1.1.1.1.1.1").isValidFormat);
|
||||
assertFalse(new AllowedSEBVersion("WIN.1111.1111.baba").isValidFormat);
|
||||
assertFalse(new AllowedSEBVersion("WIN.1.ad.1").isValidFormat);
|
||||
assertFalse(new AllowedSEBVersion("Win.1.AE").isValidFormat);
|
||||
assertFalse(new AllowedSEBVersion("Win.1.min.AE").isValidFormat);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidVersions() {
|
||||
assertTrue(new AllowedSEBVersion("Win.1.1").isValidFormat);
|
||||
assertTrue(new AllowedSEBVersion("Win.1.1.AE").isValidFormat);
|
||||
assertTrue(new AllowedSEBVersion("Win.1.1.1").isValidFormat);
|
||||
assertTrue(new AllowedSEBVersion("Win.1.1.1.AE").isValidFormat);
|
||||
assertTrue(new AllowedSEBVersion("Win.1.1.min").isValidFormat);
|
||||
assertTrue(new AllowedSEBVersion("Win.1.1.1.min").isValidFormat);
|
||||
assertTrue(new AllowedSEBVersion("Win.1.1.AE.min").isValidFormat);
|
||||
assertTrue(new AllowedSEBVersion("Win.1.1.1.AE.min").isValidFormat);
|
||||
assertTrue(new AllowedSEBVersion("Win.1.1.min.AE").isValidFormat);
|
||||
assertTrue(new AllowedSEBVersion("Win.1.1.1.min.AE").isValidFormat);
|
||||
|
||||
assertTrue(new AllowedSEBVersion("WIN.1.1").isValidFormat);
|
||||
assertTrue(new AllowedSEBVersion("Mac.1.1.AE").isValidFormat);
|
||||
assertTrue(new AllowedSEBVersion("MAC.1.1.1").isValidFormat);
|
||||
assertTrue(new AllowedSEBVersion("iOS.1.1.1.AE").isValidFormat);
|
||||
assertTrue(new AllowedSEBVersion("IOS.1.1.min").isValidFormat);
|
||||
assertTrue(new AllowedSEBVersion("ios.1.1.1.min").isValidFormat);
|
||||
assertTrue(new AllowedSEBVersion("win.1.1.AE.min").isValidFormat);
|
||||
assertTrue(new AllowedSEBVersion("mac.1.1.1.AE.min").isValidFormat);
|
||||
assertTrue(new AllowedSEBVersion("Win.1.1.min.AE").isValidFormat);
|
||||
assertTrue(new AllowedSEBVersion("Win.1.1.1.min.AE").isValidFormat);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidVersionDetails1() {
|
||||
final AllowedSEBVersion allowedSEBVersion = new AllowedSEBVersion("Win.3.1.2.AE.min");
|
||||
assertTrue(allowedSEBVersion.isValidFormat);
|
||||
assertTrue(AllowedSEBVersion.OS_WINDOWS_IDENTIFIER == allowedSEBVersion.osTypeString);
|
||||
assertTrue(allowedSEBVersion.major == 3);
|
||||
assertTrue(allowedSEBVersion.minor == 1);
|
||||
assertTrue(allowedSEBVersion.patch == 2);
|
||||
assertTrue(allowedSEBVersion.allianceEdition);
|
||||
assertTrue(allowedSEBVersion.minimal);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidVersionDetails2() {
|
||||
final AllowedSEBVersion allowedSEBVersion = new AllowedSEBVersion("Win.3.2.AE.min");
|
||||
assertTrue(allowedSEBVersion.isValidFormat);
|
||||
assertTrue(AllowedSEBVersion.OS_WINDOWS_IDENTIFIER == allowedSEBVersion.osTypeString);
|
||||
assertTrue(allowedSEBVersion.major == 3);
|
||||
assertTrue(allowedSEBVersion.minor == 2);
|
||||
assertTrue(allowedSEBVersion.patch == 0);
|
||||
assertTrue(allowedSEBVersion.allianceEdition);
|
||||
assertTrue(allowedSEBVersion.minimal);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidVersionDetails3() {
|
||||
final AllowedSEBVersion allowedSEBVersion = new AllowedSEBVersion("Win.3.2.min");
|
||||
assertTrue(allowedSEBVersion.isValidFormat);
|
||||
assertTrue(AllowedSEBVersion.OS_WINDOWS_IDENTIFIER == allowedSEBVersion.osTypeString);
|
||||
assertTrue(allowedSEBVersion.major == 3);
|
||||
assertTrue(allowedSEBVersion.minor == 2);
|
||||
assertTrue(allowedSEBVersion.patch == 0);
|
||||
assertFalse(allowedSEBVersion.allianceEdition);
|
||||
assertTrue(allowedSEBVersion.minimal);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidVersionDetails4() {
|
||||
final AllowedSEBVersion allowedSEBVersion = new AllowedSEBVersion("Win.3.2.5.AE");
|
||||
assertTrue(allowedSEBVersion.isValidFormat);
|
||||
assertTrue(AllowedSEBVersion.OS_WINDOWS_IDENTIFIER == allowedSEBVersion.osTypeString);
|
||||
assertTrue(allowedSEBVersion.major == 3);
|
||||
assertTrue(allowedSEBVersion.minor == 2);
|
||||
assertTrue(allowedSEBVersion.patch == 5);
|
||||
assertTrue(allowedSEBVersion.allianceEdition);
|
||||
assertFalse(allowedSEBVersion.minimal);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,448 @@
|
|||
/*
|
||||
* Copyright (c) 2023 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.webservice.servicelayer.session.impl;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import ch.ethz.seb.sebserver.gbl.model.exam.AllowedSEBVersion;
|
||||
import ch.ethz.seb.sebserver.gbl.model.exam.AllowedSEBVersion.ClientVersion;
|
||||
|
||||
public class SEBClientVersionServiceImplTest {
|
||||
|
||||
@Test
|
||||
public void testClientVersion1() {
|
||||
final SEBClientVersionServiceImpl clientVersionServiceMockup = getClientVersionServiceMockup();
|
||||
final ClientVersion clientVersion = clientVersionServiceMockup.extractClientVersion("", "");
|
||||
assertNull(clientVersion);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClientVersion2() {
|
||||
final SEBClientVersionServiceImpl clientVersionServiceMockup = getClientVersionServiceMockup();
|
||||
final ClientVersion clientVersion = clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19043.0 (x64)",
|
||||
"3.3.2 (x64)");
|
||||
assertNotNull(clientVersion);
|
||||
assertEquals(
|
||||
"ClientVersion [osTypeString=Win, major=3, minor=3, patch=2, isAllianceVersion=false]",
|
||||
clientVersion.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClientVersion3() {
|
||||
final SEBClientVersionServiceImpl clientVersionServiceMockup = getClientVersionServiceMockup();
|
||||
final ClientVersion clientVersion = clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19043.0 (x64)",
|
||||
"3.3.2 BETA (x64)");
|
||||
assertNull(clientVersion);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClientVersion4() {
|
||||
final SEBClientVersionServiceImpl clientVersionServiceMockup = getClientVersionServiceMockup();
|
||||
final ClientVersion clientVersion = clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19043.0 (x64)",
|
||||
"3.5.0 BETA (x64) Alliance Edition");
|
||||
assertNull(clientVersion);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClientVersion5() {
|
||||
final SEBClientVersionServiceImpl clientVersionServiceMockup = getClientVersionServiceMockup();
|
||||
final ClientVersion clientVersion = clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19042.0 (x64)",
|
||||
"3.5.0 (x64) Alliance Edition");
|
||||
assertNotNull(clientVersion);
|
||||
assertEquals(
|
||||
"ClientVersion [osTypeString=Win, major=3, minor=5, patch=0, isAllianceVersion=true]",
|
||||
clientVersion.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClientVersion6() {
|
||||
final SEBClientVersionServiceImpl clientVersionServiceMockup = getClientVersionServiceMockup();
|
||||
final ClientVersion clientVersion = clientVersionServiceMockup.extractClientVersion(
|
||||
"macOS Version 12.6.2 (Build 21G312)",
|
||||
"3.2.1AE");
|
||||
assertNotNull(clientVersion);
|
||||
assertEquals(
|
||||
"ClientVersion [osTypeString=Mac, major=3, minor=2, patch=1, isAllianceVersion=true]",
|
||||
clientVersion.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClientVersion7() {
|
||||
final SEBClientVersionServiceImpl clientVersionServiceMockup = getClientVersionServiceMockup();
|
||||
final ClientVersion clientVersion = clientVersionServiceMockup.extractClientVersion(
|
||||
"macOS Version 12.6.2 (Build 21G312)",
|
||||
"3.2.1 AE");
|
||||
assertNotNull(clientVersion);
|
||||
assertEquals(
|
||||
"ClientVersion [osTypeString=Mac, major=3, minor=2, patch=1, isAllianceVersion=true]",
|
||||
clientVersion.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClientVersion8() {
|
||||
final SEBClientVersionServiceImpl clientVersionServiceMockup = getClientVersionServiceMockup();
|
||||
final ClientVersion clientVersion = clientVersionServiceMockup.extractClientVersion(
|
||||
"macOS Version 12.6.4 (Build 21G521)",
|
||||
"3.2.4");
|
||||
assertNotNull(clientVersion);
|
||||
assertEquals(
|
||||
"ClientVersion [osTypeString=Mac, major=3, minor=2, patch=4, isAllianceVersion=false]",
|
||||
clientVersion.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClientVersion9() {
|
||||
final SEBClientVersionServiceImpl clientVersionServiceMockup = getClientVersionServiceMockup();
|
||||
final ClientVersion clientVersion = clientVersionServiceMockup.extractClientVersion(
|
||||
"iPad (iPadOS 15.6.1)",
|
||||
"3.3");
|
||||
assertNotNull(clientVersion);
|
||||
assertEquals(
|
||||
"ClientVersion [osTypeString=iOS, major=3, minor=3, patch=0, isAllianceVersion=false]",
|
||||
clientVersion.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClientVersion10() {
|
||||
final SEBClientVersionServiceImpl clientVersionServiceMockup = getClientVersionServiceMockup();
|
||||
final ClientVersion clientVersion = clientVersionServiceMockup.extractClientVersion(
|
||||
"iPhone (iOS 12.5.7)",
|
||||
"3.2.3");
|
||||
assertNotNull(clientVersion);
|
||||
assertEquals(
|
||||
"ClientVersion [osTypeString=iOS, major=3, minor=2, patch=3, isAllianceVersion=false]",
|
||||
clientVersion.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExactVersionRestriction1() {
|
||||
final AllowedSEBVersion allowedSEBVersion = new AllowedSEBVersion("Win.3.2.3");
|
||||
|
||||
final SEBClientVersionServiceImpl clientVersionServiceMockup = getClientVersionServiceMockup();
|
||||
|
||||
assertTrue(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19043.0 (x64)",
|
||||
"3.2.3")));
|
||||
assertFalse(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"iPhone (iOS 12.5.7)",
|
||||
"3.2.3")));
|
||||
assertFalse(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"macOS Version 12.6.4 (Build 21G521)",
|
||||
"3.2.3")));
|
||||
|
||||
assertFalse(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19043.0 (x64)",
|
||||
"3.2")));
|
||||
assertFalse(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19043.0 (x64)",
|
||||
"3.2.3.1")));
|
||||
assertFalse(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19043.0 (x64)",
|
||||
"3.2.3 AE")));
|
||||
assertFalse(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19043.0 (x64)",
|
||||
"3.2.3 BETA")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExactAEVersionRestriction1() {
|
||||
final AllowedSEBVersion allowedSEBVersion = new AllowedSEBVersion("Win.3.2.3.AE");
|
||||
final SEBClientVersionServiceImpl clientVersionServiceMockup = getClientVersionServiceMockup();
|
||||
|
||||
assertFalse(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19043.0 (x64)",
|
||||
"3.2.3")));
|
||||
assertFalse(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"iPhone (iOS 12.5.7)",
|
||||
"3.2.3")));
|
||||
assertFalse(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"macOS Version 12.6.4 (Build 21G521)",
|
||||
"3.2.3")));
|
||||
|
||||
assertFalse(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19043.0 (x64)",
|
||||
"3.2")));
|
||||
assertFalse(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19043.0 (x64)",
|
||||
"3.2.3.1")));
|
||||
assertTrue(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19043.0 (x64)",
|
||||
"3.2.3 AE")));
|
||||
assertTrue(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19043.0 (x64)",
|
||||
"3.2.3AE")));
|
||||
|
||||
assertFalse(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19043.0 (x64)",
|
||||
"3.2.3 AE BETA")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimalVersionRestriction1() {
|
||||
final AllowedSEBVersion allowedSEBVersion = new AllowedSEBVersion("Win.3.2.min");
|
||||
|
||||
final SEBClientVersionServiceImpl clientVersionServiceMockup = getClientVersionServiceMockup();
|
||||
|
||||
assertFalse(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"iPhone (iOS 12.5.7)",
|
||||
"3.2.3")));
|
||||
assertFalse(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"macOS Version 12.6.4 (Build 21G521)",
|
||||
"3.2.3")));
|
||||
assertFalse(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19043.0 (x64)",
|
||||
"3.1.13")));
|
||||
assertFalse(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19043.0 (x64)",
|
||||
"3.2.3 AE")));
|
||||
|
||||
assertTrue(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19043.0 (x64)",
|
||||
"3.2")));
|
||||
assertTrue(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19043.0 (x64)",
|
||||
"3.2.0")));
|
||||
assertTrue(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19043.0 (x64)",
|
||||
"3.2.1")));
|
||||
assertTrue(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19043.0 (x64)",
|
||||
"3.3.1")));
|
||||
assertFalse(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19043.0 (x64)",
|
||||
"3.3.1 BETA")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimalVersionRestriction2() {
|
||||
final AllowedSEBVersion allowedSEBVersion = new AllowedSEBVersion("mac.3.2.min");
|
||||
|
||||
final SEBClientVersionServiceImpl clientVersionServiceMockup = getClientVersionServiceMockup();
|
||||
|
||||
assertFalse(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"iPhone (iOS 12.5.7)",
|
||||
"3.2.3")));
|
||||
assertTrue(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"macOS Version 12.6.4 (Build 21G521)",
|
||||
"3.2.3")));
|
||||
assertFalse(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19043.0 (x64)",
|
||||
"3.1.13")));
|
||||
assertFalse(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19043.0 (x64)",
|
||||
"3.2.3 AE")));
|
||||
|
||||
assertFalse(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19043.0 (x64)",
|
||||
"3.2")));
|
||||
assertFalse(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19043.0 (x64)",
|
||||
"3.2.0")));
|
||||
assertFalse(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19043.0 (x64)",
|
||||
"3.2.1")));
|
||||
assertFalse(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19043.0 (x64)",
|
||||
"3.3.1")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimalVersionRestriction3() {
|
||||
final AllowedSEBVersion allowedSEBVersion = new AllowedSEBVersion("ios.3.2.min");
|
||||
|
||||
final SEBClientVersionServiceImpl clientVersionServiceMockup = getClientVersionServiceMockup();
|
||||
|
||||
assertTrue(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"iPhone (iOS 12.5.7)",
|
||||
"3.2.3")));
|
||||
assertFalse(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"iPhone (iOS 12.5.7)",
|
||||
"3.2.3 BETA")));
|
||||
assertFalse(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"macOS Version 12.6.4 (Build 21G521)",
|
||||
"3.2.3")));
|
||||
assertFalse(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19043.0 (x64)",
|
||||
"3.1.13")));
|
||||
assertFalse(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19043.0 (x64)",
|
||||
"3.2.3 AE")));
|
||||
|
||||
assertFalse(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19043.0 (x64)",
|
||||
"3.2")));
|
||||
assertFalse(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19043.0 (x64)",
|
||||
"3.2.0")));
|
||||
assertFalse(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19043.0 (x64)",
|
||||
"3.2.1")));
|
||||
assertFalse(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19043.0 (x64)",
|
||||
"3.3.1")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimalVersionRestriction4() {
|
||||
final AllowedSEBVersion allowedSEBVersion = new AllowedSEBVersion("Win.3.2.1.min");
|
||||
|
||||
final SEBClientVersionServiceImpl clientVersionServiceMockup = getClientVersionServiceMockup();
|
||||
|
||||
assertFalse(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"iPhone (iOS 12.5.7)",
|
||||
"3.2.3")));
|
||||
assertFalse(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"macOS Version 12.6.4 (Build 21G521)",
|
||||
"3.2.3")));
|
||||
assertFalse(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19043.0 (x64)",
|
||||
"3.1.13")));
|
||||
assertFalse(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19043.0 (x64)",
|
||||
"3.2.3 AE")));
|
||||
|
||||
assertFalse(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19043.0 (x64)",
|
||||
"3.2")));
|
||||
assertFalse(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19043.0 (x64)",
|
||||
"3.2.0")));
|
||||
assertTrue(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19043.0 (x64)",
|
||||
"3.2.1")));
|
||||
assertTrue(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19043.0 (x64)",
|
||||
"3.3.1")));
|
||||
|
||||
assertFalse(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19043.0 (x64)",
|
||||
"3.3.1 BETA")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimalAEVersionRestriction1() {
|
||||
final AllowedSEBVersion allowedSEBVersion = new AllowedSEBVersion("Win.3.2.AE.min");
|
||||
|
||||
final SEBClientVersionServiceImpl clientVersionServiceMockup = getClientVersionServiceMockup();
|
||||
|
||||
assertFalse(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"iPhone (iOS 12.5.7)",
|
||||
"3.2.3")));
|
||||
assertFalse(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"macOS Version 12.6.4 (Build 21G521)",
|
||||
"3.2.3")));
|
||||
assertFalse(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19043.0 (x64)",
|
||||
"3.1.13")));
|
||||
|
||||
assertFalse(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19043.0 (x64)",
|
||||
"3.2")));
|
||||
assertFalse(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19043.0 (x64)",
|
||||
"3.2.0")));
|
||||
assertFalse(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19043.0 (x64)",
|
||||
"3.2.1")));
|
||||
assertFalse(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19043.0 (x64)",
|
||||
"3.3.1")));
|
||||
|
||||
assertTrue(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19043.0 (x64)",
|
||||
"3.2 AE")));
|
||||
assertTrue(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19043.0 (x64)",
|
||||
"3.2.0 AE")));
|
||||
assertTrue(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19043.0 (x64)",
|
||||
"3.2.1 AE")));
|
||||
assertTrue(allowedSEBVersion.match(
|
||||
clientVersionServiceMockup.extractClientVersion(
|
||||
"Windows 10, Microsoft Windows NT 10.0.19043.0 (x64)",
|
||||
"3.3.1 AE")));
|
||||
}
|
||||
|
||||
private SEBClientVersionServiceImpl getClientVersionServiceMockup() {
|
||||
return new SEBClientVersionServiceImpl(
|
||||
null,
|
||||
null,
|
||||
"Win,Windows",
|
||||
"macOS",
|
||||
"iOS,iPad,iPadOS",
|
||||
"1.0.0.0,BETA");
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue