]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
pytest: token_factory copes with empty claims
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Mon, 13 Nov 2023 00:36:00 +0000 (13:36 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Mon, 27 Nov 2023 22:37:32 +0000 (22:37 +0000)
We don't have a good story yet with regard to empty claims, but we at
least want to be able to create them in tests.

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/tests/token_factory.py

index b2d17b4356c92cf33fe058e97237a70a3f6e9d4c..74a0f6baa57287e688bbd3e2d6d042487fef7fb0 100644 (file)
@@ -43,17 +43,17 @@ def list_to_claim(k, v, case_sensitive=False):
 
     c = security.CLAIM_SECURITY_ATTRIBUTE_RELATIVE_V1()
 
-    if len(v) == 0:
-        raise ValueError("empty claim lists are not valid"
-                         f" (for {k})")
-
-    t = type(v[0])
-    for val in v[1:]:
-        if type(val) != t:
-            raise TypeError(f"claim values for '{k}' "
-                            "should all be the same type")
+    if len(v) != 0:
+        t = type(v[0])
+        c.value_type = CLAIM_VAL_TYPES[t]
+        for val in v[1:]:
+            if type(val) != t:
+                raise TypeError(f"claim values for '{k}' "
+                                "should all be the same type")
+    else:
+        # pick an arbitrary type
+        c.value_type = CLAIM_VAL_TYPES['uint']
     c.name = k
-    c.value_type = CLAIM_VAL_TYPES[t]
     c.values = v
     c.value_count = len(v)
     if case_sensitive: