-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_authentication.py
More file actions
62 lines (54 loc) · 2.53 KB
/
test_authentication.py
File metadata and controls
62 lines (54 loc) · 2.53 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from pathlib import Path
import pytest
from cbltest import CBLPyTest
from cbltest.api.cbltestclass import CBLTestClass
SCRIPT_DIR = str(Path(__file__).parent)
class TestAuthentication(CBLTestClass):
@pytest.mark.asyncio(loop_scope="session")
async def test_basic_auth(self, cblpytest: CBLPyTest) -> None:
self.mark_test_step("test_basic_auth")
edge_server = await cblpytest.edge_servers[0].configure_dataset(
db_name="names", config_file=f"{SCRIPT_DIR}/config/test_basic_auth.json"
)
valid_auth = ("username8", "password8")
invalid_auth = ("invalid_user", "wrong_password")
self.mark_test_step("testing valid auth")
await edge_server.add_user(name=valid_auth[0], password=valid_auth[1])
await edge_server.set_auth(name=valid_auth[0], password=valid_auth[1])
active_tasks = await edge_server.get_active_tasks()
self.mark_test_step(f"Active Tasks: {active_tasks}")
self.mark_test_step("testing invalid auth")
await edge_server.set_auth(name=invalid_auth[0], password=invalid_auth[1])
failed = False
try:
await edge_server.get_active_tasks()
except Exception:
failed = True
self.mark_test_step("invalid auth failed as expected")
assert failed, "invalid auth did not fail as expected"
self.mark_test_step("testing anonymous auth ")
await edge_server.set_auth(auth=False)
failed = False
try:
await edge_server.get_active_tasks()
except Exception:
failed = True
self.mark_test_step("No auth failed as expected")
assert failed, "No auth did not fail as expected"
@pytest.mark.asyncio(loop_scope="session")
async def test_valid_tls_mtls(
self, cblpytest: CBLPyTest, dataset_path: Path
) -> None:
self.mark_test_step("test_valid_tls")
edge_server = await cblpytest.edge_servers[0].configure_dataset(
db_name="names", config_file=f"{SCRIPT_DIR}/config/test_tls_config.json"
)
self.mark_test_step("get server information with TLS")
version = await edge_server.get_version()
self.mark_test_step(f"VERSION:{version}")
edge_server = await cblpytest.edge_servers[0].configure_dataset(
db_name="names", config_file=f"{SCRIPT_DIR}/config/test_mtls_config.json"
)
self.mark_test_step("get server information with TLS")
version = await edge_server.get_version()
self.mark_test_step(f"VERSION:{version}")