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
d781c453
Commit
d781c453
authored
Aug 18, 2022
by
Christoph Ziebuhr
Committed by
oroulet
Aug 20, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Always close session
parent
d2203fe7
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
15 additions
and
22 deletions
+15
-22
asyncua/client/client.py
asyncua/client/client.py
+8
-4
asyncua/client/ua_client.py
asyncua/client/ua_client.py
+4
-1
asyncua/server/uaprocessor.py
asyncua/server/uaprocessor.py
+1
-0
tests/test_crypto_connect.py
tests/test_crypto_connect.py
+1
-12
tests/test_permissions.py
tests/test_permissions.py
+1
-5
No files found.
asyncua/client/client.py
View file @
d781c453
...
@@ -272,15 +272,20 @@ class Client:
...
@@ -272,15 +272,20 @@ class Client:
await
self
.
open_secure_channel
()
await
self
.
open_secure_channel
()
try
:
try
:
await
self
.
create_session
()
await
self
.
create_session
()
try
:
await
self
.
activate_session
(
username
=
self
.
_username
,
password
=
self
.
_password
,
certificate
=
self
.
user_certificate
)
except
Exception
:
# clean up session
await
self
.
close_session
()
raise
except
Exception
:
except
Exception
:
# clean up secure channel
# clean up secure channel
self
.
close_secure_channel
()
await
self
.
close_secure_channel
()
raise
raise
except
Exception
:
except
Exception
:
# clean up open socket
# clean up open socket
self
.
disconnect_socket
()
self
.
disconnect_socket
()
raise
raise
await
self
.
activate_session
(
username
=
self
.
_username
,
password
=
self
.
_password
,
certificate
=
self
.
user_certificate
)
async
def
disconnect
(
self
):
async
def
disconnect
(
self
):
"""
"""
...
@@ -301,8 +306,7 @@ class Client:
...
@@ -301,8 +306,7 @@ class Client:
await
self
.
uaclient
.
connect_socket
(
self
.
server_url
.
hostname
,
self
.
server_url
.
port
)
await
self
.
uaclient
.
connect_socket
(
self
.
server_url
.
hostname
,
self
.
server_url
.
port
)
def
disconnect_socket
(
self
):
def
disconnect_socket
(
self
):
if
self
.
uaclient
:
self
.
uaclient
.
disconnect_socket
()
self
.
uaclient
.
disconnect_socket
()
async
def
send_hello
(
self
):
async
def
send_hello
(
self
):
"""
"""
...
...
asyncua/client/ua_client.py
View file @
d781c453
...
@@ -7,7 +7,7 @@ from typing import Dict, List, Optional, Union
...
@@ -7,7 +7,7 @@ from typing import Dict, List, Optional, Union
from
asyncua
import
ua
from
asyncua
import
ua
from
..ua.ua_binary
import
struct_from_binary
,
uatcp_to_binary
,
struct_to_binary
,
nodeid_from_binary
,
header_from_binary
from
..ua.ua_binary
import
struct_from_binary
,
uatcp_to_binary
,
struct_to_binary
,
nodeid_from_binary
,
header_from_binary
from
..ua.uaerrors
import
BadTimeout
,
BadNoSubscription
,
BadSessionClosed
,
UaStructParsingError
from
..ua.uaerrors
import
BadTimeout
,
BadNoSubscription
,
BadSessionClosed
,
BadUserAccessDenied
,
UaStructParsingError
from
..common.connection
import
SecureConnection
from
..common.connection
import
SecureConnection
...
@@ -335,6 +335,9 @@ class UaClient:
...
@@ -335,6 +335,9 @@ class UaClient:
# Alternatively we could make sure that there are no publish requests in flight when
# Alternatively we could make sure that there are no publish requests in flight when
# closing the session.
# closing the session.
pass
pass
except
BadUserAccessDenied
:
# Problem: older versions of asyncua didn't allow closing non-activated sessions. just ignore it.
pass
async
def
browse
(
self
,
parameters
):
async
def
browse
(
self
,
parameters
):
self
.
logger
.
info
(
"browse"
)
self
.
logger
.
info
(
"browse"
)
...
...
asyncua/server/uaprocessor.py
View file @
d781c453
...
@@ -149,6 +149,7 @@ class UaProcessor:
...
@@ -149,6 +149,7 @@ class UaProcessor:
async
def
_process_message
(
self
,
typeid
,
requesthdr
,
seqhdr
,
body
):
async
def
_process_message
(
self
,
typeid
,
requesthdr
,
seqhdr
,
body
):
if
typeid
in
[
ua
.
NodeId
(
ua
.
ObjectIds
.
CreateSessionRequest_Encoding_DefaultBinary
),
if
typeid
in
[
ua
.
NodeId
(
ua
.
ObjectIds
.
CreateSessionRequest_Encoding_DefaultBinary
),
ua
.
NodeId
(
ua
.
ObjectIds
.
CloseSessionRequest_Encoding_DefaultBinary
),
ua
.
NodeId
(
ua
.
ObjectIds
.
ActivateSessionRequest_Encoding_DefaultBinary
),
ua
.
NodeId
(
ua
.
ObjectIds
.
ActivateSessionRequest_Encoding_DefaultBinary
),
ua
.
NodeId
(
ua
.
ObjectIds
.
FindServersRequest_Encoding_DefaultBinary
),
ua
.
NodeId
(
ua
.
ObjectIds
.
FindServersRequest_Encoding_DefaultBinary
),
ua
.
NodeId
(
ua
.
ObjectIds
.
GetEndpointsRequest_Encoding_DefaultBinary
)]:
ua
.
NodeId
(
ua
.
ObjectIds
.
GetEndpointsRequest_Encoding_DefaultBinary
)]:
...
...
tests/test_crypto_connect.py
View file @
d781c453
...
@@ -248,10 +248,6 @@ async def test_certificate_handling_failure(srv_crypto_one_cert):
...
@@ -248,10 +248,6 @@ async def test_certificate_handling_failure(srv_crypto_one_cert):
async
with
clt
:
async
with
clt
:
assert
await
clt
.
get_objects_node
().
get_children
()
assert
await
clt
.
get_objects_node
().
get_children
()
with
pytest
.
raises
(
ua
.
uaerrors
.
BadUserAccessDenied
):
# disconnect manually to close the event loop and appease pytest
await
clt
.
disconnect
()
async
def
test_encrypted_private_key_handling_failure
(
srv_crypto_one_cert
):
async
def
test_encrypted_private_key_handling_failure
(
srv_crypto_one_cert
):
_
,
cert
=
srv_crypto_one_cert
_
,
cert
=
srv_crypto_one_cert
...
@@ -269,10 +265,6 @@ async def test_encrypted_private_key_handling_failure(srv_crypto_one_cert):
...
@@ -269,10 +265,6 @@ async def test_encrypted_private_key_handling_failure(srv_crypto_one_cert):
async
with
clt
:
async
with
clt
:
assert
await
clt
.
get_objects_node
().
get_children
()
assert
await
clt
.
get_objects_node
().
get_children
()
with
pytest
.
raises
(
ua
.
uaerrors
.
BadUserAccessDenied
):
# disconnect manually to close the event loop and appease pytest
await
clt
.
disconnect
()
async
def
test_certificate_handling_mismatched_creds
(
srv_crypto_one_cert
):
async
def
test_certificate_handling_mismatched_creds
(
srv_crypto_one_cert
):
_
,
cert
=
srv_crypto_one_cert
_
,
cert
=
srv_crypto_one_cert
...
@@ -413,9 +405,6 @@ async def test_anonymous_rejection():
...
@@ -413,9 +405,6 @@ async def test_anonymous_rejection():
cert
,
cert
,
mode
=
ua
.
MessageSecurityMode
.
SignAndEncrypt
mode
=
ua
.
MessageSecurityMode
.
SignAndEncrypt
)
)
with
pytest
.
raises
(
ua
.
UaStatusCodeError
)
as
exc_info
:
with
pytest
.
raises
(
ua
.
uaerrors
.
BadIdentityTokenRejected
)
:
await
clt
.
connect
()
await
clt
.
connect
()
with
pytest
.
raises
(
ua
.
UaStatusCodeError
):
await
clt
.
disconnect
()
assert
ua
.
StatusCodes
.
BadIdentityTokenRejected
==
exc_info
.
type
.
code
await
srv
.
stop
()
await
srv
.
stop
()
tests/test_permissions.py
View file @
d781c453
...
@@ -125,8 +125,4 @@ async def test_permissions_anonymous(srv_crypto_one_cert):
...
@@ -125,8 +125,4 @@ async def test_permissions_anonymous(srv_crypto_one_cert):
)
)
await
clt
.
connect
()
await
clt
.
connect
()
await
clt
.
get_endpoints
()
await
clt
.
get_endpoints
()
with
pytest
.
raises
(
ua
.
uaerrors
.
BadUserAccessDenied
):
await
clt
.
disconnect
()
# currently CloseSessionRequest ist not allowed so excpetion is expected
# why CloseSession is not allowed if CreateSession works?
# but to prevent leaking tasks we do disconnect and get the exception
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