Skip to content

Commit

Permalink
Remove six module
Browse files Browse the repository at this point in the history
  • Loading branch information
gcoxmoz committed Dec 28, 2023
1 parent a8b33f1 commit f124e8f
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 36 deletions.
8 changes: 2 additions & 6 deletions iamvpnlibrary/iamvpnbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@
import re
import collections
import ast
try:
import configparser
except ImportError: # pragma: no cover
from six.moves import configparser
import six
import configparser

ParsedACL = collections.namedtuple(
'ParsedACL', ['rule', 'address', 'portstring', 'description'])
Expand Down Expand Up @@ -92,7 +88,7 @@ def verify_sudo_user(self, username_is=None, username_as=None):
# We will override this only after going through a gauntlet:
if username_is and username_as:
# ^ bypass on deletes
if (isinstance(self.sudo_username_regexp, six.string_types) and
if (isinstance(self.sudo_username_regexp, str) and
isinstance(self.sudo_users, list) and username_is in self.sudo_users):
# ^ This is deliberately unforgiving, as a safety measure.
# At this point we have:
Expand Down
21 changes: 10 additions & 11 deletions iamvpnlibrary/iamvpnldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import re
import socket
import ldap
import six
import netaddr
from .iamvpnbase import IAMVPNLibraryBase, ParsedACL

Expand Down Expand Up @@ -140,7 +139,7 @@ def _get_user_dn_by_username(self, input_username):
return: str of their DN
raises if there's no such user.
"""
if not isinstance(input_username, six.string_types):
if not isinstance(input_username, str):
raise TypeError(input_username, 'Argument must be a string')
res = self.conn.search_s(
self.config.get('ldap_base'), ldap.SCOPE_SUBTREE,
Expand Down Expand Up @@ -269,7 +268,7 @@ def _split_vpn_acl_string(input_string): # pylint: disable=too-many-branches
return: ParsedACL
raise for horrible inputs
"""
if not isinstance(input_string, six.string_types):
if not isinstance(input_string, str):
raise TypeError(input_string, 'Argument must be a string')
# input_string should be:
# '1.1.1.1 # foo.m.c'
Expand Down Expand Up @@ -361,7 +360,7 @@ def _fetch_vpn_acls_for_user(self, input_email):
input_email: "[email protected]"
return: ldap response
"""
if not isinstance(input_email, six.string_types):
if not isinstance(input_email, str):
raise TypeError(input_email, 'Argument must be a string')
user_dn = self._get_user_dn_by_username(input_email)
rdn_attr = self.config.get('ldap_vpn_acls_rdn_attribute')
Expand Down Expand Up @@ -401,7 +400,7 @@ def _sanitized_vpn_acls_for_user(self, input_email): # pylint: disable=too-many
different people want different results (every ACL? every IP?
Just the IPs? What about a CIDR that encapsulates another?)
"""
if not isinstance(input_email, six.string_types):
if not isinstance(input_email, str):
raise TypeError(input_email, 'Argument must be a string')
raw_acls = self._fetch_vpn_acls_for_user(input_email)
acls = []
Expand Down Expand Up @@ -482,7 +481,7 @@ def user_allowed_to_vpn(self, input_email):
Outside user: duo_openvpn
Outside user: duo_openvpn kill script
"""
if not isinstance(input_email, six.string_types):
if not isinstance(input_email, str):
raise TypeError(input_email, 'Argument must be a string')
if not self.is_online():
return self.fail_open
Expand Down Expand Up @@ -513,7 +512,7 @@ def does_user_require_vpn_mfa(self, input_email):
Outside user: duo_openvpn
"""
if not isinstance(input_email, six.string_types):
if not isinstance(input_email, str):
raise TypeError(input_email, 'Argument must be a string')
if not self.is_online():
# This is going to be a bit of mental gymnastics.
Expand Down Expand Up @@ -570,7 +569,7 @@ def get_allowed_vpn_ips(self, input_email):
Outside user: openvpn-client-connect
"""
if not isinstance(input_email, six.string_types):
if not isinstance(input_email, str):
raise TypeError(input_email, 'Argument must be a string')
if not self.is_online():
# Absentee server means no IPs
Expand All @@ -591,7 +590,7 @@ def get_allowed_vpn_acls(self, input_email):
Outside user: openvpn-netfilter
"""
if not isinstance(input_email, six.string_types):
if not isinstance(input_email, str):
raise TypeError(input_email, 'Argument must be a string')
if not self.is_online():
# Absentee server means no ACLs
Expand All @@ -614,9 +613,9 @@ def non_mfa_vpn_authentication(self, input_username, input_password):
Outside user: duo_openvpn
"""
if not isinstance(input_username, six.string_types):
if not isinstance(input_username, str):
raise TypeError(input_username, 'Argument must be a string')
if not isinstance(input_password, six.string_types):
if not isinstance(input_password, str):
raise TypeError(input_password, 'Argument must be a string')
if not self.is_online():
# A user could not be looked up. fail open as needed.
Expand Down
5 changes: 1 addition & 4 deletions test/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@

import unittest
import os
import configparser
import test.context # pylint: disable=unused-import
import mock
from iamvpnlibrary.iamvpnbase import IAMVPNLibraryBase
try:
import configparser
except ImportError: # pragma: no cover
from six.moves import configparser


class TestBaseFunctions(unittest.TestCase):
Expand Down
11 changes: 5 additions & 6 deletions test/test_private_ldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from netaddr import IPNetwork
import mock
import ldap
import six
from iamvpnlibrary.iamvpnldap import IAMVPNLibraryLDAP
from iamvpnlibrary.iamvpnbase import ParsedACL

Expand Down Expand Up @@ -145,7 +144,7 @@ def test_fetch_vpn_acls_for_user(self):
# the LDAP format changed. Most of this you don't need to stare at.
self.assertIsInstance(acl, tuple,
'Did not get an LDAP ACL tuple')
self.assertIsInstance(acl[0], six.string_types,
self.assertIsInstance(acl[0], str,
('The supposed LDAP ACL tuple did not have '
'a DN string as arg 0'))
self.assertIsInstance(acl[1], dict,
Expand Down Expand Up @@ -235,18 +234,18 @@ def test_sanitized_vpn_acls(self):
self.assertIsInstance(pacl, ParsedACL,
'Did not return a list of ParsedACLs')
# rule can be empty
self.assertIsInstance(pacl.rule, six.string_types,
self.assertIsInstance(pacl.rule, str,
'The ParsedACL rule was not a string')
# address is an object and must be there
self.assertIsInstance(pacl.address, IPNetwork,
'The ParsedACL address was not an IPNetwork')
self.assertGreaterEqual(pacl.address.size, 1,
'The ParsedACL address did not have a size?')
# portstring can be empty
self.assertIsInstance(pacl.portstring, six.string_types,
self.assertIsInstance(pacl.portstring, str,
'The ParsedACL portstring was not a string')
# description can be empty
self.assertIsInstance(pacl.description, six.string_types,
self.assertIsInstance(pacl.description, str,
'The ParsedACL description was not a string')

def test_vpn_mfa_exempt_users(self):
Expand Down Expand Up @@ -297,7 +296,7 @@ def test_get_user_dn_by_username(self):
if self.normal_user is None: # pragma: no cover
self.skipTest('Must provide a .normal_user to test')
result = self.library._get_user_dn_by_username(self.normal_user)
self.assertIsInstance(result, six.string_types,
self.assertIsInstance(result, str,
'search for username must return a DN string')
self.assertIn(','+self.library.config['ldap_base'], result,
('A random user from the set does not match '
Expand Down
9 changes: 4 additions & 5 deletions test/test_public_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from netaddr import IPNetwork
import mock
import ldap
import six
from iamvpnlibrary import IAMVPNLibrary
from iamvpnlibrary.iamvpnbase import ParsedACL
from iamvpnlibrary.iamvpnldap import IAMVPNLibraryLDAP
Expand Down Expand Up @@ -80,7 +79,7 @@ def test_02_serverup_good(self):
self.assertGreater(len(result), 5,
'If this failed, someone has very few acls.')
addr = result[0]
self.assertIsInstance(addr, six.string_types,
self.assertIsInstance(addr, str,
'Check did not return IP strings')
try:
# verify that we're returning parseable strings
Expand Down Expand Up @@ -122,18 +121,18 @@ def test_03_serverup_good(self):
self.assertIsInstance(pacl, ParsedACL,
'Did not return a list of ParsedACLs')
# rule can be empty
self.assertIsInstance(pacl.rule, six.string_types,
self.assertIsInstance(pacl.rule, str,
'The ParsedACL rule was not a string')
# address is an object and must be there
self.assertIsInstance(pacl.address, IPNetwork,
'The ParsedACL address was not an IPNetwork')
self.assertGreaterEqual(pacl.address.size, 1,
'The ParsedACL address did not have a size?')
# portstring can be empty
self.assertIsInstance(pacl.portstring, six.string_types,
self.assertIsInstance(pacl.portstring, str,
'The ParsedACL portstring was not a string')
# description can be empty
self.assertIsInstance(pacl.description, six.string_types,
self.assertIsInstance(pacl.description, str,
'The ParsedACL description was not a string')

def test_03_serverup_bad(self):
Expand Down
5 changes: 1 addition & 4 deletions test/test_spinup_ldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@
# file, so, we tell pylint that we're cool with it:

import unittest
import configparser
import test.context # pylint: disable=unused-import
import netaddr
from netaddr import IPNetwork
import mock
import ldap
from iamvpnlibrary.iamvpnbase import IAMVPNLibraryBase, ParsedACL
from iamvpnlibrary.iamvpnldap import IAMVPNLibraryLDAP
try:
import configparser
except ImportError: # pragma: no cover
from six.moves import configparser


class TestLDAPSpinup(unittest.TestCase):
Expand Down

0 comments on commit f124e8f

Please sign in to comment.