This commit is contained in:
parent
70d7249e12
commit
a973dc3f6d
@ -160,19 +160,14 @@ public class ValidationService implements Reloadable {
|
|||||||
for(String restriction : restrictions) {
|
for(String restriction : restrictions) {
|
||||||
if(restriction.startsWith("regex:")) {
|
if(restriction.startsWith("regex:")) {
|
||||||
restriction = restriction.replace("regex:", "");
|
restriction = restriction.replace("regex:", "");
|
||||||
if(ip.matches(restriction)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if(domain.matches(restriction)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if(ip.equals(restriction)) {
|
restriction = restriction.replaceAll("\\*","(.*)");
|
||||||
return true;
|
}
|
||||||
}
|
if(ip.matches(restriction)) {
|
||||||
if(domain.equalsIgnoreCase(restriction)) {
|
return true;
|
||||||
return true;
|
}
|
||||||
}
|
if(domain.matches(restriction)) {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@ -350,13 +350,16 @@ public class ValidationServiceTest {
|
|||||||
// given
|
// given
|
||||||
given(settings.getProperty(RestrictionSettings.ENABLE_RESTRICTED_USERS)).willReturn(true);
|
given(settings.getProperty(RestrictionSettings.ENABLE_RESTRICTED_USERS)).willReturn(true);
|
||||||
given(settings.getProperty(RestrictionSettings.RESTRICTED_USERS))
|
given(settings.getProperty(RestrictionSettings.RESTRICTED_USERS))
|
||||||
.willReturn(Arrays.asList("Bobby;127.0.0.4", "Tamara;32.24.16.8", "Gabriel;regex:93\\.23\\.44\\..*"));
|
.willReturn(Arrays.asList("Bobby;127.0.0.4", "Tamara;32.24.16.8", "Gabriel;regex:93\\.23\\.44\\..*", "emanuel;94.65.24.*", "imyourisp;*.yourisp.net"));
|
||||||
validationService.reload();
|
validationService.reload();
|
||||||
|
|
||||||
Player bobby = mockPlayer("bobby", "127.0.0.4");
|
Player bobby = mockPlayer("bobby", "127.0.0.4");
|
||||||
Player tamara = mockPlayer("taMARA", "8.8.8.8");
|
Player tamara = mockPlayer("taMARA", "8.8.8.8");
|
||||||
Player gabriel = mockPlayer("Gabriel", "93.23.44.65");
|
Player gabriel = mockPlayer("Gabriel", "93.23.44.65");
|
||||||
Player gabriel2 = mockPlayer("Gabriel", "93.23.33.34");
|
Player gabriel2 = mockPlayer("Gabriel", "93.23.33.34");
|
||||||
|
Player emanuel = mockPlayer("emanuel", "94.65.24.10");
|
||||||
|
Player emanuel2 = mockPlayer("emanuel", "94.65.60.10");
|
||||||
|
Player imyourisp = mockPlayer("imyourisp", "bazinga.yourisp.net");
|
||||||
Player notRestricted = mockPlayer("notRestricted", "0.0.0.0");
|
Player notRestricted = mockPlayer("notRestricted", "0.0.0.0");
|
||||||
|
|
||||||
// when
|
// when
|
||||||
@ -364,6 +367,9 @@ public class ValidationServiceTest {
|
|||||||
boolean isTamaraAdmitted = validationService.fulfillsNameRestrictions(tamara);
|
boolean isTamaraAdmitted = validationService.fulfillsNameRestrictions(tamara);
|
||||||
boolean isGabrielAdmitted = validationService.fulfillsNameRestrictions(gabriel);
|
boolean isGabrielAdmitted = validationService.fulfillsNameRestrictions(gabriel);
|
||||||
boolean isGabriel2Admitted = validationService.fulfillsNameRestrictions(gabriel2);
|
boolean isGabriel2Admitted = validationService.fulfillsNameRestrictions(gabriel2);
|
||||||
|
boolean isEmanuelAdmitted = validationService.fulfillsNameRestrictions(emanuel);
|
||||||
|
boolean isEmanuel2Admitted = validationService.fulfillsNameRestrictions(emanuel2);
|
||||||
|
boolean isImyourispAdmitted = validationService.fulfillsNameRestrictions(imyourisp);
|
||||||
boolean isNotRestrictedAdmitted = validationService.fulfillsNameRestrictions(notRestricted);
|
boolean isNotRestrictedAdmitted = validationService.fulfillsNameRestrictions(notRestricted);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
@ -371,6 +377,9 @@ public class ValidationServiceTest {
|
|||||||
assertThat(isTamaraAdmitted, equalTo(false));
|
assertThat(isTamaraAdmitted, equalTo(false));
|
||||||
assertThat(isGabrielAdmitted, equalTo(true));
|
assertThat(isGabrielAdmitted, equalTo(true));
|
||||||
assertThat(isGabriel2Admitted, equalTo(false));
|
assertThat(isGabriel2Admitted, equalTo(false));
|
||||||
|
assertThat(isEmanuelAdmitted, equalTo(true));
|
||||||
|
assertThat(isEmanuel2Admitted, equalTo(false));
|
||||||
|
assertThat(isImyourispAdmitted, equalTo(true));
|
||||||
assertThat(isNotRestrictedAdmitted, equalTo(true));
|
assertThat(isNotRestrictedAdmitted, equalTo(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user