[mielecloud] Less strict e-mail validation (#10928)
* [mielecloud] Less strict e-mail validation Signed-off-by: Björn Lange <bjoern.lange@tu-dortmund.de> * Some more e-mail validation test cases Signed-off-by: Björn Lange <bjoern.lange@tu-dortmund.de> Co-authored-by: Björn Lange <bjoern.lange@tu-dortmund.de>
This commit is contained in:
parent
bd1d8f4980
commit
dbefba3fdd
|
@ -70,18 +70,25 @@ public final class ForwardToLoginServlet extends AbstractRedirectionServlet {
|
|||
logger.warn("Request is missing client ID.");
|
||||
return getErrorRedirectionUrl(PairAccountServlet.MISSING_CLIENT_ID_PARAMETER_NAME);
|
||||
}
|
||||
clientId = clientId.strip();
|
||||
|
||||
if (clientSecret == null || clientSecret.isEmpty()) {
|
||||
logger.warn("Request is missing client secret.");
|
||||
return getErrorRedirectionUrl(PairAccountServlet.MISSING_CLIENT_SECRET_PARAMETER_NAME);
|
||||
}
|
||||
clientSecret = clientSecret.strip();
|
||||
|
||||
if (bridgeId == null || bridgeId.isEmpty()) {
|
||||
logger.warn("Request is missing bridge ID.");
|
||||
return getErrorRedirectionUrl(PairAccountServlet.MISSING_BRIDGE_ID_PARAMETER_NAME);
|
||||
}
|
||||
bridgeId = bridgeId.strip();
|
||||
|
||||
if (email == null || email.isEmpty()) {
|
||||
logger.warn("Request is missing e-mail address.");
|
||||
return getErrorRedirectionUrl(PairAccountServlet.MISSING_EMAIL_PARAMETER_NAME);
|
||||
}
|
||||
email = email.strip();
|
||||
|
||||
ThingUID bridgeUid = null;
|
||||
try {
|
||||
|
|
|
@ -23,7 +23,8 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
|
|||
*/
|
||||
@NonNullByDefault
|
||||
public final class EmailValidator {
|
||||
private static final Pattern EMAIL_PATTERN = Pattern.compile("^[\\w-_\\.+]*[\\w-_\\.]\\@([\\w]+\\.)+[\\w]+[\\w]$");
|
||||
private static final Pattern EMAIL_PATTERN = Pattern
|
||||
.compile("^[a-zA-Z_0-9\\.+%-]{3,}\\@([a-zA-Z_0-9-]+\\.)+[a-z]+$");
|
||||
|
||||
private EmailValidator() {
|
||||
throw new UnsupportedOperationException();
|
||||
|
|
|
@ -53,7 +53,7 @@
|
|||
</div>
|
||||
<div class="form-group">
|
||||
<label for="email">E-mail address:</label>
|
||||
<input type="text" class="form-control" id="email" name="email" placeholder="Enter the e-mail address associated with your Miele Cloud Account" required pattern="[a-z0-9._%+-]{3,}@[a-z]{3,}([.]{1}[a-z]{2,}|[.]{1}[a-z]{2,}[.]{1}[a-z]{2,})" />
|
||||
<input type="text" class="form-control" id="email" name="email" placeholder="Enter the e-mail address associated with your Miele Cloud Account" required pattern="[a-zA-Z_0-9.+%-]{3,}@([a-zA-Z_0-9-]+[.])+[a-z]+)" />
|
||||
</div>
|
||||
<button type="submit" class="btn btn-danger btn-lg">Pair Account</button>
|
||||
</form>
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
/**
|
||||
* Copyright (c) 2010-2021 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.openhab.binding.mielecloud.internal.util;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
/**
|
||||
* @author Björn Lange - Initial Contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class EmailValidatorTest {
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = { "example@openhab.org", "itsme@test24.com", "my-account@t-online.de", "Some@dDRESs.edu",
|
||||
"min@Length.com" })
|
||||
void validEmailAddress(String emailAddress) {
|
||||
// when:
|
||||
var valid = EmailValidator.isValid(emailAddress);
|
||||
|
||||
// then:
|
||||
assertTrue(valid);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = { "examp!e@###.org", "to@o.short.com" })
|
||||
void invalidEmailAddress(String emailAddress) {
|
||||
// when:
|
||||
var valid = EmailValidator.isValid(emailAddress);
|
||||
|
||||
// then:
|
||||
assertFalse(valid);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue