mirror of
https://github.com/yannh/kubeconform.git
synced 2026-02-20 10:27:02 +00:00
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
This commit is contained in:
parent
563e1db94c
commit
aaecabe0b7
3 changed files with 42 additions and 2 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
FROM python:3.9.7-alpine3.14
|
FROM python:3.9.7-alpine3.14
|
||||||
RUN apk --no-cache add bats
|
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 fixtures /code/fixtures
|
||||||
|
COPY acceptance.bats openapi2jsonschema.py /code/
|
||||||
WORKDIR /code
|
WORKDIR /code
|
||||||
RUN pip install -r requirements.txt
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,42 @@ setup() {
|
||||||
rm -f prometheus-monitoring-v1.json
|
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" {
|
@test "Should generate expected prometheus resource" {
|
||||||
run ./openapi2jsonschema.py fixtures/prometheus-operator-0prometheusCustomResourceDefinition.yaml
|
run ./openapi2jsonschema.py fixtures/prometheus-operator-0prometheusCustomResourceDefinition.yaml
|
||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,9 @@ import json
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import urllib.request
|
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():
|
def test_additional_properties():
|
||||||
for test in iter([{
|
for test in iter([{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue