Skip to content

Commit

Permalink
support disabling ssl validation in openapi2jsonschema.py (#167)
Browse files Browse the repository at this point in the history
* support disabling ssl validation in openapi2jsonschema.py
* added acceptance tests for disable ssl feature
* speed up bats docker build
  • Loading branch information
w7089 authored Feb 26, 2023
1 parent 563e1db commit aaecabe
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
5 changes: 3 additions & 2 deletions scripts/Dockerfile.bats
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM python:3.9.7-alpine3.14
RUN apk --no-cache add bats
COPY acceptance.bats openapi2jsonschema.py requirements.txt /code/
COPY requirements.txt /code/
RUN pip install -r /code/requirements.txt
COPY fixtures /code/fixtures
COPY acceptance.bats openapi2jsonschema.py /code/
WORKDIR /code
RUN pip install -r requirements.txt
36 changes: 36 additions & 0 deletions scripts/acceptance.bats
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,42 @@ setup() {
rm -f prometheus-monitoring-v1.json
}

@test "Should generate expected prometheus resource while disable ssl env var is set" {
run export DISABLE_SSL_CERT_VALIDATION=true
run ./openapi2jsonschema.py fixtures/prometheus-operator-0prometheusCustomResourceDefinition.yaml
[ "$status" -eq 0 ]
[ "$output" = "JSON schema written to prometheus_v1.json" ]
run diff prometheus_v1.json ./fixtures/prometheus_v1-expected.json
[ "$status" -eq 0 ]
}

@test "Should generate expected prometheus resource from an HTTPS resource while disable ssl env var is set" {
run export DISABLE_SSL_CERT_VALIDATION=true
run ./openapi2jsonschema.py https://raw.githubusercontent.com/yannh/kubeconform/aebc298047c386116eeeda9b1ada83671a58aedd/scripts/fixtures/prometheus-operator-0prometheusCustomResourceDefinition.yaml
[ "$status" -eq 0 ]
[ "$output" = "JSON schema written to prometheus_v1.json" ]
run diff prometheus_v1.json ./fixtures/prometheus_v1-expected.json
[ "$status" -eq 0 ]
}

@test "Should output filename in {kind}-{group}-{version} format while disable ssl env var is set" {
run export DISABLE_SSL_CERT_VALIDATION=true
FILENAME_FORMAT='{kind}-{group}-{version}' run ./openapi2jsonschema.py fixtures/prometheus-operator-0prometheusCustomResourceDefinition.yaml
[ "$status" -eq 0 ]
[ "$output" = "JSON schema written to prometheus-monitoring-v1.json" ]
run diff prometheus-monitoring-v1.json ./fixtures/prometheus_v1-expected.json
[ "$status" -eq 0 ]
}

@test "Should set 'additionalProperties: false' at the root while disable ssl env var is set" {
run export DISABLE_SSL_CERT_VALIDATION=true
DENY_ROOT_ADDITIONAL_PROPERTIES='true' run ./openapi2jsonschema.py fixtures/prometheus-operator-0prometheusCustomResourceDefinition.yaml
[ "$status" -eq 0 ]
[ "$output" = "JSON schema written to prometheus_v1.json" ]
run diff prometheus_v1.json ./fixtures/prometheus_v1-denyRootAdditionalProperties.json
[ "$status" -eq 0 ]
}

@test "Should generate expected prometheus resource" {
run ./openapi2jsonschema.py fixtures/prometheus-operator-0prometheusCustomResourceDefinition.yaml
[ "$status" -eq 0 ]
Expand Down
3 changes: 3 additions & 0 deletions scripts/openapi2jsonschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import sys
import os
import urllib.request
if 'DISABLE_SSL_CERT_VALIDATION' in os.environ:
import ssl
ssl._create_default_https_context = ssl._create_unverified_context

def test_additional_properties():
for test in iter([{
Expand Down

0 comments on commit aaecabe

Please sign in to comment.