def test_truesendall_after_mocket_session(): Mocket.enable() Mocket.disable() url = "https://httpbin.org/ip" resp = requests.get(url) assert resp.status_code == 200
def test_truesendall_after_mocket_session(): Mocket.enable() Mocket.disable() url = 'https://mockbin.com/ip' resp = requests.get(url) assert resp.status_code == 200
def test_scanner_google_httpproxy_env_ipv4(mocker): fqdn = "google.com" port = 443 MOCK_JARM = "27d40d40d29d40d1dc42d43d00041d4689ee210389f4f6b4b5b1b93f92252d" family = socket.AF_INET TEST_NAME = "google_com_443_httpproxy_env_ipv4" os.environ["HTTPS_PROXY"] = "http://*****:*****@127.0.0.1:3128" global conn_idx conn_idx = 0 def get_user_agent(): global conn_idx print(f"Called at {conn_idx}") hdr = {"User-Agent": f"pyJARM/UnitTest/{TEST_NAME}/{conn_idx}"} conn_idx += 1 return hdr mocker.patch( "os.urandom", return_value= b"\x17]\x18r\xb2\xe7\x14L\x82\x9anR\xe59{D\xb9\xf8\xb2P\x9cd\xb5\x03g3<\x99)\x176n", ) mocker.patch("random.choice", return_value=b"\x5a\x5a") mocker.patch.object(Proxy, "get_http_headers", side_effect=get_user_agent) Mocket.enable(TEST_NAME, "./tests/data") jarm = asyncio.run( Scanner.scan_async(fqdn, port, address_family=family, concurrency=1)) assert jarm == (MOCK_JARM, fqdn, port)
def test_scanner_google_noproxy_ipv4(mocker): fqdn = "google.com" ip = "142.250.184.174" port = 443 MOCK_JARM = "27d40d40d29d40d1dc42d43d00041d4689ee210389f4f6b4b5b1b93f92252d" family = socket.AF_INET TEST_NAME = "google_com_443_noproxy_ipv4" mocker.patch( "os.urandom", return_value= b"\x17]\x18r\xb2\xe7\x14L\x82\x9anR\xe59{D\xb9\xf8\xb2P\x9cd\xb5\x03g3<\x99)\x176n", ) mocker.patch("random.choice", return_value=b"\x5a\x5a") mocker.patch( "socket.getaddrinfo", return_value=[(family, socket.SOCK_STREAM, socket.IPPROTO_TCP, "", (ip, port))], ) Mocket.enable(TEST_NAME, "./tests/data") jarm = asyncio.run( Scanner.scan_async(fqdn, port, address_family=family, concurrency=1)) assert jarm == (MOCK_JARM, fqdn, port)
async def __aenter__(self): Mocket.enable( namespace=self.namespace, truesocket_recording_dir=self.truesocket_recording_dir, ) if self.instance: self.check_and_call("mocketize_setup")
def test_truesendall_after_mocket_session(): Mocket.enable() Mocket.disable() url = 'https://httpbin.org/ip' resp = requests.get(url) assert resp.status_code == 200
def test_default_connect(data_dir, request): """Test connection to TheSkyX If not running with a real connection then use Mocket """ # Use `--with-hardware thesky` on cli to run without mock if 'theskyx' not in request.config.getoption('--with-hardware'): Mocket.enable('theskyx', data_dir) skyx = TheSkyX() assert skyx.is_connected is True
def test_default_connect(request): """Test connection to TheSkyX If not running with a real connection then use Mocket """ # Use `--with-hardware thesky` on cli to run without mock if 'theskyx' not in request.config.getoption('--with-hardware'): Mocket.enable( 'theskyx', '{}/panoptes-utils/panoptes/utils/tests/data'.format( os.getenv('PANDIR'))) skyx = TheSkyX() assert skyx.is_connected is True
def skyx(data_dir, request): """Create TheSkyX class but don't connect.t If running with a real connection TheSkyX then the Mokcet will be disabled here. """ # Use `--with-hardware thesky` on cli to run without mock Mocket.enable('theskyx', data_dir) if 'theskyx' in request.config.getoption('--with-hardware'): Mocket.disable() theskyx = TheSkyX(connect=False) yield theskyx
def skyx(request): """Create TheSkyX class but don't connect.t If running with a real connection TheSkyX then the Mokcet will be disabled here. """ # Use `--with-hardware thesky` on cli to run without mock Mocket.enable( 'theskyx', '{}/panoptes-utils/panoptes/utils/tests/data'.format( os.getenv('PANDIR'))) if 'theskyx' in request.config.getoption('--with-hardware'): Mocket.disable() theskyx = TheSkyX(connect=False) yield theskyx
def test_gethostbyname(self): host = socket.gethostbyname('localhost') Mocket.enable() self.assertEqual(socket.gethostbyname('localhost'), '127.0.0.1') Mocket.disable() self.assertEqual(socket.gethostbyname('localhost'), host)
def test_gethostname(self): hostname = socket.gethostname() Mocket.enable() self.assertEqual(socket.gethostname(), 'localhost') Mocket.disable() self.assertEqual(socket.gethostname(), hostname)
def test_gethostbyname(self): host = socket.gethostbyname("localhost") Mocket.enable() self.assertEqual(socket.gethostbyname("localhost"), "127.0.0.1") Mocket.disable() self.assertEqual(socket.gethostbyname("localhost"), host)
def test_gethostbyname(self): host = socket.gethostbyname('localhost') Mocket.enable() self.assertEqual(socket.gethostbyname('localhost'), '127.0.0.1') Mocket.disable() self.assertEqual(socket.gethostbyname('localhost'), host)
def test_gethostname(self): hostname = socket.gethostname() Mocket.enable() self.assertEqual(socket.gethostname(), 'localhost') Mocket.disable() self.assertEqual(socket.gethostname(), hostname)