Skip to content

Hopefully fix test issues around high-level mechanism support and indicate/inquire mechs. #159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gssapi/mechs.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def __unicode__(self):

def _bytes_desc(self):
base = self.dotted_form
if rfc5801 is not None:
if rfc5801 is not None and self._saslname and self._saslname.mech_name:
base = self._saslname.mech_name

if isinstance(base, six.text_type):
Expand Down
12 changes: 6 additions & 6 deletions gssapi/tests/test_high_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,18 +380,18 @@ def test_indicate_mechs(self):
@ktu.gssapi_extension_test('rfc5801', 'RFC 5801: SASL Names')
def test_sasl_properties(self):
mechs = gssmechs.Mechanism.all_mechs()
encoding = gssutils._get_encoding()
for mech in mechs:
s = str(mech)
s.shouldnt_be_empty()
s.should_be_a(str)
s.should_be(mech._saslname.mech_name.decode(encoding))

mech.sasl_name.shouldnt_be_empty()
mech.sasl_name.should_be_a(six.text_type)
# Note that some mechanisms don't have SASL names or SASL
# descriptions; in this case, GSSAPI returns empty strings.
if mech.sasl_name:
mech.sasl_name.should_be_a(six.text_type)

mech.description.shouldnt_be_empty()
mech.description.should_be_a(six.text_type)
if mech.description:
mech.description.should_be_a(six.text_type)

cmp_mech = gssmechs.Mechanism.from_sasl_name(mech.sasl_name)
str(cmp_mech).should_be(str(mech))
Expand Down
45 changes: 28 additions & 17 deletions gssapi/tests/test_raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,17 +656,17 @@ def test_rfc5587(self):
mechs.should_be_a(set)
mechs.shouldnt_be_empty()

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

for mech in mechs:
mech.shouldnt_be_none()
mech.should_be_a(gb.OID)
last_mech = mech

inquire_out = gb.inquire_attrs_for_mech(mech)
mech_attrs = inquire_out.mech_attrs
Expand All @@ -691,7 +691,9 @@ def test_rfc5587(self):
display_out.short_desc.should_be_a(bytes)
display_out.long_desc.should_be_a(bytes)

last_attr = mech_attr
if mech_attr not in attrs_dict:
attrs_dict[mech_attr] = set()
attrs_dict[mech_attr].add(mech)

for mech_attr in known_mech_attrs:
mech_attr.shouldnt_be_none()
Expand All @@ -705,18 +707,27 @@ def test_rfc5587(self):
display_out.short_desc.should_be_a(bytes)
display_out.long_desc.should_be_a(bytes)

attrs = set([last_attr])
if mech_attr not in known_attrs_dict:
known_attrs_dict[mech_attr] = set()
known_attrs_dict[mech_attr].add(mech)

mechs = gb.indicate_mechs_by_attrs(attrs, None, None)
mechs.shouldnt_be_empty()
mechs.should_include(last_mech)
for attr, expected_mechs in attrs_dict.items():
attrs = set([attr])

mechs = gb.indicate_mechs_by_attrs(None, attrs, None)
mechs.shouldnt_include(last_mech)
mechs = gb.indicate_mechs_by_attrs(attrs, None, None)
mechs.shouldnt_be_empty()
mechs.should_be(expected_mechs)

mechs = gb.indicate_mechs_by_attrs(None, None, attrs)
mechs.shouldnt_be_empty()
mechs.should_include(last_mech)
mechs = gb.indicate_mechs_by_attrs(None, attrs, None)
for expected_mech in expected_mechs:
mechs.shouldnt_include(expected_mech)

for attr, expected_mechs in known_attrs_dict.items():
attrs = set([attr])

mechs = gb.indicate_mechs_by_attrs(None, None, attrs)
mechs.shouldnt_be_empty()
mechs.should_be(expected_mechs)

@ktu.gssapi_extension_test('rfc5587', 'RFC 5587')
def test_display_mech_attr(self):
Expand Down