-
Notifications
You must be signed in to change notification settings - Fork 367
/
Copy pathtest_password.py
59 lines (44 loc) · 1.54 KB
/
test_password.py
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
import pytest
from asyncua import Client, Server, ua
from asyncua.server.users import UserRole, User
uri = "opc.tcp://127.0.0.1:48517/baz/server"
uri_creds = "opc.tcp://foobar:hR%26yjjGhP%246%40nQ4e@127.0.0.1:48517/baz/server"
uri_wrong_creds = "opc.tcp://foobar:wrong@127.0.0.1:48517/baz/server"
class UserManager:
def get_user(self, iserver, username=None, password=None, certificate=None):
if username == "foobar" and password == "hR&yjjGhP$6@nQ4e":
return User(role=UserRole.User)
return None
@pytest.fixture()
async def srv_user():
srv = Server(user_manager=UserManager())
srv.set_endpoint(uri)
srv.set_identity_tokens([ua.UserNameIdentityToken])
await srv.init()
await srv.start()
yield srv
await srv.stop()
async def test_creds(srv_user):
clt = Client(uri)
clt.set_user("foobar")
clt.set_password("hR&yjjGhP$6@nQ4e")
await clt.connect()
await clt.disconnect()
async def test_wrong_creds(srv_user):
clt = Client(uri)
clt.set_user("foobar")
clt.set_password("wrong")
with pytest.raises(ua.uaerrors.BadUserAccessDenied):
await clt.connect()
await clt.disconnect()
async def test_creds_in_uri(srv_user):
clt = Client(uri_creds)
# check if credentials got removed
assert clt.server_url.geturl() == uri
await clt.connect()
await clt.disconnect()
async def test_wrong_creds_in_uri(srv_user):
clt = Client(uri_wrong_creds)
with pytest.raises(ua.uaerrors.BadUserAccessDenied):
await clt.connect()
await clt.disconnect()