|
1313 | 1313 | (is (= "" (bs/to-string (:body resp)))))))))
|
1314 | 1314 |
|
1315 | 1315 |
|
1316 |
| -(defn test-start-server-options [options] |
| 1316 | +(defn try-start-server [options] |
1317 | 1317 | (try
|
1318 | 1318 | (with-server (http/start-server identity (merge http-server-options options))
|
1319 | 1319 | :started)
|
|
1323 | 1323 | (deftest test-http-versions-config
|
1324 | 1324 | (testing "ssl-context as options map"
|
1325 | 1325 | (testing "with different HTTP versions in ALPN config"
|
1326 |
| - (let [result (test-start-server-options |
| 1326 | + (let [result (try-start-server |
1327 | 1327 | {:http-versions [:http2]
|
1328 | 1328 | :ssl-context (assoc test-ssl/server-ssl-context-opts
|
1329 | 1329 | :application-protocol-config
|
1330 | 1330 | (netty/application-protocol-config [:http1]))})]
|
1331 | 1331 | (is (instance? ExceptionInfo result))
|
1332 | 1332 | (is (= "Some desired HTTP versions are not part of ALPN config." (ex-message result)))))
|
1333 | 1333 | (testing "with different preference order in ALPN config"
|
1334 |
| - (let [result (test-start-server-options |
| 1334 | + (let [result (try-start-server |
1335 | 1335 | {:http-versions [:http2 :http1]
|
1336 | 1336 | :ssl-context (assoc test-ssl/server-ssl-context-opts
|
1337 | 1337 | :application-protocol-config
|
1338 | 1338 | (netty/application-protocol-config [:http1 :http2]))})]
|
1339 | 1339 | (is (instance? ExceptionInfo result))
|
1340 | 1340 | (is (= "Desired HTTP version preference order differs from ALPN config." (ex-message result)))))
|
1341 | 1341 | (testing "with extra HTTP versions in the ALPN config"
|
1342 |
| - (let [result (test-start-server-options |
| 1342 | + (let [result (try-start-server |
1343 | 1343 | {:http-versions [:http1]
|
1344 | 1344 | :ssl-context (assoc test-ssl/server-ssl-context-opts
|
1345 | 1345 | :application-protocol-config
|
1346 | 1346 | (netty/application-protocol-config [:http1 :http2]))})]
|
1347 | 1347 | (is (instance? ExceptionInfo result))
|
1348 | 1348 | (is (= "ALPN config contains more HTTP versions than desired." (ex-message result)))))
|
1349 | 1349 | (testing "with matching ALPN config"
|
1350 |
| - (let [result (test-start-server-options |
| 1350 | + (let [result (try-start-server |
1351 | 1351 | {:http-versions [:http2 :http1]
|
1352 | 1352 | :ssl-context (assoc test-ssl/server-ssl-context-opts
|
1353 | 1353 | :application-protocol-config
|
1354 | 1354 | (netty/application-protocol-config [:http2 :http1]))})]
|
1355 | 1355 | (is (= :started result))))
|
1356 | 1356 | (testing "with no ALPN config"
|
1357 |
| - (let [result (test-start-server-options |
| 1357 | + (let [result (try-start-server |
1358 | 1358 | {:http-versions [:http2 :http1]
|
1359 | 1359 | :ssl-context test-ssl/server-ssl-context-opts})]
|
1360 | 1360 | (is (= :started result)))))
|
1361 | 1361 | (testing "ssl-context as SslContext instance"
|
1362 | 1362 | (testing "with different HTTP versions in ALPN config"
|
1363 |
| - (let [result (test-start-server-options |
| 1363 | + (let [result (try-start-server |
1364 | 1364 | {:http-versions [:http2]
|
1365 | 1365 | :ssl-context (netty/coerce-ssl-server-context
|
1366 | 1366 | (assoc test-ssl/server-ssl-context-opts
|
|
1369 | 1369 | (is (instance? ExceptionInfo result))
|
1370 | 1370 | (is (= "Some desired HTTP versions are not part of ALPN config." (ex-message result)))))
|
1371 | 1371 | (testing "with different preference order in ALPN config"
|
1372 |
| - (let [result (test-start-server-options |
| 1372 | + (let [result (try-start-server |
1373 | 1373 | {:http-versions [:http2 :http1]
|
1374 | 1374 | :ssl-context (netty/coerce-ssl-server-context
|
1375 | 1375 | (assoc test-ssl/server-ssl-context-opts
|
|
1378 | 1378 | (is (instance? ExceptionInfo result))
|
1379 | 1379 | (is (= "Desired HTTP version preference order differs from ALPN config." (ex-message result)))))
|
1380 | 1380 | (testing "with extra HTTP versions in the ALPN config"
|
1381 |
| - (let [result (test-start-server-options |
| 1381 | + (let [result (try-start-server |
1382 | 1382 | {:http-versions [:http1]
|
1383 |
| - :ssl-context (netty/coerce-ssl-server-context |
| 1383 | + :ssl-context (netty/ssl-server-context |
1384 | 1384 | (assoc test-ssl/server-ssl-context-opts
|
1385 | 1385 | :application-protocol-config
|
1386 | 1386 | (netty/application-protocol-config [:http1 :http2])))})]
|
1387 | 1387 | (is (instance? ExceptionInfo result))
|
1388 | 1388 | (is (= "ALPN config contains more HTTP versions than desired." (ex-message result)))))
|
1389 | 1389 | (testing "with matching ALPN config"
|
1390 |
| - (let [result (test-start-server-options |
| 1390 | + (let [result (try-start-server |
1391 | 1391 | {:http-versions [:http2 :http1]
|
1392 | 1392 | :ssl-context (netty/coerce-ssl-server-context
|
1393 | 1393 | (assoc test-ssl/server-ssl-context-opts
|
1394 | 1394 | :application-protocol-config
|
1395 | 1395 | (netty/application-protocol-config [:http2 :http1])))})]
|
1396 | 1396 | (is (= :started result))))
|
1397 | 1397 | (testing "with no ALPN config"
|
1398 |
| - (let [result (test-start-server-options |
| 1398 | + (let [result (try-start-server |
1399 | 1399 | {:http-versions [:http2 :http1]
|
1400 | 1400 | :ssl-context test-ssl/server-ssl-context})]
|
1401 | 1401 | (is (instance? ExceptionInfo result))
|
1402 | 1402 | (is (= "Some desired HTTP versions are not part of ALPN config." (ex-message result))))))
|
1403 | 1403 | (testing "HTTP/2 without ssl-context"
|
1404 |
| - (let [result (test-start-server-options |
| 1404 | + (let [result (try-start-server |
1405 | 1405 | {:http-versions [:http2]})]
|
1406 | 1406 | ;; TODO: Shouldn't this fail?
|
1407 | 1407 | (is (= :started result))))
|
1408 | 1408 | (testing "HTTP/2 without ssl-context but with h2c"
|
1409 |
| - (let [result (test-start-server-options |
| 1409 | + (let [result (try-start-server |
1410 | 1410 | {:use-h2c? true
|
1411 | 1411 | :http-versions [:http2]})]
|
1412 | 1412 | (is (= :started result))))
|
1413 | 1413 | (testing "HTTP/2 with ssl-context *and* with h2c (which has no effect then)"
|
1414 |
| - (let [result (test-start-server-options |
| 1414 | + (let [result (try-start-server |
1415 | 1415 | {:use-h2c? true
|
1416 | 1416 | :http-versions [:http2]
|
1417 | 1417 | :ssl-context test-ssl/server-ssl-context-opts})]
|
|
0 commit comments