Skip to content

Commit de55865

Browse files
committed
Test for attr membership on a frequently-used attr
While this can still fail, less likely to fail than querying on the last-seen attr. In particular, some mechanisms will not respond to an inquiry for that attr despite claiming to have it. Signed-off-by: Alexander Scheel <[email protected]>
1 parent 48c84a8 commit de55865

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

gssapi/tests/test_raw.py

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -656,17 +656,17 @@ def test_rfc5587(self):
656656
mechs.should_be_a(set)
657657
mechs.shouldnt_be_empty()
658658

659-
# We need last_attr to be an attribute on last_mech.
660-
# Since mechs is of type set and thus not indexable, these
661-
# are used to track the last visited mech for testing
662-
# purposes, and saves a call to inquire_attrs_for_mech().
663-
last_attr = None
664-
last_mech = None
659+
# We're validating RFC 5587 here: by iterating over all mechanisms,
660+
# we can query their attributes and build a mapping of attr->{mechs}.
661+
# To test indicate_mechs_by_attrs, we can use this mapping and
662+
# ensure that, when the attribute is placed in a slot, we get the
663+
# expected result (e.g., attr in have --> mechs are present).
664+
attrs_dict = {}
665+
known_attrs_dict = {}
665666

666667
for mech in mechs:
667668
mech.shouldnt_be_none()
668669
mech.should_be_a(gb.OID)
669-
last_mech = mech
670670

671671
inquire_out = gb.inquire_attrs_for_mech(mech)
672672
mech_attrs = inquire_out.mech_attrs
@@ -691,7 +691,9 @@ def test_rfc5587(self):
691691
display_out.short_desc.should_be_a(bytes)
692692
display_out.long_desc.should_be_a(bytes)
693693

694-
last_attr = mech_attr
694+
if mech_attr not in attrs_dict:
695+
attrs_dict[mech_attr] = set()
696+
attrs_dict[mech_attr].add(mech)
695697

696698
for mech_attr in known_mech_attrs:
697699
mech_attr.shouldnt_be_none()
@@ -705,18 +707,27 @@ def test_rfc5587(self):
705707
display_out.short_desc.should_be_a(bytes)
706708
display_out.long_desc.should_be_a(bytes)
707709

708-
attrs = set([last_attr])
710+
if mech_attr not in known_attrs_dict:
711+
known_attrs_dict[mech_attr] = set()
712+
known_attrs_dict[mech_attr].add(mech)
709713

710-
mechs = gb.indicate_mechs_by_attrs(attrs, None, None)
711-
mechs.shouldnt_be_empty()
712-
mechs.should_include(last_mech)
714+
for attr, expected_mechs in attrs_dict.items():
715+
attrs = set([attr])
713716

714-
mechs = gb.indicate_mechs_by_attrs(None, attrs, None)
715-
mechs.shouldnt_include(last_mech)
717+
mechs = gb.indicate_mechs_by_attrs(attrs, None, None)
718+
mechs.shouldnt_be_empty()
719+
mechs.should_be(expected_mechs)
716720

717-
mechs = gb.indicate_mechs_by_attrs(None, None, attrs)
718-
mechs.shouldnt_be_empty()
719-
mechs.should_include(last_mech)
721+
mechs = gb.indicate_mechs_by_attrs(None, attrs, None)
722+
for expected_mech in expected_mechs:
723+
mechs.shouldnt_include(expected_mech)
724+
725+
for attr, expected_mechs in known_attrs_dict.items():
726+
attrs = set([attr])
727+
728+
mechs = gb.indicate_mechs_by_attrs(None, None, attrs)
729+
mechs.shouldnt_be_empty()
730+
mechs.should_be(expected_mechs)
720731

721732
@ktu.gssapi_extension_test('rfc5587', 'RFC 5587')
722733
def test_display_mech_attr(self):

0 commit comments

Comments
 (0)