|
10 | 10 |
|
11 | 11 | package at.bitfire.cert4android |
12 | 12 |
|
13 | | -import org.junit.AssumptionViolatedException |
14 | 13 | import org.junit.Before |
15 | | -import org.junit.BeforeClass |
16 | 14 | import org.junit.Test |
17 | | -import java.io.IOException |
18 | 15 | import java.net.URL |
19 | 16 | import java.security.cert.CertificateException |
20 | 17 | import java.security.cert.X509Certificate |
21 | 18 | import javax.net.ssl.HttpsURLConnection |
22 | 19 |
|
23 | 20 | class CustomCertManagerTest { |
24 | 21 |
|
| 22 | + private val siteCerts: List<X509Certificate> by lazy { |
| 23 | + getSiteCertificates(URL("https://www.davx5.com")) |
| 24 | + } |
25 | 25 | private lateinit var certStore: CertStore |
26 | 26 | private lateinit var certManager: CustomCertManager |
27 | 27 | private lateinit var paranoidCertManager: CustomCertManager |
@@ -77,34 +77,19 @@ class CustomCertManagerTest { |
77 | 77 | certStore.setUntrustedByUser(siteCerts.first()) |
78 | 78 | } |
79 | 79 |
|
80 | | - companion object { |
81 | | - private lateinit var siteCerts: List<X509Certificate> |
82 | | - |
83 | | - @JvmStatic |
84 | | - @BeforeClass |
85 | | - fun setUp() { |
86 | | - siteCerts = try { |
87 | | - getSiteCertificates(URL("https://www.davx5.com")) |
88 | | - } catch (_: IOException) { |
89 | | - // Skip all tests if the certs can't be fetched |
90 | | - throw AssumptionViolatedException("Couldn't load certificate from Web") |
91 | | - } |
92 | | - } |
93 | | - |
94 | | - fun getSiteCertificates(url: URL): List<X509Certificate> { |
95 | | - val conn = url.openConnection() as HttpsURLConnection |
96 | | - try { |
97 | | - conn.connectTimeout = 5000 |
98 | | - conn.readTimeout = 5000 |
99 | | - conn.inputStream.use { stream -> |
100 | | - stream.read() |
101 | | - val certs = mutableListOf<X509Certificate>() |
102 | | - conn.serverCertificates.forEach { certs += it as X509Certificate } |
103 | | - return certs |
104 | | - } |
105 | | - } finally { |
106 | | - conn.disconnect() |
| 80 | + fun getSiteCertificates(url: URL): List<X509Certificate> { |
| 81 | + val conn = url.openConnection() as HttpsURLConnection |
| 82 | + try { |
| 83 | + conn.connectTimeout = 5000 |
| 84 | + conn.readTimeout = 5000 |
| 85 | + conn.inputStream.use { stream -> |
| 86 | + stream.read() |
| 87 | + val certs = mutableListOf<X509Certificate>() |
| 88 | + conn.serverCertificates.forEach { certs += it as X509Certificate } |
| 89 | + return certs |
107 | 90 | } |
| 91 | + } finally { |
| 92 | + conn.disconnect() |
108 | 93 | } |
109 | 94 | } |
110 | 95 |
|
|
0 commit comments