From a5c0e11ec133200424649abdcfd7a5f90fc7b854 Mon Sep 17 00:00:00 2001 From: Giulia Naponiello Date: May 26 2018 00:14:13 +0000 Subject: Handling the JSON subject Checking that the subject is actually a JSON, otherwise return an error. --- diff --git a/tests/test_cli.py b/tests/test_cli.py index d3a6054..930544d 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -77,6 +77,24 @@ oidc_client_id=waiverdb assert result.output == 'Error: The config option "oidc_scopes" is required\n' +def test_malformed_subject(tmpdir): + p = tmpdir.join('client.conf') + p.write(""" +[waiverdb] +auth_method=OIDC +api_url=http://localhost:5004/api/v1.0 +oidc_id_provider=https://id.stg.fedoraproject.org/openidc/ +oidc_client_id=waiverdb +oidc_scopes= + openid + """) + runner = CliRunner() + args = ['-C', p.strpath, '-s', 'subject', '-t', 'testcase', '-c', 'comment'] + result = runner.invoke(waiverdb_cli, args) + assert result.exit_code == 1 + assert result.output == ('Error: Subject must be a JSON value.\n') + + def test_no_product_version(tmpdir): p = tmpdir.join('client.conf') p.write(""" diff --git a/waiverdb/cli.py b/waiverdb/cli.py index 493cfba..bbf0f3b 100644 --- a/waiverdb/cli.py +++ b/waiverdb/cli.py @@ -98,6 +98,11 @@ def cli(comment, waived, product_version, testcase, subject, result_id, config_f raise click.ClickException('Please specify one subject') if not result_ids and not testcase: raise click.ClickException('Please specify testcase') + if not result_ids and subject and testcase: + try: + json.loads(subject) + except json.JSONDecodeError: + raise click.ClickException('Subject must be a JSON value.') auth_method = config.get('waiverdb', 'auth_method') data_list = []