Beispiel #1
0
def test_session(
    reset_requests_ca_bundle,
    requests_mock,
    verify,
    envvar,
    expected,
    expected_with_requests,
):
    requests_mock.get("https://bla")
    import requests

    vault_cli_session = sessions.Session()
    requests_session = requests.Session()

    if envvar is not None:
        os.environ["REQUESTS_CA_BUNDLE"] = envvar
    if verify is not None:
        vault_cli_session.verify = verify
        requests_session.verify = verify

    vault_cli_session.get("https://bla")

    # If this tests fails here, it means the Session workaround doesn't
    # work anymore
    assert requests_mock.last_request.verify == expected

    requests_session.get("https://bla")

    # If this tests fails here, it means requests have solved the bug
    # and we don't need a workaround anymore
    assert requests_mock.last_request.verify == expected_with_requests
Beispiel #2
0
    def _init_client(
        self,
        url: str,
        verify: types.VerifyOrCABundle,
        login_cert: Optional[str],
        login_cert_key: Optional[str],
    ) -> None:
        self.session = sessions.Session()
        self.session.verify = verify

        cert = None
        if login_cert and login_cert_key:
            cert = (login_cert, login_cert_key)

        self.client = hvac.Client(
            url=url, verify=verify, session=self.session, cert=cert
        )
Beispiel #3
0
 def create_session(verify: types.VerifyOrCABundle) -> requests.Session:
     session = sessions.Session()
     session.verify = verify
     return session
Beispiel #4
0
 def _init_session(self, url: str, verify: types.VerifyOrCABundle) -> None:
     self.session = sessions.Session()
     self.client = hvac.Client(url=url, verify=verify, session=self.session)