-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add metadata xsd (Avviso n.29), add deprecated check switch
- Loading branch information
Showing
11 changed files
with
455 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.