Ejemplo n.º 1
0
def test_truesendall_after_mocket_session():
    Mocket.enable()
    Mocket.disable()

    url = "https://httpbin.org/ip"
    resp = requests.get(url)
    assert resp.status_code == 200
Ejemplo n.º 2
0
def test_truesendall_after_mocket_session():
    Mocket.enable()
    Mocket.disable()

    url = 'https://mockbin.com/ip'
    resp = requests.get(url)
    assert resp.status_code == 200
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
 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")
Ejemplo n.º 6
0
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
Ejemplo n.º 10
0
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
Ejemplo n.º 11
0
 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)
Ejemplo n.º 12
0
 def test_gethostname(self):
     hostname = socket.gethostname()
     Mocket.enable()
     self.assertEqual(socket.gethostname(), 'localhost')
     Mocket.disable()
     self.assertEqual(socket.gethostname(), hostname)
Ejemplo n.º 13
0
 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)
Ejemplo n.º 14
0
 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)
Ejemplo n.º 15
0
 def test_gethostname(self):
     hostname = socket.gethostname()
     Mocket.enable()
     self.assertEqual(socket.gethostname(), 'localhost')
     Mocket.disable()
     self.assertEqual(socket.gethostname(), hostname)