X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=tests%2Forg%2Fcacert%2Fgigi%2Futil%2FTestPublicSuffixes.java;fp=tests%2Forg%2Fcacert%2Fgigi%2Futil%2FTestPublicSuffixes.java;h=0000000000000000000000000000000000000000;hp=950224154004a111a326092bf02d9d1179a245ac;hb=bccd4cc0dba0f89aa045b113bac46eb8cc1dab4e;hpb=c9ed09f0007fc2c813815be927a5a24b23dab83c diff --git a/tests/org/cacert/gigi/util/TestPublicSuffixes.java b/tests/org/cacert/gigi/util/TestPublicSuffixes.java deleted file mode 100644 index 95022415..00000000 --- a/tests/org/cacert/gigi/util/TestPublicSuffixes.java +++ /dev/null @@ -1,82 +0,0 @@ -package org.cacert.gigi.util; - -import static org.junit.Assert.*; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.IDN; -import java.util.ArrayList; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameter; -import org.junit.runners.Parameterized.Parameters; - -@RunWith(Parameterized.class) -public class TestPublicSuffixes { - - /** - * Taken from - * http://mxr.mozilla.org/mozilla-central/source/netwerk/test/unit - * /data/test_psl.txt?raw=1 - */ - @Parameters(name = "publicSuffix({0}) = {1}") - public static Iterable genParams() throws IOException { - BufferedReader br = null; - try { - br = new BufferedReader(new InputStreamReader(TestPublicSuffixes.class.getResourceAsStream("TestPublicSuffixes.txt"), "UTF-8")); - ArrayList result = new ArrayList<>(); - String line; - while ((line = br.readLine()) != null) { - if (line.startsWith("//") || line.isEmpty()) { - continue; - } - String parseSuffix = "checkPublicSuffix("; - if (line.startsWith(parseSuffix)) { - String data = line.substring(parseSuffix.length(), line.length() - 2); - String[] parts = data.split(", "); - if (parts.length != 2) { - throw new Error("Syntax error in public suffix test data file: " + line); - } - result.add(new String[] { - parse(parts[0]), parse(parts[1]) - }); - } else { - throw new Error("Unparsable line: " + line); - } - } - return result; - } finally { - if (br != null) { - br.close(); - } - } - } - - private static String parse(String data) { - if (data.equals("null")) { - return null; - } - if (data.startsWith("'") && data.endsWith("'")) { - return data.substring(1, data.length() - 1); - } - throw new Error("Syntax error with literal: " + data); - } - - @Parameter(0) - public String domain; - - @Parameter(1) - public String suffix; - - @Test - public void testPublicSuffix() { - if (domain != null) { - domain = domain.toLowerCase(); - } - String publicSuffix = PublicSuffixes.getInstance().getRegistrablePart(domain == null ? null : IDN.toASCII(domain)); - assertEquals(suffix == null ? null : IDN.toASCII(suffix), publicSuffix); - } -}