Skip to content

Commit 908cad9

Browse files
authored
ci: Using service account (#214)
1 parent e5298d2 commit 908cad9

File tree

7 files changed

+58
-114
lines changed

7 files changed

+58
-114
lines changed

tests/integration/conftest.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from pytest import fixture
55
from pytest_asyncio import fixture as async_fixture
66

7+
from firebolt.client.auth import ServiceAccount, UsernamePassword
78
from firebolt.service.manager import Settings
89

910
LOGGER = getLogger(__name__)
@@ -90,3 +91,13 @@ def service_id() -> str:
9091
@fixture(scope="session")
9192
def service_secret() -> str:
9293
return must_env(SERVICE_SECRET_ENV)
94+
95+
96+
@fixture
97+
def service_auth(service_id, service_secret) -> ServiceAccount:
98+
return ServiceAccount(service_id, service_secret)
99+
100+
101+
@fixture
102+
def password_auth(username, password) -> UsernamePassword:
103+
return UsernamePassword(username, password)

tests/integration/dbapi/async/conftest.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,39 @@
11
from pytest_asyncio import fixture as async_fixture
22

33
from firebolt.async_db import Connection, connect
4-
from firebolt.client.auth import ServiceAccount, UsernamePassword
4+
from firebolt.client.auth.base import Auth
55

66

77
@async_fixture
8-
async def connection(
8+
async def username_password_connection(
99
engine_url: str,
1010
database_name: str,
11-
username: str,
12-
password: str,
11+
password_auth: Auth,
1312
account_name: str,
1413
api_endpoint: str,
1514
) -> Connection:
1615
async with await connect(
1716
engine_url=engine_url,
1817
database=database_name,
19-
auth=UsernamePassword(username, password),
18+
auth=password_auth,
2019
account_name=account_name,
2120
api_endpoint=api_endpoint,
2221
) as connection:
2322
yield connection
2423

2524

2625
@async_fixture
27-
async def service_account_connection(
26+
async def connection(
2827
engine_url: str,
2928
database_name: str,
30-
service_id: str,
31-
service_secret: str,
29+
service_auth: Auth,
3230
account_name: str,
3331
api_endpoint: str,
3432
) -> Connection:
3533
async with await connect(
3634
engine_url=engine_url,
3735
database=database_name,
38-
auth=ServiceAccount(service_id, service_secret),
36+
auth=service_auth,
3937
account_name=account_name,
4038
api_endpoint=api_endpoint,
4139
) as connection:
@@ -46,17 +44,15 @@ async def service_account_connection(
4644
async def connection_engine_name(
4745
engine_name: str,
4846
database_name: str,
49-
username: str,
50-
password: str,
47+
service_auth: Auth,
5148
account_name: str,
5249
api_endpoint: str,
5350
) -> Connection:
5451

5552
async with await connect(
5653
engine_name=engine_name,
5754
database=database_name,
58-
username=username,
59-
password=password,
55+
auth=service_auth,
6056
account_name=account_name,
6157
api_endpoint=api_endpoint,
6258
) as connection:
@@ -66,16 +62,14 @@ async def connection_engine_name(
6662
@async_fixture
6763
async def connection_no_engine(
6864
database_name: str,
69-
username: str,
70-
password: str,
65+
service_auth: Auth,
7166
account_name: str,
7267
api_endpoint: str,
7368
) -> Connection:
7469

7570
async with await connect(
7671
database=database_name,
77-
username=username,
78-
password=password,
72+
auth=service_auth,
7973
account_name=account_name,
8074
api_endpoint=api_endpoint,
8175
) as connection:

tests/integration/dbapi/async/test_auth_async.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ async def test_refresh_token(connection: Connection) -> None:
2929

3030

3131
async def test_credentials_invalidation(
32-
connection: Connection, service_account_connection: Connection
32+
connection: Connection, username_password_connection: Connection
3333
) -> None:
3434
"""Auth raises authentication error on credentials invalidation"""
3535
# Can't pytest.parametrize it due to nested event loop error
36-
for conn in [connection, service_account_connection]:
36+
for conn in [connection, username_password_connection]:
3737
with conn.cursor() as c:
3838
# Works fine
3939
await c.execute("show tables")

tests/integration/dbapi/async/test_errors_async.py

Lines changed: 11 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,20 @@
22
from pytest import mark, raises
33

44
from firebolt.async_db import Connection, connect
5+
from firebolt.client.auth import ServiceAccount, UsernamePassword
56
from firebolt.utils.exception import (
67
AccountNotFoundError,
7-
AuthenticationError,
88
EngineNotRunningError,
99
FireboltDatabaseError,
1010
FireboltEngineError,
1111
OperationalError,
1212
)
1313

1414

15-
async def test_invalid_credentials(
16-
engine_url: str, database_name: str, username: str, password: str, api_endpoint: str
17-
) -> None:
18-
"""Connection properly reacts to invalid credentials error."""
19-
async with await connect(
20-
engine_url=engine_url,
21-
database=database_name,
22-
username=username + "_",
23-
password=password + "_",
24-
api_endpoint=api_endpoint,
25-
) as connection:
26-
with raises(AuthenticationError) as exc_info:
27-
await connection.cursor().execute("show tables")
28-
29-
assert str(exc_info.value).startswith(
30-
"Failed to authenticate"
31-
), "Invalid authentication error message."
32-
33-
3415
async def test_invalid_account(
3516
database_name: str,
3617
engine_name: str,
37-
username: str,
38-
password: str,
18+
password_auth: UsernamePassword,
3919
api_endpoint: str,
4020
) -> None:
4121
"""Connection properly reacts to invalid account error."""
@@ -44,8 +24,7 @@ async def test_invalid_account(
4424
async with await connect(
4525
database=database_name,
4626
engine_name=engine_name, # Omit engine_url to force account_id lookup.
47-
username=username,
48-
password=password,
27+
auth=password_auth,
4928
account_name=account_name,
5029
api_endpoint=api_endpoint,
5130
) as connection:
@@ -59,17 +38,15 @@ async def test_invalid_account(
5938
async def test_engine_url_not_exists(
6039
engine_url: str,
6140
database_name: str,
62-
username: str,
63-
password: str,
41+
service_auth: ServiceAccount,
6442
account_name: str,
6543
api_endpoint: str,
6644
) -> None:
6745
"""Connection properly reacts to invalid engine url error."""
6846
async with await connect(
6947
engine_url=engine_url + "_",
7048
database=database_name,
71-
username=username,
72-
password=password,
49+
auth=service_auth,
7350
account_name=account_name,
7451
api_endpoint=api_endpoint,
7552
) as connection:
@@ -80,8 +57,7 @@ async def test_engine_url_not_exists(
8057
async def test_engine_name_not_exists(
8158
engine_name: str,
8259
database_name: str,
83-
username: str,
84-
password: str,
60+
service_auth: ServiceAccount,
8561
account_name: str,
8662
api_endpoint: str,
8763
) -> None:
@@ -90,8 +66,7 @@ async def test_engine_name_not_exists(
9066
async with await connect(
9167
engine_name=engine_name + "_________",
9268
database=database_name,
93-
username=username,
94-
password=password,
69+
auth=service_auth,
9570
account_name=account_name,
9671
api_endpoint=api_endpoint,
9772
) as connection:
@@ -101,8 +76,7 @@ async def test_engine_name_not_exists(
10176
async def test_engine_stopped(
10277
stopped_engine_url: str,
10378
database_name: str,
104-
username: str,
105-
password: str,
79+
service_auth: ServiceAccount,
10680
account_name: str,
10781
api_endpoint: str,
10882
) -> None:
@@ -111,8 +85,7 @@ async def test_engine_stopped(
11185
async with await connect(
11286
engine_url=stopped_engine_url,
11387
database=database_name,
114-
username=username,
115-
password=password,
88+
auth=service_auth,
11689
account_name=account_name,
11790
api_endpoint=api_endpoint,
11891
) as connection:
@@ -121,15 +94,14 @@ async def test_engine_stopped(
12194

12295
@mark.skip(reason="Behaviour is different in prod vs dev")
12396
async def test_database_not_exists(
124-
engine_url: str, database_name: str, username: str, password: str, api_endpoint: str
97+
engine_url: str, database_name: str, service_auth: ServiceAccount, api_endpoint: str
12598
) -> None:
12699
"""Connection properly reacts to invalid database error."""
127100
new_db_name = database_name + "_"
128101
async with await connect(
129102
engine_url=engine_url,
130103
database=new_db_name,
131-
username=username,
132-
password=password,
104+
auth=service_auth,
133105
api_endpoint=api_endpoint,
134106
) as connection:
135107
with raises(FireboltDatabaseError) as exc_info:

tests/integration/dbapi/sync/conftest.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
from pytest import fixture
22

3-
from firebolt.client.auth import ServiceAccount, UsernamePassword
3+
from firebolt.client.auth.base import Auth
44
from firebolt.db import Connection, connect
55

66

77
@fixture
8-
def connection(
8+
def username_password_connection(
99
engine_url: str,
1010
database_name: str,
11-
username: str,
12-
password: str,
11+
password_auth: Auth,
1312
account_name: str,
1413
api_endpoint: str,
1514
) -> Connection:
1615
connection = connect(
1716
engine_url=engine_url,
1817
database=database_name,
19-
auth=UsernamePassword(username, password),
18+
auth=password_auth,
2019
account_name=account_name,
2120
api_endpoint=api_endpoint,
2221
)
@@ -25,18 +24,17 @@ def connection(
2524

2625

2726
@fixture
28-
async def service_account_connection(
27+
async def connection(
2928
engine_url: str,
3029
database_name: str,
31-
service_id: str,
32-
service_secret: str,
30+
service_auth: Auth,
3331
account_name: str,
3432
api_endpoint: str,
3533
) -> Connection:
3634
connection = connect(
3735
engine_url=engine_url,
3836
database=database_name,
39-
auth=ServiceAccount(service_id, service_secret),
37+
auth=service_auth,
4038
account_name=account_name,
4139
api_endpoint=api_endpoint,
4240
)
@@ -48,16 +46,14 @@ async def service_account_connection(
4846
def connection_engine_name(
4947
engine_name: str,
5048
database_name: str,
51-
username: str,
52-
password: str,
49+
service_auth: Auth,
5350
account_name: str,
5451
api_endpoint: str,
5552
) -> Connection:
5653
connection = connect(
5754
engine_name=engine_name,
5855
database=database_name,
59-
username=username,
60-
password=password,
56+
auth=service_auth,
6157
account_name=account_name,
6258
api_endpoint=api_endpoint,
6359
)
@@ -68,15 +64,13 @@ def connection_engine_name(
6864
@fixture
6965
def connection_no_engine(
7066
database_name: str,
71-
username: str,
72-
password: str,
67+
service_auth: Auth,
7368
account_name: str,
7469
api_endpoint: str,
7570
) -> Connection:
7671
connection = connect(
7772
database=database_name,
78-
username=username,
79-
password=password,
73+
auth=service_auth,
8074
account_name=account_name,
8175
api_endpoint=api_endpoint,
8276
)

tests/integration/dbapi/sync/test_auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def test_refresh_token(connection: Connection) -> None:
2828
assert c._client.auth.token != old, "Auth didn't update token on expiration"
2929

3030

31-
@mark.parametrize("connection_fixture", ["connection", "service_account_connection"])
31+
@mark.parametrize("connection_fixture", ["connection", "username_password_connection"])
3232
def test_credentials_invalidation(connection_fixture: str, request) -> None:
3333
"""Auth raises Authentication Error on credentials invalidation"""
3434
with request.getfixturevalue(connection_fixture).cursor() as c:

0 commit comments

Comments
 (0)