[Git][clojure-team/trapperkeeper-webserver-jetty9-clojure][upstream] New upstream version 4.4.1
Jérôme Charaoui (@lavamind)
gitlab at salsa.debian.org
Wed Oct 19 06:05:11 BST 2022
Jérôme Charaoui pushed to branch upstream at Debian Clojure Maintainers / trapperkeeper-webserver-jetty9-clojure
Commits:
3f35508f by Jérôme Charaoui at 2022-10-18T23:22:26-04:00
New upstream version 4.4.1
- - - - -
20 changed files:
- + .github/workflows/snyk_merge.yaml
- .travis.yml
- CHANGELOG.md
- CODEOWNERS
- dev-resources/jdk11-fips-security
- dev-resources/jdk8-fips-security
- doc/jetty-config.md
- project.clj
- src/puppetlabs/trapperkeeper/services/webserver/jetty9_config.clj
- test/clj/puppetlabs/trapperkeeper/services/webrouting/webrouting_service_handlers_test.clj
- test/clj/puppetlabs/trapperkeeper/services/webrouting/webrouting_service_override_settings_test.clj
- test/clj/puppetlabs/trapperkeeper/services/webrouting/webrouting_service_proxy_test.clj
- test/clj/puppetlabs/trapperkeeper/services/webrouting/webrouting_service_test.clj
- test/clj/puppetlabs/trapperkeeper/services/webserver/jetty9_config_test.clj
- test/clj/puppetlabs/trapperkeeper/services/webserver/jetty9_core_test.clj
- test/clj/puppetlabs/trapperkeeper/services/webserver/jetty9_default_config_test.clj
- test/clj/puppetlabs/trapperkeeper/services/webserver/jetty9_service_handlers_test.clj
- test/clj/puppetlabs/trapperkeeper/services/webserver/jetty9_service_override_settings_test.clj
- test/clj/puppetlabs/trapperkeeper/services/webserver/jetty9_service_proxy_test.clj
- test/clj/puppetlabs/trapperkeeper/services/webserver/jetty9_service_test.clj
Changes:
=====================================
.github/workflows/snyk_merge.yaml
=====================================
@@ -0,0 +1,29 @@
+---
+name: Snyk Clojure Merge
+
+on: push
+
+jobs:
+ snyk_clojure:
+ runs-on: ubuntu-latest
+ steps:
+ - name: Connect to Twingate
+ uses: twingate/github-action at v1
+ with:
+ service-key: ${{ secrets.TWINGATE_PUBLIC_REPO_KEY }}
+ - name: checkout the current HEAD
+ uses: actions/checkout at v2
+ with:
+ fetch-depth: 1
+ persist-credentials: false
+ - name: Run Clojure Snyk Scan
+ id: scan
+ uses: puppetlabs/security-snyk-clojure-action at v2
+ with:
+ snykToken: ${{ secrets.SNYK_PE_TOKEN }}
+ snykOrg: 'puppet-enterprise'
+ snykProject: 'trapperkeeper-webserver-jetty9'
+ snykPolicy: '.snyk'
+ - name: Check output
+ if: steps.scan.outputs.vulns != ''
+ run: echo "Vulnerabilities detected; ${{ steps.scan.outputs.vulns }}" && exit 1
=====================================
.travis.yml
=====================================
@@ -1,5 +1,5 @@
language: clojure
-lein: 2.9.1
+lein: 2.9.10
jobs:
include:
- stage: jdk8
=====================================
CHANGELOG.md
=====================================
@@ -1,3 +1,65 @@
+## 4.4.1
+* update clj-parent to 5.2.9, which includes the stylefruits/gniazdo dependency.
+
+## 4.4.0
+* update clj-parent which moves to the `18on` series of bouncy castle from the `15on` series.
+
+## 4.3.1
+* update to Jetty 9.4.48 for additional bug fixes
+
+## 4.3.0
+
+(maint) Update to Jetty 9.4.44 for small bug fixes and dependency bumps
+(PE-32764) Update default ciphers:
+ - Remove the TLS_CHACHA20_POLY1305_SHA256 cipher
+ - Add TLS_DHE_RSA* ciphers
+ - Add the RSA ECDHE AES 256 cipher to the FIPS list
+ - Rearrange the cipher list to be in the preferred order
+
+## 4.2.1
+
+(maint) Enable TLS 1.3 by default for FIPS [#232](https://github.com/puppetlabs/trapperkeeper-webserver-jetty9/pull/232)
+
+## 4.2.0
+
+[TK-494](https://tickets.puppetlabs.com/browse/TK-494) Enable TLS 1.3 by default.
+
+## 4.1.8
+
+Update Jetty to 9.4.43 to resolve CVE-2021-34429
+
+## 4.1.7
+
+Update Jetty to 9.4.42 to resolve CVE-2021-28169
+
+## 4.1.6
+
+Update jetty to 9.4.40 to attempt to avoid a connection reset bug.
+
+## 4.1.5
+
+Update jetty to 9.4.39.v20210325 to resolve CVEs:
+
+- CVE-2021-28165 - #6072 - jetty server high CPU when client send data length > 17408
+- CVE-2021-28164 - #6101 - Normalize ambiguous URIs
+- CVE-2021-28163 - #6102 - Exclude webapps directory from deployment scan
+
+## 4.1.4
+
+Update clj-kitchensink to 3.1.3 via an update of clj-parent to 4.6.18
+
+## 4.1.3
+
+Update flatland/ordered to 1.5.9, to avoid conflicting with other libs.
+
+## 4.1.2
+
+Ship artifacts with Java 8 builds.
+
+## 4.1.1
+
+Update jetty version to 9.4.36. This is a maintenance update.
+
## 4.1.0
Update jetty version to 9.4.28. This is a maintenance update.
@@ -64,7 +126,7 @@ This is a feature release with backwards breaking changes.
## 2.3.1
* [TK-473](https://tickets.puppetlabs.com/browse/TK-473) Stop reporting jetty
- version in responses
+ version in responses
## 2.3.0
=====================================
CODEOWNERS
=====================================
@@ -1,4 +1 @@
-# This will cause the puppetserver-maintainers group to be assigned
-# review of any opened PRs against the branches containing this file.
-
-* @puppetlabs/puppetserver-maintainers
+* @puppetlabs/dumpling
=====================================
dev-resources/jdk11-fips-security
=====================================
@@ -61,7 +61,7 @@
# List of providers and their preference orders (see above):
#
security.provider.1=org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider
-security.provider.2=org.bouncycastle.jsse.provider.BouncyCastleJsseProvider fips:BCFIPS
+security.provider.2=org.bouncycastle.jsse.provider.BouncyCastleJsseProvider fips:org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider
security.provider.3=SUN
security.provider.4=SunRsaSign
#security.provider.5=SunEC
=====================================
dev-resources/jdk8-fips-security
=====================================
@@ -66,7 +66,7 @@
# List of providers and their preference orders (see above):
#
security.provider.1=org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider
-security.provider.2=org.bouncycastle.jsse.provider.BouncyCastleJsseProvider fips:BCFIPS
+security.provider.2=org.bouncycastle.jsse.provider.BouncyCastleJsseProvider fips:org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider
security.provider.3=sun.security.provider.Sun
security.provider.4=sun.security.rsa.SunRsaSign
#security.provider.5=sun.security.ec.SunEC
=====================================
doc/jetty-config.md
=====================================
@@ -240,12 +240,15 @@ you'll need to use the all-caps cipher suite name.
If not supplied, trapperkeeper uses this list of cipher suites:
- - `TLS_DHE_RSA_WITH_AES_128_GCM_SHA256`
- - `TLS_DHE_RSA_WITH_AES_256_GCM_SHA384`
+ - `TLS_AES_128_GCM_SHA256`
+ - `TLS_AES_256_GCM_SHA384`
+ - `TLS_CHACHA20_POLY1305_SHA256`
- `TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256`
- - `TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384`
- `TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256`
+ - `TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384`
- `TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384`
+ - `TLS_DHE_RSA_WITH_AES_128_GCM_SHA256`
+ - `TLS_DHE_RSA_WITH_AES_256_GCM_SHA384`
### `ssl-protocols`
@@ -259,10 +262,9 @@ example: `TLSv1, TLSv1.1, TLSv1.2`.
If not supplied, trapperkeeper uses this list of SSL protocols:
+- `TLSv1.3`
- `TLSv1.2`
-When running on Java 11 users are encouraged to add `TLSv1.3` to the list of supported protocols.
-
### `client-auth`
=====================================
project.clj
=====================================
@@ -1,14 +1,14 @@
-(def jetty-version "9.4.28.v20200408")
+(def jetty-version "9.4.48.v20220622")
-(defproject puppetlabs/trapperkeeper-webserver-jetty9 "4.1.0"
+(defproject puppetlabs/trapperkeeper-webserver-jetty9 "4.4.1"
:description "A jetty9-based webserver implementation for use with the puppetlabs/trapperkeeper service framework."
:url "https://github.com/puppetlabs/trapperkeeper-webserver-jetty9"
:license {:name "Apache License, Version 2.0"
:url "http://www.apache.org/licenses/LICENSE-2.0"}
- :min-lein-version "2.8.1"
+ :min-lein-version "2.9.1"
- :parent-project {:coords [puppetlabs/clj-parent "4.2.4"]
+ :parent-project {:coords [puppetlabs/clj-parent "5.2.9"]
:inherit [:managed-dependencies]}
;; Abort when version ranges or version conflicts are detected in
@@ -20,7 +20,7 @@
[org.clojure/tools.logging]
[org.codehaus.janino/janino]
- [org.flatland/ordered "1.5.7"]
+ [org.flatland/ordered "1.5.9"]
[javax.servlet/javax.servlet-api "3.1.0"]
;; Jetty Webserver
@@ -76,26 +76,26 @@
[puppetlabs/trapperkeeper nil :classifier "test"]
[org.clojure/tools.namespace]
[compojure]
- [stylefruits/gniazdo "1.1.1" :exclusions [org.eclipse.jetty.websocket/websocket-api
- org.eclipse.jetty.websocket/websocket-client
- org.eclipse.jetty/jetty-util]]
+ [stylefruits/gniazdo nil :exclusions [org.eclipse.jetty.websocket/websocket-api
+ org.eclipse.jetty.websocket/websocket-client
+ org.eclipse.jetty/jetty-util]]
[ring/ring-core]]
:resource-paths ["dev-resources"]
:jvm-opts ["-Djava.util.logging.config.file=dev-resources/logging.properties"]}
:dev [:defaults
- {:dependencies [[org.bouncycastle/bcpkix-jdk15on]]}]
+ {:dependencies [[org.bouncycastle/bcpkix-jdk18on]]}]
;; per https://github.com/technomancy/leiningen/issues/1907
;; the provided profile is necessary for lein jar / lein install
- :provided {:dependencies [[org.bouncycastle/bcpkix-jdk15on]]
+ :provided {:dependencies [[org.bouncycastle/bcpkix-jdk18on]]
:resource-paths ["dev-resources"]}
:fips [:defaults ; merge in the dev profile
{:dependencies [[org.bouncycastle/bcpkix-fips]
[org.bouncycastle/bc-fips]
[org.bouncycastle/bctls-fips]]
- :exclusions [[org.bouncycastle/bcpkix-jdk15on]]
+ :exclusions [[org.bouncycastle/bcpkix-jdk18on]]
;; this only ensures that we run with the proper profiles
;; during testing. This JVM opt will be set in the puppet module
;; that sets up the JVM classpaths during installation.
@@ -117,5 +117,5 @@
:main puppetlabs.trapperkeeper.main
:repositories [["puppet-releases" "https://artifactory.delivery.puppetlabs.net/artifactory/list/clojure-releases__local/"]
- ["puppet-snapshots" "https://artifactory.delivery.puppetlabs.net/artifactory/list/clojure-snapshots__local/"]]
- )
+ ["puppet-snapshots" "https://artifactory.delivery.puppetlabs.net/artifactory/list/clojure-snapshots__local/"]])
+
=====================================
src/puppetlabs/trapperkeeper/services/webserver/jetty9_config.clj
=====================================
@@ -58,20 +58,31 @@
;;; their implicit defaults reflect the security issue. The latter is far more
;;; risky for our downstream apps, thus it was decided that it makes sense to
;;; keep these overrides.
-(def acceptable-ciphers
- ["TLS_DHE_RSA_WITH_AES_128_GCM_SHA256"
- "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384"
+(def tls-1-dot-3-ciphers
+ ["TLS_AES_128_GCM_SHA256"
+ "TLS_AES_256_GCM_SHA384"])
+
+(def tls-1-dot-2-ciphers
+ ["TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384"
+ "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384"
+ "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"
"TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256"
+ "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384"
+ "TLS_DHE_RSA_WITH_AES_128_GCM_SHA256"])
+
+(def acceptable-ciphers
+ (into [] (concat tls-1-dot-3-ciphers tls-1-dot-2-ciphers)))
+
+(def fips-tls-1-dot-2-ciphers
+ ["TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384"
"TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384"
"TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"
- "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384"])
+ "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256"])
(def acceptable-ciphers-fips
- ["TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256"
- "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384"
- "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"])
+ (into [] (concat tls-1-dot-3-ciphers fips-tls-1-dot-2-ciphers)))
-(def default-protocols ["TLSv1.2"])
+(def default-protocols ["TLSv1.3" "TLSv1.2"])
(def default-client-auth :need)
(def default-allow-renegotiation false)
=====================================
test/clj/puppetlabs/trapperkeeper/services/webrouting/webrouting_service_handlers_test.clj
=====================================
@@ -8,8 +8,7 @@
[puppetlabs.trapperkeeper.app :refer [get-service]]
[puppetlabs.trapperkeeper.testutils.webrouting.common :refer :all]
[puppetlabs.trapperkeeper.testutils.bootstrap :refer [with-app-with-config]]
- [puppetlabs.trapperkeeper.testutils.logging
- :refer [with-test-logging]]
+ [puppetlabs.trapperkeeper.testutils.logging :refer [with-test-logging]]
[puppetlabs.trapperkeeper.testutils.webserver :as testutils]))
(use-fixtures :once
@@ -44,151 +43,155 @@
:foo "/bar"}}})
(deftest add-context-handler-test
- (testing "static content context with web routing"
- (with-app-with-config app
- [jetty9-service
- webrouting-service
- test-dummy]
- webrouting-plaintext-config
- (let [s (get-service app :WebroutingService)
- add-context-handler (partial add-context-handler s)
- resource "logback.xml"
- svc (get-service app :TestDummy)]
- (add-context-handler svc dev-resources-dir)
- (let [response (http-get (str "http://localhost:8080/foo/" resource))]
- (is (= (:status response) 200))
- (is (= (:body response) (slurp (str dev-resources-dir resource))))))))
-
- (testing "static content context with multiple routes"
- (with-app-with-config app
- [jetty9-service
- webrouting-service
- test-dummy]
- webrouting-plaintext-multiroute-config
- (let [s (get-service app :WebroutingService)
- add-context-handler (partial add-context-handler s)
- resource "logback.xml"
- svc (get-service app :TestDummy)]
- (add-context-handler svc dev-resources-dir {:route-id :quux})
- (add-context-handler svc dev-resources-dir {:route-id :foo})
- (let [response (http-get (str "http://localhost:8080/foo/" resource))]
- (is (= (:status response) 200))
- (is (= (:body response) (slurp (str dev-resources-dir resource)))))
- (let [response (http-get (str "http://localhost:8080/bar/" resource))]
- (is (= (:status response) 200))
- (is (= (:body response) (slurp (str dev-resources-dir resource)))))))))
+ (with-test-logging
+ (testing "static content context with web routing"
+ (with-app-with-config app
+ [jetty9-service
+ webrouting-service
+ test-dummy]
+ webrouting-plaintext-config
+ (let [s (get-service app :WebroutingService)
+ add-context-handler (partial add-context-handler s)
+ resource "logback.xml"
+ svc (get-service app :TestDummy)]
+ (add-context-handler svc dev-resources-dir)
+ (let [response (http-get (str "http://localhost:8080/foo/" resource))]
+ (is (= (:status response) 200))
+ (is (= (:body response) (slurp (str dev-resources-dir resource))))))))
+
+ (testing "static content context with multiple routes"
+ (with-app-with-config app
+ [jetty9-service
+ webrouting-service
+ test-dummy]
+ webrouting-plaintext-multiroute-config
+ (let [s (get-service app :WebroutingService)
+ add-context-handler (partial add-context-handler s)
+ resource "logback.xml"
+ svc (get-service app :TestDummy)]
+ (add-context-handler svc dev-resources-dir {:route-id :quux})
+ (add-context-handler svc dev-resources-dir {:route-id :foo})
+ (let [response (http-get (str "http://localhost:8080/foo/" resource))]
+ (is (= (:status response) 200))
+ (is (= (:body response) (slurp (str dev-resources-dir resource)))))
+ (let [response (http-get (str "http://localhost:8080/bar/" resource))]
+ (is (= (:status response) 200))
+ (is (= (:body response) (slurp (str dev-resources-dir resource))))))))))
(deftest ring-handler-test-web-routing
- (testing "ring request over http succeeds with web-routing"
- (with-app-with-config app
- [jetty9-service
- webrouting-service
- test-dummy]
- webrouting-plaintext-config
- (let [s (get-service app :WebroutingService)
- add-ring-handler (partial add-ring-handler s)
- body "Hi World"
- ring-handler (fn [req] {:status 200 :body body})
- svc (get-service app :TestDummy)]
- (add-ring-handler svc ring-handler)
- (let [response (http-get "http://localhost:8080/foo")]
- (is (= (:status response) 200))
- (is (= (:body response) body))))))
-
- (testing "ring request over http succeeds with multiple web-routes"
- (with-app-with-config app
- [jetty9-service
- webrouting-service
- test-dummy]
- webrouting-plaintext-multiroute-config
- (let [s (get-service app :WebroutingService)
- add-ring-handler (partial add-ring-handler s)
- body "Hi World"
- ring-handler (fn [req] {:status 200 :body body})
- svc (get-service app :TestDummy)]
- (add-ring-handler svc ring-handler {:route-id :quux})
- (add-ring-handler svc ring-handler {:route-id :foo})
- (let [response (http-get "http://localhost:8080/foo")]
- (is (= (:status response) 200))
- (is (= (:body response) body)))
- (let [response (http-get "http://localhost:8080/bar")]
- (is (= (:status response) 200))
- (is (= (:body response) body)))))))
+ (with-test-logging
+ (testing "ring request over http succeeds with web-routing"
+ (with-app-with-config app
+ [jetty9-service
+ webrouting-service
+ test-dummy]
+ webrouting-plaintext-config
+ (let [s (get-service app :WebroutingService)
+ add-ring-handler (partial add-ring-handler s)
+ body "Hi World"
+ ring-handler (fn [req] {:status 200 :body body})
+ svc (get-service app :TestDummy)]
+ (add-ring-handler svc ring-handler)
+ (let [response (http-get "http://localhost:8080/foo")]
+ (is (= (:status response) 200))
+ (is (= (:body response) body))))))
+
+ (testing "ring request over http succeeds with multiple web-routes"
+ (with-app-with-config app
+ [jetty9-service
+ webrouting-service
+ test-dummy]
+ webrouting-plaintext-multiroute-config
+ (let [s (get-service app :WebroutingService)
+ add-ring-handler (partial add-ring-handler s)
+ body "Hi World"
+ ring-handler (fn [req] {:status 200 :body body})
+ svc (get-service app :TestDummy)]
+ (add-ring-handler svc ring-handler {:route-id :quux})
+ (add-ring-handler svc ring-handler {:route-id :foo})
+ (let [response (http-get "http://localhost:8080/foo")]
+ (is (= (:status response) 200))
+ (is (= (:body response) body)))
+ (let [response (http-get "http://localhost:8080/bar")]
+ (is (= (:status response) 200))
+ (is (= (:body response) body))))))))
(deftest servlet-test-web-routing
- (testing "request to servlet over http succeeds with web routing"
- (with-app-with-config app
- [jetty9-service
- webrouting-service
- test-dummy]
- webrouting-plaintext-config
- (let [s (get-service app :WebroutingService)
- add-servlet-handler (partial add-servlet-handler s)
- body "Hey there"
- servlet (SimpleServlet. body)
- svc (get-service app :TestDummy)]
- (add-servlet-handler svc servlet)
- (let [response (http-get "http://localhost:8080/foo")]
- (is (= (:status response) 200))
- (is (= (:body response) body))))))
-
- (testing "request to servlet over http succeeds with multiple web routes"
- (with-app-with-config app
- [jetty9-service
- webrouting-service
- test-dummy]
- webrouting-plaintext-multiroute-config
- (let [s (get-service app :WebroutingService)
- add-servlet-handler (partial add-servlet-handler s)
- body "Hey there"
- servlet (SimpleServlet. body)
- svc (get-service app :TestDummy)]
- (add-servlet-handler svc servlet {:route-id :quux})
- (add-servlet-handler svc servlet {:route-id :foo})
- (let [response (http-get "http://localhost:8080/foo")]
- (is (= (:status response) 200))
- (is (= (:body response) body)))
- (let [response (http-get "http://localhost:8080/bar")]
- (is (= (:status response) 200))
- (is (= (:body response) body)))))))
+ (with-test-logging
+ (testing "request to servlet over http succeeds with web routing"
+ (with-app-with-config app
+ [jetty9-service
+ webrouting-service
+ test-dummy]
+ webrouting-plaintext-config
+ (let [s (get-service app :WebroutingService)
+ add-servlet-handler (partial add-servlet-handler s)
+ body "Hey there"
+ servlet (SimpleServlet. body)
+ svc (get-service app :TestDummy)]
+ (add-servlet-handler svc servlet)
+ (let [response (http-get "http://localhost:8080/foo")]
+ (is (= (:status response) 200))
+ (is (= (:body response) body))))))
+
+ (testing "request to servlet over http succeeds with multiple web routes"
+ (with-app-with-config app
+ [jetty9-service
+ webrouting-service
+ test-dummy]
+ webrouting-plaintext-multiroute-config
+ (let [s (get-service app :WebroutingService)
+ add-servlet-handler (partial add-servlet-handler s)
+ body "Hey there"
+ servlet (SimpleServlet. body)
+ svc (get-service app :TestDummy)]
+ (add-servlet-handler svc servlet {:route-id :quux})
+ (add-servlet-handler svc servlet {:route-id :foo})
+ (let [response (http-get "http://localhost:8080/foo")]
+ (is (= (:status response) 200))
+ (is (= (:body response) body)))
+ (let [response (http-get "http://localhost:8080/bar")]
+ (is (= (:status response) 200))
+ (is (= (:body response) body))))))))
(deftest war-test-web-routing
- (testing "WAR support with web routing"
- (with-app-with-config app
- [jetty9-service
- webrouting-service
- test-dummy]
- webrouting-plaintext-config
- (let [s (get-service app :WebroutingService)
- add-war-handler (partial add-war-handler s)
- war "helloWorld.war"
- svc (get-service app :TestDummy)]
- (add-war-handler svc (str dev-resources-dir war))
- (let [response (http-get "http://localhost:8080/foo/hello")]
- (is (= (:status response) 200))
- (is (= (:body response)
- "<html>\n<head><title>Hello World Servlet</title></head>\n<body>Hello World!!</body>\n</html>\n"))))))
-
- (testing "WAR support with multiple web routes"
- (with-app-with-config app
- [jetty9-service
- webrouting-service
- test-dummy]
- webrouting-plaintext-multiroute-config
- (let [s (get-service app :WebroutingService)
- add-war-handler (partial add-war-handler s)
- war "helloWorld.war"
- svc (get-service app :TestDummy)]
- (add-war-handler svc (str dev-resources-dir war) {:route-id :quux})
- (add-war-handler svc (str dev-resources-dir war) {:route-id :foo})
- (let [response (http-get "http://localhost:8080/foo/hello")]
- (is (= (:status response) 200))
- (is (= (:body response)
- "<html>\n<head><title>Hello World Servlet</title></head>\n<body>Hello World!!</body>\n</html>\n")))
- (let [response (http-get "http://localhost:8080/bar/hello")]
- (is (= (:status response) 200))
- (is (= (:body response)
- "<html>\n<head><title>Hello World Servlet</title></head>\n<body>Hello World!!</body>\n</html>\n")))))))
+ (with-test-logging
+ (testing "WAR support with web routing"
+ (with-app-with-config app
+ [jetty9-service
+ webrouting-service
+ test-dummy]
+ webrouting-plaintext-config
+ (let [s (get-service app :WebroutingService)
+ add-war-handler (partial add-war-handler s)
+ war "helloWorld.war"
+ svc (get-service app :TestDummy)]
+ (add-war-handler svc (str dev-resources-dir war))
+ (let [response (http-get "http://localhost:8080/foo/hello")]
+ (is (= (:status response) 200))
+ (is (= (:body response)
+ "<html>\n<head><title>Hello World Servlet</title></head>\n<body>Hello World!!</body>\n</html>\n"))))))
+
+ (testing "WAR support with multiple web routes"
+ (with-app-with-config app
+ [jetty9-service
+ webrouting-service
+ test-dummy]
+ webrouting-plaintext-multiroute-config
+ (let [s (get-service app :WebroutingService)
+ add-war-handler (partial add-war-handler s)
+ war "helloWorld.war"
+ svc (get-service app :TestDummy)]
+ (add-war-handler svc (str dev-resources-dir war) {:route-id :quux})
+ (add-war-handler svc (str dev-resources-dir war) {:route-id :foo})
+ (let [response (http-get "http://localhost:8080/foo/hello")]
+ (is (= (:status response) 200))
+ (is (= (:body response)
+ "<html>\n<head><title>Hello World Servlet</title></head>\n<body>Hello World!!</body>\n</html>\n")))
+ (let [response (http-get "http://localhost:8080/bar/hello")]
+ (is (= (:status response) 200))
+ (is (= (:body response)
+ "<html>\n<head><title>Hello World Servlet</title></head>\n<body>Hello World!!</body>\n</html>\n"))))))))
(deftest endpoints-test-web-routing
(testing (str "get-registered-endpoints and log-registered-endpoints are "
=====================================
test/clj/puppetlabs/trapperkeeper/services/webrouting/webrouting_service_override_settings_test.clj
=====================================
@@ -91,4 +91,4 @@
(is (logged? #"^webserver config overridden for key 'ssl-crl-path'")
"Didn't find log message for override of 'ssl-crl-path'"))
(is (= overrides @override-result)
- "Unexpected response to override-webserver-settings! call.")))))
\ No newline at end of file
+ "Unexpected response to override-webserver-settings! call.")))))
=====================================
test/clj/puppetlabs/trapperkeeper/services/webrouting/webrouting_service_proxy_test.clj
=====================================
@@ -5,6 +5,7 @@
[puppetlabs.trapperkeeper.testutils.webrouting.common :refer :all]
[puppetlabs.trapperkeeper.app :refer [get-service]]
[puppetlabs.trapperkeeper.testutils.bootstrap :refer [with-app-with-config]]
+ [puppetlabs.trapperkeeper.testutils.logging :refer [with-test-logging]]
[puppetlabs.trapperkeeper.services :as tk-services]
[schema.test :as schema-test]
[puppetlabs.trapperkeeper.testutils.webserver :as testutils]))
@@ -33,36 +34,37 @@
(defmacro with-target-and-proxy-servers
[{:keys [target proxy proxy-config proxy-opts]} & body]
- `(with-app-with-config proxy-target-app#
- [jetty9-service
- webrouting-service
- dummy-service1]
- {:webserver ~target
- :web-router-service {:puppetlabs.trapperkeeper.services.webrouting.webrouting-service-proxy-test/dummy-service1 "/hello"}}
- (let [target-webserver# (get-service proxy-target-app# :WebroutingService)
- svc# (get-service proxy-target-app# :DummyService1)]
- (add-ring-handler
- target-webserver#
- svc#
- (fn [req#]
- (if (= "/hello/world" (:uri req#))
- {:status 200 :body (str "Hello, World!"
- ((:headers req#) "x-fancy-proxy-header"))}
- {:status 404 :body "D'oh"}))))
- (with-app-with-config proxy-app#
+ `(with-test-logging
+ (with-app-with-config proxy-target-app#
[jetty9-service
webrouting-service
- dummy-service2]
- {:webserver ~proxy
- :web-router-service {:puppetlabs.trapperkeeper.services.webrouting.webrouting-service-proxy-test/dummy-service2
- {:bar "/hello-proxy"
- :foo "/goodbye-proxy"}}}
- (let [proxy-webserver# (get-service proxy-app# :WebroutingService)
- svc# (get-service proxy-app# :DummyService2)]
- (if ~proxy-opts
- (add-proxy-route proxy-webserver# svc# ~proxy-config ~proxy-opts)
- (add-proxy-route proxy-webserver# svc# ~proxy-config {:route-id :bar})))
- ~@body)))
+ dummy-service1]
+ {:webserver ~target
+ :web-router-service {:puppetlabs.trapperkeeper.services.webrouting.webrouting-service-proxy-test/dummy-service1 "/hello"}}
+ (let [target-webserver# (get-service proxy-target-app# :WebroutingService)
+ svc# (get-service proxy-target-app# :DummyService1)]
+ (add-ring-handler
+ target-webserver#
+ svc#
+ (fn [req#]
+ (if (= "/hello/world" (:uri req#))
+ {:status 200 :body (str "Hello, World!"
+ ((:headers req#) "x-fancy-proxy-header"))}
+ {:status 404 :body "D'oh"}))))
+ (with-app-with-config proxy-app#
+ [jetty9-service
+ webrouting-service
+ dummy-service2]
+ {:webserver ~proxy
+ :web-router-service {:puppetlabs.trapperkeeper.services.webrouting.webrouting-service-proxy-test/dummy-service2
+ {:bar "/hello-proxy"
+ :foo "/goodbye-proxy"}}}
+ (let [proxy-webserver# (get-service proxy-app# :WebroutingService)
+ svc# (get-service proxy-app# :DummyService2)]
+ (if ~proxy-opts
+ (add-proxy-route proxy-webserver# svc# ~proxy-config ~proxy-opts)
+ (add-proxy-route proxy-webserver# svc# ~proxy-config {:route-id :bar})))
+ ~@body))))
(deftest proxy-test-web-routing
(testing "proxy support with web routing"
=====================================
test/clj/puppetlabs/trapperkeeper/services/webrouting/webrouting_service_test.clj
=====================================
@@ -106,90 +106,91 @@
:bar "/bar"}}})
(deftest webrouting-service-test
- (testing "Other services can successfully use webrouting service"
- (with-app-with-config
- app
- [jetty9-service webrouting-service test-service test-websocket-service]
- webrouting-plaintext-multiserver-multiroute-config
- (let [response (http-get "http://localhost:8080/foo/")]
- (is (= (:status response) 200))
- (is (= (:body response) "Hello World!")))
- (let [response (http-get "http://localhost:8080/bar/")]
- (is (= (:status response) 200))
- (is (= (:body response) "Hello World!")))
- (let [response (http-get "http://localhost:9000/foo/")]
- (is (= (:status response) 200))
- (is (= (:body response) "Hello World!")))
- (let [response (http-get "http://localhost:9000/bar/")]
- (is (= (:status response) 200))
- (is (= (:body response) "Hello World!")))
- (let [message (promise)
- websocket (ws-client/connect "ws://localhost:8080/baz"
- :on-receive (fn [text] (deliver message text)))]
- (is (= @message "heyo"))
- (ws-client/close websocket))))
-
- (testing "Error occurs when specifying service that does not exist in config file"
- (with-app-with-config
- app
- [jetty9-service webrouting-service not-real]
- webrouting-plaintext-config
- (let [s (tk-app/get-service app :WebroutingService)
- add-ring-handler (partial add-ring-handler s)
- body "Hello World!"
- ring-handler (fn [req] {:status 200 :body body})
- svc (tk-app/get-service app :NotReal)]
- (is (thrown? IllegalArgumentException (add-ring-handler svc ring-handler))))))
-
- (testing "Error occurs when endpoints don't have servers and no default is set"
- (with-app-with-config
- app
- [jetty9-service webrouting-service test-service-2]
- no-default-config
- (let [s (tk-app/get-service app :WebroutingService)
- add-ring-handler (partial add-ring-handler s)
- body "Hello World!"
- ring-handler (fn [req] {:status 200 :body body})
- svc (tk-app/get-service app :TestService2)]
- (is (thrown? IllegalArgumentException (add-ring-handler svc ring-handler))))))
-
- (testing "Error occurs when not specifying a route-id for a multi-route config"
- (with-app-with-config
- app
- [jetty9-service webrouting-service test-service-2]
- default-route-config
- (let [s (tk-app/get-service app :WebroutingService)
- svc (tk-app/get-service app :TestService2)
- add-ring-handler (partial add-ring-handler s)
- ring-handler (fn [req] {:status 200 :body ""})]
- (is (thrown? IllegalArgumentException (add-ring-handler svc ring-handler))))))
-
- (testing "Can access route-ids for a service"
- (with-app-with-config
- app
- [jetty9-service webrouting-service test-service test-service-2]
- webrouting-plaintext-multiserver-multiroute-config
- (let [s (tk-app/get-service app :WebroutingService)
- svc (tk-app/get-service app :TestService)
- svc2 (tk-app/get-service app :TestService2)
- get-route (partial get-route s)]
- (is (= "/foo" (get-route svc :bert)))
- (is (= "/bar" (get-route svc :bar)))
- (is (= "/foo" (get-route svc :baz)))
- (is (= "/bar" (get-route svc :quux)))
- (is (= "/foo" (get-route svc2))))))
-
- (testing "Can access server for a service"
- (with-app-with-config
- app
- [jetty9-service webrouting-service test-service test-service-2 test-service-3]
- webrouting-plaintext-multiserver-multiroute-config
- (let [s (tk-app/get-service app :WebroutingService)
- svc (tk-app/get-service app :TestService)
- svc2 (tk-app/get-service app :TestService2)
- svc3 (tk-app/get-service app :TestService3)
- get-server (partial get-server s)]
- (is (= "foo" (get-server svc :baz)))
- (is (= nil (get-server svc :bar)))
- (is (= nil (get-server svc2)))
- (is (= "foo" (get-server svc3)))))))
+ (with-test-logging
+ (testing "Other services can successfully use webrouting service"
+ (with-app-with-config
+ app
+ [jetty9-service webrouting-service test-service test-websocket-service]
+ webrouting-plaintext-multiserver-multiroute-config
+ (let [response (http-get "http://localhost:8080/foo/")]
+ (is (= (:status response) 200))
+ (is (= (:body response) "Hello World!")))
+ (let [response (http-get "http://localhost:8080/bar/")]
+ (is (= (:status response) 200))
+ (is (= (:body response) "Hello World!")))
+ (let [response (http-get "http://localhost:9000/foo/")]
+ (is (= (:status response) 200))
+ (is (= (:body response) "Hello World!")))
+ (let [response (http-get "http://localhost:9000/bar/")]
+ (is (= (:status response) 200))
+ (is (= (:body response) "Hello World!")))
+ (let [message (promise)
+ websocket (ws-client/connect "ws://localhost:8080/baz"
+ :on-receive (fn [text] (deliver message text)))]
+ (is (= @message "heyo"))
+ (ws-client/close websocket))))
+
+ (testing "Error occurs when specifying service that does not exist in config file"
+ (with-app-with-config
+ app
+ [jetty9-service webrouting-service not-real]
+ webrouting-plaintext-config
+ (let [s (tk-app/get-service app :WebroutingService)
+ add-ring-handler (partial add-ring-handler s)
+ body "Hello World!"
+ ring-handler (fn [req] {:status 200 :body body})
+ svc (tk-app/get-service app :NotReal)]
+ (is (thrown? IllegalArgumentException (add-ring-handler svc ring-handler))))))
+
+ (testing "Error occurs when endpoints don't have servers and no default is set"
+ (with-app-with-config
+ app
+ [jetty9-service webrouting-service test-service-2]
+ no-default-config
+ (let [s (tk-app/get-service app :WebroutingService)
+ add-ring-handler (partial add-ring-handler s)
+ body "Hello World!"
+ ring-handler (fn [req] {:status 200 :body body})
+ svc (tk-app/get-service app :TestService2)]
+ (is (thrown? IllegalArgumentException (add-ring-handler svc ring-handler))))))
+
+ (testing "Error occurs when not specifying a route-id for a multi-route config"
+ (with-app-with-config
+ app
+ [jetty9-service webrouting-service test-service-2]
+ default-route-config
+ (let [s (tk-app/get-service app :WebroutingService)
+ svc (tk-app/get-service app :TestService2)
+ add-ring-handler (partial add-ring-handler s)
+ ring-handler (fn [req] {:status 200 :body ""})]
+ (is (thrown? IllegalArgumentException (add-ring-handler svc ring-handler))))))
+
+ (testing "Can access route-ids for a service"
+ (with-app-with-config
+ app
+ [jetty9-service webrouting-service test-service test-service-2]
+ webrouting-plaintext-multiserver-multiroute-config
+ (let [s (tk-app/get-service app :WebroutingService)
+ svc (tk-app/get-service app :TestService)
+ svc2 (tk-app/get-service app :TestService2)
+ get-route (partial get-route s)]
+ (is (= "/foo" (get-route svc :bert)))
+ (is (= "/bar" (get-route svc :bar)))
+ (is (= "/foo" (get-route svc :baz)))
+ (is (= "/bar" (get-route svc :quux)))
+ (is (= "/foo" (get-route svc2))))))
+
+ (testing "Can access server for a service"
+ (with-app-with-config
+ app
+ [jetty9-service webrouting-service test-service test-service-2 test-service-3]
+ webrouting-plaintext-multiserver-multiroute-config
+ (let [s (tk-app/get-service app :WebroutingService)
+ svc (tk-app/get-service app :TestService)
+ svc2 (tk-app/get-service app :TestService2)
+ svc3 (tk-app/get-service app :TestService3)
+ get-server (partial get-server s)]
+ (is (= "foo" (get-server svc :baz)))
+ (is (= nil (get-server svc :bar)))
+ (is (= nil (get-server svc2)))
+ (is (= "foo" (get-server svc3))))))))
=====================================
test/clj/puppetlabs/trapperkeeper/services/webserver/jetty9_config_test.clj
=====================================
@@ -451,7 +451,7 @@
(testing "scripted changes are executed properly"
(add-ring-handler ring-handler path)
(let [response (http-get
- (format "http://localhost:10000/%s" path))]
+ (format "http://localhost:10000%s" path))]
(is (= (:status response) 200))
(is (= (:body response) body)))))))))
=====================================
test/clj/puppetlabs/trapperkeeper/services/webserver/jetty9_core_test.clj
=====================================
@@ -22,8 +22,7 @@
[puppetlabs.trapperkeeper.testutils.logging :refer [with-test-logging]]
[puppetlabs.trapperkeeper.testutils.bootstrap :refer [with-app-with-config]]
[schema.test :as schema-test]
- [puppetlabs.trapperkeeper.testutils.webserver :as testutils]
- [puppetlabs.trapperkeeper.testutils.logging :as tk-log-testutils]))
+ [puppetlabs.trapperkeeper.testutils.webserver :as testutils]))
(use-fixtures :once
schema-test/validate-schemas
@@ -83,80 +82,82 @@
resp))))
(deftest compression
- (testing "should return"
- ;; Jetty may not Gzip encode a response body if the size of the response
- ;; is less than 256 bytes, so returning a larger body to ensure that Gzip
- ;; encoding is used where desired for these tests
- (let [body (apply str (repeat 1000 "f"))
- app (fn [req]
- (-> body
- (rr/response)
- (rr/status 200)
- (rr/content-type "text/plain")
- (rr/charset "UTF-8")))]
- (with-test-webserver app port
- (testing "a gzipped response when request wants a compressed one and
- server not configured with a default for gzip-enable"
- (validate-gzip-encoding-when-gzip-requested body port))
-
- (testing "a gzipped response when a post request asks for a compressed one
- and the server not configured with a default for gzip-enable"
- (validate-gzip-encoding-when-gzip-requested-on-post-requests body port))
-
- (testing "an uncompressed response when request doesn't ask for a
- compressed one and server not configured with a default for
- gzip-enable"
- (validate-no-gzip-encoding-when-gzip-not-requested body port)))
-
- (with-test-webserver-and-config app port {:gzip-enable true}
- (testing "a gzipped response when request wants a compressed one and
- server configured with a true value for gzip-enable"
- (validate-gzip-encoding-when-gzip-requested body port))
-
- (testing "an uncompressed response when request doesn't ask for a
- compressed one and server configured with a true value for
- gzip-enable"
- (validate-no-gzip-encoding-when-gzip-not-requested body port)))
-
- (with-test-webserver-and-config app port {:gzip-enable false}
- (testing "an uncompressed response when request wants a compressed one
- but server configured with a false value for gzip-enable"
- (validate-no-gzip-encoding-even-though-gzip-requested body port))
-
- (testing "an uncompressed response when request doesn't ask for a
- compressed one and server configured with a false value for
- gzip-enable"
- (validate-no-gzip-encoding-when-gzip-not-requested body port)))
-
- (with-test-webserver-and-config
- app
- port {:gzip-enable true
- :access-log-config
- (str "./dev-resources/puppetlabs/trapperkeeper/services/webserver/"
- "request-logging.xml")}
- (testing "(TK-429) a gzipped response when request wants a compressed one
- and server configured with a true value for gzip-enable and an
- access-log-config"
- (validate-gzip-encoding-when-gzip-requested body port))))))
+ (with-test-logging
+ (testing "should return"
+ ;; Jetty may not Gzip encode a response body if the size of the response
+ ;; is less than 256 bytes, so returning a larger body to ensure that Gzip
+ ;; encoding is used where desired for these tests
+ (let [body (apply str (repeat 1000 "f"))
+ app (fn [req]
+ (-> body
+ (rr/response)
+ (rr/status 200)
+ (rr/content-type "text/plain")
+ (rr/charset "UTF-8")))]
+ (with-test-webserver app port
+ (testing "a gzipped response when request wants a compressed one and
+ server not configured with a default for gzip-enable"
+ (validate-gzip-encoding-when-gzip-requested body port))
+
+ (testing "a gzipped response when a post request asks for a compressed one
+ and the server not configured with a default for gzip-enable"
+ (validate-gzip-encoding-when-gzip-requested-on-post-requests body port))
+
+ (testing "an uncompressed response when request doesn't ask for a
+ compressed one and server not configured with a default for
+ gzip-enable"
+ (validate-no-gzip-encoding-when-gzip-not-requested body port)))
+
+ (with-test-webserver-and-config app port {:gzip-enable true}
+ (testing "a gzipped response when request wants a compressed one and
+ server configured with a true value for gzip-enable"
+ (validate-gzip-encoding-when-gzip-requested body port))
+
+ (testing "an uncompressed response when request doesn't ask for a
+ compressed one and server configured with a true value for
+ gzip-enable"
+ (validate-no-gzip-encoding-when-gzip-not-requested body port)))
+
+ (with-test-webserver-and-config app port {:gzip-enable false}
+ (testing "an uncompressed response when request wants a compressed one
+ but server configured with a false value for gzip-enable"
+ (validate-no-gzip-encoding-even-though-gzip-requested body port))
+
+ (testing "an uncompressed response when request doesn't ask for a
+ compressed one and server configured with a false value for
+ gzip-enable"
+ (validate-no-gzip-encoding-when-gzip-not-requested body port)))
+
+ (with-test-webserver-and-config
+ app
+ port {:gzip-enable true
+ :access-log-config
+ (str "./dev-resources/puppetlabs/trapperkeeper/services/webserver/"
+ "request-logging.xml")}
+ (testing "(TK-429) a gzipped response when request wants a compressed one
+ and server configured with a true value for gzip-enable and an
+ access-log-config"
+ (validate-gzip-encoding-when-gzip-requested body port)))))))
(deftest jmx
- (testing "by default Jetty JMX support is enabled"
- (with-test-webserver #() _
- (testing "and should return a valid Jetty MBeans object"
- (let [mbeans (jmx/mbean-names "org.eclipse.jetty.jmx:*")]
- (is (not (empty? mbeans)))))
-
- (testing "and should not return data when we query for something unexpected"
- (let [mbeans (jmx/mbean-names "foobarbaz:*")]
- (is (empty? mbeans))))))
-
- (testing "server starts up and shuts down cleanly when jmx is disabled"
- (let [config {:webserver {:port 9000
- :host "localhost"
- :jmx-enable "false"}}]
- (with-app-with-config app
- [jetty9-service]
- config))))
+ (with-test-logging
+ (testing "by default Jetty JMX support is enabled"
+ (with-test-webserver #() _
+ (testing "and should return a valid Jetty MBeans object"
+ (let [mbeans (jmx/mbean-names "org.eclipse.jetty.jmx:*")]
+ (is (not (empty? mbeans)))))
+
+ (testing "and should not return data when we query for something unexpected"
+ (let [mbeans (jmx/mbean-names "foobarbaz:*")]
+ (is (empty? mbeans))))))
+
+ (testing "server starts up and shuts down cleanly when jmx is disabled"
+ (let [config {:webserver {:port 9000
+ :host "localhost"
+ :jmx-enable "false"}}]
+ (with-app-with-config app
+ [jetty9-service]
+ config)))))
(deftest override-webserver-settings!-tests
(let [default-state {:mbean-container nil
@@ -304,151 +305,153 @@
{:max-threads 9042, :queue-max-size nil})))))
(deftest create-server-queue-max-size-test
- (let [get-queue-for-partial-http-config (fn [config]
- (get-server-thread-pool-queue
- (create-server-with-config
- (munge-http-connector-config
- config))))
- default-server-min-threads (.getMinThreads
- get-thread-pool-for-default-server)]
- (testing "default queue max size passed through to thread pool queue"
- (is (= (.getMaxCapacity (get-server-thread-pool-queue (Server.)))
- (.getMaxCapacity (get-queue-for-partial-http-config
- {:queue-max-size nil})))))
- (testing "custom default queue max size passed through to thread pool queue"
- (is (= 393
- (.getMaxCapacity (get-queue-for-partial-http-config
- {:queue-max-size 393})))))
- (testing (str "default max threads passed through to thread pool when "
- "queue-max-size set")
- (is (= default-server-max-threads
- (get-max-threads-for-partial-http-config
- {:max-threads nil, :queue-max-size 1}))))
- (testing "min threads passed through to thread pool when queue-max-size set"
- (is (= default-server-min-threads
- (.getMinThreads (get-thread-pool-for-partial-http-config
- {:queue-max-size 1})))))
- (testing "idle timeout passed through to thread pool when queue-max-size set"
- (is (= (.getIdleTimeout get-thread-pool-for-default-server)
- (.getIdleTimeout (get-thread-pool-for-partial-http-config
- {:queue-max-size 1})))))
- (testing (str "queue min size set on thread pool queue equal to min threads "
- "when queue max size greater than min threads")
- (is (= default-server-min-threads
- (.getCapacity (get-queue-for-partial-http-config
- {:queue-max-size
- (inc default-server-min-threads)})))))
- (testing (str "queue min size set on thread pool queue equal to queue max "
- "size when queue max size less than min threads")
- (let [queue-max-size (dec default-server-min-threads)]
- (is (= queue-max-size
+ (with-test-logging
+ (let [get-queue-for-partial-http-config (fn [config]
+ (get-server-thread-pool-queue
+ (create-server-with-config
+ (munge-http-connector-config
+ config))))
+ default-server-min-threads (.getMinThreads
+ get-thread-pool-for-default-server)]
+ (testing "default queue max size passed through to thread pool queue"
+ (is (= (.getMaxCapacity (get-server-thread-pool-queue (Server.)))
+ (.getMaxCapacity (get-queue-for-partial-http-config
+ {:queue-max-size nil})))))
+ (testing "custom default queue max size passed through to thread pool queue"
+ (is (= 393
+ (.getMaxCapacity (get-queue-for-partial-http-config
+ {:queue-max-size 393})))))
+ (testing (str "default max threads passed through to thread pool when "
+ "queue-max-size set")
+ (is (= default-server-max-threads
+ (get-max-threads-for-partial-http-config
+ {:max-threads nil, :queue-max-size 1}))))
+ (testing "min threads passed through to thread pool when queue-max-size set"
+ (is (= default-server-min-threads
+ (.getMinThreads (get-thread-pool-for-partial-http-config
+ {:queue-max-size 1})))))
+ (testing "idle timeout passed through to thread pool when queue-max-size set"
+ (is (= (.getIdleTimeout get-thread-pool-for-default-server)
+ (.getIdleTimeout (get-thread-pool-for-partial-http-config
+ {:queue-max-size 1})))))
+ (testing (str "queue min size set on thread pool queue equal to min threads "
+ "when queue max size greater than min threads")
+ (is (= default-server-min-threads
(.getCapacity (get-queue-for-partial-http-config
- {:queue-max-size queue-max-size}))))))))
+ {:queue-max-size
+ (inc default-server-min-threads)})))))
+ (testing (str "queue min size set on thread pool queue equal to queue max "
+ "size when queue max size less than min threads")
+ (let [queue-max-size (dec default-server-min-threads)]
+ (is (= queue-max-size
+ (.getCapacity (get-queue-for-partial-http-config
+ {:queue-max-size queue-max-size})))))))))
(deftest create-server-idle-timeout-test
- (testing "idle-timeout configured properly for http connector"
- (let [server (create-server-with-partial-http-config
- {:http {:idle-timeout-milliseconds 3000}})
- connectors (.getConnectors server)]
- (is (= 1 (count connectors))
- "Unexpected number of connectors for server")
- (is (= 3000 (.getIdleTimeout (first connectors)))
- "Unexpected idle time for connector")))
- (testing "idle-timeout configured properly for multiple connectors"
- (let [server (create-server-with-partial-http-and-https-config
- {:http {:port 25
- :idle-timeout-milliseconds 9001}
- :https {:port 92
- :idle-timeout-milliseconds 9002}})
- connectors (.getConnectors server)]
- (is (= 2 (count connectors))
- "Unexpected number of connectors for server")
- (is (= 25 (.getPort (first connectors)))
- "Unexpected port for first connector")
- (is (= 9001 (.getIdleTimeout (first connectors)))
- "Unexpected idle timeout for first connector")
- (is (= 92 (.getPort (second connectors)))
- "Unexpected port for second connector")
- (is (= 9002 (.getIdleTimeout (second connectors)))
- "Unexpected idle time for second connector"))))
+ (with-test-logging
+ (testing "idle-timeout configured properly for http connector"
+ (let [server (create-server-with-partial-http-config
+ {:http {:idle-timeout-milliseconds 3000}})
+ connectors (.getConnectors server)]
+ (is (= 1 (count connectors))
+ "Unexpected number of connectors for server")
+ (is (= 3000 (.getIdleTimeout (first connectors)))
+ "Unexpected idle time for connector")))
+ (testing "idle-timeout configured properly for multiple connectors"
+ (let [server (create-server-with-partial-http-and-https-config
+ {:http {:port 25
+ :idle-timeout-milliseconds 9001}
+ :https {:port 92
+ :idle-timeout-milliseconds 9002}})
+ connectors (.getConnectors server)]
+ (is (= 2 (count connectors))
+ "Unexpected number of connectors for server")
+ (is (= 25 (.getPort (first connectors)))
+ "Unexpected port for first connector")
+ (is (= 9001 (.getIdleTimeout (first connectors)))
+ "Unexpected idle timeout for first connector")
+ (is (= 92 (.getPort (second connectors)))
+ "Unexpected port for second connector")
+ (is (= 9002 (.getIdleTimeout (second connectors)))
+ "Unexpected idle time for second connector")))))
(deftest create-server-acceptor-threads-test
- (testing "nil acceptors configured properly for http connector"
- (let [server (create-server-with-partial-http-config
- {:http {:acceptor-threads nil}})
- connectors (.getConnectors server)]
- (is (= 1 (count connectors))
- "Unexpected number of connectors for server")
- (is (= (.getAcceptors (ServerConnector. (Server.)))
- (.getAcceptors (first connectors)))
- "Unexpected number of acceptor threads for connector")))
- (testing "non-nil acceptors configured properly for http connector"
- (let [server (tk-log-testutils/with-test-logging
- (create-server-with-partial-http-config
- {:http {:acceptor-threads 42}}))
- connectors (.getConnectors server)]
- (is (= 1 (count connectors))
- "Unexpected number of connectors for server")
- (is (= 42 (.getAcceptors (first connectors)))
- "Unexpected number of acceptor threads for connector")))
- (testing "non-nil acceptors configured properly for multiple connectors"
- (let [server (tk-log-testutils/with-test-logging
- (create-server-with-partial-http-and-https-config
- {:http {:port 25
- :acceptor-threads 91}
- :https {:port 92
- :acceptor-threads 63}}))
- connectors (.getConnectors server)]
- (is (= 2 (count connectors))
- "Unexpected number of connectors for server")
- (is (= 25 (.getPort (first connectors)))
- "Unexpected port for first connector")
- (is (= 91 (.getAcceptors (first connectors)))
- "Unexpected number of acceptor threads for first connector")
- (is (= 92 (.getPort (second connectors)))
- "Unexpected port for second connector")
- (is (= 63 (.getAcceptors (second connectors)))
- "Unexpected number of acceptor threads for second connector"))))
-
-(deftest create-server-selector-threads-test
- (letfn [(selector-threads [connector]
- (-> connector
- (.getSelectorManager)
- (.getSelectorCount)))]
- (testing "nil selectors configured properly for http connector"
+ (with-test-logging
+ (testing "nil acceptors configured properly for http connector"
(let [server (create-server-with-partial-http-config
- {:http {:selector-threads nil}})
+ {:http {:acceptor-threads nil}})
connectors (.getConnectors server)]
(is (= 1 (count connectors))
"Unexpected number of connectors for server")
- (is (= (selector-threads (ServerConnector. (Server.)))
- (selector-threads (first connectors)))
- "Unexpected number of selectors for connector")))
- (testing "non-nil selectors configured properly for http connector"
- (let [server (create-server-with-partial-http-config
- {:http {:selector-threads 42}})
+ (is (= (.getAcceptors (ServerConnector. (Server.)))
+ (.getAcceptors (first connectors)))
+ "Unexpected number of acceptor threads for connector")))
+ (testing "non-nil acceptors configured properly for http connector"
+ (let [server (create-server-with-partial-http-config
+ {:http {:acceptor-threads 42}})
connectors (.getConnectors server)]
(is (= 1 (count connectors))
"Unexpected number of connectors for server")
- (is (= 42 (selector-threads (first connectors)))
- "Unexpected number of selector threads for connector")))
- (testing "non-nil selectors configured properly for multiple connectors"
+ (is (= 42 (.getAcceptors (first connectors)))
+ "Unexpected number of acceptor threads for connector")))
+ (testing "non-nil acceptors configured properly for multiple connectors"
(let [server (create-server-with-partial-http-and-https-config
- {:http {:port 25
- :selector-threads 91}
- :https {:port 92
- :selector-threads 63}})
+ {:http {:port 25
+ :acceptor-threads 91}
+ :https {:port 92
+ :acceptor-threads 63}})
connectors (.getConnectors server)]
(is (= 2 (count connectors))
"Unexpected number of connectors for server")
(is (= 25 (.getPort (first connectors)))
"Unexpected port for first connector")
- (is (= 91 (selector-threads (first connectors)))
- "Unexpected number of selector threads for first connector")
+ (is (= 91 (.getAcceptors (first connectors)))
+ "Unexpected number of acceptor threads for first connector")
(is (= 92 (.getPort (second connectors)))
"Unexpected port for second connector")
- (is (= 63 (selector-threads (second connectors)))
- "Unexpected number of selector threads for second connector")))))
+ (is (= 63 (.getAcceptors (second connectors)))
+ "Unexpected number of acceptor threads for second connector")))))
+
+(deftest create-server-selector-threads-test
+ (with-test-logging
+ (letfn [(selector-threads [connector]
+ (-> connector
+ (.getSelectorManager)
+ (.getSelectorCount)))]
+ (testing "nil selectors configured properly for http connector"
+ (let [server (create-server-with-partial-http-config
+ {:http {:selector-threads nil}})
+ connectors (.getConnectors server)]
+ (is (= 1 (count connectors))
+ "Unexpected number of connectors for server")
+ (is (= (selector-threads (ServerConnector. (Server.)))
+ (selector-threads (first connectors)))
+ "Unexpected number of selectors for connector")))
+ (testing "non-nil selectors configured properly for http connector"
+ (let [server (create-server-with-partial-http-config
+ {:http {:selector-threads 42}})
+ connectors (.getConnectors server)]
+ (is (= 1 (count connectors))
+ "Unexpected number of connectors for server")
+ (is (= 42 (selector-threads (first connectors)))
+ "Unexpected number of selector threads for connector")))
+ (testing "non-nil selectors configured properly for multiple connectors"
+ (let [server (create-server-with-partial-http-and-https-config
+ {:http {:port 25
+ :selector-threads 91}
+ :https {:port 92
+ :selector-threads 63}})
+ connectors (.getConnectors server)]
+ (is (= 2 (count connectors))
+ "Unexpected number of connectors for server")
+ (is (= 25 (.getPort (first connectors)))
+ "Unexpected port for first connector")
+ (is (= 91 (selector-threads (first connectors)))
+ "Unexpected number of selector threads for first connector")
+ (is (= 92 (.getPort (second connectors)))
+ "Unexpected port for second connector")
+ (is (= 63 (selector-threads (second connectors)))
+ "Unexpected number of selector threads for second connector"))))))
(deftest test-idle-timeout
(let [read-lines (fn [r]
@@ -501,40 +504,41 @@
resp))))))))))
(deftest request-body-max-size
- (let [bigger-post-data (apply str (repeat 21 "f"))
- smaller-post-data (apply str (repeat 20 "f"))
- no-request-body-response "no request body"
- get-request (fn [port]
- (http-sync/get (format "http://localhost:%d/" port)
- {:as :text}))
- post-request (fn [port body]
- (http-sync/post (format "http://localhost:%d/" port)
- {:headers
- {"content-type" "text/plain"}
- :body body
- :as :text}))
- app (fn [req]
- (let [body (slurp (:body req))]
- (-> (if (empty? body)
- no-request-body-response
- body)
- (rr/response)
- (rr/status 200)
- (rr/content-type "text/plain")
- (rr/charset "UTF-8"))))]
- (with-test-webserver-and-config
- app
- port
- {:request-body-max-size 20}
- (testing "posting data larger than the configured limit fails with 413"
- (let [response (post-request port bigger-post-data)]
- (is (= 413 (:status response)))
- (is (= "" (:body response)))))
- (testing "posting data within the configured limit succeeds"
- (let [response (post-request port smaller-post-data)]
- (is (= 200 (:status response)))
- (is (= smaller-post-data (:body response)))))
- (testing "request with no content-length succeeds when limit configured"
- (let [response (get-request port)]
- (is (= 200 (:status response)))
- (is (= no-request-body-response (:body response))))))))
+ (with-test-logging
+ (let [bigger-post-data (apply str (repeat 21 "f"))
+ smaller-post-data (apply str (repeat 20 "f"))
+ no-request-body-response "no request body"
+ get-request (fn [port]
+ (http-sync/get (format "http://localhost:%d/" port)
+ {:as :text}))
+ post-request (fn [port body]
+ (http-sync/post (format "http://localhost:%d/" port)
+ {:headers
+ {"content-type" "text/plain"}
+ :body body
+ :as :text}))
+ app (fn [req]
+ (let [body (slurp (:body req))]
+ (-> (if (empty? body)
+ no-request-body-response
+ body)
+ (rr/response)
+ (rr/status 200)
+ (rr/content-type "text/plain")
+ (rr/charset "UTF-8"))))]
+ (with-test-webserver-and-config
+ app
+ port
+ {:request-body-max-size 20}
+ (testing "posting data larger than the configured limit fails with 413"
+ (let [response (post-request port bigger-post-data)]
+ (is (= 413 (:status response)))
+ (is (= "" (:body response)))))
+ (testing "posting data within the configured limit succeeds"
+ (let [response (post-request port smaller-post-data)]
+ (is (= 200 (:status response)))
+ (is (= smaller-post-data (:body response)))))
+ (testing "request with no content-length succeeds when limit configured"
+ (let [response (get-request port)]
+ (is (= 200 (:status response)))
+ (is (= no-request-body-response (:body response)))))))))
=====================================
test/clj/puppetlabs/trapperkeeper/services/webserver/jetty9_default_config_test.clj
=====================================
@@ -46,7 +46,7 @@ react accordingly."
[puppetlabs.trapperkeeper.services :refer [service-context]]
[puppetlabs.trapperkeeper.services.webserver.jetty9-core :as core]
[puppetlabs.trapperkeeper.testutils.webserver :as testutils]
- [puppetlabs.trapperkeeper.testutils.logging :as tk-log-testutils])
+ [puppetlabs.trapperkeeper.testutils.logging :refer [with-test-logging]])
(:import (org.eclipse.jetty.server HttpConfiguration ServerConnector Server)
(org.eclipse.jetty.util.thread QueuedThreadPool)))
@@ -61,32 +61,33 @@ react accordingly."
"Unexpected default for 'request-header-max-size'")))
(deftest default-proxy-http-client-settings-test
- (with-app-with-config app
- [jetty9-service]
- {:webserver {:host "localhost" :port 8080}}
- (let [s (get-service app :WebserverService)
- server-context (get-in (service-context s) [:jetty9-servers :default])
- proxy-servlet (core/proxy-servlet
- server-context
- {:host "localhost"
- :path "/foo"
- :port 8080}
- {})
- _ (core/add-servlet-handler
- server-context
- proxy-servlet
- "/proxy"
- {}
- true
- false)
- client (.createHttpClient proxy-servlet)]
- ;; See: https://github.com/eclipse/jetty.project/blob/jetty-9.4.1.v20170120/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java#L135
- (is (= 4096 (.getRequestBufferSize client))
- "Unexpected default for proxy 'request-buffer-size'")
- ;; See: https://github.com/eclipse/jetty.project/blob/jetty-9.4.1.v20170120/jetty-proxy/src/main/java/org/eclipse/jetty/proxy/AbstractProxyServlet.java#L304-L307
- (is (= 30000 (.getIdleTimeout client))
- "Unexpected default for proxy 'idle-timeout'")
- (.stop client))))
+ (with-test-logging
+ (with-app-with-config app
+ [jetty9-service]
+ {:webserver {:host "localhost" :port 8080}}
+ (let [s (get-service app :WebserverService)
+ server-context (get-in (service-context s) [:jetty9-servers :default])
+ proxy-servlet (core/proxy-servlet
+ server-context
+ {:host "localhost"
+ :path "/foo"
+ :port 8080}
+ {})
+ _ (core/add-servlet-handler
+ server-context
+ proxy-servlet
+ "/proxy"
+ {}
+ true
+ false)
+ client (.createHttpClient proxy-servlet)]
+ ;; See: https://github.com/eclipse/jetty.project/blob/jetty-9.4.1.v20170120/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java#L135
+ (is (= 4096 (.getRequestBufferSize client))
+ "Unexpected default for proxy 'request-buffer-size'")
+ ;; See: https://github.com/eclipse/jetty.project/blob/jetty-9.4.1.v20170120/jetty-proxy/src/main/java/org/eclipse/jetty/proxy/AbstractProxyServlet.java#L304-L307
+ (is (= 30000 (.getIdleTimeout client))
+ "Unexpected default for proxy 'idle-timeout'")
+ (.stop client)))))
(defn selector-thread-count
[max-threads]
=====================================
test/clj/puppetlabs/trapperkeeper/services/webserver/jetty9_service_handlers_test.clj
=====================================
@@ -22,342 +22,348 @@
testutils/assert-clean-shutdown)
(deftest static-content-test
- (testing "static content context"
- (with-app-with-config app
- [jetty9-service]
- jetty-plaintext-config
- (let [s (get-service app :WebserverService)
- add-context-handler (partial add-context-handler s)
- path "/resources"
- resource "logback.xml"]
- (add-context-handler dev-resources-dir path)
- (let [response (http-get (str "http://localhost:8080" path "/" resource))]
- (is (= (:status response) 200))
- (is (= (:body response) (slurp (str dev-resources-dir resource))))))))
+ (with-test-logging
+ (testing "static content context"
+ (with-app-with-config app
+ [jetty9-service]
+ jetty-plaintext-config
+ (let [s (get-service app :WebserverService)
+ add-context-handler (partial add-context-handler s)
+ path "/resources"
+ resource "logback.xml"]
+ (add-context-handler dev-resources-dir path)
+ (let [response (http-get (str "http://localhost:8080" path "/" resource))]
+ (is (= (:status response) 200))
+ (is (= (:body response) (slurp (str dev-resources-dir resource))))))))
- (testing "static content context with add-context-handler-to"
- (with-app-with-config app
- [jetty9-service]
- jetty-multiserver-plaintext-config
- (let [s (get-service app :WebserverService)
- add-context-handler (partial add-context-handler s)
- path "/resources"
- resource "logback.xml"]
- (add-context-handler dev-resources-dir path {:server-id :foo})
- (let [response (http-get (str "http://localhost:8085" path "/" resource))]
- (is (= (:status response) 200))
- (is (= (:body response) (slurp (str dev-resources-dir resource))))))))
+ (testing "static content context with add-context-handler-to"
+ (with-app-with-config app
+ [jetty9-service]
+ jetty-multiserver-plaintext-config
+ (let [s (get-service app :WebserverService)
+ add-context-handler (partial add-context-handler s)
+ path "/resources"
+ resource "logback.xml"]
+ (add-context-handler dev-resources-dir path {:server-id :foo})
+ (let [response (http-get (str "http://localhost:8085" path "/" resource))]
+ (is (= (:status response) 200))
+ (is (= (:body response) (slurp (str dev-resources-dir resource))))))))
- (testing "customization of static content context"
- (with-app-with-config app
- [jetty9-service]
- jetty-plaintext-config
- (let [s (get-service app :WebserverService)
- add-context-handler (partial add-context-handler s)
- path "/resources"
- body "Hey there"
- servlet-path "/hey"
- servlet (SimpleServlet. body)
- context-listeners [(reify ServletContextListener
- (contextInitialized [this event]
- (doto (.addServlet (.getServletContext event) "simple" servlet)
- (.addMapping (into-array [servlet-path]))))
- (contextDestroyed [this event]))]]
- (add-context-handler dev-resources-dir path {:context-listeners context-listeners})
- (let [response (http-get (str "http://localhost:8080" path servlet-path))]
- (is (= (:status response) 200))
- (is (= (:body response) body)))))))
+ (testing "customization of static content context"
+ (with-app-with-config app
+ [jetty9-service]
+ jetty-plaintext-config
+ (let [s (get-service app :WebserverService)
+ add-context-handler (partial add-context-handler s)
+ path "/resources"
+ body "Hey there"
+ servlet-path "/hey"
+ servlet (SimpleServlet. body)
+ context-listeners [(reify ServletContextListener
+ (contextInitialized [this event]
+ (doto (.addServlet (.getServletContext event) "simple" servlet)
+ (.addMapping (into-array [servlet-path]))))
+ (contextDestroyed [this event]))]]
+ (add-context-handler dev-resources-dir path {:context-listeners context-listeners})
+ (let [response (http-get (str "http://localhost:8080" path servlet-path))]
+ (is (= (:status response) 200))
+ (is (= (:body response) body))))))))
(deftest add-context-handler-symlinks-test
- (let [resource "logback.xml"
- resource-link "logback-link.xml"
- logback (slurp (str dev-resources-dir resource))
- link (Paths/get (str dev-resources-dir resource-link) (into-array java.lang.String []))
- file (Paths/get resource (into-array java.lang.String []))]
- (try
- (Files/createSymbolicLink link file (into-array FileAttribute []))
+ (with-test-logging
+ (let [resource "logback.xml"
+ resource-link "logback-link.xml"
+ logback (slurp (str dev-resources-dir resource))
+ link (Paths/get (str dev-resources-dir resource-link) (into-array java.lang.String []))
+ file (Paths/get resource (into-array java.lang.String []))]
+ (try
+ (Files/createSymbolicLink link file (into-array FileAttribute []))
- (testing "symlinks served when :follow-links is true"
- (with-app-with-config app
- [jetty9-service]
- jetty-plaintext-config
- (let [s (get-service app :WebserverService)
- add-context-handler (partial add-context-handler s)
- path "/resources"]
- (add-context-handler dev-resources-dir path {:follow-links true})
- (let [response (http-get (str "http://localhost:8080" path "/" resource))]
- (is (= (:status response) 200))
- (is (= (:body response) logback)))
- (let [response (http-get (str "http://localhost:8080" path "/" resource-link))]
- (is (= (:status response) 200))
- (is (= (:body response) logback))))))
+ (testing "symlinks served when :follow-links is true"
+ (with-app-with-config app
+ [jetty9-service]
+ jetty-plaintext-config
+ (let [s (get-service app :WebserverService)
+ add-context-handler (partial add-context-handler s)
+ path "/resources"]
+ (add-context-handler dev-resources-dir path {:follow-links true})
+ (let [response (http-get (str "http://localhost:8080" path "/" resource))]
+ (is (= (:status response) 200))
+ (is (= (:body response) logback)))
+ (let [response (http-get (str "http://localhost:8080" path "/" resource-link))]
+ (is (= (:status response) 200))
+ (is (= (:body response) logback))))))
- (testing "symlinks not served when :follow-links is false"
- (with-app-with-config app
- [jetty9-service]
- jetty-plaintext-config
- (let [s (get-service app :WebserverService)
- add-context-handler (partial add-context-handler s)
- path "/resources"]
- (add-context-handler dev-resources-dir path {:follow-links false})
- (let [response (http-get (str "http://localhost:8080" path "/" resource))]
- (is (= (:status response) 200))
- (is (= (:body response) logback)))
- (let [response (http-get (str "http://localhost:8080" path "/" resource-link))]
- (is (= (:status response) 404))))))
+ (testing "symlinks not served when :follow-links is false"
+ (with-app-with-config app
+ [jetty9-service]
+ jetty-plaintext-config
+ (let [s (get-service app :WebserverService)
+ add-context-handler (partial add-context-handler s)
+ path "/resources"]
+ (add-context-handler dev-resources-dir path {:follow-links false})
+ (let [response (http-get (str "http://localhost:8080" path "/" resource))]
+ (is (= (:status response) 200))
+ (is (= (:body response) logback)))
+ (let [response (http-get (str "http://localhost:8080" path "/" resource-link))]
+ (is (= (:status response) 404))))))
- (finally
- (Files/delete link)))))
+ (finally
+ (Files/delete link))))))
(deftest servlet-test
- (testing "request to servlet over http succeeds"
- (with-app-with-config app
- [jetty9-service]
- jetty-plaintext-config
- (let [s (get-service app :WebserverService)
- add-servlet-handler (partial add-servlet-handler s)
- body "Hey there"
- path "/hey"
- servlet (SimpleServlet. body)]
- (add-servlet-handler servlet path)
- (let [response (http-get
- (str "http://localhost:8080" path))]
- (is (= (:status response) 200))
- (is (= (:body response) body))))))
+ (with-test-logging
+ (testing "request to servlet over http succeeds"
+ (with-app-with-config app
+ [jetty9-service]
+ jetty-plaintext-config
+ (let [s (get-service app :WebserverService)
+ add-servlet-handler (partial add-servlet-handler s)
+ body "Hey there"
+ path "/hey"
+ servlet (SimpleServlet. body)]
+ (add-servlet-handler servlet path)
+ (let [response (http-get
+ (str "http://localhost:8080" path))]
+ (is (= (:status response) 200))
+ (is (= (:body response) body))))))
- (testing "request to servlet over http succeeds with add-servlet-handler-to"
- (with-app-with-config app
- [jetty9-service]
- jetty-multiserver-plaintext-config
- (let [s (get-service app :WebserverService)
- add-servlet-handler (partial add-servlet-handler s)
- body "Hey there"
- path "/hey"
- servlet (SimpleServlet. body)]
- (add-servlet-handler servlet path {:server-id :foo})
- (let [response (http-get
- (str "http://localhost:8085" path))]
- (is (= (:status response) 200))
- (is (= (:body response) body))))))
+ (testing "request to servlet over http succeeds with add-servlet-handler-to"
+ (with-app-with-config app
+ [jetty9-service]
+ jetty-multiserver-plaintext-config
+ (let [s (get-service app :WebserverService)
+ add-servlet-handler (partial add-servlet-handler s)
+ body "Hey there"
+ path "/hey"
+ servlet (SimpleServlet. body)]
+ (add-servlet-handler servlet path {:server-id :foo})
+ (let [response (http-get
+ (str "http://localhost:8085" path))]
+ (is (= (:status response) 200))
+ (is (= (:body response) body))))))
- (testing "request to servlet initialized with empty param succeeds"
- (with-app-with-config app
- [jetty9-service]
- jetty-plaintext-config
- (let [s (get-service app :WebserverService)
- add-servlet-handler (partial add-servlet-handler s)
- body "Hey there"
- path "/hey"
- servlet (SimpleServlet. body)]
- (add-servlet-handler servlet path {:servlet-init-params {}})
- (let [response (http-get (str "http://localhost:8080" path))]
- (is (= (:status response) 200))
- (is (= (:body response) body))))))
+ (testing "request to servlet initialized with empty param succeeds"
+ (with-app-with-config app
+ [jetty9-service]
+ jetty-plaintext-config
+ (let [s (get-service app :WebserverService)
+ add-servlet-handler (partial add-servlet-handler s)
+ body "Hey there"
+ path "/hey"
+ servlet (SimpleServlet. body)]
+ (add-servlet-handler servlet path {:servlet-init-params {}})
+ (let [response (http-get (str "http://localhost:8080" path))]
+ (is (= (:status response) 200))
+ (is (= (:body response) body))))))
- (testing "request to servlet initialized with non-empty params succeeds"
- (with-app-with-config app
- [jetty9-service]
- jetty-plaintext-config
- (let [s (get-service app :WebserverService)
- add-servlet-handler (partial add-servlet-handler s)
- body "Hey there"
- path "/hey"
- init-param-one "value of init param one"
- init-param-two "value of init param two"
- servlet (SimpleServlet. body)]
- (add-servlet-handler servlet
- path
- {:servlet-init-params {"init-param-one" init-param-one
- "init-param-two" init-param-two}})
- (let [response (http-get
- (str "http://localhost:8080" path "/init-param-one"))]
- (is (= (:status response) 200))
- (is (= (:body response) init-param-one)))
- (let [response (http-get
- (str "http://localhost:8080" path "/init-param-two"))]
- (is (= (:status response) 200))
- (is (= (:body response) init-param-two)))))))
+ (testing "request to servlet initialized with non-empty params succeeds"
+ (with-app-with-config app
+ [jetty9-service]
+ jetty-plaintext-config
+ (let [s (get-service app :WebserverService)
+ add-servlet-handler (partial add-servlet-handler s)
+ body "Hey there"
+ path "/hey"
+ init-param-one "value of init param one"
+ init-param-two "value of init param two"
+ servlet (SimpleServlet. body)]
+ (add-servlet-handler servlet
+ path
+ {:servlet-init-params {"init-param-one" init-param-one
+ "init-param-two" init-param-two}})
+ (let [response (http-get
+ (str "http://localhost:8080" path "/init-param-one"))]
+ (is (= (:status response) 200))
+ (is (= (:body response) init-param-one)))
+ (let [response (http-get
+ (str "http://localhost:8080" path "/init-param-two"))]
+ (is (= (:status response) 200))
+ (is (= (:body response) init-param-two))))))))
(deftest websocket-test
- (testing "Websocket handlers"
- (with-app-with-config app
- [jetty9-service]
- jetty-plaintext-config
- (let [s (get-service app :WebserverService)
- add-websocket-handler (partial add-websocket-handler s)
- path "/test"
- connected (atom 0)
- server-messages (atom [])
- server-binary-messages (atom [])
- client-messages (atom [])
- client-binary-messages (atom [])
- client-request-path (atom "")
- client-remote-addr (atom "")
- client-is-ssl (atom nil)
- closed-request-path (atom "")
- binary-client-message (promise)
- closed (promise)
- handlers {:on-connect (fn [ws]
- (ws-session/send! ws "Hello client!")
- (swap! connected inc)
- (reset! client-request-path (ws-session/request-path ws))
- (reset! client-remote-addr (.. (ws-session/remote-addr ws) (toString)))
- (reset! client-is-ssl (ws-session/ssl? ws)))
- :on-text (fn [ws text]
- (ws-session/send! ws (str "You said: " text))
- (swap! server-messages conj text))
- :on-bytes (fn [ws bytes offset len]
- (let [as-vec (vec bytes)]
- (ws-session/send! ws (byte-array (reverse as-vec)))
- (swap! server-binary-messages conj as-vec)))
- :on-error (fn [ws error]) ;; TODO - Add test for on-error behaviour
- :on-close (fn [ws code reason] (swap! connected dec)
- (reset! closed-request-path (ws-session/request-path ws))
- (deliver closed true))}]
- (add-websocket-handler handlers path)
- (let [socket (ws-client/connect (str "ws://localhost:8080" path "/foo")
- :on-receive (fn [text] (swap! client-messages conj text))
- :on-binary (fn [bytes offset len]
- (let [as-vec (vec bytes)]
- (swap! client-binary-messages conj as-vec)
- (deliver binary-client-message true))))]
- (ws-client/send-msg socket "Hello websocket handler")
- (ws-client/send-msg socket "You look dandy")
- (ws-client/send-msg socket (byte-array [2 1 2 3 3]))
- (deref binary-client-message)
- (is (= @connected 1))
- (is (= @client-request-path "/foo"))
- (is (re-matches #"/127\.0\.0\.1:\d+" @client-remote-addr))
- (is (= @client-is-ssl false))
- (ws-client/close socket)
- (deref closed)
- (is (= @closed-request-path "/foo"))
- (is (= @connected 0))
- (is (= @server-binary-messages [[2 1 2 3 3]]))
- (is (= @client-binary-messages [[3 3 2 1 2]]))
- (is (= @client-messages ["Hello client!"
- "You said: Hello websocket handler"
- "You said: You look dandy"]))
- (is (= @server-messages ["Hello websocket handler"
- "You look dandy"]))))))
- (testing "can close without supplying a reason"
- (with-app-with-config app
- [jetty9-service]
- jetty-plaintext-config
- (let [s (get-service app :WebserverService)
- add-websocket-handler (partial add-websocket-handler s)
- path "/test"
- closed (promise)
- handlers {:on-connect (fn [ws] (ws-session/close! ws))}]
- (add-websocket-handler handlers path)
- (let [socket (ws-client/connect (str "ws://localhost:8080" path)
- :on-close (fn [code reason] (deliver closed code)))]
- ;; 1000 is for normal closure https://tools.ietf.org/html/rfc6455#section-7.4.1
- (is (= 1000 @closed))))))
- (testing "can close with reason"
- (with-app-with-config app
- [jetty9-service]
- jetty-plaintext-config
- (let [s (get-service app :WebserverService)
- add-websocket-handler (partial add-websocket-handler s)
- path "/test"
- closed (promise)
- handlers {:on-connect (fn [ws] (ws-session/close! ws 4000 "Bye"))}]
- (add-websocket-handler handlers path)
- (let [socket (ws-client/connect (str "ws://localhost:8080" path)
- :on-close (fn [code reason] (deliver closed [code reason])))]
- (is (= [4000 "Bye"] @closed)))))))
+ (with-test-logging
+ (testing "Websocket handlers"
+ (with-app-with-config app
+ [jetty9-service]
+ jetty-plaintext-config
+ (let [s (get-service app :WebserverService)
+ add-websocket-handler (partial add-websocket-handler s)
+ path "/test"
+ connected (atom 0)
+ server-messages (atom [])
+ server-binary-messages (atom [])
+ client-messages (atom [])
+ client-binary-messages (atom [])
+ client-request-path (atom "")
+ client-remote-addr (atom "")
+ client-is-ssl (atom nil)
+ closed-request-path (atom "")
+ binary-client-message (promise)
+ closed (promise)
+ handlers {:on-connect (fn [ws]
+ (ws-session/send! ws "Hello client!")
+ (swap! connected inc)
+ (reset! client-request-path (ws-session/request-path ws))
+ (reset! client-remote-addr (.. (ws-session/remote-addr ws) (toString)))
+ (reset! client-is-ssl (ws-session/ssl? ws)))
+ :on-text (fn [ws text]
+ (ws-session/send! ws (str "You said: " text))
+ (swap! server-messages conj text))
+ :on-bytes (fn [ws bytes offset len]
+ (let [as-vec (vec bytes)]
+ (ws-session/send! ws (byte-array (reverse as-vec)))
+ (swap! server-binary-messages conj as-vec)))
+ :on-error (fn [ws error]) ;; TODO - Add test for on-error behaviour
+ :on-close (fn [ws code reason] (swap! connected dec)
+ (reset! closed-request-path (ws-session/request-path ws))
+ (deliver closed true))}]
+ (add-websocket-handler handlers path)
+ (let [socket (ws-client/connect (str "ws://localhost:8080" path "/foo")
+ :on-receive (fn [text] (swap! client-messages conj text))
+ :on-binary (fn [bytes offset len]
+ (let [as-vec (vec bytes)]
+ (swap! client-binary-messages conj as-vec)
+ (deliver binary-client-message true))))]
+ (ws-client/send-msg socket "Hello websocket handler")
+ (ws-client/send-msg socket "You look dandy")
+ (ws-client/send-msg socket (byte-array [2 1 2 3 3]))
+ (deref binary-client-message)
+ (is (= @connected 1))
+ (is (= @client-request-path "/foo"))
+ (is (re-matches #"/127\.0\.0\.1:\d+" @client-remote-addr))
+ (is (= @client-is-ssl false))
+ (ws-client/close socket)
+ (deref closed)
+ (is (= @closed-request-path "/foo"))
+ (is (= @connected 0))
+ (is (= @server-binary-messages [[2 1 2 3 3]]))
+ (is (= @client-binary-messages [[3 3 2 1 2]]))
+ (is (= @client-messages ["Hello client!"
+ "You said: Hello websocket handler"
+ "You said: You look dandy"]))
+ (is (= @server-messages ["Hello websocket handler"
+ "You look dandy"]))))))
+ (testing "can close without supplying a reason"
+ (with-app-with-config app
+ [jetty9-service]
+ jetty-plaintext-config
+ (let [s (get-service app :WebserverService)
+ add-websocket-handler (partial add-websocket-handler s)
+ path "/test"
+ closed (promise)
+ handlers {:on-connect (fn [ws] (ws-session/close! ws))}]
+ (add-websocket-handler handlers path)
+ (let [socket (ws-client/connect (str "ws://localhost:8080" path)
+ :on-close (fn [code reason] (deliver closed code)))]
+ ;; 1000 is for normal closure https://tools.ietf.org/html/rfc6455#section-7.4.1
+ (is (= 1000 @closed))))))
+ (testing "can close with reason"
+ (with-app-with-config app
+ [jetty9-service]
+ jetty-plaintext-config
+ (let [s (get-service app :WebserverService)
+ add-websocket-handler (partial add-websocket-handler s)
+ path "/test"
+ closed (promise)
+ handlers {:on-connect (fn [ws] (ws-session/close! ws 4000 "Bye"))}]
+ (add-websocket-handler handlers path)
+ (let [socket (ws-client/connect (str "ws://localhost:8080" path)
+ :on-close (fn [code reason] (deliver closed [code reason])))]
+ (is (= [4000 "Bye"] @closed))))))))
(deftest war-test
- (testing "WAR support"
- (with-app-with-config app
- [jetty9-service]
- jetty-plaintext-config
- (let [s (get-service app :WebserverService)
- add-war-handler (partial add-war-handler s)
- path "/test"
- war "helloWorld.war"]
- (add-war-handler (str dev-resources-dir war) path)
- (let [response (http-get (str "http://localhost:8080" path "/hello"))]
- (is (= (:status response) 200))
- (is (= (:body response)
- "<html>\n<head><title>Hello World Servlet</title></head>\n<body>Hello World!!</body>\n</html>\n"))))))
+ (with-test-logging
+ (testing "WAR support"
+ (with-app-with-config app
+ [jetty9-service]
+ jetty-plaintext-config
+ (let [s (get-service app :WebserverService)
+ add-war-handler (partial add-war-handler s)
+ path "/test"
+ war "helloWorld.war"]
+ (add-war-handler (str dev-resources-dir war) path)
+ (let [response (http-get (str "http://localhost:8080" path "/hello"))]
+ (is (= (:status response) 200))
+ (is (= (:body response)
+ "<html>\n<head><title>Hello World Servlet</title></head>\n<body>Hello World!!</body>\n</html>\n"))))))
- (testing "WAR support with add-war-handler-to"
- (with-app-with-config app
- [jetty9-service]
- jetty-multiserver-plaintext-config
- (let [s (get-service app :WebserverService)
- add-war-handler (partial add-war-handler s)
- path "/test"
- war "helloWorld.war"]
- (add-war-handler (str dev-resources-dir war) path {:server-id :foo})
- (let [response (http-get (str "http://localhost:8085" path "/hello"))]
- (is (= (:status response) 200))
- (is (= (:body response)
- "<html>\n<head><title>Hello World Servlet</title></head>\n<body>Hello World!!</body>\n</html>\n")))))))
+ (testing "WAR support with add-war-handler-to"
+ (with-app-with-config app
+ [jetty9-service]
+ jetty-multiserver-plaintext-config
+ (let [s (get-service app :WebserverService)
+ add-war-handler (partial add-war-handler s)
+ path "/test"
+ war "helloWorld.war"]
+ (add-war-handler (str dev-resources-dir war) path {:server-id :foo})
+ (let [response (http-get (str "http://localhost:8085" path "/hello"))]
+ (is (= (:status response) 200))
+ (is (= (:body response)
+ "<html>\n<head><title>Hello World Servlet</title></head>\n<body>Hello World!!</body>\n</html>\n"))))))))
(deftest endpoints-test
(testing "Retrieve all endpoints"
- (with-app-with-config app
- [jetty9-service]
- jetty-plaintext-config
- (let [s (get-service app :WebserverService)
- path-context "/ernie"
- path-context2 "/gonzo"
- path-context3 "/goblinking"
- path-ring "/bert"
- path-servlet "/foo"
- path-war "/bar"
- path-proxy "/baz"
- path-websocket "/quux"
- get-registered-endpoints (partial get-registered-endpoints s)
- add-context-handler (partial add-context-handler s)
- add-ring-handler (partial add-ring-handler s)
- add-servlet-handler (partial add-servlet-handler s)
- add-war-handler (partial add-war-handler s)
- add-proxy-route (partial add-proxy-route s)
- add-websocket-handler (partial add-websocket-handler s)
- ring-handler (fn [req] {:status 200 :body "Hi world"})
- body "This is a test"
- servlet (SimpleServlet. body)
- context-listeners [(reify ServletContextListener
- (contextInitialized [this event]
- (doto (.addServlet (.getServletContext event) "simple" servlet)
- (.addMapping (into-array [path-servlet]))))
- (contextDestroyed [this event]))]
- war "helloWorld.war"
- websocket-handlers {:on-connect (fn [ws])}
- target {:host "0.0.0.0"
- :port 9000
- :path "/ernie"}
- target2 {:host "localhost"
- :port 10000
- :path "/kermit"}]
- (add-context-handler dev-resources-dir path-context)
- (add-context-handler dev-resources-dir path-context2 {:context-listeners []})
- (add-context-handler dev-resources-dir path-context3 {:context-listeners context-listeners})
- (add-ring-handler ring-handler path-ring)
- (add-servlet-handler servlet path-servlet)
- (add-war-handler (str dev-resources-dir war) path-war)
- (add-proxy-route target path-proxy)
- (add-proxy-route target2 path-proxy {})
- (add-websocket-handler websocket-handlers path-websocket)
- (let [endpoints (get-registered-endpoints)]
- (is (= endpoints {"/ernie" [{:type :context :base-path dev-resources-dir
- :context-listeners []}]
- "/gonzo" [{:type :context :base-path dev-resources-dir
- :context-listeners []}]
- "/goblinking" [{:type :context :base-path dev-resources-dir
- :context-listeners context-listeners}]
- "/bert" [{:type :ring}]
- "/foo" [{:type :servlet :servlet (type servlet)}]
- "/bar" [{:type :war :war-path (str dev-resources-dir war)}]
- "/baz" [{:type :proxy :target-host "0.0.0.0" :target-port 9000
- :target-path "/ernie"}
- {:type :proxy :target-host "localhost" :target-port 10000
- :target-path "/kermit"}]
- "/quux" [{:type :websocket}]}))))))
+ (with-test-logging
+ (with-app-with-config app
+ [jetty9-service]
+ jetty-plaintext-config
+ (let [s (get-service app :WebserverService)
+ path-context "/ernie"
+ path-context2 "/gonzo"
+ path-context3 "/goblinking"
+ path-ring "/bert"
+ path-servlet "/foo"
+ path-war "/bar"
+ path-proxy "/baz"
+ path-websocket "/quux"
+ get-registered-endpoints (partial get-registered-endpoints s)
+ add-context-handler (partial add-context-handler s)
+ add-ring-handler (partial add-ring-handler s)
+ add-servlet-handler (partial add-servlet-handler s)
+ add-war-handler (partial add-war-handler s)
+ add-proxy-route (partial add-proxy-route s)
+ add-websocket-handler (partial add-websocket-handler s)
+ ring-handler (fn [req] {:status 200 :body "Hi world"})
+ body "This is a test"
+ servlet (SimpleServlet. body)
+ context-listeners [(reify ServletContextListener
+ (contextInitialized [this event]
+ (doto (.addServlet (.getServletContext event) "simple" servlet)
+ (.addMapping (into-array [path-servlet]))))
+ (contextDestroyed [this event]))]
+ war "helloWorld.war"
+ websocket-handlers {:on-connect (fn [ws])}
+ target {:host "0.0.0.0"
+ :port 9000
+ :path "/ernie"}
+ target2 {:host "localhost"
+ :port 10000
+ :path "/kermit"}]
+ (add-context-handler dev-resources-dir path-context)
+ (add-context-handler dev-resources-dir path-context2 {:context-listeners []})
+ (add-context-handler dev-resources-dir path-context3 {:context-listeners context-listeners})
+ (add-ring-handler ring-handler path-ring)
+ (add-servlet-handler servlet path-servlet)
+ (add-war-handler (str dev-resources-dir war) path-war)
+ (add-proxy-route target path-proxy)
+ (add-proxy-route target2 path-proxy {})
+ (add-websocket-handler websocket-handlers path-websocket)
+ (let [endpoints (get-registered-endpoints)]
+ (is (= endpoints {"/ernie" [{:type :context :base-path dev-resources-dir
+ :context-listeners []}]
+ "/gonzo" [{:type :context :base-path dev-resources-dir
+ :context-listeners []}]
+ "/goblinking" [{:type :context :base-path dev-resources-dir
+ :context-listeners context-listeners}]
+ "/bert" [{:type :ring}]
+ "/foo" [{:type :servlet :servlet (type servlet)}]
+ "/bar" [{:type :war :war-path (str dev-resources-dir war)}]
+ "/baz" [{:type :proxy :target-host "0.0.0.0" :target-port 9000
+ :target-path "/ernie"}
+ {:type :proxy :target-host "localhost" :target-port 10000
+ :target-path "/kermit"}]
+ "/quux" [{:type :websocket}]})))))))
(testing "Log endpoints"
(with-test-logging
@@ -375,96 +381,99 @@
(is (logged? #"^\{\"\/bert\" \[\{:type :ring\}\]\}$" :info)))))))
(deftest trailing-slash-redirect-test
- (testing "redirects when no trailing slash is present are disabled by default"
- (with-app-with-config app
- [jetty9-service]
- jetty-plaintext-config
- (let [s (get-service app :WebserverService)
- add-ring-handler (partial add-ring-handler s)
- ring-handler (fn [req] {:status 200 :body "Hi world"})
- path "/hello"]
- (add-ring-handler ring-handler path)
- (let [response (http-get "http://localhost:8080/hello" {:as :text
- :follow-redirects false})]
- (is (= (:status response) 200))
- (is (= (:body response) "Hi world"))
- (is (= (get-in response [:opts :url]) "http://localhost:8080/hello"))))))
+ (with-test-logging
+ (testing "redirects when no trailing slash is present are disabled by default"
+ (with-app-with-config app
+ [jetty9-service]
+ jetty-plaintext-config
+ (let [s (get-service app :WebserverService)
+ add-ring-handler (partial add-ring-handler s)
+ ring-handler (fn [req] {:status 200 :body "Hi world"})
+ path "/hello"]
+ (add-ring-handler ring-handler path)
+ (let [response (http-get "http://localhost:8080/hello" {:as :text
+ :follow-redirects false})]
+ (is (= (:status response) 200))
+ (is (= (:body response) "Hi world"))
+ (is (= (get-in response [:opts :url]) "http://localhost:8080/hello"))))))
- (testing "redirects when no trailing slash is present and option is enabled"
- (with-app-with-config app
- [jetty9-service]
- jetty-plaintext-config
- (let [s (get-service app :WebserverService)
- add-ring-handler (partial add-ring-handler s)
- ring-handler (fn [req] {:status 200 :body "Hi world"})
- path "/hello"]
- (add-ring-handler ring-handler path {:redirect-if-no-trailing-slash true})
- (let [response (http-get "http://localhost:8080/hello" {:as :text
- :follow-redirects false})]
- (is (= (:status response) 302))
- (is (= (get-in response [:headers "location"]) "http://localhost:8080/hello/"))
- (is (= (get-in response [:opts :url]) "http://localhost:8080/hello")))))))
+ (testing "redirects when no trailing slash is present and option is enabled"
+ (with-app-with-config app
+ [jetty9-service]
+ jetty-plaintext-config
+ (let [s (get-service app :WebserverService)
+ add-ring-handler (partial add-ring-handler s)
+ ring-handler (fn [req] {:status 200 :body "Hi world"})
+ path "/hello"]
+ (add-ring-handler ring-handler path {:redirect-if-no-trailing-slash true})
+ (let [response (http-get "http://localhost:8080/hello" {:as :text
+ :follow-redirects false})]
+ (is (= (:status response) 302))
+ (is (= (get-in response [:headers "location"]) "http://localhost:8080/hello/"))
+ (is (= (get-in response [:opts :url]) "http://localhost:8080/hello"))))))))
(defn ring-handler-echoing-request-uri
[]
(fn [req] {:status 200 :body (:uri req)}))
(deftest normalize-request-uri-enabled-for-ring-handler-test
- (testing "when uri request normalization enabled for ring handler"
- (with-app-with-config
- app
- [jetty9-service]
- jetty-plaintext-config
- (let [webserver-service (get-service app :WebserverService)]
- (add-ring-handler webserver-service
- (ring-handler-echoing-request-uri)
- "/hello"
- {:normalize-request-uri true})
- (testing "uri with encoded characters is properly decoded"
- (let [response (http-get "http://localhost:8080/hello%2f%2f%77o%72l%64"
- {:as :text})]
- (is (= (:status response) 200))
- (is (= (:body response) "/hello/world"))))
- (testing "uri with relative path above root is rejected"
- (let [response
- (http-get
- "http://localhost:8080/hello/world/%2E%2E/%2E%2E/%2E%2E/cleveland"
- {:as :text})]
- (is (= (:status response) 400))))
- (testing "uri with relative path below root is rejected"
- (let [response (http-get
- "http://localhost:8080/hello/world/%2E%2E/cleveland"
- {:as :text})]
- (is (= (:status response) 400))))))))
+ (with-test-logging
+ (testing "when uri request normalization enabled for ring handler"
+ (with-app-with-config
+ app
+ [jetty9-service]
+ jetty-plaintext-config
+ (let [webserver-service (get-service app :WebserverService)]
+ (add-ring-handler webserver-service
+ (ring-handler-echoing-request-uri)
+ "/hello"
+ {:normalize-request-uri true})
+ (testing "uri with encoded characters is properly decoded"
+ (let [response (http-get "http://localhost:8080/hello%2f%2f%77o%72l%64"
+ {:as :text})]
+ (is (= (:status response) 200))
+ (is (= (:body response) "/hello/world"))))
+ (testing "uri with relative path above root is rejected"
+ (let [response
+ (http-get
+ "http://localhost:8080/hello/world/%2E%2E/%2E%2E/%2E%2E/cleveland"
+ {:as :text})]
+ (is (= (:status response) 400))))
+ (testing "uri with relative path below root is rejected"
+ (let [response (http-get
+ "http://localhost:8080/hello/world/%2E%2E/cleveland"
+ {:as :text})]
+ (is (= (:status response) 400)))))))))
(deftest normalize-request-uri-disabled-for-ring-handler-test
- (testing "when uri request normalization disabled for ring handler"
- (with-app-with-config
- app
- [jetty9-service]
- jetty-plaintext-config
- (let [webserver-service (get-service app :WebserverService)]
- (add-ring-handler webserver-service
- (ring-handler-echoing-request-uri)
- "/hello"
- {:normalize-request-uri false})
- (testing "uri with encoded characters is properly decoded"
- (let [response (http-get "http://localhost:8080/hello%2f%2f%77o%72l%64"
- {:as :text})]
- (is (= (:status response) 200))
- (is (= (:body response) "/hello%2f%2f%77o%72l%64"))))
- (testing "uri with relative path above root is rejected"
- (let [response
- (http-get
- "http://localhost:8080/hello/world/%2E%2E/%2E%2E/%2E%2E/cleveland"
- {:as :text})]
- (is (= (:status response) 400))))
- (testing "uri with relative path below root is resolved"
- (let [response (http-get
- "http://localhost:8080/hello/world/%2E%2E/cleveland"
- {:as :text})]
- (is (= (:status response) 200))
- (is (= (:body response) "/hello/world/%2E%2E/cleveland"))))))))
+ (with-test-logging
+ (testing "when uri request normalization disabled for ring handler"
+ (with-app-with-config
+ app
+ [jetty9-service]
+ jetty-plaintext-config
+ (let [webserver-service (get-service app :WebserverService)]
+ (add-ring-handler webserver-service
+ (ring-handler-echoing-request-uri)
+ "/hello"
+ {:normalize-request-uri false})
+ (testing "uri with encoded characters is properly decoded"
+ (let [response (http-get "http://localhost:8080/hello%2f%2f%77o%72l%64"
+ {:as :text})]
+ (is (= (:status response) 200))
+ (is (= (:body response) "/hello%2f%2f%77o%72l%64"))))
+ (testing "uri with relative path above root is rejected"
+ (let [response
+ (http-get
+ "http://localhost:8080/hello/world/%2E%2E/%2E%2E/%2E%2E/cleveland"
+ {:as :text})]
+ (is (= (:status response) 400))))
+ (testing "uri with relative path below root is resolved"
+ (let [response (http-get
+ "http://localhost:8080/hello/world/%2E%2E/cleveland"
+ {:as :text})]
+ (is (= (:status response) 200))
+ (is (= (:body response) "/hello/world/%2E%2E/cleveland")))))))))
(defn servlet-echoing-request-uri
[]
@@ -477,60 +486,62 @@
(.setStatus response 200))))
(deftest normalize-request-uri-enabled-for-servlet-test
- (testing "when uri request normalization enabled for servlet"
- (with-app-with-config
- app
- [jetty9-service]
- jetty-plaintext-config
- (let [webserver-service (get-service app :WebserverService)]
- (add-servlet-handler
- webserver-service
- (servlet-echoing-request-uri)
- "/hello"
- {:normalize-request-uri true})
- (testing "uri with encoded characters is properly decoded"
- (let [response (http-get "http://localhost:8080/hello%2f%2f%77o%72l%64"
- {:as :text})]
- (is (= (:status response) 200))
- (is (= (:body response) "/hello/world"))))
- (testing "uri with relative path above root is rejected"
- (let [response
- (http-get
- "http://localhost:8080/hello/world/%2E%2E/%2E%2E/%2E%2E/cleveland"
- {:as :text})]
- (is (= (:status response) 400))))
- (testing "uri with relative path below root is rejected"
- (let [response (http-get
- "http://localhost:8080/hello/world/%2E%2E/cleveland"
- {:as :text})]
- (is (= (:status response) 400))))))))
+ (with-test-logging
+ (testing "when uri request normalization enabled for servlet"
+ (with-app-with-config
+ app
+ [jetty9-service]
+ jetty-plaintext-config
+ (let [webserver-service (get-service app :WebserverService)]
+ (add-servlet-handler
+ webserver-service
+ (servlet-echoing-request-uri)
+ "/hello"
+ {:normalize-request-uri true})
+ (testing "uri with encoded characters is properly decoded"
+ (let [response (http-get "http://localhost:8080/hello%2f%2f%77o%72l%64"
+ {:as :text})]
+ (is (= (:status response) 200))
+ (is (= (:body response) "/hello/world"))))
+ (testing "uri with relative path above root is rejected"
+ (let [response
+ (http-get
+ "http://localhost:8080/hello/world/%2E%2E/%2E%2E/%2E%2E/cleveland"
+ {:as :text})]
+ (is (= (:status response) 400))))
+ (testing "uri with relative path below root is rejected"
+ (let [response (http-get
+ "http://localhost:8080/hello/world/%2E%2E/cleveland"
+ {:as :text})]
+ (is (= (:status response) 400)))))))))
(deftest normalize-request-uri-disabled-for-servlet-test
- (testing "when uri request normalization disabled for servlet"
- (with-app-with-config
- app
- [jetty9-service]
- jetty-plaintext-config
- (let [webserver-service (get-service app :WebserverService)]
- (add-servlet-handler
- webserver-service
- (servlet-echoing-request-uri)
- "/hello"
- {:normalize-request-uri false})
- (testing "uri with encoded characters is not decoded"
- (let [response (http-get "http://localhost:8080/hello%2f%2f%77o%72l%64"
- {:as :text})]
- (is (= (:status response) 200))
- (is (= (:body response) "/hello%2f%2f%77o%72l%64"))))
- (testing "uri with relative path above root is rejected"
- (let [response
- (http-get
- "http://localhost:8080/hello/world/%2E%2E/%2E%2E/%2E%2E/cleveland"
- {:as :text})]
- (is (= (:status response) 400))))
- (testing "uri with relative path below root is resolved"
- (let [response (http-get
- "http://localhost:8080/hello/world/%2E%2E/cleveland"
- {:as :text})]
- (is (= (:status response) 200))
- (is (= (:body response) "/hello/world/%2E%2E/cleveland"))))))))
+ (with-test-logging
+ (testing "when uri request normalization disabled for servlet"
+ (with-app-with-config
+ app
+ [jetty9-service]
+ jetty-plaintext-config
+ (let [webserver-service (get-service app :WebserverService)]
+ (add-servlet-handler
+ webserver-service
+ (servlet-echoing-request-uri)
+ "/hello"
+ {:normalize-request-uri false})
+ (testing "uri with encoded characters is not decoded"
+ (let [response (http-get "http://localhost:8080/hello%2f%2f%77o%72l%64"
+ {:as :text})]
+ (is (= (:status response) 200))
+ (is (= (:body response) "/hello%2f%2f%77o%72l%64"))))
+ (testing "uri with relative path above root is rejected"
+ (let [response
+ (http-get
+ "http://localhost:8080/hello/world/%2E%2E/%2E%2E/%2E%2E/cleveland"
+ {:as :text})]
+ (is (= (:status response) 400))))
+ (testing "uri with relative path below root is resolved"
+ (let [response (http-get
+ "http://localhost:8080/hello/world/%2E%2E/cleveland"
+ {:as :text})]
+ (is (= (:status response) 200))
+ (is (= (:body response) "/hello/world/%2E%2E/cleveland")))))))))
=====================================
test/clj/puppetlabs/trapperkeeper/services/webserver/jetty9_service_override_settings_test.clj
=====================================
@@ -153,40 +153,42 @@
(override-webserver-settings!
overrides))
context))]
- (with-app-with-config
- app
- [jetty9-service service1]
- jetty-ssl-no-certs-config
- (let [s (get-service app :WebserverService)
- add-ring-handler (partial add-ring-handler s)
- body "Hi World"
- path "/hi_world"
- ring-handler (fn [req] {:status 200 :body body})]
- (add-ring-handler ring-handler path)
- (let [response (http-get
- (format "https://localhost:%d%s/" ssl-port path)
- default-options-for-https-client)]
- (is (= (:status response) 200)
- "Unsuccessful http response code ring handler response.")
- (is (= (:body response) body)
- "Unexpected body in ring handler response."))))
- (is (= overrides @override-result)
- "Unexpected response to override-webserver-settings! call.")))
+ (with-test-logging
+ (with-app-with-config
+ app
+ [jetty9-service service1]
+ jetty-ssl-no-certs-config
+ (let [s (get-service app :WebserverService)
+ add-ring-handler (partial add-ring-handler s)
+ body "Hi World"
+ path "/hi_world"
+ ring-handler (fn [req] {:status 200 :body body})]
+ (add-ring-handler ring-handler path)
+ (let [response (http-get
+ (format "https://localhost:%d%s/" ssl-port path)
+ default-options-for-https-client)]
+ (is (= (:status response) 200)
+ "Unsuccessful http response code ring handler response.")
+ (is (= (:body response) body)
+ "Unexpected body in ring handler response."))))
+ (is (= overrides @override-result)
+ "Unexpected response to override-webserver-settings! call."))))
(testing "attempt to override SSL settings fails when override call made
after webserver has already started"
(let [override-result (atom nil)
service1 (tk-services/service [])]
- (with-app-with-config
- app
- [jetty9-service service1]
- jetty-plaintext-config
- (let [s (get-service app :WebserverService)
- override-webserver-settings! (partial
- override-webserver-settings!
- s)]
- (is (thrown-with-msg? java.lang.IllegalStateException
- #"overrides cannot be set because webserver has already processed the config"
- (override-webserver-settings! overrides)))))))
+ (with-test-logging
+ (with-app-with-config
+ app
+ [jetty9-service service1]
+ jetty-plaintext-config
+ (let [s (get-service app :WebserverService)
+ override-webserver-settings! (partial
+ override-webserver-settings!
+ s)]
+ (is (thrown-with-msg? java.lang.IllegalStateException
+ #"overrides cannot be set because webserver has already processed the config"
+ (override-webserver-settings! overrides))))))))
(testing "second attempt to override SSL settings fails"
(let [second-override-result (atom nil)
service1 (tk-services/service
@@ -204,22 +206,23 @@
(override-webserver-settings!
overrides))))
context))]
- (with-app-with-config
- app
- [jetty9-service service1]
- jetty-plaintext-config
- (let [s (get-service app :WebserverService)
- add-ring-handler (partial add-ring-handler s)
- body "Hi World"
- path "/hi_world"
- ring-handler (fn [req] {:status 200 :body body})]
- (add-ring-handler ring-handler path)
- (let [response (http-get
- (format "https://localhost:%d%s/" ssl-port path)
- default-options-for-https-client)]
- (is (= (:status response) 200)
- "Unsuccessful http response code ring handler response.")
- (is (= (:body response) body)
- "Unexpected body in ring handler response."))))
- (is (instance? IllegalStateException @second-override-result)
- "Second call to setting overrides did not throw expected exception.")))))
\ No newline at end of file
+ (with-test-logging
+ (with-app-with-config
+ app
+ [jetty9-service service1]
+ jetty-plaintext-config
+ (let [s (get-service app :WebserverService)
+ add-ring-handler (partial add-ring-handler s)
+ body "Hi World"
+ path "/hi_world"
+ ring-handler (fn [req] {:status 200 :body body})]
+ (add-ring-handler ring-handler path)
+ (let [response (http-get
+ (format "https://localhost:%d%s/" ssl-port path)
+ default-options-for-https-client)]
+ (is (= (:status response) 200)
+ "Unsuccessful http response code ring handler response.")
+ (is (= (:body response) body)
+ "Unexpected body in ring handler response."))))
+ (is (instance? IllegalStateException @second-override-result)
+ "Second call to setting overrides did not throw expected exception."))))))
=====================================
test/clj/puppetlabs/trapperkeeper/services/webserver/jetty9_service_proxy_test.clj
=====================================
@@ -6,6 +6,7 @@
[puppetlabs.trapperkeeper.app :refer [get-service]]
[puppetlabs.trapperkeeper.services :refer [service]]
[puppetlabs.trapperkeeper.testutils.bootstrap :refer [with-app-with-config]]
+ [puppetlabs.trapperkeeper.testutils.logging :refer [with-test-logging]]
[ring.middleware.params :as ring-params]
[schema.test :as schema-test]
[puppetlabs.trapperkeeper.testutils.webserver :as testutils]))
@@ -94,39 +95,40 @@
[{:keys [target proxy proxy-config proxy-opts ring-handler
register-proxy-route-before-server-start?]} & body]
(let [proxy-path "/hello-proxy"]
- `(with-app-with-config proxy-target-app#
- [jetty9-service]
- {:webserver ~target}
- (let [target-webserver# (get-service proxy-target-app# :WebserverService)]
- (add-ring-handler
- target-webserver#
- ~ring-handler
- "/hello")
- (add-ring-handler
- target-webserver#
- ~ring-handler
- "/goodbye"))
- (if ~register-proxy-route-before-server-start?
- (let [proxy-service# (proxy-service ~proxy-config
- ~proxy-opts
- ~proxy-path)]
+ `(with-test-logging
+ (with-app-with-config proxy-target-app#
+ [jetty9-service]
+ {:webserver ~target}
+ (let [target-webserver# (get-service proxy-target-app# :WebserverService)]
+ (add-ring-handler
+ target-webserver#
+ ~ring-handler
+ "/hello")
+ (add-ring-handler
+ target-webserver#
+ ~ring-handler
+ "/goodbye"))
+ (if ~register-proxy-route-before-server-start?
+ (let [proxy-service# (proxy-service ~proxy-config
+ ~proxy-opts
+ ~proxy-path)]
+ (with-app-with-config proxy-app#
+ [jetty9-service proxy-service#]
+ {:webserver ~proxy}
+ ~@body))
(with-app-with-config proxy-app#
- [jetty9-service proxy-service#]
+ [jetty9-service]
{:webserver ~proxy}
- ~@body))
- (with-app-with-config proxy-app#
- [jetty9-service]
- {:webserver ~proxy}
- (let [proxy-webserver# (get-service proxy-app# :WebserverService)]
- (if ~proxy-opts
- (add-proxy-route proxy-webserver#
- ~proxy-config
- ~proxy-path
- ~proxy-opts)
- (add-proxy-route proxy-webserver#
- ~proxy-config
- ~proxy-path)))
- ~@body)))))
+ (let [proxy-webserver# (get-service proxy-app# :WebserverService)]
+ (if ~proxy-opts
+ (add-proxy-route proxy-webserver#
+ ~proxy-config
+ ~proxy-path
+ ~proxy-opts)
+ (add-proxy-route proxy-webserver#
+ ~proxy-config
+ ~proxy-path)))
+ ~@body))))))
(def common-ssl-config
{:ssl-cert "./dev-resources/config/jetty/ssl/certs/localhost.pem"
=====================================
test/clj/puppetlabs/trapperkeeper/services/webserver/jetty9_service_test.clj
=====================================
@@ -938,9 +938,8 @@
jetty-ssl-pem-config
(let [test-fn (fn [] (http-get "https://localhost:8081/hi_world" (merge default-options-for-https-client
{:ssl-protocols ["SSLv3"]})) )]
- (if (SSLUtils/isFIPS)
- (is (thrown? IllegalArgumentException (test-fn)))
- (is (thrown? SSLException (test-fn)))))))
+
+ (is (thrown? SSLException (test-fn))))))
(testing "SSLv3 is not supported even when configured"
(tk-log-testutils/with-test-logging
(with-app-with-config
@@ -954,6 +953,4 @@
(is (logged? #"When `ssl-protocols` is empty, a default of"))
(let [test-fn (fn [] (http-get "https://localhost:8081/hi_world" (merge default-options-for-https-client
{:ssl-protocols ["SSLv3"]})) )]
- (if (SSLUtils/isFIPS)
- (is (thrown? IllegalArgumentException (test-fn)))
- (is (thrown? SSLException (test-fn)))))))))
+ (is (thrown? SSLException (test-fn))))))))
View it on GitLab: https://salsa.debian.org/clojure-team/trapperkeeper-webserver-jetty9-clojure/-/commit/3f35508f4b59fd3530fd595d609942f3befc9495
--
View it on GitLab: https://salsa.debian.org/clojure-team/trapperkeeper-webserver-jetty9-clojure/-/commit/3f35508f4b59fd3530fd595d609942f3befc9495
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-java-commits/attachments/20221019/3b576ebc/attachment.htm>
More information about the pkg-java-commits
mailing list