1388
by Robert Ancell
Add regression test for Python greeters |
1 |
#!/usr/bin/python
|
2 |
||
3 |
import sys |
|
4 |
import os |
|
5 |
import struct |
|
6 |
import socket |
|
7 |
import subprocess |
|
8 |
import signal |
|
9 |
from gi.repository import GLib |
|
10 |
from gi.repository import LightDM |
|
11 |
||
12 |
loop = GLib.MainLoop () |
|
13 |
||
14 |
def sigterm_cb (signum, frame): |
|
15 |
sys.stderr.write ("sigterm\n") |
|
16 |
status_notify ('GREETER %s TERMINATE SIGNAL=%d' % (os.getenv ('DISPLAY'), signum)) |
|
17 |
loop.quit (); |
|
18 |
signal.signal (signal.SIGTERM, sigterm_cb) |
|
19 |
||
20 |
status_socket = None |
|
21 |
||
22 |
def status_notify (message): |
|
23 |
sys.stderr.write ("status_notify\n"); |
|
24 |
if status_socket is not None: |
|
25 |
status_socket.send (struct.pack ('i', len (message)) + message) |
|
26 |
else: |
|
27 |
sys.stderr.write ('%s\n' % message) |
|
28 |
||
29 |
def request_cb (channel, condition): |
|
30 |
sys.stderr.write ("request_cb\n") |
|
31 |
length = status_socket.recv (4) |
|
32 |
sys.stderr.write ("read %d\n" % len (length)) |
|
33 |
if len (length) == 0: |
|
34 |
return False |
|
35 |
if len (length) > 0: |
|
36 |
(l,) = struct.unpack ('i', length) |
|
37 |
request = status_socket.recv (l) |
|
38 |
sys.stderr.write ("read '%s' %d\n" % (request, len (request))) |
|
39 |
||
40 |
r = 'GREETER %s AUTHENTICATE' % os.getenv ('DISPLAY') |
|
41 |
if request == r: |
|
42 |
greeter.authenticate (None) |
|
43 |
||
44 |
r = 'GREETER %s AUTHENTICATE USERNAME=' % os.getenv ('DISPLAY') |
|
45 |
if request.startswith (r): |
|
46 |
greeter.authenticate (request[len(r):]) |
|
47 |
||
1542
by Robert Ancell
Correctly implement and test autologin timeouts |
48 |
r = 'GREETER %s AUTHENTICATE-GUEST' % os.getenv ('DISPLAY') |
49 |
if request == r: |
|
50 |
greeter.authenticate_as_guest () |
|
51 |
||
52 |
r = 'GREETER %s AUTHENTICATE-AUTOLOGIN' % os.getenv ('DISPLAY') |
|
53 |
if request == r: |
|
54 |
greeter.authenticate_autologin () |
|
55 |
||
1535.1.2
by Robert Ancell
Add some tests and more work on remote sessions |
56 |
r = 'GREETER %s AUTHENTICATE-REMOTE SESSION=' % os.getenv ('DISPLAY') |
57 |
if request.startswith (r): |
|
58 |
greeter.authenticate_remote (request[len(r):], None) |
|
59 |
||
1388
by Robert Ancell
Add regression test for Python greeters |
60 |
r = 'GREETER %s RESPOND TEXT=\"' % os.getenv ('DISPLAY') |
61 |
if request.startswith (r): |
|
62 |
greeter.respond (request[len (r):-1]) |
|
63 |
||
64 |
r = 'GREETER %s START-SESSION' % os.getenv ('DISPLAY') |
|
65 |
if request == r: |
|
66 |
sys.stderr.write ("start-session\n"); |
|
67 |
if not greeter.start_session_sync (None): |
|
68 |
sys.stderr.write ("start-session-failed\n"); |
|
69 |
status_notify ('GREETER %s SESSION-FAILED' % os.getenv ('DISPLAY')) |
|
70 |
sys.stderr.write ("start-session ok\n"); |
|
71 |
||
72 |
r = 'GREETER %s START-SESSION SESSION=' % os.getenv ('DISPLAY') |
|
73 |
if request.startswith (r): |
|
74 |
if not greeter.start_session_sync (request[len(r):]): |
|
1399
by Robert Ancell
Fix up test X server atom handling so keyboard tests work |
75 |
status_notify ('GREETER %s SESSION-FAILED' % os.getenv ('DISPLAY')) |
76 |
||
77 |
r = 'GREETER %s LOG-LAYOUT' % os.getenv ('DISPLAY') |
|
78 |
if request == r: |
|
79 |
layout = LightDM.get_layout ().get_name () |
|
80 |
status_notify ('GREETER %s LOG-LAYOUT LAYOUT=%s' % (os.getenv ('DISPLAY'), layout)) |
|
1388
by Robert Ancell
Add regression test for Python greeters |
81 |
|
82 |
r = 'GREETER %s LOG-LAYOUT USERNAME=' % os.getenv ('DISPLAY') |
|
83 |
if request.startswith (r): |
|
84 |
username = request[len(r):] |
|
1399
by Robert Ancell
Fix up test X server atom handling so keyboard tests work |
85 |
user = LightDM.UserList.get_instance ().get_user_by_name (username) |
86 |
layout = user.get_layout () |
|
1388
by Robert Ancell
Add regression test for Python greeters |
87 |
if layout is None: |
88 |
layout = '' |
|
89 |
status_notify ('GREETER %s LOG-LAYOUT USERNAME=%s LAYOUT=%s' % (os.getenv ('DISPLAY'), username, layout)) |
|
90 |
||
91 |
r = 'GREETER %s LOG-LANGUAGE USERNAME=' % os.getenv ('DISPLAY') |
|
92 |
if request.startswith (r): |
|
93 |
username = request[len(r):] |
|
94 |
user = lightdm_user_list_get_user_by_name (lightdm_user_list_get_instance (), username) |
|
95 |
language = lightdm_user_get_language (user) |
|
96 |
if language is None: |
|
97 |
language = '' |
|
98 |
status_notify ('GREETER %s LOG-LANGUAGE USERNAME=%s LANGUAGE=%s' % (os.getenv ('DISPLAY'), username, language)) |
|
99 |
||
100 |
sys.stderr.write ("request_cb end\n") |
|
101 |
return True |
|
102 |
||
1466
by Robert Ancell
Remove LIGHTDM_TEST_STATUS_SOCKET variable - just use LIGHTDM_TEST_ROOT instead |
103 |
path = os.getenv ('LIGHTDM_TEST_ROOT') + '/.status-socket' |
104 |
status_socket = socket.socket (socket.AF_UNIX, socket.SOCK_STREAM) |
|
105 |
status_socket.connect (path) |
|
106 |
GLib.io_add_watch (status_socket.fileno (), GLib.IO_IN, request_cb) |
|
1388
by Robert Ancell
Add regression test for Python greeters |
107 |
|
108 |
status_notify ('GREETER %s START' % os.getenv ('DISPLAY')) |
|
109 |
||
110 |
# NOTE: There don't seem to be any good X bindings so we have to mock up our own...
|
|
111 |
(host, display) = os.getenv ('DISPLAY').split (':') |
|
112 |
if host == '': |
|
113 |
x_socket = socket.socket (socket.AF_UNIX, socket.SOCK_STREAM) |
|
114 |
x_socket.connect ('/tmp/.X11-unix/X%s' % display) |
|
115 |
else: |
|
116 |
x_socket = socket.socket (socket.AF_INET, socket.SOCK_STREAM) |
|
117 |
x_socket.connect ((host, 6000 + int (display))) |
|
118 |
authority = subprocess.check_output(['xauth', 'list']).split () |
|
119 |
auth_name = '' |
|
120 |
auth_data = '' |
|
121 |
if len (authority) >= 3: |
|
122 |
auth_name = authority[1] |
|
123 |
hex = authority[2] |
|
124 |
while len (hex) >= 2: |
|
125 |
auth_data += chr (int (hex[:2], 16)) |
|
126 |
hex = hex[2:] |
|
127 |
def pad (value): |
|
128 |
if len (value) % 4 != 0: |
|
129 |
return value + '\x00' * (4 - len (value) % 4) |
|
130 |
else: |
|
131 |
return value |
|
132 |
x_socket.send (struct.pack ('!cxHHHHxx', 'B', 11, 0, len (auth_name), len (auth_data)) + pad (auth_name) + pad (auth_data)) |
|
133 |
data = x_socket.recv (1024) |
|
134 |
if ord (data[0]) != 1: |
|
135 |
status_notify ('GREETER %s FAIL-CONNECT-XSERVER' % os.getenv ('DISPLAY')) |
|
136 |
exit (1) |
|
137 |
||
138 |
status_notify ('GREETER %s CONNECT-XSERVER' % (os.getenv ('DISPLAY'))) |
|
139 |
||
140 |
def show_message_cb (greeter, text, type): |
|
141 |
status_notify ('GREETER %s SHOW-MESSAGE TEXT=\"%s\"' % (os.getenv ('DISPLAY'), text)) |
|
142 |
||
143 |
def show_prompt_cb (greeter, text, type): |
|
144 |
status_notify ('GREETER %s SHOW-PROMPT TEXT=\"%s\"' % (os.getenv ('DISPLAY'), text)) |
|
145 |
||
146 |
def authentication_complete_cb (greeter): |
|
147 |
if greeter.get_is_authenticated (): |
|
148 |
is_authenticated = 'TRUE' |
|
149 |
else: |
|
150 |
is_authenticated = 'FALSE' |
|
151 |
if greeter.get_authentication_user () is not None: |
|
152 |
status_notify ('GREETER %s AUTHENTICATION-COMPLETE USERNAME=%s AUTHENTICATED=%s' % (os.getenv ('DISPLAY'), greeter.get_authentication_user (), is_authenticated)) |
|
153 |
else: |
|
154 |
status_notify ('GREETER %s AUTHENTICATION-COMPLETE AUTHENTICATED=%s' % (os.getenv ('DISPLAY'), is_authenticated)) |
|
155 |
||
1542
by Robert Ancell
Correctly implement and test autologin timeouts |
156 |
def autologin_timer_expired_cb (greeter): |
157 |
status_notify ('GREETER %s AUTOLOGIN-TIMER-EXPIRED' % os.getenv ('DISPLAY')) |
|
158 |
||
1388
by Robert Ancell
Add regression test for Python greeters |
159 |
greeter = LightDM.Greeter () |
160 |
greeter.connect ('show-message', show_message_cb) |
|
161 |
greeter.connect ('show-prompt', show_prompt_cb) |
|
162 |
greeter.connect ('authentication-complete', authentication_complete_cb) |
|
1542
by Robert Ancell
Correctly implement and test autologin timeouts |
163 |
greeter.connect ('autologin-timer-expired', autologin_timer_expired_cb) |
1388
by Robert Ancell
Add regression test for Python greeters |
164 |
|
165 |
status_notify ('GREETER %s CONNECT-TO-DAEMON' % os.getenv ('DISPLAY')) |
|
166 |
if not greeter.connect_sync (): |
|
167 |
status_notify ('GREETER %s FAIL-CONNECT-DAEMON' % os.getenv ('DISPLAY')) |
|
168 |
exit (1) |
|
169 |
||
170 |
status_notify ('GREETER %s CONNECTED-TO-DAEMON' % os.getenv ('DISPLAY')) |
|
171 |
||
172 |
if greeter.get_select_user_hint () is not None: |
|
173 |
status_notify ('GREETER %s SELECT-USER-HINT USERNAME=%s' % (os.getenv ('DISPLAY'), greeter.get_select_user_hint ())) |
|
1396
by Robert Ancell
Add Lock D-Bus method that locks the seat and provides a hint to the greeter to be in lock mode |
174 |
if greeter.get_lock_hint (): |
1542
by Robert Ancell
Correctly implement and test autologin timeouts |
175 |
status_notify ('GREETER %s LOCK-HINT' % os.getenv ('DISPLAY')); |
1388
by Robert Ancell
Add regression test for Python greeters |
176 |
|
177 |
loop.run () |