@@ -656,17 +656,17 @@ def test_rfc5587(self):
656
656
mechs .should_be_a (set )
657
657
mechs .shouldnt_be_empty ()
658
658
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 = {}
665
666
666
667
for mech in mechs :
667
668
mech .shouldnt_be_none ()
668
669
mech .should_be_a (gb .OID )
669
- last_mech = mech
670
670
671
671
inquire_out = gb .inquire_attrs_for_mech (mech )
672
672
mech_attrs = inquire_out .mech_attrs
@@ -691,7 +691,9 @@ def test_rfc5587(self):
691
691
display_out .short_desc .should_be_a (bytes )
692
692
display_out .long_desc .should_be_a (bytes )
693
693
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 )
695
697
696
698
for mech_attr in known_mech_attrs :
697
699
mech_attr .shouldnt_be_none ()
@@ -705,18 +707,27 @@ def test_rfc5587(self):
705
707
display_out .short_desc .should_be_a (bytes )
706
708
display_out .long_desc .should_be_a (bytes )
707
709
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 )
709
713
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 ])
713
716
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 )
716
720
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 )
720
731
721
732
@ktu .gssapi_extension_test ('rfc5587' , 'RFC 5587' )
722
733
def test_display_mech_attr (self ):
0 commit comments