def t21(): pretty = '%s t21' % __file__ print(pretty) sock, port = find_free_port() accounts = {'admin':'key2', 'root':'key3', 'nobody':'key4'} c = MockControl(port, 'key1', sock, accounts) c.start() r = RemoteControl(('',port), 'key4', timeout=5) who = r.whoami() if who != 'key4': print('FAIL %s: wrong who: %s' % (pretty, who)) c.terminate() c.join() return False r = RemoteControl(('',port), 'key4', timeout=5) try: r.whoami_preauth() except Exception, e: if str(e) != 'not authorized to make this call': print('FAIL %s: wrong error: %s' % (pretty, str(e))) c.terminate() c.join() return False
def t11(): pretty = '%s t11' % __file__ print(pretty) s,p1 = find_free_port() q1 = Pipe() ctr1 = MockControl(p1, 'password', s, [], q1) ctr1.start() s,p2 = find_free_port() q2 = Pipe() ctr2 = MockControl(p2, None, s, [], q2) ctr2.start() # ask ctr1 to create a connection to ctr2 rem1 = RemoteControl(('',p1), 'password', timeout=5) msg = rem1.connect_remote(('',p2), None) if msg != 'pong': print('FAIL %s: bad connection established: %s' % (pretty, msg)) ctr1.terminate() ctr2.terminate() ctr1.join() ctr2.join() return False # tell ctr1 to shut down and wait for out of band ack rem1.stop(__async__=True) try: msg = q1.get(1) except Exception, e: print('FAIL %s: first oob not received: %s' % (pretty, str(e))) ctr1.terminate() ctr2.terminate() return False
def t23(): pretty = '%s t23' % __file__ print(pretty) sock, port = find_free_port() c = MockControl(port, None, sock, {'admin':None, 'root':None}) c.start() r = RemoteControl(('',port), 'foo bar', timeout=5) who = r.whoami_preauth() if who != None: print('FAIL %s: wrong who: %s' % (pretty, who)) c.terminate() c.join() return False c.terminate() c.join() return True
def t17(): pretty = '%s t17' % __file__ print(pretty) sock, port = find_free_port() c = MockControl(port, 'key1', sock, {'alt':'key'}) c.start() r = RemoteControl(('',port), 'key', timeout=5) who = r.whoami() result = True if who != 'key': print('FAIL %s: wrong who: %s' % (pretty, who)) result = False c.terminate() c.join() return result
def t07(): pretty = '%s t7' % __file__ print(pretty) s,p = find_free_port() ctrl = MockControl(p, 'password', s) ctrl.start() con1 = RemoteControl(('',p), 'password', 1) try: con1.raise_exit() except Exit: pass # good ctrl.join(2) con2 = BlockingConnection(('',p), 'password') try: con2.connect(timeout=1) except ConnectionRefused, e: pass # good
def t20(): pretty = '%s t20' % __file__ print(pretty) sock, port = find_free_port() accounts = {'admin':'key2', 'root':'key3', 'nobody':'key4'} c = MockControl(port, 'key1', sock, accounts) c.start() r = RemoteControl(('',port), 'key2', timeout=5) who = r.whoami_preauth() if who != 'key2': print('FAIL %s: wrong who: %s' % (pretty, who)) c.terminate() c.join() return False c.terminate() c.join() return True
def t18(): pretty = '%s t18' % __file__ print(pretty) sock, port = find_free_port() c = MockControl(port, 'key1', sock, {'alt2':'key2', 'alt3':'key3'}) c.start() result = True for key in ['key1', 'key2', 'key3']: r = RemoteControl(('',port), key, timeout=5) who = r.whoami() if who != key: print('FAIL %s: wrong who: %s' % (pretty, who)) result = False break c.terminate() c.join() return result
def t19(): pretty = '%s t19' % __file__ print(pretty) sock, port = find_free_port() c = MockControl(port, 'key1', sock, {'alt2':'key2', 'alt3':'key3'}) c.start() r = RemoteControl(('',port), 'no such key', timeout=5) who = r.whoami() if who != None: print('FAIL %s: wrong who 1: %s' % (pretty, who)) c.terminate() c.join() return False r = RemoteControl(('',port), 'key3', timeout=5) who = r.whoami() if who != 'key3': print('FAIL %s: wrong who 2: %s' % (pretty, who)) c.terminate() c.join() return False c.terminate() c.join() return True
def t12(): pretty = '%s t12' % __file__ print(pretty) s,p1 = find_free_port() ctr1 = MockControl(p1, 'password', s) ctr1.start() s,p2 = find_free_port() q = Pipe() ctr2 = MockControl(p2, None, s, [], q) ctr2.start() # ask ctr1 to create a connection to ctr2 rem1 = RemoteControl(('',p1), 'password', timeout=5) msg = rem1.connect_remote(('',p2), None) if msg != 'pong': print('FAIL %s: bad connection established: %s' % (pretty, msg)) ctr1.terminate() ctr2.terminate() ctr1.join() ctr2.join() return False # kill ctr1 ctr1.kill() # check if ctr2 discovered the connection loss from ctr1 result = True try: msg = q.get(1) if type(msg) != list: # no way of knowing the exact content beforehand print('FAIL %s: wrong oob received: %s' % (pretty, msg)) result = False except Exception, e: print('FAIL %s: oob not received: %s' % (pretty, str(e))) result = False
def t13(): pretty = '%s t13' % __file__ print(pretty) s,p1 = find_free_port() q1 = Pipe() ctr1 = MockControl(p1, 'pass', s, [], q1) ctr1.start() s,p2 = find_free_port() q2 = Pipe() ctr2 = MockControl(p2, 'secret', s, [], q2) ctr2.start() # ask ctr1 to create a connection to ctr2 rem1 = RemoteControl(('',p1), 'pass', timeout=5) msg = rem1.connect_remote(('',p2), 'secret') if msg != 'pong': print('FAIL %s: bad connection established: %s' % (pretty, msg)) ctr1.terminate() ctr2.terminate() ctr1.join() ctr2.join() return False # stop ctr1 but don't drop the connection to it (rem1 is still in scope and # doesn't get garbage collected or expressely closed) rem1.stop(__async__=True) ctr1.join() # check if ctr2 discovered the connection loss from ctr1 result = True try: msg = q2.get(1) if type(msg) != list: # no way of knowing the exact content beforehand print('FAIL %s: wrong oob received: %s' % (pretty, msg)) result = False except Exception, e: print('FAIL %s: oob not received: %s' % (pretty, str(e))) result = False
q1 = Pipe() c = MockControl(port, 'pass', sock, [], q1) c.start() q2 = Pipe() p = Ping(args=(port,q2)) p.start() result = True try: result = q2.get(timeout=5) except Exception, e: print('FAIL %s: death was mocked: %s' % (pretty, str(e))) result = False c.terminate() c.join() return result # check that extra authkeys can be used to authenticate when the primary key is # not set def t16(): pretty = '%s t16' % __file__ print(pretty) sock, port = find_free_port() c = MockControl(port, None, sock, {'alt':'key'}) c.start() r = RemoteControl(('',port), 'key', timeout=5) who = r.whoami()