mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-02 07:17:57 +02:00
tests: add secret agent API test tool
This commit is contained in:
parent
fc82bbc412
commit
ca1338007c
2 changed files with 74 additions and 0 deletions
|
|
@ -39,6 +39,12 @@ test_policy_hosts_LDADD = \
|
|||
$(top_builddir)/src/libtest-policy-hosts.la \
|
||||
$(GLIB_LIBS)
|
||||
|
||||
####### secret agent interface test #######
|
||||
|
||||
EXTRA_DIST = test-secret-agent.py
|
||||
|
||||
###########################################
|
||||
|
||||
if WITH_TESTS
|
||||
|
||||
check-local: test-dhcp-options test-policy-hosts
|
||||
|
|
|
|||
68
src/tests/test-secret-agent.py
Executable file
68
src/tests/test-secret-agent.py
Executable file
|
|
@ -0,0 +1,68 @@
|
|||
#!/bin/env python
|
||||
# -*- Mode: python; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
|
||||
import glib
|
||||
import gobject
|
||||
import sys
|
||||
import dbus
|
||||
import dbus.service
|
||||
import dbus.mainloop.glib
|
||||
|
||||
IFACE_SECRET_AGENT = 'org.freedesktop.NetworkManager.SecretAgent'
|
||||
IFACE_AGENT_MANAGER = 'org.freedesktop.NetworkManager.AgentManager'
|
||||
|
||||
class NotAuthorizedException(dbus.DBusException):
|
||||
_dbus_error_name = IFACE_SECRET_AGENT + '.NotAuthorized'
|
||||
|
||||
class Agent(dbus.service.Object):
|
||||
def __init__(self, bus, object_path):
|
||||
self.agents = {}
|
||||
self.bus = bus
|
||||
dbus.service.Object.__init__(self, bus, object_path)
|
||||
|
||||
@dbus.service.method(IFACE_SECRET_AGENT,
|
||||
in_signature='a{sa{sv}}osasb',
|
||||
out_signature='a{sa{sv}}',
|
||||
sender_keyword='sender')
|
||||
def GetSecrets(self, connection_hash, connection_path, setting_name, hints, request_new, sender=None):
|
||||
if not sender:
|
||||
raise NotAuthorizedException("Internal error: couldn't get sender")
|
||||
uid = self.bus.get_unix_user(sender)
|
||||
if uid != 0:
|
||||
raise NotAuthorizedException("UID %d not authorized" % uid)
|
||||
|
||||
print "Secrets requested path '%s' setting '%s' hints '%s' new %d" % (connection_path, setting_name, str(hints), request_new)
|
||||
|
||||
# return some random GSM secrets
|
||||
s_gsm = dbus.Dictionary({'password': 'asdfadfasdfaf'})
|
||||
con = dbus.Dictionary({'gsm': s_gsm})
|
||||
return con
|
||||
|
||||
def register(proxy):
|
||||
proxy.Register("test.agent.id", dbus_interface=IFACE_AGENT_MANAGER)
|
||||
print "Registered!"
|
||||
return False
|
||||
|
||||
def unregister(proxy, loop):
|
||||
proxy.Unregister(dbus_interface=IFACE_AGENT_MANAGER)
|
||||
loop.quit()
|
||||
return False
|
||||
|
||||
def main():
|
||||
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
|
||||
|
||||
bus = dbus.SystemBus()
|
||||
obj = Agent(bus, "/org/freedesktop/NetworkManager/SecretAgent")
|
||||
proxy = bus.get_object("org.freedesktop.NetworkManager",
|
||||
"/org/freedesktop/NetworkManager/AgentManager")
|
||||
|
||||
mainloop = gobject.MainLoop()
|
||||
|
||||
gobject.idle_add(register, proxy)
|
||||
gobject.timeout_add_seconds(10, unregister, proxy, mainloop)
|
||||
print "Running test secret agent"
|
||||
mainloop.run()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
Loading…
Add table
Reference in a new issue