s3:test:wbinfo_sids2xids: test the results with singular calls with filled and with...
[Samba.git] / source3 / script / tests / test_wbinfo_sids2xids_int.py
blob8826f53f1f400840e70cfa57dae95b5127619cf8
1 #!/usr/bin/env python
3 import sys,os,subprocess
6 if len(sys.argv) != 3:
7 print "Usage: test_wbinfo_sids2xids_int.py wbinfo net"
8 sys.exit(1)
10 wbinfo = sys.argv[1]
11 netcmd = sys.argv[2]
13 def flush_cache():
14 os.system(netcmd + "cache flush")
16 domain = subprocess.Popen([wbinfo, "--own-domain"],
17 stdout=subprocess.PIPE).communicate()[0].strip()
18 domsid = subprocess.Popen([wbinfo, "-n", domain + "\\"],
19 stdout=subprocess.PIPE).communicate()[0]
20 domsid = domsid.split(' ')[0]
22 #print domain
23 #print domsid
25 sids=[ domsid + '-512', 'S-1-5-32-545', domsid + '-513' ]
27 flush_cache
29 sids2xids = subprocess.Popen([wbinfo, '--sids-to-unix-ids=' + ','.join(sids)],
30 stdout=subprocess.PIPE).communicate()[0].strip()
32 gids=[]
34 for line in sids2xids.split('\n'):
35 result = line.split(' ')[2:]
37 if result[0] == 'gid':
38 gid = result[1]
39 else:
40 gid = ''
41 if gid == '-1':
42 gid = ''
43 gids.append(gid)
45 # Check the list produced by the sids-to-xids call with the
46 # singular variant (sid-to-gid) for each sid in turn.
47 def check_singular(sids, gids):
48 i=0
49 for sid in sids:
50 gid = subprocess.Popen([wbinfo, '--sid-to-gid', sid],
51 stdout=subprocess.PIPE).communicate()[0].strip()
52 if gid != gids[i]:
53 print "Expected %s, got %s\n", gid, gids[i]
54 sys.exit(1)
55 i+=1
57 # first round: with filled cache
58 check_singular(sids, gids)
60 # second round: with empty cache
61 flush_cache
62 check_singular(sids, gids)
64 sys.exit(0)