Skip to content

Commit 4f30d86

Browse files
author
Rebecka Gulliksson
committed
Make metadata script possible to test without Click test runner.
1 parent 7f5daae commit 4f30d86

File tree

2 files changed

+17
-20
lines changed

2 files changed

+17
-20
lines changed

src/satosa/scripts/satosa_saml_metadata.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
from saml2.config import Config
55
from saml2.sigver import security_context
66

7-
from satosa.metadata_creation.saml_metadata import create_signed_entities_descriptor
87
from ..metadata_creation.saml_metadata import create_entity_descriptors
8+
from ..metadata_creation.saml_metadata import create_signed_entities_descriptor
99
from ..satosa_config import SATOSAConfig
1010

1111

@@ -16,16 +16,7 @@ def _get_security_context(key, cert):
1616
return security_context(conf)
1717

1818

19-
@click.command()
20-
@click.argument("proxy_conf")
21-
@click.argument("key")
22-
@click.argument("cert")
23-
@click.option("--dir",
24-
type=click.Path(exists=True, file_okay=False, dir_okay=True, writable=True, readable=False,
25-
resolve_path=False),
26-
default=".", help="Where the output files should be written.")
27-
@click.option("--valid", type=click.INT, default=None, help="Number of hours the metadata should be valid.")
28-
def construct_saml_metadata(proxy_conf, key, cert, dir, valid):
19+
def create_and_write_saml_metadata(proxy_conf, key, cert, dir, valid):
2920
"""
3021
Generates SAML metadata for the given PROXY_CONF, signed with the given KEY and associated CERT.
3122
"""
@@ -42,3 +33,16 @@ def construct_saml_metadata(proxy_conf, key, cert, dir, valid):
4233
print("Writing metadata to '{}'".format(path))
4334
with open(path, "w") as f:
4435
f.write(metadata)
36+
37+
38+
@click.command()
39+
@click.argument("proxy_conf")
40+
@click.argument("key")
41+
@click.argument("cert")
42+
@click.option("--dir",
43+
type=click.Path(exists=True, file_okay=False, dir_okay=True, writable=True, readable=False,
44+
resolve_path=False),
45+
default=".", help="Where the output files should be written.")
46+
@click.option("--valid", type=click.INT, default=None, help="Number of hours the metadata should be valid.")
47+
def construct_saml_metadata(proxy_conf, key, cert, dir, valid):
48+
create_and_write_saml_metadata(proxy_conf, key, cert, dir, valid)

tests/satosa/scripts/test_satosa_saml_metadata.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import glob
2-
import json
32
import os
43

5-
from click.testing import CliRunner
64
from saml2.config import Config
75
from saml2.mdstore import MetaDataFile
86
from saml2.sigver import security_context
97

10-
from satosa.scripts.satosa_saml_metadata import construct_saml_metadata
8+
from satosa.scripts.satosa_saml_metadata import create_and_write_saml_metadata
119

1210

1311
class TestConstructSAMLMetadata:
@@ -16,12 +14,7 @@ def test_command(self, tmpdir, cert_and_key, satosa_config_dict, saml_frontend_c
1614
satosa_config_dict["FRONTEND_MODULES"] = [saml_frontend_config]
1715
satosa_config_dict["BACKEND_MODULES"] = [saml_backend_config]
1816

19-
config_path = os.path.join(str(tmpdir), "config.yaml")
20-
with open(config_path, "w") as f:
21-
f.write(json.dumps(satosa_config_dict))
22-
23-
runner = CliRunner()
24-
runner.invoke(construct_saml_metadata, [config_path, cert_and_key[1], cert_and_key[0], '--dir', str(tmpdir)])
17+
create_and_write_saml_metadata(satosa_config_dict, cert_and_key[1], cert_and_key[0], str(tmpdir), None)
2518

2619
conf = Config()
2720
conf.cert_file = cert_and_key[0]

0 commit comments

Comments
 (0)