From 1257fc18c8816e024d519f1db6ad9bae79feccc0 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Mon, 10 May 2021 11:10:52 -0400 Subject: [PATCH] Additional test coverage and corresponding bug fixes for password auth on Python 3. --- src/allmydata/frontends/auth.py | 2 +- src/allmydata/test/test_auth.py | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/allmydata/frontends/auth.py b/src/allmydata/frontends/auth.py index f2ac99b8f..376cdebe4 100644 --- a/src/allmydata/frontends/auth.py +++ b/src/allmydata/frontends/auth.py @@ -80,5 +80,5 @@ class AccountFileChecker(object): return defer.fail(error.UnauthorizedLogin()) d = defer.maybeDeferred(creds.checkPassword, correct) - d.addCallback(self._cbPasswordMatch, str(creds.username)) + d.addCallback(self._cbPasswordMatch, creds.username) return d diff --git a/src/allmydata/test/test_auth.py b/src/allmydata/test/test_auth.py index f808f72ab..4922ca5f3 100644 --- a/src/allmydata/test/test_auth.py +++ b/src/allmydata/test/test_auth.py @@ -65,7 +65,7 @@ class AccountFileCheckerKeyTests(unittest.TestCase): avatarId = self.checker.requestAvatarId(key_credentials) return self.assertFailure(avatarId, error.UnauthorizedLogin) - def test_password_auth_user(self): + def test_password_auth_user_with_ssh_key(self): """ AccountFileChecker.requestAvatarId returns a Deferred that fires with UnauthorizedLogin if called with an SSHPrivateKey object for a username @@ -76,6 +76,29 @@ class AccountFileCheckerKeyTests(unittest.TestCase): avatarId = self.checker.requestAvatarId(key_credentials) return self.assertFailure(avatarId, error.UnauthorizedLogin) + def test_password_auth_user_with_correct_password(self): + """ + AccountFileChecker.requestAvatarId returns a Deferred that fires with + the user if the correct password is given. + """ + key_credentials = credentials.UsernamePassword(b"alice", b"password") + d = self.checker.requestAvatarId(key_credentials) + def authenticated(avatarId): + self.assertEqual( + (b"alice", + b"URI:DIR2:aaaaaaaaaaaaaaaaaaaaaaaaaa:1111111111111111111111111111111111111111111111111111"), + (avatarId.username, avatarId.rootcap)) + return d + + def test_password_auth_user_with_wrong_password(self): + """ + AccountFileChecker.requestAvatarId returns a Deferred that fires with + UnauthorizedLogin if the wrong password is given. + """ + key_credentials = credentials.UsernamePassword(b"alice", b"WRONG") + avatarId = self.checker.requestAvatarId(key_credentials) + return self.assertFailure(avatarId, error.UnauthorizedLogin) + def test_unrecognized_key(self): """ AccountFileChecker.requestAvatarId returns a Deferred that fires with