Skip to content

Commit aaecabe

Browse files
authored
support disabling ssl validation in openapi2jsonschema.py (#167)
* support disabling ssl validation in openapi2jsonschema.py * added acceptance tests for disable ssl feature * speed up bats docker build
1 parent 563e1db commit aaecabe

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

scripts/Dockerfile.bats

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
FROM python:3.9.7-alpine3.14
22
RUN apk --no-cache add bats
3-
COPY acceptance.bats openapi2jsonschema.py requirements.txt /code/
3+
COPY requirements.txt /code/
4+
RUN pip install -r /code/requirements.txt
45
COPY fixtures /code/fixtures
6+
COPY acceptance.bats openapi2jsonschema.py /code/
57
WORKDIR /code
6-
RUN pip install -r requirements.txt

scripts/acceptance.bats

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,42 @@ setup() {
55
rm -f prometheus-monitoring-v1.json
66
}
77

8+
@test "Should generate expected prometheus resource while disable ssl env var is set" {
9+
run export DISABLE_SSL_CERT_VALIDATION=true
10+
run ./openapi2jsonschema.py fixtures/prometheus-operator-0prometheusCustomResourceDefinition.yaml
11+
[ "$status" -eq 0 ]
12+
[ "$output" = "JSON schema written to prometheus_v1.json" ]
13+
run diff prometheus_v1.json ./fixtures/prometheus_v1-expected.json
14+
[ "$status" -eq 0 ]
15+
}
16+
17+
@test "Should generate expected prometheus resource from an HTTPS resource while disable ssl env var is set" {
18+
run export DISABLE_SSL_CERT_VALIDATION=true
19+
run ./openapi2jsonschema.py https://raw.githubusercontent.com/yannh/kubeconform/aebc298047c386116eeeda9b1ada83671a58aedd/scripts/fixtures/prometheus-operator-0prometheusCustomResourceDefinition.yaml
20+
[ "$status" -eq 0 ]
21+
[ "$output" = "JSON schema written to prometheus_v1.json" ]
22+
run diff prometheus_v1.json ./fixtures/prometheus_v1-expected.json
23+
[ "$status" -eq 0 ]
24+
}
25+
26+
@test "Should output filename in {kind}-{group}-{version} format while disable ssl env var is set" {
27+
run export DISABLE_SSL_CERT_VALIDATION=true
28+
FILENAME_FORMAT='{kind}-{group}-{version}' run ./openapi2jsonschema.py fixtures/prometheus-operator-0prometheusCustomResourceDefinition.yaml
29+
[ "$status" -eq 0 ]
30+
[ "$output" = "JSON schema written to prometheus-monitoring-v1.json" ]
31+
run diff prometheus-monitoring-v1.json ./fixtures/prometheus_v1-expected.json
32+
[ "$status" -eq 0 ]
33+
}
34+
35+
@test "Should set 'additionalProperties: false' at the root while disable ssl env var is set" {
36+
run export DISABLE_SSL_CERT_VALIDATION=true
37+
DENY_ROOT_ADDITIONAL_PROPERTIES='true' run ./openapi2jsonschema.py fixtures/prometheus-operator-0prometheusCustomResourceDefinition.yaml
38+
[ "$status" -eq 0 ]
39+
[ "$output" = "JSON schema written to prometheus_v1.json" ]
40+
run diff prometheus_v1.json ./fixtures/prometheus_v1-denyRootAdditionalProperties.json
41+
[ "$status" -eq 0 ]
42+
}
43+
844
@test "Should generate expected prometheus resource" {
945
run ./openapi2jsonschema.py fixtures/prometheus-operator-0prometheusCustomResourceDefinition.yaml
1046
[ "$status" -eq 0 ]

scripts/openapi2jsonschema.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
import sys
77
import os
88
import urllib.request
9+
if 'DISABLE_SSL_CERT_VALIDATION' in os.environ:
10+
import ssl
11+
ssl._create_default_https_context = ssl._create_unverified_context
912

1013
def test_additional_properties():
1114
for test in iter([{

0 commit comments

Comments
 (0)