Mercurial > hg > monetdb-java
annotate tests/TLSTester.java @ 858:d74e850e2991
Resolve warning: [deprecation] URL(String) in URL has been deprecated
author | Martin van Dinther <martin.van.dinther@monetdbsolutions.com> |
---|---|
date | Thu, 01 Feb 2024 14:11:10 +0100 (14 months ago) |
parents | 839d76eeb4ae |
children | 68994abe3e03 |
rev | line source |
---|---|
855
839d76eeb4ae
Added missing Copyright header comments
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
851
diff
changeset
|
1 /* |
839d76eeb4ae
Added missing Copyright header comments
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
851
diff
changeset
|
2 * SPDX-License-Identifier: MPL-2.0 |
839d76eeb4ae
Added missing Copyright header comments
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
851
diff
changeset
|
3 * |
839d76eeb4ae
Added missing Copyright header comments
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
851
diff
changeset
|
4 * This Source Code Form is subject to the terms of the Mozilla Public |
839d76eeb4ae
Added missing Copyright header comments
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
851
diff
changeset
|
5 * License, v. 2.0. If a copy of the MPL was not distributed with this |
839d76eeb4ae
Added missing Copyright header comments
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
851
diff
changeset
|
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
839d76eeb4ae
Added missing Copyright header comments
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
851
diff
changeset
|
7 * |
839d76eeb4ae
Added missing Copyright header comments
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
851
diff
changeset
|
8 * Copyright 2024 MonetDB Foundation; |
839d76eeb4ae
Added missing Copyright header comments
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
851
diff
changeset
|
9 * Copyright August 2008 - 2023 MonetDB B.V.; |
839d76eeb4ae
Added missing Copyright header comments
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
851
diff
changeset
|
10 * Copyright 1997 - July 2008 CWI. |
839d76eeb4ae
Added missing Copyright header comments
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
851
diff
changeset
|
11 */ |
839d76eeb4ae
Added missing Copyright header comments
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
851
diff
changeset
|
12 |
802
5d04490bc58b
Add tests using monetdb-tlstester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
13 import org.monetdb.mcl.net.Parameter; |
5d04490bc58b
Add tests using monetdb-tlstester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
14 |
5d04490bc58b
Add tests using monetdb-tlstester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
15 import java.io.*; |
5d04490bc58b
Add tests using monetdb-tlstester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
16 import java.net.URL; |
5d04490bc58b
Add tests using monetdb-tlstester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
17 import java.net.URLConnection; |
5d04490bc58b
Add tests using monetdb-tlstester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
18 import java.nio.charset.StandardCharsets; |
5d04490bc58b
Add tests using monetdb-tlstester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
19 import java.nio.file.Files; |
5d04490bc58b
Add tests using monetdb-tlstester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
20 import java.sql.Connection; |
5d04490bc58b
Add tests using monetdb-tlstester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
21 import java.sql.DriverManager; |
5d04490bc58b
Add tests using monetdb-tlstester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
22 import java.sql.SQLException; |
5d04490bc58b
Add tests using monetdb-tlstester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
23 import java.util.HashMap; |
805
2fee4b71baac
Set ALPN protocol if the runtime supports it
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
804
diff
changeset
|
24 import java.util.HashSet; |
802
5d04490bc58b
Add tests using monetdb-tlstester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
25 import java.util.Properties; |
5d04490bc58b
Add tests using monetdb-tlstester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
26 |
5d04490bc58b
Add tests using monetdb-tlstester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
27 public class TLSTester { |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
28 final HashMap<String, File> fileCache = new HashMap<>(); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
29 int verbose = 0; |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
30 String serverHost = null; |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
31 String altHost = null; |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
32 int serverPort = -1; |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
33 boolean enableTrusted = false; |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
34 File tempDir = null; |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
35 private final HashSet<String> preparedButNotRun = new HashSet<>(); |
802
5d04490bc58b
Add tests using monetdb-tlstester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
36 |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
37 public TLSTester(String[] args) { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
38 for (int i = 0; i < args.length; i++) { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
39 String arg = args[i]; |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
40 if (arg.equals("-v")) { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
41 verbose = 1; |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
42 } else if (arg.equals("-a")) { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
43 altHost = args[++i]; |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
44 } else if (arg.equals("-t")) { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
45 enableTrusted = true; |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
46 } else if (!arg.startsWith("-") && serverHost == null) { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
47 int idx = arg.indexOf(':'); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
48 if (idx > 0) { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
49 serverHost = arg.substring(0, idx); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
50 try { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
51 serverPort = Integer.parseInt(arg.substring(idx + 1)); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
52 if (serverPort > 0 && serverPort < 65536) |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
53 continue; |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
54 } catch (NumberFormatException ignored) { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
55 } |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
56 } |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
57 // if we get here it wasn't very valid |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
58 throw new IllegalArgumentException("Invalid argument: " + arg); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
59 } else { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
60 throw new IllegalArgumentException("Unexpected argument: " + arg); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
61 } |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
62 } |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
63 } |
802
5d04490bc58b
Add tests using monetdb-tlstester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
64 |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
65 public static void main(String[] args) throws IOException, SQLException, ClassNotFoundException { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
66 Class.forName("org.monetdb.jdbc.MonetDriver"); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
67 TLSTester main = new TLSTester(args); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
68 main.run(); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
69 } |
802
5d04490bc58b
Add tests using monetdb-tlstester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
70 |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
71 private HashMap<String, Integer> loadPortMap(String testName) throws IOException { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
72 HashMap<String, Integer> portMap = new HashMap<>(); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
73 InputStream in = fetchData("/?test=" + testName); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
74 BufferedReader br = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8)); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
75 for (String line = br.readLine(); line != null; line = br.readLine()) { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
76 int idx = line.indexOf(':'); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
77 String service = line.substring(0, idx); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
78 int port; |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
79 try { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
80 port = Integer.parseInt(line.substring(idx + 1)); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
81 } catch (NumberFormatException e) { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
82 throw new RuntimeException("Invalid port map line: " + line); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
83 } |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
84 portMap.put(service, port); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
85 } |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
86 return portMap; |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
87 } |
802
5d04490bc58b
Add tests using monetdb-tlstester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
88 |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
89 private File resource(String resource) throws IOException { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
90 if (!fileCache.containsKey(resource)) |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
91 fetchResource(resource); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
92 return fileCache.get(resource); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
93 } |
802
5d04490bc58b
Add tests using monetdb-tlstester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
94 |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
95 private void fetchResource(String resource) throws IOException { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
96 if (!resource.startsWith("/")) { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
97 throw new IllegalArgumentException("Resource must start with slash: " + resource); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
98 } |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
99 if (tempDir == null) { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
100 tempDir = Files.createTempDirectory("tlstest").toFile(); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
101 tempDir.deleteOnExit(); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
102 } |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
103 File outPath = new File(tempDir, resource.substring(1)); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
104 try (InputStream in = fetchData(resource); FileOutputStream out = new FileOutputStream(outPath)) { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
105 byte[] buffer = new byte[12]; |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
106 while (true) { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
107 int n = in.read(buffer); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
108 if (n <= 0) |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
109 break; |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
110 out.write(buffer, 0, n); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
111 } |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
112 } |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
113 fileCache.put(resource, outPath); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
114 } |
802
5d04490bc58b
Add tests using monetdb-tlstester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
115 |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
116 private byte[] fetchBytes(String resource) throws IOException { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
117 ByteArrayOutputStream out = new ByteArrayOutputStream(); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
118 try (InputStream in = fetchData(resource)) { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
119 byte[] buffer = new byte[22]; |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
120 while (true) { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
121 int nread = in.read(buffer); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
122 if (nread <= 0) |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
123 break; |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
124 out.write(buffer, 0, nread); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
125 } |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
126 return out.toByteArray(); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
127 } |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
128 } |
802
5d04490bc58b
Add tests using monetdb-tlstester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
129 |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
130 private InputStream fetchData(String resource) throws IOException { |
858
d74e850e2991
Resolve warning: [deprecation] URL(String) in URL has been deprecated
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
855
diff
changeset
|
131 URL url = new java.net.URI("http://" + serverHost + ":" + serverPort + resource).toURL; |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
132 URLConnection conn = url.openConnection(); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
133 conn.connect(); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
134 return conn.getInputStream(); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
135 } |
802
5d04490bc58b
Add tests using monetdb-tlstester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
136 |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
137 private void run() throws IOException, SQLException { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
138 test_connect_plain(); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
139 test_connect_tls(); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
140 test_refuse_no_cert(); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
141 test_refuse_wrong_cert(); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
142 test_refuse_wrong_host(); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
143 test_refuse_tlsv12(); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
144 test_refuse_expired(); |
855
839d76eeb4ae
Added missing Copyright header comments
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
851
diff
changeset
|
145 // test_connect_client_auth1(); |
839d76eeb4ae
Added missing Copyright header comments
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
851
diff
changeset
|
146 // test_connect_client_auth2(); |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
147 test_fail_tls_to_plain(); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
148 test_fail_plain_to_tls(); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
149 test_connect_server_name(); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
150 test_connect_alpn_mapi9(); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
151 test_connect_trusted(); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
152 test_refuse_trusted_wrong_host(); |
805
2fee4b71baac
Set ALPN protocol if the runtime supports it
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
804
diff
changeset
|
153 |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
154 // did we forget to call expectSucceed and expectFailure somewhere? |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
155 if (!preparedButNotRun.isEmpty()) { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
156 String names = String.join(", ", preparedButNotRun); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
157 throw new RuntimeException("Not all tests called expectSuccess/expectFailure: " + names); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
158 } |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
159 } |
802
5d04490bc58b
Add tests using monetdb-tlstester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
160 |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
161 private void test_connect_plain() throws IOException, SQLException { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
162 attempt("connect_plain", "plain").with(Parameter.TLS, false).expectSuccess(); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
163 } |
802
5d04490bc58b
Add tests using monetdb-tlstester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
164 |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
165 private void test_connect_tls() throws IOException, SQLException { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
166 Attempt attempt = attempt("connect_tls", "server1"); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
167 attempt.withFile(Parameter.CERT, "/ca1.crt").expectSuccess(); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
168 } |
802
5d04490bc58b
Add tests using monetdb-tlstester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
169 |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
170 private void test_refuse_no_cert() throws IOException, SQLException { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
171 attempt("refuse_no_cert", "server1").expectFailure("PKIX path building failed"); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
172 } |
802
5d04490bc58b
Add tests using monetdb-tlstester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
173 |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
174 private void test_refuse_wrong_cert() throws IOException, SQLException { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
175 Attempt attempt = attempt("refuse_wrong_cert", "server1"); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
176 attempt.withFile(Parameter.CERT, "/ca2.crt").expectFailure("PKIX path building failed"); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
177 } |
802
5d04490bc58b
Add tests using monetdb-tlstester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
178 |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
179 private void test_refuse_wrong_host() throws IOException, SQLException { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
180 Attempt attempt = attempt("refuse_wrong_host", "server1").with(Parameter.HOST, altHost); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
181 attempt.withFile(Parameter.CERT, "/ca1.crt").expectFailure("No subject alternative DNS name"); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
182 } |
802
5d04490bc58b
Add tests using monetdb-tlstester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
183 |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
184 private void test_refuse_tlsv12() throws IOException, SQLException { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
185 Attempt attempt = attempt("refuse_tlsv12", "tls12"); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
186 attempt.withFile(Parameter.CERT, "/ca1.crt").expectFailure("protocol_version"); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
187 } |
802
5d04490bc58b
Add tests using monetdb-tlstester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
188 |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
189 private void test_refuse_expired() throws IOException, SQLException { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
190 Attempt attempt = attempt("refuse_expired", "expiredcert"); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
191 attempt.withFile(Parameter.CERT, "/ca1.crt").expectFailure("PKIX path validation failed"); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
192 } |
802
5d04490bc58b
Add tests using monetdb-tlstester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
193 |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
194 private void test_connect_client_auth1() throws IOException, SQLException { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
195 attempt("connect_client_auth1", "clientauth") |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
196 .withFile(Parameter.CERT, "/ca1.crt") |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
197 .withFile(Parameter.CLIENTKEY, "/client2.keycrt") |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
198 .expectSuccess(); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
199 } |
802
5d04490bc58b
Add tests using monetdb-tlstester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
200 |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
201 private void test_connect_client_auth2() throws IOException, SQLException { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
202 attempt("connect_client_auth2", "clientauth") |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
203 .withFile(Parameter.CERT, "/ca1.crt") |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
204 .withFile(Parameter.CLIENTKEY, "/client2.key") |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
205 .withFile(Parameter.CLIENTCERT, "/client2.crt") |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
206 .expectSuccess(); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
207 } |
802
5d04490bc58b
Add tests using monetdb-tlstester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
208 |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
209 private void test_fail_tls_to_plain() throws IOException, SQLException { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
210 Attempt attempt = attempt("fail_tls_to_plain", "plain"); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
211 attempt.withFile(Parameter.CERT, "/ca1.crt").expectFailure(""); |
802
5d04490bc58b
Add tests using monetdb-tlstester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
212 |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
213 } |
802
5d04490bc58b
Add tests using monetdb-tlstester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
214 |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
215 private void test_fail_plain_to_tls() throws IOException, SQLException { |
851
157dcb2d6516
relax wording of expected exception
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
834
diff
changeset
|
216 attempt("fail_plain_to_tls", "server1").with(Parameter.TLS, false).expectFailure("Cannot connect", "Could not connect"); |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
217 } |
802
5d04490bc58b
Add tests using monetdb-tlstester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
218 |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
219 private void test_connect_server_name() throws IOException, SQLException { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
220 Attempt attempt = attempt("connect_server_name", "sni"); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
221 attempt.withFile(Parameter.CERT, "/ca1.crt").expectSuccess(); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
222 } |
802
5d04490bc58b
Add tests using monetdb-tlstester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
223 |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
224 private void test_connect_alpn_mapi9() throws IOException, SQLException { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
225 attempt("connect_alpn_mapi9", "alpn_mapi9").withFile(Parameter.CERT, "/ca1.crt").expectSuccess(); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
226 } |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
227 |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
228 private void test_connect_trusted() throws IOException, SQLException { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
229 attempt("connect_trusted", null) |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
230 .with(Parameter.HOST, "monetdb.ergates.nl") |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
231 .with(Parameter.PORT, 50000) |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
232 .expectSuccess(); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
233 } |
802
5d04490bc58b
Add tests using monetdb-tlstester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
234 |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
235 private void test_refuse_trusted_wrong_host() throws IOException, SQLException { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
236 attempt("test_refuse_trusted_wrong_host", null) |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
237 .with(Parameter.HOST, "monetdbxyz.ergates.nl") |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
238 .with(Parameter.PORT, 50000) |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
239 .expectFailure("No subject alternative DNS name"); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
240 } |
802
5d04490bc58b
Add tests using monetdb-tlstester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
241 |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
242 private Attempt attempt(String testName, String portName) throws IOException { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
243 preparedButNotRun.add(testName); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
244 return new Attempt(testName, portName); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
245 } |
802
5d04490bc58b
Add tests using monetdb-tlstester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
246 |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
247 private class Attempt { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
248 private final String testName; |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
249 private final Properties props = new Properties(); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
250 boolean disabled = false; |
802
5d04490bc58b
Add tests using monetdb-tlstester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
251 |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
252 public Attempt(String testName, String portName) throws IOException { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
253 HashMap<String, Integer> portMap = loadPortMap(testName); |
802
5d04490bc58b
Add tests using monetdb-tlstester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
254 |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
255 this.testName = testName; |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
256 with(Parameter.TLS, true); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
257 with(Parameter.HOST, serverHost); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
258 with(Parameter.SO_TIMEOUT, 3000); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
259 if (portName != null) { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
260 Integer port = portMap.get(portName); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
261 if (port != null) { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
262 with(Parameter.PORT, port); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
263 } else { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
264 throw new RuntimeException("Unknown port name: " + portName); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
265 } |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
266 } |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
267 } |
802
5d04490bc58b
Add tests using monetdb-tlstester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
268 |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
269 private Attempt with(Parameter parm, String value) { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
270 props.setProperty(parm.name, value); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
271 return this; |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
272 } |
802
5d04490bc58b
Add tests using monetdb-tlstester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
273 |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
274 private Attempt with(Parameter parm, int value) { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
275 props.setProperty(parm.name, Integer.toString(value)); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
276 return this; |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
277 } |
802
5d04490bc58b
Add tests using monetdb-tlstester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
278 |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
279 private Attempt with(Parameter parm, boolean value) { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
280 props.setProperty(parm.name, value ? "true" : "false"); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
281 return this; |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
282 } |
802
5d04490bc58b
Add tests using monetdb-tlstester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
283 |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
284 private Attempt withFile(Parameter parm, String certResource) throws IOException { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
285 File certFile = resource(certResource); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
286 String path = certFile.getPath(); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
287 with(parm, path); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
288 return this; |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
289 } |
802
5d04490bc58b
Add tests using monetdb-tlstester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
290 |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
291 public void expectSuccess() throws SQLException { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
292 preparedButNotRun.remove(testName); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
293 if (disabled) |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
294 return; |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
295 try { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
296 Connection conn = DriverManager.getConnection("jdbc:monetdb:", props); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
297 conn.close(); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
298 } catch (SQLException e) { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
299 if (e.getMessage().startsWith("Sorry, this is not a real MonetDB instance")) { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
300 // it looks like a failure but this is actually our success scenario |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
301 // because this is what the TLS Tester does when the connection succeeds. |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
302 return; |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
303 } |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
304 // other exceptions ARE errors and should be reported. |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
305 throw e; |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
306 } |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
307 } |
802
5d04490bc58b
Add tests using monetdb-tlstester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
308 |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
309 public void expectFailure(String... expectedMessages) throws SQLException { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
310 if (disabled) |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
311 return; |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
312 try { |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
313 expectSuccess(); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
314 throw new RuntimeException("Expected test " + testName + " to throw an exception but it didn't"); |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
315 } catch (SQLException e) { |
855
839d76eeb4ae
Added missing Copyright header comments
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
851
diff
changeset
|
316 for (String expected : expectedMessages) { |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
317 if (e.getMessage().contains(expected)) |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
318 return; |
855
839d76eeb4ae
Added missing Copyright header comments
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
851
diff
changeset
|
319 } |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
320 String message = "Test " + testName + " threw the wrong exception: " + e.getMessage() + '\n' + "Expected:\n <" + String.join(">\n <", expectedMessages) + ">"; |
851
157dcb2d6516
relax wording of expected exception
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
834
diff
changeset
|
321 throw new RuntimeException(message, e); |
834
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
322 } |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
323 } |
5aa19bbed0d6
Comments and formatting
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
805
diff
changeset
|
324 } |
802
5d04490bc58b
Add tests using monetdb-tlstester
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
325 } |