Skip to content

Commit

Permalink
Emit deprecation warning
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed Feb 20, 2024
1 parent 4579efc commit 28b2b01
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
8 changes: 8 additions & 0 deletions singer_sdk/authenticators.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import base64
import math
import typing as t
import warnings
from datetime import timedelta
from types import MappingProxyType
from urllib.parse import parse_qs, urlencode, urlsplit, urlunsplit
Expand Down Expand Up @@ -319,6 +320,13 @@ def __init__(
password: API password.
"""
super().__init__(stream=stream)
warnings.warn(
"BasicAuthenticator is deprecated. Use "
"requests.auth.HTTPBasicAuth instead.",
DeprecationWarning,
stacklevel=2,
)

credentials = f"{username}:{password}".encode()
auth_token = base64.b64encode(credentials).decode("ascii")
auth_credentials = {"Authorization": f"Basic {auth_token}"}
Expand Down
16 changes: 15 additions & 1 deletion tests/core/rest/test_authenticators.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
)
from requests.auth import HTTPProxyAuth, _basic_auth_str

from singer_sdk.authenticators import OAuthAuthenticator, OAuthJWTAuthenticator
from singer_sdk.authenticators import (
BasicAuthenticator,
OAuthAuthenticator,
OAuthJWTAuthenticator,
)

if t.TYPE_CHECKING:
import requests_mock
Expand Down Expand Up @@ -218,3 +222,13 @@ def test_requests_library_auth(rest_tap: Tap):

assert isinstance(stream.authenticator, HTTPProxyAuth)
assert r.headers["Proxy-Authorization"] == _basic_auth_str("username", "password")


def test_basic_auth_deprecation_warning(rest_tap: Tap):
"""Validate that a warning is emitted when using BasicAuthenticator."""
stream: RESTStream = rest_tap.streams["some_stream"]
with pytest.deprecated_call(match="BasicAuthenticator is deprecated") as recorder:
BasicAuthenticator(stream=stream, username="username", password="password") # noqa: S106

assert len(recorder.list) == 1
assert recorder.list[0].filename.endswith("test_authenticators.py")

0 comments on commit 28b2b01

Please sign in to comment.