def test_build_credentials_ssh_up(self): dummy = DummyDaemon() cred_out = [ 'auth_port_ssh|||22', '1.3.6.1.4.1.25623.1.0.103591:1:entry:SSH login name:|||username', '1.3.6.1.4.1.25623.1.0.103591:3:' 'password:SSH password (unsafe!):|||pass', '1.3.6.1.4.1.25623.1.0.103591:7:entry:SSH privilege login name:|||', '1.3.6.1.4.1.25623.1.0.103591:8:' 'password:SSH privilege password:|||', ] cred_dict = { 'ssh': { 'type': 'up', 'port': '22', 'username': '******', 'password': '******', } } p_handler = PreferenceHandler( '1234-1234', None, dummy.scan_collection, None ) ret = p_handler.build_credentials_as_prefs(cred_dict) self.assertCountEqual(ret, cred_out)
def test_build_credentials(self): w = DummyDaemon() cred_out = [ '1.3.6.1.4.1.25623.1.0.105058:1:entry:ESXi login name:|||username', '1.3.6.1.4.1.25623.1.0.105058:2:password:ESXi login password:|||pass', 'auth_port_ssh|||22', '1.3.6.1.4.1.25623.1.0.103591:1:entry:SSH login name:|||username', '1.3.6.1.4.1.25623.1.0.103591:2:password:SSH key passphrase:|||pass', '1.3.6.1.4.1.25623.1.0.103591:4:file:SSH private key:|||', '1.3.6.1.4.1.25623.1.0.90023:1:entry:SMB login:|||username', '1.3.6.1.4.1.25623.1.0.90023:2:password]:SMB password :|||pass', '1.3.6.1.4.1.25623.1.0.105076:1:password:SNMP Community:some comunity', '1.3.6.1.4.1.25623.1.0.105076:2:entry:SNMPv3 Username:username', '1.3.6.1.4.1.25623.1.0.105076:3:password:SNMPv3 Password:pass', '1.3.6.1.4.1.25623.1.0.105076:4:radio:SNMPv3 Authentication Algorithm:some auth algo', '1.3.6.1.4.1.25623.1.0.105076:5:password:SNMPv3 Privacy Password:privacy pass', '1.3.6.1.4.1.25623.1.0.105076:6:radio:SNMPv3 Privacy Algorithm:privacy algo', ] cred_dict = { 'ssh': { 'type': 'ssh', 'port': '22', 'username': '******', 'password': '******', }, 'smb': { 'type': 'smb', 'username': '******', 'password': '******' }, 'esxi': { 'type': 'esxi', 'username': '******', 'password': '******', }, 'snmp': { 'type': 'snmp', 'username': '******', 'password': '******', 'community': 'some comunity', 'auth_algorithm': 'some auth algo', 'privacy_password': '******', 'privacy_algorithm': 'privacy algo', }, } p = PreferenceHandler('1234-1234', None, w.scan_collection, None) ret = p.build_credentials_as_prefs(cred_dict) self.assertEqual(len(ret), len(cred_out)) self.assertIn('auth_port_ssh|||22', cred_out) self.assertIn( '1.3.6.1.4.1.25623.1.0.90023:1:entry:SMB login:|||username', cred_out, )