diff options
author | John Snow | 2021-04-21 20:20:22 +0200 |
---|---|---|
committer | Markus Armbruster | 2021-04-30 12:59:54 +0200 |
commit | 4918bb7defbdcb1e27cc2adf4e1604486d778ece (patch) | |
tree | 0082b34f878d1c7dc8cf42c493a2597de312f253 /tests/qapi-schema | |
parent | qapi/expr.py: move string check upwards in check_type (diff) | |
download | qemu-4918bb7defbdcb1e27cc2adf4e1604486d778ece.tar.gz qemu-4918bb7defbdcb1e27cc2adf4e1604486d778ece.tar.xz qemu-4918bb7defbdcb1e27cc2adf4e1604486d778ece.zip |
qapi/expr.py: Check type of union and alternate 'data' member
Prior to this commit, specifying a non-object value here causes the QAPI
parser to crash in expr.py with a stack trace with (likely) an
AttributeError when we attempt to call that value's items() method.
This member needs to be an object (Dict), and not anything else. Add a
check for this with a nicer error message, and formalize that check with
new test cases that exercise that error.
Signed-off-by: John Snow <jsnow@redhat.com>
Message-Id: <20210421182032.3521476-8-jsnow@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'tests/qapi-schema')
-rw-r--r-- | tests/qapi-schema/alternate-data-invalid.err | 2 | ||||
-rw-r--r-- | tests/qapi-schema/alternate-data-invalid.json | 4 | ||||
-rw-r--r-- | tests/qapi-schema/alternate-data-invalid.out | 0 | ||||
-rw-r--r-- | tests/qapi-schema/meson.build | 2 | ||||
-rw-r--r-- | tests/qapi-schema/union-invalid-data.err | 2 | ||||
-rw-r--r-- | tests/qapi-schema/union-invalid-data.json | 6 | ||||
-rw-r--r-- | tests/qapi-schema/union-invalid-data.out | 0 |
7 files changed, 16 insertions, 0 deletions
diff --git a/tests/qapi-schema/alternate-data-invalid.err b/tests/qapi-schema/alternate-data-invalid.err new file mode 100644 index 0000000000..55f1033aef --- /dev/null +++ b/tests/qapi-schema/alternate-data-invalid.err @@ -0,0 +1,2 @@ +alternate-data-invalid.json: In alternate 'Alt': +alternate-data-invalid.json:2: 'data' must be an object diff --git a/tests/qapi-schema/alternate-data-invalid.json b/tests/qapi-schema/alternate-data-invalid.json new file mode 100644 index 0000000000..7d5d905581 --- /dev/null +++ b/tests/qapi-schema/alternate-data-invalid.json @@ -0,0 +1,4 @@ +# Alternate type requires an object for 'data' +{ 'alternate': 'Alt', + 'data': ['rubbish', 'nonsense'] +} diff --git a/tests/qapi-schema/alternate-data-invalid.out b/tests/qapi-schema/alternate-data-invalid.out new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/qapi-schema/alternate-data-invalid.out diff --git a/tests/qapi-schema/meson.build b/tests/qapi-schema/meson.build index 8ba6917132..d7163e6601 100644 --- a/tests/qapi-schema/meson.build +++ b/tests/qapi-schema/meson.build @@ -14,6 +14,7 @@ schemas = [ 'alternate-conflict-string.json', 'alternate-conflict-bool-string.json', 'alternate-conflict-num-string.json', + 'alternate-data-invalid.json', 'alternate-empty.json', 'alternate-invalid-dict.json', 'alternate-nested.json', @@ -192,6 +193,7 @@ schemas = [ 'union-clash-branches.json', 'union-empty.json', 'union-invalid-base.json', + 'union-invalid-data.json', 'union-optional-branch.json', 'union-unknown.json', 'unknown-escape.json', diff --git a/tests/qapi-schema/union-invalid-data.err b/tests/qapi-schema/union-invalid-data.err new file mode 100644 index 0000000000..e26cf769a3 --- /dev/null +++ b/tests/qapi-schema/union-invalid-data.err @@ -0,0 +1,2 @@ +union-invalid-data.json: In union 'TestUnion': +union-invalid-data.json:2: 'data' must be an object diff --git a/tests/qapi-schema/union-invalid-data.json b/tests/qapi-schema/union-invalid-data.json new file mode 100644 index 0000000000..395ba24d39 --- /dev/null +++ b/tests/qapi-schema/union-invalid-data.json @@ -0,0 +1,6 @@ +# the union data type must be an object. +{ 'union': 'TestUnion', + 'base': 'int', + 'discriminator': 'int', + 'data': ['rubbish', 'nonsense'] +} diff --git a/tests/qapi-schema/union-invalid-data.out b/tests/qapi-schema/union-invalid-data.out new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/qapi-schema/union-invalid-data.out |