File: test_authentication_pyamqp.py

package info (click to toggle)
python-azure 20250603%2Bgit-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 851,724 kB
  • sloc: python: 7,362,925; ansic: 804; javascript: 287; makefile: 195; sh: 145; xml: 109
file content (34 lines) | stat: -rw-r--r-- 1,170 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import pytest
import functools

from unittest.mock import Mock
from azure.eventhub._pyamqp.sasl import SASLAnonymousCredential, SASLPlainCredential
from azure.eventhub._pyamqp.authentication import SASLPlainAuth, JWTTokenAuth, SASTokenAuth


def test_sasl_plain_auth():
    auth = SASLPlainAuth(authcid="authcid", passwd="passwd", authzid="Some Authzid")
    assert auth.auth_type == "AUTH_SASL_PLAIN"
    assert auth.sasl.mechanism == b"PLAIN"
    assert auth.sasl.start() == b"Some Authzid\x00authcid\x00passwd"


def test_jwt_token_auth():
    credential = Mock()
    attr = {"get_token.return_value": "my_token"}
    credential.configure_mock(**attr)
    auth = JWTTokenAuth(
        uri="my_uri", audience="my_audience_field", get_token=functools.partial(credential.get_token, "my_auth_uri")
    )

    assert auth.uri == "my_uri"
    assert auth.audience == "my_audience_field"


def test_sas_token_auth():
    auth = SASTokenAuth(uri="my_uri", audience="my_audience", username="username", password="password")

    assert auth.uri == "my_uri"
    assert auth.audience == "my_audience"
    assert auth.username == "username"
    assert auth.password == "password"