diff options
author | Jeff Forcier <jeff@bitprophet.org> | 2023-05-18 16:50:42 -0400 |
---|---|---|
committer | Jeff Forcier <jeff@bitprophet.org> | 2023-05-22 12:22:05 -0400 |
commit | ce454580c03997d9b5873fe31e1ce27d1c64cf12 (patch) | |
tree | a0e2234b832b0ddda194da03c92b01d0f5ce6f2e /tests | |
parent | 31a5a30cf50d3971693417ccfd1e15c1f8302147 (diff) |
Start testing AuthStrategy
Plus!
- Document AuthStrategy and AuthHandler modules (latter never had docs?
lol)
- Minor tweaks to these modules' docstrings etc
- Stop comparing to __all__ in __init__.py, ugh
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auth.py | 42 | ||||
-rw-r--r-- | tests/test_util.py | 6 |
2 files changed, 46 insertions, 2 deletions
diff --git a/tests/auth.py b/tests/auth.py index 23d578d0..eacaf210 100644 --- a/tests/auth.py +++ b/tests/auth.py @@ -4,12 +4,16 @@ Tests focusing primarily on the authentication step. Thus, they concern AuthHandler and AuthStrategy, with a side of Transport. """ +from unittest.mock import Mock + from pytest import raises from paramiko import ( AuthenticationException, + AuthSource, BadAuthenticationType, DSSKey, + NoneAuth, PKey, RSAKey, SSHException, @@ -278,7 +282,6 @@ class SHA2SignaturePubkeys: privkey = RSAKey.from_private_key_file(_support("rsa.key")) with server( pubkeys=[privkey], - # TODO: why is this passing without a username? connect=dict(pkey=privkey), init=dict( disabled_algorithms=dict(pubkeys=["ssh-rsa", "rsa-sha2-256"]) @@ -311,3 +314,40 @@ class SHA2SignaturePubkeys: ) as (tc, ts): assert tc.is_authenticated() assert tc._agreed_pubkey_algorithm == "rsa-sha2-256" + + +class AuthSource_: + class base_class: + def init_requires_and_saves_username(self): + with raises(TypeError): + AuthSource() + assert AuthSource(username="foo").username == "foo" + + def dunder_repr_delegates_to_helper(self): + source = AuthSource("foo") + source._repr = Mock(wraps=lambda: "whatever") + repr(source) + source._repr.assert_called_once_with() + + def repr_helper_prints_basic_kv_pairs(self): + assert repr(AuthSource("foo")) == "AuthSource()" + assert ( + AuthSource("foo")._repr(bar="open") == "AuthSource(bar='open')" + ) + + def authenticate_takes_transport_and_is_abstract(self): + # TODO: this test kinda just goes away once we're typed? + with raises(TypeError): + AuthSource("foo").authenticate() + with raises(NotImplementedError): + AuthSource("foo").authenticate(None) + + class NoneAuth_: + def authenticate_auths_none(self): + trans = Mock() + NoneAuth("foo").authenticate(trans) + trans.auth_none.assert_called_once_with("foo") + + +class AuthStrategy_: + pass diff --git a/tests/test_util.py b/tests/test_util.py index ec03846b..4a8cf972 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -49,6 +49,9 @@ class UtilTest(unittest.TestCase): "Agent", "AgentKey", "AuthenticationException", + "AuthHandler", + "AuthSource", + "AuthStrategy", "AutoAddPolicy", "BadAuthenticationType", "BufferedFile", @@ -60,6 +63,7 @@ class UtilTest(unittest.TestCase): "HostKeys", "Message", "MissingHostKeyPolicy", + "NoneAuth", "PasswordRequiredException", "RSAKey", "RejectPolicy", @@ -82,7 +86,7 @@ class UtilTest(unittest.TestCase): "WarningPolicy", "util", ): - assert name in paramiko.__all__ + assert name in dir(paramiko) def test_generate_key_bytes(self): key_bytes = paramiko.util.generate_key_bytes( |