Tests: add encrypted OPCUA browsing test. wxPython4
authorEdouard Tisserant <edouard.tisserant@gmail.com>
Tue, 15 Nov 2022 14:04:10 +0100
branchwxPython4
changeset 3676 2f79540660f6
parent 3675 d331eb981b44
child 3677 6d9040e07c32
Tests: add encrypted OPCUA browsing test.
tests/ide_tests/opcua_browse_encrypted.sikuli/opcua_browse_encrypted.py
tests/ide_tests/opcua_browse_encrypted.sikuli/opcua_browse_server.png
tests/ide_tests/opcua_browse_encrypted.sikuli/opcua_node.png
tests/ide_tests/opcua_browse_encrypted.sikuli/opcua_service.bash
tests/projects/opcua_browse_encrypted/beremiz.xml
tests/projects/opcua_browse_encrypted/opcua_0@opcua/baseconfnode.xml
tests/projects/opcua_browse_encrypted/opcua_0@opcua/confnode.xml
tests/projects/opcua_browse_encrypted/opcua_0@opcua/selected.csv
tests/projects/opcua_browse_encrypted/plc.xml
tests/projects/opcua_browse_encrypted/py_ext_0@py_ext/baseconfnode.xml
tests/projects/opcua_browse_encrypted/py_ext_0@py_ext/pyfile.xml
--- /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")
Binary file tests/ide_tests/opcua_browse_encrypted.sikuli/opcua_browse_server.png has changed
Binary file tests/ide_tests/opcua_browse_encrypted.sikuli/opcua_node.png has changed
--- /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
--- /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 @@
+<?xml version='1.0' encoding='utf-8'?>
+<BeremizRoot xmlns:xsd="http://www.w3.org/2001/XMLSchema" URI_location="LOCAL://">
+  <TargetType/>
+</BeremizRoot>
--- /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 @@
+<?xml version='1.0' encoding='utf-8'?>
+<BaseParams xmlns:xsd="http://www.w3.org/2001/XMLSchema" IEC_Channel="0" Name="opcua_0"/>
--- /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 @@
+<?xml version='1.0' encoding='utf-8'?>
+<OPCUAClient xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+  <AuthType>
+    <x509 Certificate="my_cert.der" PrivateKey="my_private_key.pem">
+      <Policy/>
+      <Mode/>
+    </x509>
+  </AuthType>
+</OPCUAClient>
--- /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 @@
+<?xml version='1.0' encoding='utf-8'?>
+<project xmlns:ns1="http://www.plcopen.org/xml/tc6_0201" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.plcopen.org/xml/tc6_0201">
+  <fileHeader companyName="Unknown" productName="Unnamed" productVersion="1" creationDateTime="2022-07-16T10:46:25"/>
+  <contentHeader name="Unnamed" modificationDateTime="2022-11-10T17:51:34">
+    <coordinateInfo>
+      <fbd>
+        <scaling x="5" y="5"/>
+      </fbd>
+      <ld>
+        <scaling x="0" y="0"/>
+      </ld>
+      <sfc>
+        <scaling x="0" y="0"/>
+      </sfc>
+    </coordinateInfo>
+  </contentHeader>
+  <types>
+    <dataTypes/>
+    <pous>
+      <pou name="program0" pouType="program">
+        <interface>
+          <localVars>
+            <variable name="LocalVar0" address="%IL0.2">
+              <type>
+                <LREAL/>
+              </type>
+            </variable>
+            <variable name="LocalVar1" address="%QL0.3">
+              <type>
+                <LREAL/>
+              </type>
+            </variable>
+          </localVars>
+          <localVars>
+            <variable name="python_poll0">
+              <type>
+                <derived name="python_poll"/>
+              </type>
+            </variable>
+          </localVars>
+        </interface>
+        <body>
+          <FBD>
+            <inVariable localId="1" executionOrderId="0" height="25" width="85" negated="false">
+              <position x="160" y="190"/>
+              <connectionPointOut>
+                <relPosition x="85" y="10"/>
+              </connectionPointOut>
+              <expression>LocalVar0</expression>
+            </inVariable>
+            <outVariable localId="2" executionOrderId="0" height="24" width="82" negated="false">
+              <position x="238" y="49"/>
+              <connectionPointIn>
+                <relPosition x="0" y="11"/>
+                <connection refLocalId="9">
+                  <position x="238" y="60"/>
+                  <position x="204" y="60"/>
+                </connection>
+              </connectionPointIn>
+              <expression>LocalVar1</expression>
+            </outVariable>
+            <block localId="4" typeName="python_poll" instanceName="python_poll0" executionOrderId="0" height="60" width="98">
+              <position x="658" y="101"/>
+              <inputVariables>
+                <variable formalParameter="TRIG">
+                  <connectionPointIn>
+                    <relPosition x="0" y="29"/>
+                    <connection refLocalId="7">
+                      <position x="658" y="130"/>
+                      <position x="623" y="130"/>
+                    </connection>
+                  </connectionPointIn>
+                </variable>
+                <variable formalParameter="CODE">
+                  <connectionPointIn>
+                    <relPosition x="0" y="49"/>
+                    <connection refLocalId="6" formalParameter="OUT">
+                      <position x="658" y="150"/>
+                      <position x="560" y="150"/>
+                    </connection>
+                  </connectionPointIn>
+                </variable>
+              </inputVariables>
+              <inOutVariables/>
+              <outputVariables>
+                <variable formalParameter="ACK">
+                  <connectionPointOut>
+                    <relPosition x="98" y="29"/>
+                  </connectionPointOut>
+                </variable>
+                <variable formalParameter="RESULT">
+                  <connectionPointOut>
+                    <relPosition x="98" y="49"/>
+                  </connectionPointOut>
+                </variable>
+              </outputVariables>
+            </block>
+            <block localId="5" typeName="LREAL_TO_STRING" executionOrderId="0" height="40" width="130">
+              <position x="280" y="170"/>
+              <inputVariables>
+                <variable formalParameter="IN">
+                  <connectionPointIn>
+                    <relPosition x="0" y="30"/>
+                    <connection refLocalId="1">
+                      <position x="280" y="200"/>
+                      <position x="255" y="200"/>
+                      <position x="255" y="200"/>
+                      <position x="300" y="200"/>
+                      <position x="300" y="200"/>
+                      <position x="245" y="200"/>
+                    </connection>
+                  </connectionPointIn>
+                </variable>
+              </inputVariables>
+              <inOutVariables/>
+              <outputVariables>
+                <variable formalParameter="OUT">
+                  <connectionPointOut>
+                    <relPosition x="130" y="30"/>
+                  </connectionPointOut>
+                </variable>
+              </outputVariables>
+            </block>
+            <block localId="6" typeName="CONCAT" executionOrderId="0" height="165" width="63">
+              <position x="497" y="108"/>
+              <inputVariables>
+                <variable formalParameter="IN1">
+                  <connectionPointIn>
+                    <relPosition x="0" y="42"/>
+                    <connection refLocalId="3">
+                      <position x="497" y="150"/>
+                      <position x="330" y="150"/>
+                    </connection>
+                  </connectionPointIn>
+                </variable>
+                <variable formalParameter="IN2">
+                  <connectionPointIn>
+                    <relPosition x="0" y="92"/>
+                    <connection refLocalId="5" formalParameter="OUT">
+                      <position x="497" y="200"/>
+                      <position x="410" y="200"/>
+                    </connection>
+                  </connectionPointIn>
+                </variable>
+                <variable formalParameter="IN3">
+                  <connectionPointIn>
+                    <relPosition x="0" y="142"/>
+                    <connection refLocalId="8">
+                      <position x="497" y="250"/>
+                      <position x="225" y="250"/>
+                    </connection>
+                  </connectionPointIn>
+                </variable>
+              </inputVariables>
+              <inOutVariables/>
+              <outputVariables>
+                <variable formalParameter="OUT">
+                  <connectionPointOut>
+                    <relPosition x="63" y="42"/>
+                  </connectionPointOut>
+                </variable>
+              </outputVariables>
+            </block>
+            <inVariable localId="7" executionOrderId="0" height="24" width="44" negated="false">
+              <position x="579" y="116"/>
+              <connectionPointOut>
+                <relPosition x="44" y="14"/>
+              </connectionPointOut>
+              <expression>TRUE</expression>
+            </inVariable>
+            <inVariable localId="3" executionOrderId="0" height="25" width="180" negated="false">
+              <position x="160" y="140"/>
+              <connectionPointOut>
+                <relPosition x="180" y="10"/>
+              </connectionPointOut>
+              <expression>'pfunc("'</expression>
+            </inVariable>
+            <inVariable localId="8" executionOrderId="0" height="25" width="230" negated="false">
+              <position x="165" y="240"/>
+              <connectionPointOut>
+                <relPosition x="230" y="10"/>
+              </connectionPointOut>
+              <expression>'\n")'</expression>
+            </inVariable>
+            <inVariable localId="9" executionOrderId="0" height="29" width="45" negated="false">
+              <position x="159" y="47"/>
+              <connectionPointOut>
+                <relPosition x="45" y="13"/>
+              </connectionPointOut>
+              <expression>3.4</expression>
+            </inVariable>
+          </FBD>
+        </body>
+      </pou>
+    </pous>
+  </types>
+  <instances>
+    <configurations>
+      <configuration name="config">
+        <resource name="resource1">
+          <task name="task0" priority="0" interval="T#100ms">
+            <pouInstance name="instance0" typeName="program0"/>
+          </task>
+        </resource>
+      </configuration>
+    </configurations>
+  </instances>
+</project>
--- /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 @@
+<?xml version='1.0' encoding='utf-8'?>
+<BaseParams xmlns:xsd="http://www.w3.org/2001/XMLSchema" IEC_Channel="1" Name="py_ext_0"/>
--- /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 @@
+<?xml version='1.0' encoding='utf-8'?>
+<PyFile xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+  <variables/>
+  <globals>
+    <xhtml:p><![CDATA[
+import sys
+def pfunc(arg):
+    sys.stdout.write(arg)
+    sys.stdout.flush()
+
+pfunc("globals section\n")
+
+]]></xhtml:p>
+  </globals>
+  <init>
+    <xhtml:p><![CDATA[
+pfunc("init section\n")
+]]></xhtml:p>
+  </init>
+  <cleanup>
+    <xhtml:p><![CDATA[
+pfunc("cleanup section\n")
+]]></xhtml:p>
+  </cleanup>
+  <start>
+    <xhtml:p><![CDATA[
+pfunc("start section\n")
+]]></xhtml:p>
+  </start>
+  <stop>
+    <xhtml:p><![CDATA[
+pfunc("stop section\n")
+
+]]></xhtml:p>
+  </stop>
+</PyFile>