Skip to content

Commit

Permalink
test: update tests for disable request verifications
Browse files Browse the repository at this point in the history
  • Loading branch information
shreddedbacon committed Jul 8, 2024
1 parent 314d841 commit 86e65b2
Show file tree
Hide file tree
Showing 63 changed files with 271 additions and 1 deletion.
14 changes: 13 additions & 1 deletion internal/templating/ingress/templates_ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,22 @@ func GenerateIngressTemplate(
additionalAnnotations["nginx.ingress.kubernetes.io/ssl-redirect"] = "true"
additionalAnnotations["ingress.kubernetes.io/ssl-redirect"] = "true"
}
if lValues.EnvironmentType == "development" || *&route.Autogenerated == true {
if lValues.EnvironmentType == "development" || route.Autogenerated {
additionalAnnotations["nginx.ingress.kubernetes.io/server-snippet"] = "add_header X-Robots-Tag \"noindex, nofollow\";\n"
}

// if idling request verification is in the `.lagoon.yml` and true, add the annotation. this supports production and development environment types
// in the event that production environments support idling properly that option could be available to then
// idle standby environments or production environments generally in opensource lagoon
if route.RequestVerification != nil && *route.RequestVerification {
// @TODO: this will eventually be changed to a `lagoon.sh` instead of `amazee.io` namespaced annotation in the future once
// aergia is fully integrated into the uselagoon namespace
additionalAnnotations["idling.amazee.io/disable-request-verification"] = "true"
} else {
// otherwise force false
additionalAnnotations["idling.amazee.io/disable-request-verification"] = "false"
}

// check if a user has defined hsts configuration
if route.HSTSEnabled != nil && *route.HSTSEnabled {
hstsHeader := fmt.Sprintf("more_set_headers \"Strict-Transport-Security: max-age=%d", route.HSTSMaxAge)
Expand Down
39 changes: 39 additions & 0 deletions internal/templating/ingress/templates_ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,45 @@ func TestGenerateKubeTemplate(t *testing.T) {
},
want: "test-resources/result-wildcard-ingress2.yaml",
},
{
name: "custom-ingress7",
args: args{
route: lagoon.RouteV2{
Domain: "extra-long-name.a-really-long-name-that-should-truncate.www.example.com",
LagoonService: "nginx",
MonitoringPath: "/",
Insecure: helpers.StrPtr("Redirect"),
TLSAcme: helpers.BoolPtr(true),
Migrate: helpers.BoolPtr(false),
Annotations: map[string]string{
"custom-annotation": "custom annotation value",
},
Fastly: lagoon.Fastly{
Watch: false,
},
RequestVerification: helpers.BoolPtr(true),
IngressName: "extra-long-name.a-really-long-name-that-should-truncate.www.example.com",
},
values: generator.BuildValues{
Project: "example-project",
Environment: "environment-with-really-really-reall-3fdb",
EnvironmentType: "development",
Namespace: "myexample-project-environment-with-really-really-reall-3fdb",
BuildType: "branch",
LagoonVersion: "v2.x.x",
Kubernetes: "lagoon.local",
Branch: "environment-with-really-really-reall-3fdb",
Monitoring: generator.MonitoringConfig{
AlertContact: "abcdefg",
StatusPageID: "12345",
Enabled: true,
},
Route: "https://extra-long-name.a-really-long-name-that-should-truncate.www.example.com/",
},
activeStandby: false,
},
want: "test-resources/result-custom-ingress7.yaml",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ metadata:
annotations:
custom-annotation: custom annotation value
fastly.amazee.io/watch: "false"
idling.amazee.io/disable-request-verification: "false"
ingress.kubernetes.io/ssl-redirect: "true"
kubernetes.io/tls-acme: "true"
lagoon.sh/branch: environment-with-really-really-reall-3fdb
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ metadata:
annotations:
custom-annotation: custom annotation value
fastly.amazee.io/watch: "false"
idling.amazee.io/disable-request-verification: "false"
ingress.kubernetes.io/ssl-redirect: "true"
kubernetes.io/tls-acme: "true"
lagoon.sh/branch: environment-with-really-really-reall-3fdb
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ metadata:
annotations:
custom-annotation: custom annotation value
fastly.amazee.io/watch: "false"
idling.amazee.io/disable-request-verification: "false"
ingress.kubernetes.io/ssl-redirect: "true"
kubernetes.io/tls-acme: "true"
lagoon.sh/branch: environment-with-really-really-reall-3fdb
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ metadata:
acme.cert-manager.io/http01-ingress-class: nginx
custom-annotation: custom annotation value
fastly.amazee.io/watch: "false"
idling.amazee.io/disable-request-verification: "false"
ingress.kubernetes.io/ssl-redirect: "true"
kubernetes.io/tls-acme: "true"
lagoon.sh/branch: environment-with-really-really-reall-3fdb
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ metadata:
acme.cert-manager.io/http01-ingress-class: nginx
custom-annotation: custom annotation value
fastly.amazee.io/watch: "false"
idling.amazee.io/disable-request-verification: "false"
ingress.kubernetes.io/ssl-redirect: "true"
kubernetes.io/tls-acme: "true"
lagoon.sh/branch: environment-with-really-really-reall-3fdb
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ metadata:
acme.cert-manager.io/http01-ingress-class: nginx
custom-annotation: custom annotation value
fastly.amazee.io/watch: "false"
idling.amazee.io/disable-request-verification: "false"
ingress.kubernetes.io/ssl-redirect: "true"
kubernetes.io/tls-acme: "true"
lagoon.sh/branch: environment-with-really-really-reall-3fdb
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ metadata:
acme.cert-manager.io/http01-ingress-class: nginx
custom-annotation: custom annotation value
fastly.amazee.io/watch: "false"
idling.amazee.io/disable-request-verification: "false"
ingress.kubernetes.io/ssl-redirect: "true"
kubernetes.io/tls-acme: "true"
lagoon.sh/branch: environment-with-really-really-reall-3fdb
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
custom-annotation: custom annotation value
fastly.amazee.io/watch: "false"
idling.amazee.io/disable-request-verification: "true"
ingress.kubernetes.io/ssl-redirect: "true"
kubernetes.io/tls-acme: "true"
lagoon.sh/branch: environment-with-really-really-reall-3fdb
lagoon.sh/version: v2.x.x
nginx.ingress.kubernetes.io/server-snippet: |
add_header X-Robots-Tag "noindex, nofollow";
nginx.ingress.kubernetes.io/ssl-redirect: "true"
creationTimestamp: null
labels:
app.kubernetes.io/instance: extra-long-name-f6c8a
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: custom-ingress
helm.sh/chart: custom-ingress-0.1.0
lagoon.sh/autogenerated: "false"
lagoon.sh/buildType: branch
lagoon.sh/environment: environment-with-really-really-reall-3fdb
lagoon.sh/environmentType: development
lagoon.sh/project: example-project
lagoon.sh/service: extra-long-name-f6c8a
lagoon.sh/service-type: custom-ingress
name: extra-long-name.a-really-long-name-that-should-truncate.www.example.com
spec:
rules:
- host: extra-long-name.a-really-long-name-that-should-truncate.www.example.com
http:
paths:
- backend:
service:
name: nginx
port:
name: http
path: /
pathType: Prefix
tls:
- hosts:
- extra-long-name.a-really-long-name-that-should-truncate.www.example.com
secretName: extra-long-name-f6c8a-tls
status:
loadBalancer: {}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ metadata:
acme.cert-manager.io/http01-ingress-class: nginx
custom-annotation: custom annotation value
fastly.amazee.io/watch: "false"
idling.amazee.io/disable-request-verification: "false"
ingress.kubernetes.io/ssl-redirect: "true"
kubernetes.io/tls-acme: "false"
lagoon.sh/branch: environment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ metadata:
acme.cert-manager.io/http01-ingress-class: nginx
custom-annotation: custom annotation value
fastly.amazee.io/watch: "false"
idling.amazee.io/disable-request-verification: "false"
ingress.kubernetes.io/ssl-redirect: "true"
kubernetes.io/tls-acme: "false"
lagoon.sh/branch: environment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ kind: Ingress
metadata:
annotations:
fastly.amazee.io/watch: "false"
idling.amazee.io/disable-request-verification: "false"
ingress.kubernetes.io/ssl-redirect: "false"
kubernetes.io/tls-acme: "true"
lagoon.sh/branch: drush-first
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ kind: Ingress
metadata:
annotations:
fastly.amazee.io/watch: "false"
idling.amazee.io/disable-request-verification: "false"
ingress.kubernetes.io/ssl-redirect: "false"
kubernetes.io/tls-acme: "true"
lagoon.sh/branch: feature/migration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ kind: Ingress
metadata:
annotations:
fastly.amazee.io/watch: "false"
idling.amazee.io/disable-request-verification: "false"
ingress.kubernetes.io/ssl-redirect: "false"
kubernetes.io/tls-acme: "true"
lagoon.sh/branch: feature
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ kind: Ingress
metadata:
annotations:
fastly.amazee.io/watch: "false"
idling.amazee.io/disable-request-verification: "false"
ingress.kubernetes.io/ssl-redirect: "false"
kubernetes.io/tls-acme: "false"
lagoon.sh/branch: production
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ kind: Ingress
metadata:
annotations:
fastly.amazee.io/watch: "false"
idling.amazee.io/disable-request-verification: "false"
ingress.kubernetes.io/ssl-redirect: "true"
kubernetes.io/tls-acme: "true"
lagoon.sh/branch: main
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ kind: Ingress
metadata:
annotations:
fastly.amazee.io/watch: "false"
idling.amazee.io/disable-request-verification: "false"
ingress.kubernetes.io/ssl-redirect: "true"
kubernetes.io/tls-acme: "true"
lagoon.sh/branch: main
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ kind: Ingress
metadata:
annotations:
fastly.amazee.io/watch: "false"
idling.amazee.io/disable-request-verification: "false"
ingress.kubernetes.io/ssl-redirect: "true"
kubernetes.io/tls-acme: "true"
lagoon.sh/prBaseBranch: main2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ kind: Ingress
metadata:
annotations:
fastly.amazee.io/watch: "false"
idling.amazee.io/disable-request-verification: "false"
ingress.kubernetes.io/ssl-redirect: "true"
kubernetes.io/tls-acme: "true"
lagoon.sh/branch: main
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ kind: Ingress
metadata:
annotations:
fastly.amazee.io/watch: "false"
idling.amazee.io/disable-request-verification: "false"
ingress.kubernetes.io/ssl-redirect: "false"
kubernetes.io/tls-acme: "true"
lagoon.sh/branch: main
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ kind: Ingress
metadata:
annotations:
fastly.amazee.io/watch: "false"
idling.amazee.io/disable-request-verification: "false"
ingress.kubernetes.io/ssl-redirect: "true"
kubernetes.io/tls-acme: "true"
lagoon.sh/branch: main
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ kind: Ingress
metadata:
annotations:
fastly.amazee.io/watch: "false"
idling.amazee.io/disable-request-verification: "false"
ingress.kubernetes.io/ssl-redirect: "true"
kubernetes.io/tls-acme: "false"
lagoon.sh/branch: main
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ kind: Ingress
metadata:
annotations:
fastly.amazee.io/watch: "false"
idling.amazee.io/disable-request-verification: "false"
ingress.kubernetes.io/ssl-redirect: "true"
kubernetes.io/tls-acme: "false"
lagoon.sh/branch: main
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ kind: Ingress
metadata:
annotations:
fastly.amazee.io/watch: "false"
idling.amazee.io/disable-request-verification: "false"
ingress.kubernetes.io/ssl-redirect: "true"
kubernetes.io/tls-acme: "true"
lagoon.sh/branch: main
Expand Down
47 changes: 47 additions & 0 deletions internal/testdata/node/autogen-templates/ingress-15/node.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
fastly.amazee.io/watch: "false"
idling.amazee.io/disable-request-verification: "true"
ingress.kubernetes.io/ssl-redirect: "true"
kubernetes.io/tls-acme: "true"
lagoon.sh/branch: main
lagoon.sh/version: v2.7.x
monitor.stakater.com/enabled: "false"
nginx.ingress.kubernetes.io/server-snippet: |
add_header X-Robots-Tag "noindex, nofollow";
nginx.ingress.kubernetes.io/ssl-redirect: "true"
creationTimestamp: null
labels:
app.kubernetes.io/instance: node
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: autogenerated-ingress
helm.sh/chart: autogenerated-ingress-0.1.0
lagoon.sh/autogenerated: "true"
lagoon.sh/buildType: branch
lagoon.sh/environment: main
lagoon.sh/environmentType: production
lagoon.sh/project: example-project
lagoon.sh/service: node
lagoon.sh/service-type: node
name: node
spec:
rules:
- host: node-example-project-main.example.com
http:
paths:
- backend:
service:
name: node
port:
name: http
path: /
pathType: Prefix
tls:
- hosts:
- node-example-project-main.example.com
secretName: node-tls
status:
loadBalancer: {}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ kind: Ingress
metadata:
annotations:
fastly.amazee.io/watch: "false"
idling.amazee.io/disable-request-verification: "false"
ingress.kubernetes.io/ssl-redirect: "true"
kubernetes.io/tls-acme: "true"
lagoon.sh/prBaseBranch: main2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ kind: Ingress
metadata:
annotations:
fastly.amazee.io/watch: "false"
idling.amazee.io/disable-request-verification: "false"
ingress.kubernetes.io/ssl-redirect: "true"
kubernetes.io/tls-acme: "true"
lagoon.sh/branch: main
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ kind: Ingress
metadata:
annotations:
fastly.amazee.io/watch: "false"
idling.amazee.io/disable-request-verification: "false"
ingress.kubernetes.io/ssl-redirect: "true"
kubernetes.io/tls-acme: "true"
lagoon.sh/branch: short-router-url-from-a-very-long-environment-name-like-this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ kind: Ingress
metadata:
annotations:
fastly.amazee.io/watch: "false"
idling.amazee.io/disable-request-verification: "false"
ingress.kubernetes.io/ssl-redirect: "true"
kubernetes.io/tls-acme: "true"
lagoon.sh/branch: main
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ metadata:
annotations:
fastly.amazee.io/service-id: service-id
fastly.amazee.io/watch: "true"
idling.amazee.io/disable-request-verification: "false"
ingress.kubernetes.io/ssl-redirect: "true"
kubernetes.io/tls-acme: "true"
lagoon.sh/branch: main
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ metadata:
annotations:
fastly.amazee.io/service-id: service-id
fastly.amazee.io/watch: "true"
idling.amazee.io/disable-request-verification: "false"
ingress.kubernetes.io/ssl-redirect: "true"
kubernetes.io/tls-acme: "true"
lagoon.sh/branch: main
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ metadata:
fastly.amazee.io/api-secret-name: fastly-api-secretname
fastly.amazee.io/service-id: service-id
fastly.amazee.io/watch: "true"
idling.amazee.io/disable-request-verification: "false"
ingress.kubernetes.io/ssl-redirect: "true"
kubernetes.io/tls-acme: "true"
lagoon.sh/branch: main
Expand Down
Loading

0 comments on commit 86e65b2

Please sign in to comment.