# HG changeset patch # User Edouard Tisserant # Date 1668517450 -3600 # Node ID 2f79540660f6a2cb2eec14769eb910625fc32398 # Parent d331eb981b4404bc906a000fd05dfb0429b92c4f Tests: add encrypted OPCUA browsing test. diff -r d331eb981b44 -r 2f79540660f6 tests/ide_tests/opcua_browse_encrypted.sikuli/opcua_browse_encrypted.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/ide_tests/opcua_browse_encrypted.sikuli/opcua_browse_encrypted.py Tue Nov 15 14:04:10 2022 +0100 @@ -0,0 +1,69 @@ +""" This test opens, modifies, builds and runs exemple project named "python". +Test succeeds if runtime's stdout behaves as expected +""" + +import os +import time + +# allow module import from current test directory's parent +addImportPath(os.path.dirname(getBundlePath())) + +# common test definitions module +from sikuliberemiz import run_test, AuxiliaryProcess + +def test(app): + + server = AuxiliaryProcess(app, ["/bin/bash",os.path.join(getBundlePath(),"opcua_service.bash")]) + #server = AuxiliaryProcess(app, ["/bin/bash","-c","echo $PWD"]) + + server.waitPatternInStdout("CERTS READY", 5) + + app.doubleClick("opcua_node.png") + + app.WaitIdleUI() + + # app.click("Browse Server") # OCR didn't work because of gradient in button... + app.click("opcua_browse_server.png") + + app.WaitIdleUI() + + app.doubleClick("Objects") + + app.WaitIdleUI() + + app.doubleClick("TestObject") + + app.dragNdrop("TestIn", "output variables") + + app.wait(1) + + app.dragNdrop("TestOut", "input variables") + + app.wait(3) + + app.k.Clean() + + app.waitForChangeAndIdleStdout() + + app.k.Build() + + app.waitForChangeAndIdleStdout() + + app.k.Connect() + + app.waitForChangeAndIdleStdout() + + app.k.Transfer() + + app.waitForChangeAndIdleStdout() + + app.k.Run() + + # wait 10 seconds for 10 patterns + res = app.waitPatternInStdout("6.8", 10) + + server.close() + + return res + +run_test(test, testproject="opcua_browse_encrypted") diff -r d331eb981b44 -r 2f79540660f6 tests/ide_tests/opcua_browse_encrypted.sikuli/opcua_browse_server.png Binary file tests/ide_tests/opcua_browse_encrypted.sikuli/opcua_browse_server.png has changed diff -r d331eb981b44 -r 2f79540660f6 tests/ide_tests/opcua_browse_encrypted.sikuli/opcua_node.png Binary file tests/ide_tests/opcua_browse_encrypted.sikuli/opcua_node.png has changed diff -r d331eb981b44 -r 2f79540660f6 tests/ide_tests/opcua_browse_encrypted.sikuli/opcua_service.bash --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/ide_tests/opcua_browse_encrypted.sikuli/opcua_service.bash Tue Nov 15 14:04:10 2022 +0100 @@ -0,0 +1,51 @@ +#!/bin/bash + +echo "Instant encrypted OPC-UA server for test" + +yes "" | openssl req -x509 -newkey rsa:2048 -keyout my_private_key.pem -out my_cert.pem \ + -days 355 -nodes -addext "subjectAltName = URI:urn:example.org:FreeOpcUa:python-opcua" +openssl x509 -outform der -in my_cert.pem -out my_cert.der + +PROJECT_FILES_DIR=$BEREMIZPATH/tests/projects/opcua_browse_encrypted/project_files +mkdir $PROJECT_FILES_DIR +cp my_cert.der my_private_key.pem $PROJECT_FILES_DIR + +echo "CERTS READY" + +# Run server +exec $BEREMIZPYTHONPATH - << EOF + +import sys +import time + +from opcua import ua, Server + +server = Server() +server.set_endpoint("opc.tcp://127.0.0.1:4840/freeopcua/server/") + +server.set_security_policy([ua.SecurityPolicyType.Basic256Sha256_SignAndEncrypt]) +server.load_certificate("my_cert.der") +server.load_private_key("my_private_key.pem") + +uri = "http://beremiz.github.io" +idx = server.register_namespace(uri) + +objects = server.get_objects_node() + +testobj = objects.add_object(idx, "TestObject") +testvarout = testobj.add_variable(idx, "TestOut", 1.2) +testvar = testobj.add_variable(idx, "TestIn", 5.6) +testvar.set_writable() + +server.start() + +try: + while True: + time.sleep(1) + inval=testvar.get_value() + print inval + testvarout.set_value(inval*2) + sys.stdout.flush() +finally: + server.stop() +EOF diff -r d331eb981b44 -r 2f79540660f6 tests/projects/opcua_browse_encrypted/beremiz.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/projects/opcua_browse_encrypted/beremiz.xml Tue Nov 15 14:04:10 2022 +0100 @@ -0,0 +1,4 @@ + + + + diff -r d331eb981b44 -r 2f79540660f6 tests/projects/opcua_browse_encrypted/opcua_0@opcua/baseconfnode.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/projects/opcua_browse_encrypted/opcua_0@opcua/baseconfnode.xml Tue Nov 15 14:04:10 2022 +0100 @@ -0,0 +1,2 @@ + + diff -r d331eb981b44 -r 2f79540660f6 tests/projects/opcua_browse_encrypted/opcua_0@opcua/confnode.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/projects/opcua_browse_encrypted/opcua_0@opcua/confnode.xml Tue Nov 15 14:04:10 2022 +0100 @@ -0,0 +1,9 @@ + + + + + + + + + diff -r d331eb981b44 -r 2f79540660f6 tests/projects/opcua_browse_encrypted/plc.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/projects/opcua_browse_encrypted/plc.xml Tue Nov 15 14:04:10 2022 +0100 @@ -0,0 +1,208 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + LocalVar0 + + + + + + + + + + + LocalVar1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + TRUE + + + + + + + 'pfunc("' + + + + + + + '\n")' + + + + + + + 3.4 + + + + + + + + + + + + + + + + + + diff -r d331eb981b44 -r 2f79540660f6 tests/projects/opcua_browse_encrypted/py_ext_0@py_ext/baseconfnode.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/projects/opcua_browse_encrypted/py_ext_0@py_ext/baseconfnode.xml Tue Nov 15 14:04:10 2022 +0100 @@ -0,0 +1,2 @@ + + diff -r d331eb981b44 -r 2f79540660f6 tests/projects/opcua_browse_encrypted/py_ext_0@py_ext/pyfile.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/projects/opcua_browse_encrypted/py_ext_0@py_ext/pyfile.xml Tue Nov 15 14:04:10 2022 +0100 @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + +