def test_b3270_nvt_xml_smoke(self): # Start 'nc' to read b3270's output. nc = cti.copyserver() # Start b3270. b3270 = Popen(cti.vgwrap(['b3270']), stdin=PIPE, stdout=DEVNULL) self.children.append(b3270) # Feed b3270 some actions. top = ET.Element('b3270-in') ET.SubElement( top, 'run', { 'actions': f'Open(a:c:t:127.0.0.1:{nc.port}) String(abc) Enter() Disconnect()' }) *first, _, _ = cti.xml_prettify(top).split(b'\n') b3270.stdin.write(b'\n'.join(first) + b'\n') b3270.stdin.flush() # Make sure they are passed through. out = nc.data() self.assertEqual(b"abc\r\n", out) # Wait for the processes to exit. b3270.stdin.close() self.vgwait(b3270)
def s3270_nvt_smoke(self, ipv6=False): # Start a thread to read s3270's output. nc = cti.copyserver(ipv6=ipv6) # Start s3270. s3270 = Popen(cti.vgwrap(["s3270", f"a:c:t:{nc.qloopback}:{nc.port}"]), stdin=PIPE, stdout=DEVNULL) self.children.append(s3270) # Feed s3270 some actions. s3270.stdin.write(b"String(abc)\n") s3270.stdin.write(b"Enter()\n") s3270.stdin.write(b"Disconnect()\n") s3270.stdin.write(b"Quit()\n") s3270.stdin.flush() # Make sure they are passed through. out = nc.data() self.assertEqual(b"abc\r\n", out) # Wait for the processes to exit. s3270.stdin.close() self.vgwait(s3270)
def run_script_test(self, mode): # Start a thread to read s3270's output. nc = cti.copyserver() # Start s3270. s3270 = Popen(cti.vgwrap(['s3270', '-xrm', 's3270.noTelnetInputMode: character', f'a:c:t:127.0.0.1:{nc.port}']), stdin=PIPE, stdout=DEVNULL) self.children.append(s3270) # Feed s3270 the action. text = f'Script(python3,s3270/Test/script/simple.py,-{mode},hello,there)\n' s3270.stdin.write(text.encode('utf8')) s3270.stdin.flush() # Make sure it works. out = nc.data() self.assertEqual(b'hello there', out) # Wait for the processes to exit. s3270.stdin.close() self.vgwait(s3270)
def s3270_keepalive(self, telnet=True, set=True, dynamic=False): # Start a thread to read s3270's output. nc = cti.copyserver() # Start s3270. port, ts = cti.unused_port() sval = '1' if set else '0' topt = '' if telnet else 't:' s3270 = Popen(cti.vgwrap([ 's3270', '-httpd', str(port), '-set', f'nopSeconds={sval}', f'{topt}a:c:{nc.qloopback}:{nc.port}' ]), stdin=DEVNULL, stdout=DEVNULL) self.children.append(s3270) self.check_listen(port) ts.close() # Set the option at run-time. if (dynamic): requests.get( f'http://127.0.0.1:{port}/3270/rest/json/Set(nopSeconds,1)') # Give s3270 2.5 seconds to send two NOPs (or not), then close it. time.sleep(2.5) requests.get(f'http://127.0.0.1:{port}/3270/rest/json/Quit()') # Make sure they showed up, or didn't. out = nc.data() if telnet and (set or dynamic): self.assertEqual(b'\xff\xf1\xff\xf1', out) else: self.assertEqual(b'', out) # Wait for the processes to exit. self.vgwait(s3270)
def test_b3270_nvt_json_smoke(self): # Start 'nc' to read b3270's output. nc = cti.copyserver() # Start b3270. b3270 = Popen(cti.vgwrap(['b3270', '-json']), stdin=PIPE, stdout=DEVNULL) self.children.append(b3270) # Feed b3270 some actions. j = { "run": { "actions": [{ "action": "Open", "args": [f"a:c:t:127.0.0.1:{nc.port}"] }, { "action": "String", "args": ["abc"] }, { "action": "Enter" }, { "action": "Disconnect" }] } } b3270.stdin.write(json.dumps(j).encode('utf8') + b'\n') b3270.stdin.flush() # Make sure they are passed through. out = nc.data() self.assertEqual(b"abc\r\n", out) # Wait for the processes to exit. b3270.stdin.close() self.vgwait(b3270)
def test_pr3287_multi_host_sequence(self): # Start a copy server. c = cti.copyserver(justAccept=True) # Start pr3287. handle, tracefile = tempfile.mkstemp() os.close(handle) uport, ts = cti.unused_port() ts.close() vport, ts = cti.unused_port() ts.close() # Set up a mock resolver result with the unused port, the real port and the other unused port. os.environ[ 'MOCK_SYNC_RESOLVER'] = f'127.0.0.1/{uport};127.0.0.1/{c.port};127.0.0.1/{vport}' pr3287 = Popen(cti.vgwrap( ['pr3287', '-trace', '-tracefile', tracefile, f'foo:9999']), stdout=DEVNULL, stderr=DEVNULL) os.environ['MOCK_SYNC_RESOLVER'] = '' self.children.append(pr3287) # Wait for the process to exit. c.close() self.vgwait(pr3287, assertOnFailure=False) # Make sure only two addresses are processed. with open(tracefile, 'r') as file: output = file.readlines() tried = [] for line in output: m = re.search(r'Trying (.*), port ([0-9]+)', line) if m != None: tried += [m.group(1) + ' ' + m.group(2)] os.unlink(tracefile) self.assertEqual(tried, [f'127.0.0.1 {uport}', f'127.0.0.1 {c.port}'])
def test_b3270_nvt_smoke(self): # Start 'nc' to read b3270's output. nc = cti.copyserver() # Start b3270. b3270 = Popen(cti.vgwrap(['b3270']), stdin=PIPE, stdout=DEVNULL) self.children.append(b3270) # Feed b3270 some actions. b3270.stdin.write(b'<b3270-in>\n') b3270.stdin.write( f'<run actions="Open(a:c:t:127.0.0.1:{nc.port}) String(abc) Enter() Disconnect()"/>\n' .encode('utf8')) b3270.stdin.flush() # Make sure they are passed through. out = nc.data() self.assertEqual(b'abc\r\n', out) # Wait for the processes to exit. b3270.stdin.write(b'</b3270-in>\n') b3270.stdin.close() self.vgwait(b3270)