2012-01-11 07:44:32 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2012-08-06 11:22:30 +02:00
|
|
|
#
|
|
|
|
# Copyright 2012 Red Hat Inc.
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Lesser General Public License as published
|
|
|
|
# by the Free Software Foundation; either version 2.1 of the licence or (at
|
|
|
|
# your option) any later version.
|
|
|
|
#
|
|
|
|
# See the included COPYING file for more information.
|
|
|
|
#
|
|
|
|
|
2012-01-11 07:44:32 +01:00
|
|
|
import dbus
|
|
|
|
import mock
|
|
|
|
import sys
|
|
|
|
|
|
|
|
class ErrorPrompt(mock.SecretPrompt):
|
|
|
|
def __init__(self, service, sender, prompt_name):
|
|
|
|
mock.SecretPrompt.__init__(self, service, sender, prompt_name)
|
|
|
|
|
|
|
|
@dbus.service.method('org.freedesktop.Secret.Prompt')
|
|
|
|
def Prompt(self, window_id):
|
|
|
|
raise mock.NotSupported("This should cause prompting to fail")
|
|
|
|
|
|
|
|
class VanishPrompt(mock.SecretPrompt):
|
|
|
|
def __init__(self, service, sender, prompt_name):
|
|
|
|
mock.SecretPrompt.__init__(self, service, sender, prompt_name)
|
|
|
|
|
|
|
|
@dbus.service.method('org.freedesktop.Secret.Prompt')
|
|
|
|
def Prompt(self, window_id):
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
class WindowPrompt(mock.SecretPrompt):
|
|
|
|
def __init__(self, service, sender, prompt_name):
|
|
|
|
mock.SecretPrompt.__init__(self, service, sender, prompt_name)
|
|
|
|
|
|
|
|
@dbus.service.method('org.freedesktop.Secret.Prompt')
|
|
|
|
def Prompt(self, window_id):
|
|
|
|
self.result = dbus.String(window_id, variant_level=1)
|
|
|
|
mock.SecretPrompt.Prompt(self, window_id)
|
|
|
|
|
|
|
|
service = mock.SecretService()
|
|
|
|
service.add_standard_objects()
|
|
|
|
|
|
|
|
mock.SecretPrompt(service, None, "simple")
|
2012-01-31 20:20:31 +01:00
|
|
|
mock.SecretPrompt(service, None, "delay", delay=0.1)
|
2012-01-30 16:07:55 +01:00
|
|
|
def prompt_callback():
|
|
|
|
return dbus.String("Special Result", variant_level=1)
|
|
|
|
mock.SecretPrompt(service, None, "result", action=prompt_callback)
|
2012-01-11 07:44:32 +01:00
|
|
|
ErrorPrompt(service, None, "error")
|
|
|
|
VanishPrompt(service, None, "vanish")
|
|
|
|
WindowPrompt(service, None, "window")
|
|
|
|
|
2012-08-06 11:22:30 +02:00
|
|
|
service.listen()
|