Merge "Merge branch 'stable-2.12'"
This commit is contained in:
@@ -190,6 +190,7 @@ java_test(
|
|||||||
['src/test/java/**/*.java'],
|
['src/test/java/**/*.java'],
|
||||||
excludes = TESTUTIL + PROLOG_TESTS + PROLOG_TEST_CASE + QUERY_TESTS
|
excludes = TESTUTIL + PROLOG_TESTS + PROLOG_TEST_CASE + QUERY_TESTS
|
||||||
),
|
),
|
||||||
|
resources = glob(['src/test/resources/com/google/gerrit/server/mail/*']),
|
||||||
deps = TESTUTIL_DEPS + [
|
deps = TESTUTIL_DEPS + [
|
||||||
':testutil',
|
':testutil',
|
||||||
'//gerrit-antlr:query_exception',
|
'//gerrit-antlr:query_exception',
|
||||||
@@ -202,6 +203,7 @@ java_test(
|
|||||||
'//lib:guava',
|
'//lib:guava',
|
||||||
'//lib:guava-retrying',
|
'//lib:guava-retrying',
|
||||||
'//lib:protobuf',
|
'//lib:protobuf',
|
||||||
|
'//lib/commons:validator',
|
||||||
'//lib/dropwizard:dropwizard-core',
|
'//lib/dropwizard:dropwizard-core',
|
||||||
'//lib/guice:guice-assistedinject',
|
'//lib/guice:guice-assistedinject',
|
||||||
'//lib/prolog:runtime',
|
'//lib/prolog:runtime',
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
// Copyright (C) 2016 The Android Open Source Project
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package com.google.gerrit.server.mail;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assert_;
|
||||||
|
|
||||||
|
import org.apache.commons.validator.routines.EmailValidator;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
|
||||||
|
public class ValidatorTest {
|
||||||
|
private static final String UNSUPPORTED_PREFIX = "#! ";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void validateTopLevelDomains() throws Exception {
|
||||||
|
try (InputStream in =
|
||||||
|
this.getClass().getResourceAsStream("tlds-alpha-by-domain.txt")) {
|
||||||
|
if (in == null) {
|
||||||
|
throw new Exception("TLD list not found");
|
||||||
|
}
|
||||||
|
BufferedReader r = new BufferedReader(new InputStreamReader(in));
|
||||||
|
String tld;
|
||||||
|
EmailValidator validator = EmailValidator.getInstance();
|
||||||
|
while ((tld = r.readLine()) != null) {
|
||||||
|
if (tld.startsWith("# ") || tld.startsWith("XN--")) {
|
||||||
|
// Ignore comments and non-latin domains
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (tld.startsWith(UNSUPPORTED_PREFIX)) {
|
||||||
|
String test = "test@example."
|
||||||
|
+ tld.toLowerCase().substring(UNSUPPORTED_PREFIX.length());
|
||||||
|
assert_()
|
||||||
|
.withFailureMessage("expected invalid TLD \"" + test + "\"")
|
||||||
|
.that(validator.isValid(test))
|
||||||
|
.isFalse();
|
||||||
|
} else {
|
||||||
|
String test = "test@example." + tld.toLowerCase();
|
||||||
|
assert_()
|
||||||
|
.withFailureMessage("failed to validate TLD \"" + test + "\"")
|
||||||
|
.that(validator.isValid(test))
|
||||||
|
.isTrue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -72,10 +72,15 @@ maven_jar(
|
|||||||
exclude = ['META-INF/LICENSE'],
|
exclude = ['META-INF/LICENSE'],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# When updating the version of commons-validator, also update the
|
||||||
|
# list of supported TLDs in:
|
||||||
|
# gerrit-server/src/test/resources/com/google/gerrit/server/mail/tlds-alpha-by-domain.txt
|
||||||
|
# from:
|
||||||
|
# http://data.iana.org/TLD/tlds-alpha-by-domain.txt
|
||||||
maven_jar(
|
maven_jar(
|
||||||
name = 'validator',
|
name = 'validator',
|
||||||
id = 'commons-validator:commons-validator:1.4.1',
|
id = 'commons-validator:commons-validator:1.5.1',
|
||||||
sha1 = '2231238e391057a53f92bde5bbc588622c1956c3',
|
sha1 = '86d05a46e8f064b300657f751b5a98c62807e2a0',
|
||||||
license = 'Apache2.0',
|
license = 'Apache2.0',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user