diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/README | 1 | ||||
-rwxr-xr-x | tests/echo-client | 2 | ||||
-rwxr-xr-x | tests/echo-server | 55 | ||||
-rwxr-xr-x | tests/runner | 8 | ||||
-rw-r--r-- | tests/test-dbus-user.py | 53 | ||||
-rw-r--r-- | tests/test_checker.py | 50 |
6 files changed, 169 insertions, 0 deletions
diff --git a/tests/README b/tests/README new file mode 100644 index 0000000..bae6928 --- /dev/null +++ b/tests/README @@ -0,0 +1 @@ +Be sure the client and the server are on the same bus! diff --git a/tests/echo-client b/tests/echo-client new file mode 100755 index 0000000..29cfbc5 --- /dev/null +++ b/tests/echo-client @@ -0,0 +1,2 @@ +#!/bin/bash +dbus-send --system --type=method_call --print-reply --dest=org.laptop.security.Rainbow / org.laptop.security.Rainbow.echo string:'hi' diff --git a/tests/echo-server b/tests/echo-server new file mode 100755 index 0000000..011a8f7 --- /dev/null +++ b/tests/echo-server @@ -0,0 +1,55 @@ +#!/usr/bin/env python +import os +import sys +import subprocess +from optparse import OptionParser + +import gobject + +import dbus +import dbus.service +import dbus.mainloop.glib + +def log(msg, *args): + if len(args): + print msg % args + else: + print msg + +class EchoServer(dbus.service.Object): + """The echo service.""" + SERVICE_NAME = 'org.laptop.Echo' + INTERFACE_NAME = 'org.laptop.Echo' + + def __init__(self, bus_or_name): + dbus.service.Object.__init__(self, bus_or_name, '/') + + @dbus.service.method(INTERFACE_NAME, + in_signature='s', + out_signature='s') + def echo(self, msg): + return msg + +def run(): + """Start the Rainbow DBus service.""" + parser = OptionParser(version='0.1') + parser.add_option('-f', '--bus-config-file', default='./session-olpc.conf', + help='The dbus session bus config file to test.') + opts, args = parser.parse_args() + + + dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) + + bus = dbus.SessionBus() + name = dbus.service.BusName(EchoServer.SERVICE_NAME, bus) + EchoServer(name) + + print 'Echo service running mainloop.' + mainloop = gobject.MainLoop() + mainloop.run() + +def main(): + run() + +if __name__ == '__main__': + main() diff --git a/tests/runner b/tests/runner new file mode 100755 index 0000000..88fb96e --- /dev/null +++ b/tests/runner @@ -0,0 +1,8 @@ +#!/bin/bash + +dbus-daemon --nofork --config-file=./session-olpc.conf --print-address > desc & +sleep 1 +printf "export DBUS_SESSION_BUS_ADDRESS=%s" `cat desc` > address.sh +echo 'Living util \n' +read +killall dbus-daemon diff --git a/tests/test-dbus-user.py b/tests/test-dbus-user.py new file mode 100644 index 0000000..7a3cfd8 --- /dev/null +++ b/tests/test-dbus-user.py @@ -0,0 +1,53 @@ +import os +import sys +import subprocess + +import gobject + +import dbus +import dbus.service +import dbus.mainloop.glib + +def log(msg, *args): + if len(args): + print msg % args + else: + print msg + +class EchoServer(dbus.service.Object): + """The echo service.""" + SERVICE_NAME = 'org.laptop.Echo' + INTERFACE_NAME = 'org.laptop.Echo' + + def __init__(self, bus_or_name): + dbus.service.Object.__init__(self, bus_or_name, '/') + + @dbus.service.method(INTERFACE_NAME, + in_signature='s', + out_signature='s') + def echo(self, msg): + return msg + +def run(): + """Start the Rainbow DBus service.""" + parser = OptionParser(version='0.1') + parser.add_option('-f', '--bus-config-file', default='./session-olpc.conf', + help='The dbus session bus config file to test.') + opts, args = parser.parse_args() + + + dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) + + bus = dbus.SystemBus() + name = dbus.service.BusName(Rainbow.SERVICE_NAME, bus) + EchoServer(name) + + print 'Echo service running mainloop.' + mainloop = gobject.MainLoop() + mainloop.run() + +def main(): + run() + +if __name__ == '__main__': + main() diff --git a/tests/test_checker.py b/tests/test_checker.py new file mode 100644 index 0000000..ab19920 --- /dev/null +++ b/tests/test_checker.py @@ -0,0 +1,50 @@ +from util import Checker +from os import chmod, chown, mkdir, system +from stat import S_IFDIR, S_IFREG +from os import R_OK, W_OK, X_OK + +system('rm -rf 321 d321') + +open('321', 'w').close() +ck = Checker('321', 500, 500) +chown('321', 500, 500) +chmod('321', 0321) +assert not ck.positive(R_OK, S_IFDIR) +assert ck.negative(R_OK, S_IFDIR) + +assert ck.positive(W_OK | X_OK, S_IFREG) +assert not ck.negative(W_OK | X_OK, S_IFREG) + +mkdir('d321') +chown('d321', 500, 500) +chmod('d321', 0321) +ck = Checker('d321', 500, 500) +assert not ck.positive(R_OK, S_IFREG) +assert ck.negative(R_OK, S_IFREG) + +assert ck.positive(W_OK | X_OK, S_IFDIR) +assert not ck.negative(W_OK | X_OK, S_IFDIR) + + + + + +open('241', 'w').close() +ck = Checker('241', 100, 500) +chown('241', 500, 500) +chmod('241', 0241) +assert not ck.positive(W_OK, S_IFDIR) +assert ck.negative(W_OK, S_IFDIR) + +assert ck.positive(R_OK | X_OK, S_IFREG) +assert not ck.negative(R_OK | X_OK, S_IFREG) + +mkdir('d241') +chown('d241', 500, 500) +chmod('d241', 0241) +ck = Checker('d241', 100, 500) +assert not ck.positive(W_OK, S_IFREG) +assert ck.negative(W_OK, S_IFREG) + +assert ck.positive(R_OK | X_OK, S_IFDIR) +assert not ck.negative(R_OK | X_OK, S_IFDIR) |