Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
opcua-asyncio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nikola Balog
opcua-asyncio
Commits
d2203fe7
Commit
d2203fe7
authored
Aug 19, 2022
by
Christoph Ziebuhr
Committed by
oroulet
Aug 20, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix credentials in server_url
parent
139863f8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
3 deletions
+73
-3
asyncua/client/client.py
asyncua/client/client.py
+14
-3
tests/test_password.py
tests/test_password.py
+59
-0
No files found.
asyncua/client/client.py
View file @
d2203fe7
import
asyncio
import
logging
from
typing
import
List
,
Union
,
Coroutine
,
Optional
from
urllib.parse
import
urlparse
from
urllib.parse
import
urlparse
,
unquote
from
asyncua
import
ua
from
.ua_client
import
UaClient
...
...
@@ -29,6 +29,10 @@ class Client:
use UaClient object, available as self.uaclient
which offers the raw OPC-UA services interface.
"""
_username
=
None
_password
=
None
def
__init__
(
self
,
url
:
str
,
timeout
:
float
=
4
):
"""
:param url: url of the server.
...
...
@@ -43,8 +47,15 @@ class Client:
"""
self
.
server_url
=
urlparse
(
url
)
# take initial username and password from the url
self
.
_username
=
self
.
server_url
.
username
self
.
_password
=
self
.
server_url
.
password
userinfo
,
have_info
,
hostinfo
=
self
.
server_url
.
netloc
.
rpartition
(
'@'
)
if
have_info
:
username
,
have_password
,
password
=
userinfo
.
partition
(
':'
)
self
.
_username
=
unquote
(
username
)
if
have_password
:
self
.
_password
=
unquote
(
password
)
# remove credentials from url, preventing them to be sent unencrypted in e.g. send_hello
self
.
server_url
=
self
.
server_url
.
__class__
(
self
.
server_url
[
0
],
hostinfo
,
*
self
.
server_url
[
2
:])
self
.
name
=
"Pure Python Async. Client"
self
.
description
=
self
.
name
self
.
application_uri
=
"urn:freeopcua:client"
...
...
tests/test_password.py
0 → 100644
View file @
d2203fe7
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_security_IDs
([
"Username"
])
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
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment