2022-11-01 14:37:29 +00:00
|
|
|
(ns dda.c4k-common.ingress-cert-test
|
2022-10-19 07:25:37 +00:00
|
|
|
(:require
|
|
|
|
#?(:clj [clojure.test :refer [deftest is are testing run-tests]]
|
|
|
|
:cljs [cljs.test :refer-macros [deftest is are testing run-tests]])
|
|
|
|
[clojure.spec.test.alpha :as st]
|
2022-11-01 12:56:28 +00:00
|
|
|
[dda.c4k-common.ingress-cert :as cut]))
|
2022-10-19 07:25:37 +00:00
|
|
|
|
|
|
|
(st/instrument `cut/generate-host-rule)
|
2022-11-11 08:35:42 +00:00
|
|
|
(st/instrument `cut/generate-ingress)
|
2022-10-19 07:25:37 +00:00
|
|
|
(st/instrument `cut/generate-certificate)
|
|
|
|
|
|
|
|
(deftest should-generate-rule
|
|
|
|
(is (= {:host "test.com",
|
|
|
|
:http
|
|
|
|
{:paths
|
|
|
|
[{:pathType "Prefix",
|
|
|
|
:path "/",
|
|
|
|
:backend
|
|
|
|
{:service {:name "myservice", :port {:number 3000}}}}]}}
|
|
|
|
(cut/generate-host-rule "myservice" 3000 "test.com"))))
|
|
|
|
|
2022-11-11 08:35:42 +00:00
|
|
|
(deftest should-generate-ingress
|
2022-10-19 07:25:37 +00:00
|
|
|
(is (= {:apiVersion "networking.k8s.io/v1",
|
|
|
|
:kind "Ingress",
|
|
|
|
:metadata
|
|
|
|
{:name "test-io-https-ingress",
|
|
|
|
:namespace "default",
|
2022-11-01 14:37:29 +00:00
|
|
|
:labels {:app.kubernetes.part-of "c4k-common-app"},
|
2022-11-18 08:35:34 +00:00
|
|
|
:annotations #:traefik.ingress.kubernetes.io{:router.entrypoints "web, websecure", :router.middlewares "default-redirect-https@kubernetescrd"}}}
|
2022-11-11 08:35:42 +00:00
|
|
|
(dissoc (cut/generate-ingress
|
2022-10-19 07:25:37 +00:00
|
|
|
{:issuer "prod"
|
|
|
|
:service-name "test-io-service"
|
2022-11-01 14:37:29 +00:00
|
|
|
:app-name "c4k-common-app"
|
2022-10-19 07:25:37 +00:00
|
|
|
:service-port 80
|
|
|
|
:ingress-name "test-io-https-ingress"
|
|
|
|
:fqdns ["test.de" "www.test.de" "test-it.de" "www.test-it.de"]}) :spec)))
|
|
|
|
(is (= {:tls
|
|
|
|
[{:hosts
|
|
|
|
["test.de" "www.test.de" "test-it.de" "www.test-it.de"],
|
|
|
|
:secretName "test-io-cert"}]
|
|
|
|
:rules
|
|
|
|
[{:host "test.de",
|
|
|
|
:http
|
|
|
|
{:paths [{:pathType "Prefix", :path "/", :backend {:service {:name "test-io-service", :port {:number 80}}}}]}}
|
|
|
|
{:host "www.test.de",
|
|
|
|
:http
|
|
|
|
{:paths [{:pathType "Prefix", :path "/", :backend {:service {:name "test-io-service", :port {:number 80}}}}]}}
|
|
|
|
{:host "test-it.de",
|
|
|
|
:http
|
|
|
|
{:paths [{:pathType "Prefix", :path "/", :backend {:service {:name "test-io-service", :port {:number 80}}}}]}}
|
|
|
|
{:host "www.test-it.de",
|
|
|
|
:http
|
|
|
|
{:paths [{:pathType "Prefix", :path "/", :backend {:service {:name "test-io-service", :port {:number 80}}}}]}}]}
|
2022-11-11 08:35:42 +00:00
|
|
|
(:spec (cut/generate-ingress {:issuer "prod"
|
2022-11-01 14:37:29 +00:00
|
|
|
:app-name "c4k-common-app"
|
2022-10-19 07:25:37 +00:00
|
|
|
:service-name "test-io-service"
|
|
|
|
:service-port 80
|
|
|
|
:ingress-name "test-io-https-ingress"
|
|
|
|
:cert-name "test-io-cert"
|
|
|
|
:fqdns ["test.de" "www.test.de" "test-it.de" "www.test-it.de"]})))))
|
|
|
|
|
|
|
|
(deftest should-generate-certificate
|
|
|
|
(is (= {:apiVersion "cert-manager.io/v1",
|
|
|
|
:kind "Certificate",
|
2022-11-01 14:37:29 +00:00
|
|
|
:metadata {:name "test-io-cert",
|
|
|
|
:namespace "default",
|
|
|
|
:labels {:app.kubernetes.part-of "c4k-common-app"}},
|
2022-10-19 07:25:37 +00:00
|
|
|
:spec
|
|
|
|
{:secretName "test-io-cert",
|
|
|
|
:commonName "test.de",
|
|
|
|
:duration "2160h",
|
|
|
|
:renewBefore "360h",
|
|
|
|
:dnsNames ["test.de" "test.org" "www.test.de" "www.test.org"],
|
|
|
|
:issuerRef {:name "prod", :kind "ClusterIssuer"}}}
|
2022-11-01 14:37:29 +00:00
|
|
|
(cut/generate-certificate {:fqdns ["test.de" "test.org" "www.test.de" "www.test.org"]
|
|
|
|
:app-name "c4k-common-app"
|
|
|
|
:cert-name "test-io-cert"
|
|
|
|
:issuer "prod"}))))
|