Skip to content

Commit

Permalink
Merge pull request #98 from italia/dev
Browse files Browse the repository at this point in the history
Added the command line argument to print out version, fixed #59
  • Loading branch information
Giuseppe De Marco authored Aug 28, 2021
2 parents 028981f + 44738bc commit e963699
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 15 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ Generally it's:

![Command line with more flag demoed](gallery/more-flags.gif)

### Full test set with metadata, authn request and responses

![Command line with test responses](gallery/responses.gif)

## Profiles

Each profile loads a set of test. Use `--profile $profile-name`
Expand Down
Binary file added gallery/responses.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 9 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import re

from glob import glob
from setuptools import setup

Expand All @@ -8,10 +10,14 @@ def readme():
_src_folder = 'src'
_pkg_name = 'spid_sp_test'

with open(f'src/{_pkg_name}/__init__.py', 'r') as fd:
VERSION = re.search(r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]',
fd.read(), re.MULTILINE).group(1)

setup(
name=_pkg_name,
version='0.9.13',
description="SAML2 SPID Service Provider validation tool that can be run from the command line",
version=VERSION,
description="SAML2 SPID/CIE Service Provider validation tool that can be run from the command line",
long_description=readme(),
long_description_content_type='text/markdown',
classifiers=['Development Status :: 5 - Production/Stable',
Expand All @@ -21,7 +27,7 @@ def readme():
author='Giuseppe De Marco',
author_email='[email protected]',
license='License :: OSI Approved :: European Union Public Licence 1.2 (EUPL 1.2)',
scripts=['src/spid_sp_test/spid_sp_test'],
scripts=['src/spid_sp_test/bin/spid_sp_test'],
packages=[f"{_pkg_name}"],
package_dir={f"{_pkg_name}": f"{_src_folder}/{_pkg_name}"},

Expand Down
1 change: 1 addition & 0 deletions src/spid_sp_test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@


BASE_DIR = Path(__file__).resolve().parent
__version__ = '0.9.14'
logger = logging.getLogger(__name__)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import json
import logging
import os
import sys
sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir))
sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir))

from saml2.metadata import entity_descriptor
from saml2.server import Server
from spid_sp_test import BASE_DIR
from spid_sp_test import BASE_DIR, __version__
from spid_sp_test.metadata import SpidSpMetadataCheck
from spid_sp_test.metadata_extra import SpidSpMetadataCheckExtra
from spid_sp_test.authn_request import SpidSpAuthnReqCheck
Expand All @@ -34,7 +34,7 @@ def selective_run(obj, profile, meth_list):

if __name__ == '__main__':
_desc = (f'{__file__} -h for help')
_epilog = f"""examples:
_epilog = f"""spid_sp_test {__version__} usage examples:
{__file__} --metadata-url file://metadata.xml
{__file__} --metadata-url http://localhost:8000/spid/metadata --extra
{__file__} --metadata-url http://localhost:8000/spid/metadata -l test_Organization test_Signature
Expand Down Expand Up @@ -255,12 +255,22 @@ if __name__ == '__main__':
help='print out the default user attributes used in automatic responses'
)

parser.add_argument(
'-v', '--version',
required=False, action="store_true",
help='print out spid-sp-test version'
)


args = parser.parse_args()
logging.basicConfig(level=getattr(logging, args.debug))

if len(sys.argv) == 1:
parser.print_help(sys.stderr)
sys.exit(1)
elif args.version:
print(__version__)
sys.exit(0)

profile = f"test_profile_{args.profile.replace('-', '_')}"

Expand Down
2 changes: 1 addition & 1 deletion src/spid_sp_test/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def test_SPSSODescriptor_SPID(self):
else:
self._assertTrue(
False,
f"SPSSODescriptor element not found",
"SPSSODescriptor element not found",
test_id=[""],
**_data,
)
Expand Down
8 changes: 4 additions & 4 deletions src/spid_sp_test/metadata_extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,23 +129,23 @@ def test_SPSSODescriptor_extra(self):
else:
self._assertTrue(
False,
f"SPSSODescriptor element not found",
"SPSSODescriptor element not found",
test_id=[""],
**_data,
)
return self.is_ok(_method)

for attr in ["protocolSupportEnumeration", "WantAssertionsSigned"]:
self._assertTrue(
(attr in spsso[0].attrib),
(attr in _spsso.attrib),
f"The {attr} attribute MUST be present",
description=spsso[0].attrib,
test_id=["1.6.1", "1.6.7"],
**_data,
)

if attr == "protocolSupportEnumeration":
a = spsso[0].get(attr)
a = _spsso.get(attr)
self._assertTrue(
a, f"The {attr} attribute MUST have a value", description=a, **_data
)
Expand All @@ -160,7 +160,7 @@ def test_SPSSODescriptor_extra(self):
)

if attr == "WantAssertionsSigned":
a = spsso[0].get(attr)
a = _spsso.get(attr)
self._assertTrue(
a,
f"The {attr} attribute MUST have a value",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_01_metadata.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os

DIR='metadata'
CMD = "python3 src/spid_sp_test/spid_sp_test --metadata-url file://tests/{} --extra --debug ERROR"
CMD = "python3 src/spid_sp_test/bin/spid_sp_test --metadata-url file://tests/{} --extra --debug ERROR"


def run_cmd(mfname) -> int:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_02_authn.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os

BASE_CMD = "python3 src/spid_sp_test/spid_sp_test"
BASE_CMD = "python3 src/spid_sp_test/bin/spid_sp_test"
BASE_METADATA = "spid-django-other.xml"
CMD = BASE_CMD + " --extra --metadata-url file://tests/metadata/{} --authn-url file://tests/authn/{} --debug ERROR"

Expand Down
3 changes: 1 addition & 2 deletions tests/test_03_responses.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import os

CMD = "python3 src/spid_sp_test/spid_sp_test --metadata-url file://tests/metadata/spid-django-other.xml --authn-url file://tests/authn/spid_django_post.html --extra --debug ERROR -tr -nsr"
CMD = "python3 src/spid_sp_test/bin/spid_sp_test --metadata-url file://tests/metadata/spid-django-other.xml --authn-url file://tests/authn/spid_django_post.html --extra --debug ERROR -tr -nsr"


def test_all_default_responses():
es = os.system(CMD)
assert es == 0

0 comments on commit e963699

Please sign in to comment.