diff --git a/src/clj/puppetlabs/services/ca/certificate_authority_core.clj b/src/clj/puppetlabs/services/ca/certificate_authority_core.clj index 2a59daa7b..f488200b7 100644 --- a/src/clj/puppetlabs/services/ca/certificate_authority_core.clj +++ b/src/clj/puppetlabs/services/ca/certificate_authority_core.clj @@ -257,6 +257,24 @@ request-cert) (log/warn (i18n/trs "Request is missing a certificate for an endpoint that requires a certificate.")))))) + +(schema/defn handle-bulk-cert-signing + [_request + ca_settings :- ca/CaSettings] + + (let [_certnames (:certnames ca_settings)] + (-> (rr/response (cheshire/generate-string {})) + (rr/status 200) + (rr/content-type "application/json")))) + +(schema/defn handle-bulk-cert-signing-all + [_request + _ca-settings :- ca/CaSettings] + (-> (rr/response (cheshire/generate-string {})) + (rr/status 200) + (rr/content-type "application/json"))) + + (schema/defn ^:always-validate handle-cert-renewal "Given a request and the CA settings, if there is a cert present in the request @@ -517,7 +535,7 @@ (comidi/routes (comidi/context ["/v1"] (ANY ["/certificate_status/" :subject] [subject] - (certificate-status subject ca-settings report-activity)) + (certificate-status subject ca-settings report-activity)) (comidi/context ["/certificate_statuses/"] (ANY [[#"[^/]+" :ignored-but-required]] request (certificate-statuses request ca-settings)) @@ -540,7 +558,11 @@ (PUT ["/clean"] request (handle-cert-clean request ca-settings report-activity)) (POST ["/certificate_renewal"] request - (handle-cert-renewal request ca-settings report-activity))) + (handle-cert-renewal request ca-settings report-activity)) + (POST ["/sign"] request + (handle-bulk-cert-signing request ca-settings)) + (POST ["/sign/all"] request + (handle-bulk-cert-signing-all request ca-settings))) (comidi/not-found "Not Found"))) (schema/defn ^:always-validate diff --git a/test/integration/puppetlabs/services/certificate_authority/certificate_authority_int_test.clj b/test/integration/puppetlabs/services/certificate_authority/certificate_authority_int_test.clj index f36b1e81d..a6258296c 100644 --- a/test/integration/puppetlabs/services/certificate_authority/certificate_authority_int_test.clj +++ b/test/integration/puppetlabs/services/certificate_authority/certificate_authority_int_test.clj @@ -1152,6 +1152,52 @@ :body "Bad data"})] (is (= 400 (:status response))))))) +(deftest ca-bulk-signing-endpoint-test + (testing "returns 200 response " + (bootstrap/with-puppetserver-running-with-mock-jrubies + "JRuby mocking is safe here because all of the requests are to the CA + endpoints, which are implemented in Clojure." + app + {:jruby-puppet + {:gem-path [(ks/absolute-path jruby-testutils/gem-path)]} + :webserver + {:ssl-cert (str bootstrap/server-conf-dir "/ssl/certs/localhost.pem") + :ssl-key (str bootstrap/server-conf-dir "/ssl/private_keys/localhost.pem") + :ssl-ca-cert (str bootstrap/server-conf-dir "/ca/ca_crt.pem") + :ssl-crl-path (str bootstrap/server-conf-dir "/ssl/crl.pem")} + :certificate-authority + {:certnames ["cert3" "cert1" "cert8"]}} + (let [response (http-client/post + "https://localhost:8140/puppet-ca/v1/sign" + {:ssl-cert (str bootstrap/server-conf-dir "/ca/ca_crt.pem") + :ssl-key (str bootstrap/server-conf-dir "/ca/ca_key.pem") + :ssl-ca-cert (str bootstrap/server-conf-dir "/ca/ca_crt.pem") + :as :text + :headers {"Accept" "application/json"}})] + (is (= 200 (:status response))))))) + +(deftest ca-bulk-signing-all-endpoint-test + (testing "returns a 200 when provided certname array " + (bootstrap/with-puppetserver-running-with-mock-jrubies + "JRuby mocking is safe here because all of the requests are to the CA + endpoints, which are implemented in Clojure." + app + {:jruby-puppet + {:gem-path [(ks/absolute-path jruby-testutils/gem-path)]} + :webserver + {:ssl-cert (str bootstrap/server-conf-dir "/ssl/certs/localhost.pem") + :ssl-key (str bootstrap/server-conf-dir "/ssl/private_keys/localhost.pem") + :ssl-ca-cert (str bootstrap/server-conf-dir "/ca/ca_crt.pem") + :ssl-crl-path (str bootstrap/server-conf-dir "/ssl/crl.pem")}} + (let [response (http-client/post + "https://localhost:8140/puppet-ca/v1/sign/all" + {:ssl-cert (str bootstrap/server-conf-dir "/ca/ca_crt.pem") + :ssl-key (str bootstrap/server-conf-dir "/ca/ca_key.pem") + :ssl-ca-cert (str bootstrap/server-conf-dir "/ca/ca_crt.pem") + :as :text + :headers {"Accept" "application/json"}})] + (is (= 200 (:status response))))))) + (deftest ca-certificate-renew-endpoint-test (testing "with the feature enabled" (testing "with allow-header-cert-info = false (default)"