2011-10-19 05:35:22 +04:00
# Unix SMB/CIFS implementation.
# Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2011
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
""" Tests for option parsing.
"""
import optparse
from samba . getopt import (
AUTO_USE_KERBEROS ,
DONT_USE_KERBEROS ,
MUST_USE_KERBEROS ,
2021-04-07 15:16:52 +03:00
parse_kerberos_arg_legacy ,
2011-10-19 05:35:22 +04:00
parse_kerberos_arg ,
2018-07-30 09:14:37 +03:00
)
2011-10-19 05:35:22 +04:00
import samba . tests
2018-07-30 09:20:39 +03:00
2011-10-19 05:35:22 +04:00
class KerberosOptionTests ( samba . tests . TestCase ) :
2021-04-07 15:16:52 +03:00
def test_legacy_parse_true ( self ) :
2020-02-07 01:02:38 +03:00
self . assertEqual (
2021-04-07 15:16:52 +03:00
MUST_USE_KERBEROS , parse_kerberos_arg_legacy ( " yes " , " --kerberos " ) )
2020-02-07 01:02:38 +03:00
self . assertEqual (
2021-04-07 15:16:52 +03:00
MUST_USE_KERBEROS , parse_kerberos_arg_legacy ( " true " , " --kerberos " ) )
2020-02-07 01:02:38 +03:00
self . assertEqual (
2021-04-07 15:16:52 +03:00
MUST_USE_KERBEROS , parse_kerberos_arg_legacy ( " 1 " , " --kerberos " ) )
2011-10-19 05:35:22 +04:00
2021-04-07 15:16:52 +03:00
def test_legacy_parse_false ( self ) :
2020-02-07 01:02:38 +03:00
self . assertEqual (
2021-04-07 15:16:52 +03:00
DONT_USE_KERBEROS , parse_kerberos_arg_legacy ( " no " , " --kerberos " ) )
2020-02-07 01:02:38 +03:00
self . assertEqual (
2021-04-07 15:16:52 +03:00
DONT_USE_KERBEROS , parse_kerberos_arg_legacy ( " false " , " --kerberos " ) )
2020-02-07 01:02:38 +03:00
self . assertEqual (
2021-04-07 15:16:52 +03:00
DONT_USE_KERBEROS , parse_kerberos_arg_legacy ( " 0 " , " --kerberos " ) )
2011-10-19 05:35:22 +04:00
2021-04-07 15:16:52 +03:00
def test_legacy_parse_auto ( self ) :
2020-02-07 01:02:38 +03:00
self . assertEqual (
2021-04-07 15:16:52 +03:00
AUTO_USE_KERBEROS , parse_kerberos_arg_legacy ( " auto " , " --kerberos " ) )
def test_legacy_parse_invalid ( self ) :
self . assertRaises ( optparse . OptionValueError ,
parse_kerberos_arg_legacy , " blah? " , " --kerberos " )
def test_parse_valid ( self ) :
self . assertEqual (
MUST_USE_KERBEROS , parse_kerberos_arg ( " required " , " --use-kerberos " ) )
self . assertEqual (
AUTO_USE_KERBEROS , parse_kerberos_arg ( " desired " , " --use-kerberos " ) )
self . assertEqual (
DONT_USE_KERBEROS , parse_kerberos_arg ( " off " , " --use-kerberos " ) )
2011-10-19 05:35:22 +04:00
def test_parse_invalid ( self ) :
self . assertRaises ( optparse . OptionValueError ,
2021-04-07 15:16:52 +03:00
parse_kerberos_arg , " wurst " , " --use-kerberos " )