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 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 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 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