Skip to content

Commit

Permalink
add metadata xsd (Avviso n.29), add deprecated check switch
Browse files Browse the repository at this point in the history
  • Loading branch information
damikael committed Sep 24, 2020
1 parent 95cc8b1 commit 5753163
Show file tree
Hide file tree
Showing 11 changed files with 455 additions and 16 deletions.
1 change: 1 addition & 0 deletions specs-compliance-tests/test/sp/metadata_xsd_ag.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def setUp(self):
if path not in _report:
if c == len(paths):
_report[path] = {
'type': 'ag',
'description': self.shortDescription(),
'assertions': [],
}
Expand Down
123 changes: 123 additions & 0 deletions specs-compliance-tests/test/sp/metadata_xsd_sp-av29.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# Copyright 2018 AgID - Agenzia per l'Italia Digitale
#
# Licensed under the EUPL, Version 1.2 or - as soon they will be approved by
# the European Commission - subsequent versions of the EUPL (the "Licence").
#
# You may not use this work except in compliance with the Licence.
#
# You may obtain a copy of the Licence at:
#
# https://joinup.ec.europa.eu/software/page/eupl
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the Licence is distributed on an "AS IS" basis, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# Licence for the specific language governing permissions and limitations
# under the Licence.

import json
import os
import subprocess
import unittest

from io import BytesIO
from lxml import etree as ET

from common import constants
from common import dump_pem
import common.helpers
import common.wrap
import urllib.parse
import requests
import time

METADATA = os.getenv('SP_METADATA', None)
DATA_DIR = os.getenv('DATA_DIR', './data')


class TestSPMetadataXSD(unittest.TestCase, common.wrap.TestCaseWrap):
longMessage = False

@classmethod
def tearDownClass(cls):
fname = '%s/sp-metadata-xsd-sp-av29.json' % DATA_DIR
with open(fname, 'w') as f:
f.write(json.dumps(cls.report, indent=2))
f.close()

def setUp(self):
self.failures = []
_report = self.__class__.report
paths = self.id().split('.')
c = 1
for path in paths:
if path not in _report:
if c == len(paths):
_report[path] = {
'type': 'sp-av29',
'description': self.shortDescription(),
'assertions': [],
}
else:
_report[path] = {}
_report = _report[path]
c += 1

if not METADATA:
self.fail('SP_METADATA not set')

with open(METADATA, 'rb') as md_file:
md = md_file.read()
md_file.close()

self.doc = ET.parse(BytesIO(md))
common.helpers.del_ns(self.doc)

def tearDown(self):
if self.failures:
self.fail(common.helpers.dump_failures(self.failures))

def test_xsd(self):
'''Validate the SP metadata against the SAML 2.0 Medadata XSD (Avviso SPID n. 29)'''

cmd = ' '.join(['xmllint',
'--noout',
'--schema ./xsd/saml-schema-metadata-sp-spid-av29.xsd',
METADATA])
is_valid = True
msg = 'the metadata must validate against the XSD'
try:
subprocess.run(cmd, shell=True, check=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
except subprocess.CalledProcessError as err:
is_valid = False
lines = [msg]
if err.stderr:
stderr = (
'stderr: ' +
'\nstderr: '.join(
list(
filter(
None,
err.stderr.decode('utf-8').split('\n')
)
)
)
)
lines.append(stderr)
if err.stdout:
stdout = (
'stdout: ' +
'\nstdout: '.join(
list(
filter(
None,
err.stdout.decode('utf-8').split('\n')
)
)
)
)
lines.append(stdout)
msg = '\n'.join(lines)

self._assertTrue(is_valid, msg)
3 changes: 2 additions & 1 deletion specs-compliance-tests/test/sp/metadata_xsd_sp.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def setUp(self):
if path not in _report:
if c == len(paths):
_report[path] = {
'type': 'sp',
'description': self.shortDescription(),
'assertions': [],
}
Expand All @@ -77,7 +78,7 @@ def tearDown(self):
self.fail(common.helpers.dump_failures(self.failures))

def test_xsd(self):
'''Validate the SP metadata against the SAML 2.0 Medadata XSD'''
'''Validate the SP metadata against the SAML 2.0 Medadata XSD (DEPRECATED)'''

cmd = ' '.join(['xmllint',
'--noout',
Expand Down
12 changes: 12 additions & 0 deletions specs-compliance-tests/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
[tox]
envlist =
cleanup,
sp-metadata-xsd-sp,
sp-metadata-xsd-sp-av29,
sp-metadata-xsd-ag,
sp-metadata-strict,
sp-metadata-certs,
sp-metadata-extra,
Expand Down Expand Up @@ -84,6 +87,15 @@ passenv =
commands =
python -m unittest --verbose test/sp/metadata_xsd_sp.py

[testenv:sp-metadata-xsd-sp-av29]
deps = -rrequirements.txt
passenv =
DATA_DIR
SP_METADATA
DEBUG
commands =
python -m unittest --verbose test/sp/metadata_xsd_sp-av29.py

[testenv:sp-metadata-xsd-ag]
deps = -rrequirements.txt
passenv =
Expand Down
Loading

0 comments on commit 5753163

Please sign in to comment.