1
0
mirror of https://git.yoctoproject.org/poky synced 2026-05-30 00:20:08 +00:00

bitbake: hashserv: Add become-user API

Adds API that allows a user admin to impersonate another user in the
system. This makes it easier to write external services that have
external authentication, since they can use a common user account to
access the server, then impersonate the logged in user.

(Bitbake rev: 71e2f5b52b686f34df364ae1f2fc058f45cd5e18)

Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Joshua Watt
2023-11-03 08:26:32 -06:00
committed by Richard Purdie
parent 1af725b2ec
commit 8cfb94c06c
4 changed files with 97 additions and 5 deletions
+39
View File
@@ -728,6 +728,45 @@ class HashEquivalenceCommonTests(object):
self.assertEqual(user["username"], "test-user")
self.assertEqual(user["permissions"], permissions)
def test_auth_become_user(self):
admin_client = self.start_auth_server()
user = admin_client.new_user("test-user", ["@read", "@report"])
user_info = user.copy()
del user_info["token"]
with self.auth_perms() as client, self.assertRaises(InvokeError):
client.become_user(user["username"])
with self.auth_perms("@user-admin") as client:
become = client.become_user(user["username"])
self.assertEqual(become, user_info)
info = client.get_user()
self.assertEqual(info, user_info)
# Verify become user is preserved across disconnect
client.disconnect()
info = client.get_user()
self.assertEqual(info, user_info)
# test-user doesn't have become_user permissions, so this should
# not work
with self.assertRaises(InvokeError):
client.become_user(user["username"])
# No self-service of become
with self.auth_client(user) as client, self.assertRaises(InvokeError):
client.become_user(user["username"])
# Give test user permissions to become
admin_client.set_user_perms(user["username"], ["@user-admin"])
# It's possible to become yourself (effectively a noop)
with self.auth_perms("@user-admin") as client:
become = client.become_user(client.username)
class TestHashEquivalenceUnixServer(HashEquivalenceTestSetup, HashEquivalenceCommonTests, unittest.TestCase):
def get_server_addr(self, server_idx):