tests/ide_tests/opcua_browse_encrypted.sikuli/opcua_service.bash
author Edouard Tisserant <edouard.tisserant@gmail.com>
Thu, 15 Dec 2022 14:49:52 +0100
branchwxPython4
changeset 3698 a538a163ff6f
parent 3676 2f79540660f6
child 3718 7841b651d601
permissions -rw-r--r--
IDE tests: ensure that file browser idled before entering path in new_project
3543
6210c08c1c41 tests: CLI: add simple test running python example
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
     1
#!/bin/bash
6210c08c1c41 tests: CLI: add simple test running python example
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
     2
3676
2f79540660f6 Tests: add encrypted OPCUA browsing test.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3672
diff changeset
     3
echo "Instant encrypted OPC-UA server for test"
2f79540660f6 Tests: add encrypted OPCUA browsing test.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3672
diff changeset
     4
2f79540660f6 Tests: add encrypted OPCUA browsing test.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3672
diff changeset
     5
yes "" | openssl req -x509 -newkey rsa:2048 -keyout my_private_key.pem -out my_cert.pem \
2f79540660f6 Tests: add encrypted OPCUA browsing test.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3672
diff changeset
     6
        -days 355 -nodes -addext "subjectAltName = URI:urn:example.org:FreeOpcUa:python-opcua"
2f79540660f6 Tests: add encrypted OPCUA browsing test.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3672
diff changeset
     7
openssl x509 -outform der -in my_cert.pem -out my_cert.der
2f79540660f6 Tests: add encrypted OPCUA browsing test.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3672
diff changeset
     8
2f79540660f6 Tests: add encrypted OPCUA browsing test.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3672
diff changeset
     9
PROJECT_FILES_DIR=$BEREMIZPATH/tests/projects/opcua_browse_encrypted/project_files
2f79540660f6 Tests: add encrypted OPCUA browsing test.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3672
diff changeset
    10
mkdir $PROJECT_FILES_DIR
2f79540660f6 Tests: add encrypted OPCUA browsing test.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3672
diff changeset
    11
cp my_cert.der my_private_key.pem $PROJECT_FILES_DIR
2f79540660f6 Tests: add encrypted OPCUA browsing test.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3672
diff changeset
    12
2f79540660f6 Tests: add encrypted OPCUA browsing test.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3672
diff changeset
    13
echo "CERTS READY"
3543
6210c08c1c41 tests: CLI: add simple test running python example
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    14
3549
0af7b6a96c53 CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3543
diff changeset
    15
# Run server
3672
230c8b90f3dc Tests: Add OPC-UA server browsing and veriable picking UI test.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3549
diff changeset
    16
exec $BEREMIZPYTHONPATH - << EOF
3543
6210c08c1c41 tests: CLI: add simple test running python example
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff changeset
    17
3549
0af7b6a96c53 CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3543
diff changeset
    18
import sys
0af7b6a96c53 CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3543
diff changeset
    19
import time
0af7b6a96c53 CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3543
diff changeset
    20
0af7b6a96c53 CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3543
diff changeset
    21
from opcua import ua, Server
0af7b6a96c53 CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3543
diff changeset
    22
0af7b6a96c53 CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3543
diff changeset
    23
server = Server()
0af7b6a96c53 CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3543
diff changeset
    24
server.set_endpoint("opc.tcp://127.0.0.1:4840/freeopcua/server/")
0af7b6a96c53 CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3543
diff changeset
    25
3676
2f79540660f6 Tests: add encrypted OPCUA browsing test.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3672
diff changeset
    26
server.set_security_policy([ua.SecurityPolicyType.Basic256Sha256_SignAndEncrypt])
2f79540660f6 Tests: add encrypted OPCUA browsing test.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3672
diff changeset
    27
server.load_certificate("my_cert.der")
2f79540660f6 Tests: add encrypted OPCUA browsing test.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3672
diff changeset
    28
server.load_private_key("my_private_key.pem")
2f79540660f6 Tests: add encrypted OPCUA browsing test.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3672
diff changeset
    29
3549
0af7b6a96c53 CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3543
diff changeset
    30
uri = "http://beremiz.github.io"
0af7b6a96c53 CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3543
diff changeset
    31
idx = server.register_namespace(uri)
0af7b6a96c53 CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3543
diff changeset
    32
0af7b6a96c53 CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3543
diff changeset
    33
objects = server.get_objects_node()
0af7b6a96c53 CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3543
diff changeset
    34
0af7b6a96c53 CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3543
diff changeset
    35
testobj = objects.add_object(idx, "TestObject")
0af7b6a96c53 CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3543
diff changeset
    36
testvarout = testobj.add_variable(idx, "TestOut", 1.2)
0af7b6a96c53 CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3543
diff changeset
    37
testvar = testobj.add_variable(idx, "TestIn", 5.6)
0af7b6a96c53 CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3543
diff changeset
    38
testvar.set_writable()
0af7b6a96c53 CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3543
diff changeset
    39
0af7b6a96c53 CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3543
diff changeset
    40
server.start()
0af7b6a96c53 CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3543
diff changeset
    41
0af7b6a96c53 CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3543
diff changeset
    42
try:
0af7b6a96c53 CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3543
diff changeset
    43
    while True:
0af7b6a96c53 CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3543
diff changeset
    44
        time.sleep(1)
3672
230c8b90f3dc Tests: Add OPC-UA server browsing and veriable picking UI test.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3549
diff changeset
    45
        inval=testvar.get_value()
230c8b90f3dc Tests: Add OPC-UA server browsing and veriable picking UI test.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3549
diff changeset
    46
        print inval
230c8b90f3dc Tests: Add OPC-UA server browsing and veriable picking UI test.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3549
diff changeset
    47
        testvarout.set_value(inval*2)
3549
0af7b6a96c53 CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3543
diff changeset
    48
        sys.stdout.flush()
0af7b6a96c53 CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3543
diff changeset
    49
finally:
0af7b6a96c53 CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3543
diff changeset
    50
    server.stop()
0af7b6a96c53 CLI: fix fake_wx for OPC-UA in CLI, match with test and requirements
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3543
diff changeset
    51
EOF