diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1bc3496..6ad15e6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,3 +10,5 @@ on: jobs: build: uses: axonivy-market/github-workflows/.github/workflows/ci.yml@v2 + with: + mvnArgs: -Dmaven.test.failure.ignore=true -Divy.engine.version=10.0.14 diff --git a/.gitignore b/.gitignore index d66b510..a0ceba0 100644 --- a/.gitignore +++ b/.gitignore @@ -20,5 +20,8 @@ src_wsproc/ # local config **/resources/ threema-connector/config/variables.yaml +threema-connector/config/variables.yaml_template +threema-connector/config/variables.yaml_complete -**/threema-connector-webtest/** +# threema SKD +threema-connector/lib/threema-msgapi-tool.* diff --git a/.project b/.project index d90b7fe..cba7369 100644 --- a/.project +++ b/.project @@ -1,17 +1,17 @@ - threema-connector-modules - - - - - - org.eclipse.m2e.core.maven2Builder - - - - - - org.eclipse.m2e.core.maven2Nature - + threema-connector-modules + + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + diff --git a/README.md b/README.md index da816a1..6d8f9d8 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Threema Connector -[![CI Build](https://github.com/axonivy-market/REPO-NAME/actions/workflows/ci.yml/badge.svg)](https://github.com/axonivy-market/threema-connector/actions/workflows/ci.yml) +[![CI Build](https://github.com/axonivy-market/threema-connector/actions/workflows/ci.yml/badge.svg)](https://github.com/axonivy-market/threema-connector/actions/workflows/ci.yml) Use the [Threema.Gateway API](https://threema.ch/en/gateway) to send messages to one or more recipients, enabling new notification options for your business processes. diff --git a/pom.xml b/pom.xml index d5910f9..4e22ebe 100644 --- a/pom.xml +++ b/pom.xml @@ -1,9 +1,11 @@ 4.0.0 - com.axonivy.market + com.axonivy.connector.threema threema-connector threema-connector-modules - 10.0.0-SNAPSHOT + 10.0.2-SNAPSHOT pom @@ -11,6 +13,7 @@ ${project.name}-demo ${project.name}-test ${project.name}-product + ${project.name}-webtest diff --git a/threema-connector-demo/.classpath b/threema-connector-demo/.classpath index aff6211..157b754 100644 --- a/threema-connector-demo/.classpath +++ b/threema-connector-demo/.classpath @@ -1,28 +1,32 @@ - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/threema-connector-demo/.project b/threema-connector-demo/.project index a8e34fb..7289f72 100644 --- a/threema-connector-demo/.project +++ b/threema-connector-demo/.project @@ -1,49 +1,49 @@ - threema-connector-demo - - - - - - ch.ivyteam.ivy.designer.dataClasses.ui.ivyDataClassBuilder - - - - - ch.ivyteam.ivy.designer.process.ui.ivyWebServiceProcessClassBuilder - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.wst.common.project.facet.core.builder - - - - - ch.ivyteam.ivy.designer.ide.ivyModelValidationBuilder - - - - - org.eclipse.m2e.core.maven2Builder - - - - - - ch.ivyteam.ivy.project.IvyProjectNature - org.eclipse.wst.common.modulecore.ModuleCoreNature - org.eclipse.jem.workbench.JavaEMFNature - org.eclipse.jdt.core.javanature - org.eclipse.m2e.core.maven2Nature - org.eclipse.jem.beaninfo.BeanInfoNature - org.eclipse.wst.common.project.facet.core.nature - org.eclipse.wst.jsdt.core.jsNature - + threema-connector-demo + + + + + + ch.ivyteam.ivy.designer.dataClasses.ui.ivyDataClassBuilder + + + + + ch.ivyteam.ivy.designer.process.ui.ivyWebServiceProcessClassBuilder + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + ch.ivyteam.ivy.designer.ide.ivyModelValidationBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + ch.ivyteam.ivy.project.IvyProjectNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + org.eclipse.jem.beaninfo.BeanInfoNature + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.wst.jsdt.core.jsNature + diff --git a/threema-connector-demo/.settings/.jsdtscope b/threema-connector-demo/.settings/.jsdtscope index 869c01d..e4ab59a 100644 --- a/threema-connector-demo/.settings/.jsdtscope +++ b/threema-connector-demo/.settings/.jsdtscope @@ -1,12 +1,17 @@ - - - - - - - - - + + + + + + + + + diff --git a/threema-connector-demo/.settings/org.eclipse.wst.common.component b/threema-connector-demo/.settings/org.eclipse.wst.common.component index 7e0f2c9..db6eed0 100644 --- a/threema-connector-demo/.settings/org.eclipse.wst.common.component +++ b/threema-connector-demo/.settings/org.eclipse.wst.common.component @@ -1,10 +1,18 @@ - - - - - - - - - + + + + + + + + + + diff --git a/threema-connector-demo/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml b/threema-connector-demo/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml index 9b4b9fc..e725c8d 100644 --- a/threema-connector-demo/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml +++ b/threema-connector-demo/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml @@ -1,7 +1,8 @@ - + diff --git a/threema-connector-demo/.settings/org.eclipse.wst.common.project.facet.core.xml b/threema-connector-demo/.settings/org.eclipse.wst.common.project.facet.core.xml index 156ecdb..3bb273d 100644 --- a/threema-connector-demo/.settings/org.eclipse.wst.common.project.facet.core.xml +++ b/threema-connector-demo/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -1,8 +1,8 @@ - - - - - + + + + + diff --git a/threema-connector-demo/config/persistence.xml b/threema-connector-demo/config/persistence.xml index d6b96d7..3de1768 100644 --- a/threema-connector-demo/config/persistence.xml +++ b/threema-connector-demo/config/persistence.xml @@ -1,2 +1,4 @@ - + diff --git a/threema-connector-demo/config/roles.xml b/threema-connector-demo/config/roles.xml index 59892fe..c7c6911 100644 --- a/threema-connector-demo/config/roles.xml +++ b/threema-connector-demo/config/roles.xml @@ -1,4 +1,4 @@ - Everybody + Everybody diff --git a/threema-connector-demo/config/users.xml b/threema-connector-demo/config/users.xml index 51a6906..1e173fa 100644 --- a/threema-connector-demo/config/users.xml +++ b/threema-connector-demo/config/users.xml @@ -1,2 +1,2 @@ - + diff --git a/threema-connector-demo/dataclasses/threema/connector/demo/sendDemoMessageData.ivyClass b/threema-connector-demo/dataclasses/threema/connector/demo/sendDemoMessageData.ivyClass index 54168df..43c34d8 100644 --- a/threema-connector-demo/dataclasses/threema/connector/demo/sendDemoMessageData.ivyClass +++ b/threema-connector-demo/dataclasses/threema/connector/demo/sendDemoMessageData.ivyClass @@ -8,3 +8,9 @@ type String #field type PERSISTENT #fieldModifier apiResponse List #field apiResponse PERSISTENT #fieldModifier +publicKey String #field +publicKey PERSISTENT #fieldModifier +privatekey String #field +privatekey PERSISTENT #fieldModifier +sendAnother Boolean #field +sendAnother PERSISTENT #fieldModifier diff --git a/threema-connector-demo/pom.xml b/threema-connector-demo/pom.xml index 11794b0..dddf810 100644 --- a/threema-connector-demo/pom.xml +++ b/threema-connector-demo/pom.xml @@ -1,14 +1,13 @@ - + 4.0.0 - threema.connector.demo + com.axonivy.connector.threema threema-connector-demo - 10.0.0-SNAPSHOT + 10.0.2-SNAPSHOT iar - threema.connector + com.axonivy.connector.threema threema-connector ${project.version} iar @@ -19,7 +18,7 @@ com.axonivy.ivy.ci project-build-plugin - 10.0.6 + 10.0.14 true diff --git a/threema-connector-demo/processes/MessageMultipleRecipients.p.json b/threema-connector-demo/processes/MessageMultipleRecipients.p.json deleted file mode 100644 index 86b8832..0000000 --- a/threema-connector-demo/processes/MessageMultipleRecipients.p.json +++ /dev/null @@ -1,106 +0,0 @@ -{ - "format" : "10.0.0", - "id" : "18B1ED116183D822", - "config" : { - "data" : "threema.connector.demo.sendDemoMessageData" - }, - "elements" : [ { - "id" : "f0", - "type" : "RequestStart", - "name" : "start.ivp", - "config" : { - "callSignature" : "start", - "outLink" : "start.ivp", - "tags" : "demo" - }, - "visual" : { - "at" : { "x" : 112, "y" : 64 } - }, - "connect" : { "id" : "f3", "to" : "f2" } - }, { - "id" : "f1", - "type" : "TaskEnd", - "visual" : { - "at" : { "x" : 704, "y" : 64 } - } - }, { - "id" : "f2", - "type" : "DialogCall", - "name" : "multipleRecipients", - "config" : { - "dialogId" : "threema.connector.demo.multipleRecipients", - "startMethod" : "start(threema.connector.demo.sendDemoMessageData)", - "output" : { - "map" : { - "out" : [ - "in", - "result.sendDemoMessageData", - "result.sendDemoMessageData" - ] - } - }, - "call" : { - "params" : [ - { "name" : "sendDemoMessageData", "type" : "threema.connector.demo.sendDemoMessageData" } - ], - "map" : { - "param.sendDemoMessageData" : [ - "in", - "in" - ] - } - } - }, - "visual" : { - "at" : { "x" : 240, "y" : 64 } - }, - "connect" : { "id" : "f5", "to" : "f4" } - }, { - "id" : "f4", - "type" : "SubProcessCall", - "name" : "handleMessage", - "config" : { - "processCall" : "multipleRecipients:call(String,List)", - "output" : { - "map" : { - "out" : "in", - "out.apiResponse" : "result.apiResponse" - } - }, - "call" : { - "params" : [ - { "name" : "plainMsg", "type" : "String" }, - { "name" : "receivers", "type" : "List" } - ], - "map" : { - "param.plainMsg" : "in.plainMessage", - "param.receivers" : "in.receiver.split(\"\\n\")" - } - } - }, - "visual" : { - "at" : { "x" : 408, "y" : 64 } - }, - "connect" : { "id" : "f7", "to" : "f6" } - }, { - "id" : "f6", - "type" : "DialogCall", - "name" : "ResultPage", - "config" : { - "dialogId" : "threema.connector.demo.ResultPage", - "startMethod" : "start(threema.connector.demo.sendDemoMessageData)", - "call" : { - "params" : [ - { "name" : "sendDemoMessageData", "type" : "threema.connector.demo.sendDemoMessageData" } - ], - "map" : { - "param.sendDemoMessageData" : "in" - } - } - }, - "visual" : { - "at" : { "x" : 576, "y" : 64 } - }, - "connect" : { "id" : "f8", "to" : "f1" } - } ] -} \ No newline at end of file diff --git a/threema-connector-demo/processes/MessageSingleRecipient.p.json b/threema-connector-demo/processes/MessageSingleRecipient.p.json deleted file mode 100644 index c0bbc6b..0000000 --- a/threema-connector-demo/processes/MessageSingleRecipient.p.json +++ /dev/null @@ -1,113 +0,0 @@ -{ - "format" : "10.0.0", - "id" : "18B22F69680901D3", - "config" : { - "data" : "threema.connector.demo.sendDemoMessageData" - }, - "elements" : [ { - "id" : "f0", - "type" : "RequestStart", - "name" : "start.ivp", - "config" : { - "callSignature" : "start", - "outLink" : "start.ivp", - "tags" : "demo" - }, - "visual" : { - "at" : { "x" : 96, "y" : 64 } - }, - "connect" : { "id" : "f3", "to" : "f2" } - }, { - "id" : "f1", - "type" : "TaskEnd", - "visual" : { - "at" : { "x" : 768, "y" : 64 } - } - }, { - "id" : "f2", - "type" : "DialogCall", - "name" : "singleRecipient", - "config" : { - "dialogId" : "threema.connector.demo.singleRecipient", - "startMethod" : "start(threema.connector.demo.sendDemoMessageData)", - "output" : { - "map" : { - "out" : [ - "in", - "result.sendDemoMessageData" - ] - } - }, - "call" : { - "params" : [ - { "name" : "sendDemoMessageData", "type" : "threema.connector.demo.sendDemoMessageData" } - ], - "map" : { - "param.sendDemoMessageData" : "in" - } - } - }, - "visual" : { - "at" : { "x" : 272, "y" : 64 } - }, - "connect" : { "id" : "f5", "to" : "f4" } - }, { - "id" : "f4", - "type" : "SubProcessCall", - "name" : "singleMessage", - "config" : { - "processCall" : "singleRecipient:call(String,String,util.LookupType)", - "output" : { - "map" : { - "out" : "in", - "out.plainMessage" : "in.plainMessage" - }, - "code" : "out.apiResponse.add(result.apiResponse);" - }, - "call" : { - "params" : [ - { "name" : "plainMsg", "type" : "String" }, - { "name" : "receiverID", "type" : "String" }, - { "name" : "lookupType", "type" : "util.LookupType" } - ], - "map" : { - "param.plainMsg" : "in.plainMessage", - "param.receiverID" : "in.receiver", - "param.lookupType" : "util.LookupType.getByString(in.type)" - } - } - }, - "visual" : { - "at" : { "x" : 464, "y" : 64 } - }, - "connect" : { "id" : "f7", "to" : "f6" } - }, { - "id" : "f6", - "type" : "DialogCall", - "name" : "ResultPage", - "config" : { - "dialogId" : "threema.connector.demo.ResultPage", - "startMethod" : "start(threema.connector.demo.sendDemoMessageData)", - "output" : { - "map" : { - "out" : [ - "in", - "result.sendDemoMessageData" - ] - } - }, - "call" : { - "params" : [ - { "name" : "sendDemoMessageData", "type" : "threema.connector.demo.sendDemoMessageData" } - ], - "map" : { - "param.sendDemoMessageData" : "in" - } - } - }, - "visual" : { - "at" : { "x" : 640, "y" : 64 } - }, - "connect" : { "id" : "f8", "to" : "f1" } - } ] -} \ No newline at end of file diff --git a/threema-connector-demo/processes/ThreemaDemoProcess.p.json b/threema-connector-demo/processes/ThreemaDemoProcess.p.json new file mode 100644 index 0000000..4deb411 --- /dev/null +++ b/threema-connector-demo/processes/ThreemaDemoProcess.p.json @@ -0,0 +1,302 @@ +{ + "format" : "10.0.0", + "id" : "18B8EEA3B9A84FAE", + "config" : { + "data" : "threema.connector.demo.sendDemoMessageData" + }, + "elements" : [ { + "id" : "f3", + "type" : "RequestStart", + "name" : "SendMessageToSingleRecipient.ivp", + "config" : { + "callSignature" : "SendMessageToSingleRecipient", + "outLink" : "SendMessageToSingleRecipient.ivp", + "tags" : "demo" + }, + "visual" : { + "at" : { "x" : 96, "y" : 168 } + }, + "connect" : { "id" : "f19", "to" : "f5" } + }, { + "id" : "f4", + "type" : "TaskEnd", + "visual" : { + "at" : { "x" : 936, "y" : 168 } + } + }, { + "id" : "f5", + "type" : "DialogCall", + "name" : "singleRecipient", + "config" : { + "dialogId" : "threema.connector.demo.singleRecipient", + "startMethod" : "start(threema.connector.demo.sendDemoMessageData)", + "output" : { + "map" : { + "out" : [ + "in", + "result.sendDemoMessageData" + ] + } + }, + "call" : { + "params" : [ + { "name" : "sendDemoMessageData", "type" : "threema.connector.demo.sendDemoMessageData" } + ], + "map" : { + "param.sendDemoMessageData" : "in" + } + } + }, + "visual" : { + "at" : { "x" : 272, "y" : 168 } + }, + "connect" : { "id" : "f11", "to" : "f6" } + }, { + "id" : "f6", + "type" : "SubProcessCall", + "name" : "singleMessage", + "config" : { + "processCall" : "singleRecipient:call(String,String,util.LookupType)", + "output" : { + "map" : { + "out" : "in", + "out.plainMessage" : "in.plainMessage" + }, + "code" : "out.apiResponse.add(result.apiResponse);" + }, + "call" : { + "params" : [ + { "name" : "plainMsg", "type" : "String" }, + { "name" : "receiverID", "type" : "String" }, + { "name" : "lookupType", "type" : "util.LookupType" } + ], + "map" : { + "param.plainMsg" : "in.plainMessage", + "param.receiverID" : "in.receiver", + "param.lookupType" : "util.LookupType.getByString(in.type)" + } + } + }, + "visual" : { + "at" : { "x" : 512, "y" : 168 }, + "icon" : "res:/webContent/icons/threema-icon_black.png" + }, + "connect" : { "id" : "f18", "to" : "f7" } + }, { + "id" : "f7", + "type" : "DialogCall", + "name" : "ResultPage", + "config" : { + "dialogId" : "threema.connector.demo.ResultPage", + "startMethod" : "start(threema.connector.demo.sendDemoMessageData)", + "output" : { + "map" : { + "out" : "result.sendDemoMessageData", + "out.plainMessage" : "\"\"", + "out.receiver" : "\"\"", + "out.type" : "\"\"" + } + }, + "call" : { + "params" : [ + { "name" : "sendDemoMessageData", "type" : "threema.connector.demo.sendDemoMessageData" } + ], + "map" : { + "param.sendDemoMessageData" : "in" + } + } + }, + "visual" : { + "at" : { "x" : 688, "y" : 168 } + }, + "connect" : { "id" : "f24", "to" : "f23" } + }, { + "id" : "f8", + "type" : "RequestStart", + "name" : "SendMessageToMultipleRecipients.ivp", + "config" : { + "callSignature" : "SendMessageToMultipleRecipients", + "outLink" : "SendMessageToMultipleRecipients.ivp", + "tags" : "demo" + }, + "visual" : { + "at" : { "x" : 96, "y" : 280 } + }, + "connect" : { "id" : "f20", "to" : "f10" } + }, { + "id" : "f9", + "type" : "TaskEnd", + "visual" : { + "at" : { "x" : 936, "y" : 280 } + } + }, { + "id" : "f10", + "type" : "DialogCall", + "name" : "multipleRecipients", + "config" : { + "dialogId" : "threema.connector.demo.multipleRecipients", + "startMethod" : "start(threema.connector.demo.sendDemoMessageData)", + "output" : { + "map" : { + "out" : [ + "in", + "result.sendDemoMessageData", + "result.sendDemoMessageData" + ] + } + }, + "call" : { + "params" : [ + { "name" : "sendDemoMessageData", "type" : "threema.connector.demo.sendDemoMessageData" } + ], + "map" : { + "param.sendDemoMessageData" : [ + "in", + "in" + ] + } + } + }, + "visual" : { + "at" : { "x" : 272, "y" : 280 } + }, + "connect" : { "id" : "f15", "to" : "f12" } + }, { + "id" : "f12", + "type" : "SubProcessCall", + "name" : "handleMessage", + "config" : { + "processCall" : "multipleRecipients:call(String,List)", + "output" : { + "map" : { + "out" : "in", + "out.apiResponse" : "result.apiResponse" + } + }, + "call" : { + "params" : [ + { "name" : "plainMsg", "type" : "String" }, + { "name" : "receivers", "type" : "List" } + ], + "map" : { + "param.plainMsg" : "in.plainMessage", + "param.receivers" : "in.receiver.split(\"\\n\")" + } + } + }, + "visual" : { + "at" : { "x" : 512, "y" : 280 }, + "icon" : "res:/webContent/icons/threema-icon_black.png" + }, + "connect" : { "id" : "f17", "to" : "f13" } + }, { + "id" : "f13", + "type" : "DialogCall", + "name" : "ResultPage", + "config" : { + "dialogId" : "threema.connector.demo.ResultPage", + "startMethod" : "start(threema.connector.demo.sendDemoMessageData)", + "output" : { + "map" : { + "out" : "in", + "out.plainMessage" : "\"\"", + "out.receiver" : "\"\"", + "out.type" : "\"\"" + } + }, + "call" : { + "params" : [ + { "name" : "sendDemoMessageData", "type" : "threema.connector.demo.sendDemoMessageData" } + ], + "map" : { + "param.sendDemoMessageData" : "in" + } + } + }, + "visual" : { + "at" : { "x" : 688, "y" : 280 } + }, + "connect" : { "id" : "f27", "to" : "f14" } + }, { + "id" : "f0", + "type" : "RequestStart", + "name" : "GenerateKeyPair.ivp", + "config" : { + "callSignature" : "GenerateKeyPair", + "outLink" : "GenerateKeyPair.ivp" + }, + "visual" : { + "at" : { "x" : 96, "y" : 368 } + }, + "connect" : { "id" : "f22", "to" : "f2" } + }, { + "id" : "f1", + "type" : "TaskEnd", + "visual" : { + "at" : { "x" : 936, "y" : 368 } + } + }, { + "id" : "f2", + "type" : "Script", + "name" : "generateKeyPair", + "config" : { + "output" : { + "code" : [ + "import util.KeyPairGenerator;", + "import util.KeyPairGenerator.KeyPair;", + "", + "KeyPair keys = KeyPairGenerator.generate();", + "", + "out.publicKey = keys.publicKey();", + "out.privateKey = keys.privateKey();" + ] + } + }, + "visual" : { + "at" : { "x" : 272, "y" : 368 } + }, + "connect" : { "id" : "f26", "to" : "f25" } + }, { + "id" : "f25", + "type" : "DialogCall", + "name" : "KeyPair", + "config" : { + "dialogId" : "threema.connector.demo.KeyPair", + "startMethod" : "start(String,String)", + "call" : { + "params" : [ + { "name" : "publicKey", "type" : "String" }, + { "name" : "privatekey", "type" : "String" } + ], + "map" : { + "param.publicKey" : "in.publicKey", + "param.privatekey" : "in.privatekey" + } + } + }, + "visual" : { + "at" : { "x" : 520, "y" : 368 } + }, + "connect" : { "id" : "f21", "to" : "f1" } + }, { + "id" : "f23", + "type" : "Alternative", + "visual" : { + "at" : { "x" : 840, "y" : 168 } + }, + "connect" : [ + { "id" : "f16", "to" : "f5", "via" : [ { "x" : 840, "y" : 104 }, { "x" : 272, "y" : 104 } ], "condition" : "in.sendAnother" }, + { "id" : "f29", "to" : "f4" } + ] + }, { + "id" : "f14", + "type" : "Alternative", + "visual" : { + "at" : { "x" : 840, "y" : 280 } + }, + "connect" : [ + { "id" : "f31", "to" : "f10", "via" : [ { "x" : 840, "y" : 216 }, { "x" : 272, "y" : 216 } ], "condition" : "in.sendAnother" }, + { "id" : "f30", "to" : "f9" } + ] + } ] +} \ No newline at end of file diff --git a/threema-connector-demo/src_hd/threema/connector/demo/KeyPair/KeyPair.rddescriptor b/threema-connector-demo/src_hd/threema/connector/demo/KeyPair/KeyPair.rddescriptor new file mode 100644 index 0000000..ae605f0 --- /dev/null +++ b/threema-connector-demo/src_hd/threema/connector/demo/KeyPair/KeyPair.rddescriptor @@ -0,0 +1,7 @@ + + + + viewTechnology + JSF + + diff --git a/threema-connector-demo/src_hd/threema/connector/demo/KeyPair/KeyPair.xhtml b/threema-connector-demo/src_hd/threema/connector/demo/KeyPair/KeyPair.xhtml new file mode 100644 index 0000000..7e3573a --- /dev/null +++ b/threema-connector-demo/src_hd/threema/connector/demo/KeyPair/KeyPair.xhtml @@ -0,0 +1,36 @@ + + + + KeyPair + + +

Keypair for Threema.Gateway

+

Use the following keys to request a new End-to-End Threema.Gateway ID over at Theema Gateway.

+ + + + + + + + + + + + +
+
+ + +
+
+ +
+
+
+ + \ No newline at end of file diff --git a/threema-connector-demo/src_hd/threema/connector/demo/KeyPair/KeyPairData.ivyClass b/threema-connector-demo/src_hd/threema/connector/demo/KeyPair/KeyPairData.ivyClass new file mode 100644 index 0000000..2ee413c --- /dev/null +++ b/threema-connector-demo/src_hd/threema/connector/demo/KeyPair/KeyPairData.ivyClass @@ -0,0 +1,6 @@ +KeyPairData #class +threema.connector.demo.KeyPair #namespace +publicKey String #field +publicKey PERSISTENT #fieldModifier +privatekey String #field +privatekey PERSISTENT #fieldModifier diff --git a/threema-connector-demo/src_hd/threema/connector/demo/KeyPair/KeyPairProcess.p.json b/threema-connector-demo/src_hd/threema/connector/demo/KeyPair/KeyPairProcess.p.json new file mode 100644 index 0000000..257b427 --- /dev/null +++ b/threema-connector-demo/src_hd/threema/connector/demo/KeyPair/KeyPairProcess.p.json @@ -0,0 +1,54 @@ +{ + "format" : "10.0.0", + "id" : "18B8EF27D89ED10D", + "kind" : "HTML_DIALOG", + "config" : { + "data" : "threema.connector.demo.KeyPair.KeyPairData" + }, + "elements" : [ { + "id" : "f0", + "type" : "HtmlDialogStart", + "name" : "start(String,String)", + "config" : { + "callSignature" : "start", + "input" : { + "params" : [ + { "name" : "publicKey", "type" : "String" }, + { "name" : "privatekey", "type" : "String" } + ], + "map" : { + "out.publicKey" : "param.publicKey", + "out.privatekey" : "param.privatekey" + } + }, + "guid" : "18B8EF27D8A1D1A5" + }, + "visual" : { + "at" : { "x" : 96, "y" : 64 } + }, + "connect" : { "id" : "f2", "to" : "f1" } + }, { + "id" : "f1", + "type" : "HtmlDialogEnd", + "visual" : { + "at" : { "x" : 224, "y" : 64 } + } + }, { + "id" : "f3", + "type" : "HtmlDialogEventStart", + "name" : "close", + "config" : { + "guid" : "18B8EF27D8CA39FE" + }, + "visual" : { + "at" : { "x" : 96, "y" : 160 } + }, + "connect" : { "id" : "f5", "to" : "f4" } + }, { + "id" : "f4", + "type" : "HtmlDialogExit", + "visual" : { + "at" : { "x" : 224, "y" : 160 } + } + } ] +} \ No newline at end of file diff --git a/threema-connector-demo/src_hd/threema/connector/demo/ResultPage/ResultPage.xhtml b/threema-connector-demo/src_hd/threema/connector/demo/ResultPage/ResultPage.xhtml index bb3fba1..6755089 100644 --- a/threema-connector-demo/src_hd/threema/connector/demo/ResultPage/ResultPage.xhtml +++ b/threema-connector-demo/src_hd/threema/connector/demo/ResultPage/ResultPage.xhtml @@ -1,39 +1,49 @@ - - + ResultPage -

Message Status

+

Message Status

- - - - + + + - - - - - + + + + + + + + + - - - + - -
- - + +
diff --git a/threema-connector-demo/src_hd/threema/connector/demo/ResultPage/ResultPageProcess.p.json b/threema-connector-demo/src_hd/threema/connector/demo/ResultPage/ResultPageProcess.p.json index 7f85581..1a3cf61 100644 --- a/threema-connector-demo/src_hd/threema/connector/demo/ResultPage/ResultPageProcess.p.json +++ b/threema-connector-demo/src_hd/threema/connector/demo/ResultPage/ResultPageProcess.p.json @@ -44,7 +44,13 @@ "type" : "HtmlDialogEventStart", "name" : "close", "config" : { - "guid" : "18B23815CA6B079E" + "guid" : "18B23815CA6B079E", + "output" : { + "map" : { + "out" : "in", + "out.sendDemoMessageData.sendAnother" : "false" + } + } }, "visual" : { "at" : { "x" : 96, "y" : 160 } @@ -80,5 +86,22 @@ "at" : { "x" : 208, "y" : 64 } }, "connect" : { "id" : "f7", "to" : "f1" } + }, { + "id" : "f8", + "type" : "HtmlDialogEventStart", + "name" : "sendAnother", + "config" : { + "guid" : "18B8F438B7519CB7", + "output" : { + "map" : { + "out" : "in", + "out.sendDemoMessageData.sendAnother" : "true" + } + } + }, + "visual" : { + "at" : { "x" : 96, "y" : 224 } + }, + "connect" : { "id" : "f9", "to" : "f4" } } ] } \ No newline at end of file diff --git a/threema-connector-demo/src_hd/threema/connector/demo/multipleRecipients/multipleRecipients.xhtml b/threema-connector-demo/src_hd/threema/connector/demo/multipleRecipients/multipleRecipients.xhtml index fbe397d..1496a81 100644 --- a/threema-connector-demo/src_hd/threema/connector/demo/multipleRecipients/multipleRecipients.xhtml +++ b/threema-connector-demo/src_hd/threema/connector/demo/multipleRecipients/multipleRecipients.xhtml @@ -1,32 +1,44 @@ - - + multipleRecipients

Send Message to multiple recipients via Threema

- - - - - - - - - + + + + + + + +
- - + +
diff --git a/threema-connector-demo/src_hd/threema/connector/demo/singleRecipient/singleRecipient.xhtml b/threema-connector-demo/src_hd/threema/connector/demo/singleRecipient/singleRecipient.xhtml index 00ce132..14fcf3d 100644 --- a/threema-connector-demo/src_hd/threema/connector/demo/singleRecipient/singleRecipient.xhtml +++ b/threema-connector-demo/src_hd/threema/connector/demo/singleRecipient/singleRecipient.xhtml @@ -1,41 +1,76 @@ - + - + singleRecipient

Send Message via Threema

- - - - - - - + + + + + + - - - - + + + + - -
- - + +
- + + +
diff --git a/threema-connector-demo/webContent/layouts/frame-10.xhtml b/threema-connector-demo/webContent/layouts/frame-10.xhtml new file mode 100644 index 0000000..e0a3f36 --- /dev/null +++ b/threema-connector-demo/webContent/layouts/frame-10.xhtml @@ -0,0 +1,61 @@ + + + + + + + + + + <ui:insert name="title">Ivy Html Dialog</ui:insert> + + + + + + + + + +
+ + default content + +
+ + + + + + + +
+ \ No newline at end of file diff --git a/threema-connector-demo/webContent/layouts/includes/exception-details.xhtml b/threema-connector-demo/webContent/layouts/includes/exception-details.xhtml index bbc3cce..f04a69b 100644 --- a/threema-connector-demo/webContent/layouts/includes/exception-details.xhtml +++ b/threema-connector-demo/webContent/layouts/includes/exception-details.xhtml @@ -6,104 +6,125 @@ xmlns:pe="http://primefaces.org/ui/extensions" xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"> - - - + + + -

- -

+

+ +

- -

Error id

-

#{errorPage.exceptionId}

-

Error Timestamp

-

#{errorPage.createdAt}

-
+ +

Error + id

+

#{errorPage.exceptionId}

+

Error + Timestamp

+

#{errorPage.createdAt}

+
- - - -

Attributes

-
- - + + + +

Attributes

+
+
+ + + + + + + + - - + + - - - - - - - - - -
NameValue
NameValue
-
-
-

Thrown by

-

Process: - -
Element: - -

-
- - -

Process call stack

- -
#{caller.callerElement}
-
-
- -

Technical cause

-
#{causedBy.class.simpleName}: #{causedBy.message.trim()}
-
-
+ + + + +
+

Thrown by

+

+ Process: + +
Element: + +

+
-

Request Uri

-

#{errorPage.getRequestUri()}

+ +

Process call stack

+ +
+      
+        #{caller.callerElement}
+      
+    

-

Servlet

-

#{errorPage.getServletName()}

+
+ +

Technical cause

+ +
+        #{causedBy.class.simpleName}: #{causedBy.message.trim()}
+      
+

+
-

Application

-

#{errorPage.applicationName}

-
+

Request Uri

+

#{errorPage.getRequestUri()}

+
+

Servlet

+

#{errorPage.getServletName()}

+
+ +

Application

+

#{errorPage.applicationName}

+
- -

Thread local values

-
- - + +

Thread local values

+
+
+ + + + + + + + - - + + - - - - - - - - - -
KeyValue
KeyValue
-
-
-
- -

Stack-Trace

-
#{errorPage.getStackTrace()}
+ + + + +
+ +

Stack-Trace

+
+    #{errorPage.getStackTrace()}
+  
+ diff --git a/threema-connector-demo/webContent/layouts/includes/exception.xhtml b/threema-connector-demo/webContent/layouts/includes/exception.xhtml index 1b255a2..1ed05ae 100644 --- a/threema-connector-demo/webContent/layouts/includes/exception.xhtml +++ b/threema-connector-demo/webContent/layouts/includes/exception.xhtml @@ -6,42 +6,42 @@ xmlns:ic="http://ivyteam.ch/jsf/component" xmlns:p="http://primefaces.org/ui" xmlns:pe="http://primefaces.org/ui/extensions"> - - - - + + + + - - - -
-
- - -
+ + + +
+
+ + +
- - + + - - - - + + + + -
- +
+ \ No newline at end of file diff --git a/threema-connector-demo/webContent/layouts/includes/footer.xhtml b/threema-connector-demo/webContent/layouts/includes/footer.xhtml index f21699e..912a1cc 100644 --- a/threema-connector-demo/webContent/layouts/includes/footer.xhtml +++ b/threema-connector-demo/webContent/layouts/includes/footer.xhtml @@ -1,18 +1,19 @@ + xmlns:f="http://xmlns.jcp.org/jsf/core" + xmlns:h="http://xmlns.jcp.org/jsf/html" + xmlns:ui="http://xmlns.jcp.org/jsf/facelets" + xmlns:ic="http://ivyteam.ch/jsf/component" + xmlns:p="http://primefaces.org/ui" + xmlns:pe="http://primefaces.org/ui/extensions"> - -
- - #{ivyAdvisor.applicationName} - - -
-
+ +
+ + #{ivyAdvisor.applicationName} + + +
+
\ No newline at end of file diff --git a/threema-connector-demo/webContent/layouts/includes/progress-loader.xhtml b/threema-connector-demo/webContent/layouts/includes/progress-loader.xhtml index 0d68a75..4b9d1ce 100644 --- a/threema-connector-demo/webContent/layouts/includes/progress-loader.xhtml +++ b/threema-connector-demo/webContent/layouts/includes/progress-loader.xhtml @@ -1,5 +1,9 @@ - + diff --git a/threema-connector-product/README.md b/threema-connector-product/README.md index 1499368..5134c5a 100644 --- a/threema-connector-product/README.md +++ b/threema-connector-product/README.md @@ -11,22 +11,11 @@ Credentials and credits are required to send messages. The credentials can be cr ![Result screen](./images/resultScreen.png) ## Setup -This Connector requires an "End-to-End Threema ID". [Request new ID](https://gateway.threema.ch/en/id-request) -
-For generating the keys and requesting a new Threema.Gateway ID refer to [Generate keys](https://gateway.threema.ch/en/developer/howto/create-keys/php). - -To use the Threema Connector, add the following variables to your Axon Ivy Project: +1. Generate a new key pair using the "GenerateKeyPair" process. +2. Create "End-to-End Threema ID" at: [Request new ID](https://gateway.threema.ch/en/id-request)
+Free credits for testing purposes can be requested at [support-gateway@threema.ch](mailto:support-gateway@threema.ch)
+3. Add the following variables to your Axon Ivy Project: ``` -Variables: - connector: - - # Your Threema.Gateway ID - threemaId: '' - - # Your Threema.Gateway Secret - secret: '' - - # Your private key associated with your Threema.Gateway ID - privateKey: '' +@variables.yaml@ ``` diff --git a/threema-connector-product/pom.xml b/threema-connector-product/pom.xml index 8978530..ba20a2d 100644 --- a/threema-connector-product/pom.xml +++ b/threema-connector-product/pom.xml @@ -1,8 +1,8 @@ 4.0.0 - com.axonivy.market - MY-PRODUCT-NAME-product - 10.0.0-SNAPSHOT + com.axonivy.connector.threema + threema-connector-product + 10.0.2-SNAPSHOT pom diff --git a/threema-connector-product/product.json b/threema-connector-product/product.json index a5a4b33..97d486b 100644 --- a/threema-connector-product/product.json +++ b/threema-connector-product/product.json @@ -6,8 +6,8 @@ "data": { "projects": [ { - "groupId": "MY-GROUP-ID", - "artifactId": "MY-PRODUCT-NAME-demo", + "groupId": "com.axonivy.connector.threema", + "artifactId": "threema-connector-demo", "version": "${version}", "type": "iar" } @@ -28,8 +28,8 @@ "data": { "dependencies": [ { - "groupId": "MY-GROUP-ID", - "artifactId": "MY-PRODUCT-NAME", + "groupId": "com.axonivy.connector.threema", + "artifactId": "threema-connector", "version": "${version}", "type": "iar" } @@ -44,27 +44,6 @@ } ] } - }, - { - "id": "maven-dropins", - "data": { - "dependencies": [ - { - "groupId": "MY-GROUP-ID", - "artifactId": "MY-PRODUCT-NAME", - "version": "${version}" - } - ], - "repositories": [ - { - "id": "maven.axonivy.com", - "url": "https://maven.axonivy.com", - "snapshots": { - "enabled": "true" - } - } - ] - } } ] } diff --git a/threema-connector-product/zip.xml b/threema-connector-product/zip.xml index 003f06c..ed24bd5 100644 --- a/threema-connector-product/zip.xml +++ b/threema-connector-product/zip.xml @@ -1,4 +1,7 @@ - + zip false diff --git a/threema-connector-test/.classpath b/threema-connector-test/.classpath index 7d6b6e2..8e30989 100644 --- a/threema-connector-test/.classpath +++ b/threema-connector-test/.classpath @@ -1,40 +1,45 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/threema-connector-test/.project b/threema-connector-test/.project index 2ecc6d6..7068587 100644 --- a/threema-connector-test/.project +++ b/threema-connector-test/.project @@ -1,49 +1,49 @@ - threema-connector-test - - - - - - ch.ivyteam.ivy.designer.dataClasses.ui.ivyDataClassBuilder - - - - - ch.ivyteam.ivy.designer.process.ui.ivyWebServiceProcessClassBuilder - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.wst.common.project.facet.core.builder - - - - - ch.ivyteam.ivy.designer.ide.ivyModelValidationBuilder - - - - - org.eclipse.m2e.core.maven2Builder - - - - - - ch.ivyteam.ivy.project.IvyProjectNature - org.eclipse.wst.common.modulecore.ModuleCoreNature - org.eclipse.jem.workbench.JavaEMFNature - org.eclipse.jdt.core.javanature - org.eclipse.m2e.core.maven2Nature - org.eclipse.jem.beaninfo.BeanInfoNature - org.eclipse.wst.common.project.facet.core.nature - org.eclipse.wst.jsdt.core.jsNature - + threema-connector-test + + + + + + ch.ivyteam.ivy.designer.dataClasses.ui.ivyDataClassBuilder + + + + + ch.ivyteam.ivy.designer.process.ui.ivyWebServiceProcessClassBuilder + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + ch.ivyteam.ivy.designer.ide.ivyModelValidationBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + ch.ivyteam.ivy.project.IvyProjectNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + org.eclipse.jem.beaninfo.BeanInfoNature + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.wst.jsdt.core.jsNature + diff --git a/threema-connector-test/.settings/.jsdtscope b/threema-connector-test/.settings/.jsdtscope index 869c01d..e4ab59a 100644 --- a/threema-connector-test/.settings/.jsdtscope +++ b/threema-connector-test/.settings/.jsdtscope @@ -1,12 +1,17 @@ - - - - - - - - - + + + + + + + + + diff --git a/threema-connector-test/.settings/org.eclipse.wst.common.component b/threema-connector-test/.settings/org.eclipse.wst.common.component index 41c9806..dec10f3 100644 --- a/threema-connector-test/.settings/org.eclipse.wst.common.component +++ b/threema-connector-test/.settings/org.eclipse.wst.common.component @@ -1,10 +1,18 @@ - - - - - - - - - + + + + + + + + + + diff --git a/threema-connector-test/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml b/threema-connector-test/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml index 9b4b9fc..e725c8d 100644 --- a/threema-connector-test/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml +++ b/threema-connector-test/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml @@ -1,7 +1,8 @@ - + diff --git a/threema-connector-test/.settings/org.eclipse.wst.common.project.facet.core.xml b/threema-connector-test/.settings/org.eclipse.wst.common.project.facet.core.xml index 156ecdb..3bb273d 100644 --- a/threema-connector-test/.settings/org.eclipse.wst.common.project.facet.core.xml +++ b/threema-connector-test/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -1,8 +1,8 @@ - - - - - + + + + + diff --git a/threema-connector-test/config/persistence.xml b/threema-connector-test/config/persistence.xml index d6b96d7..3de1768 100644 --- a/threema-connector-test/config/persistence.xml +++ b/threema-connector-test/config/persistence.xml @@ -1,2 +1,4 @@ - + diff --git a/threema-connector-test/config/roles.xml b/threema-connector-test/config/roles.xml index 59892fe..c7c6911 100644 --- a/threema-connector-test/config/roles.xml +++ b/threema-connector-test/config/roles.xml @@ -1,4 +1,4 @@ - Everybody + Everybody diff --git a/threema-connector-test/config/users.xml b/threema-connector-test/config/users.xml index 51a6906..1e173fa 100644 --- a/threema-connector-test/config/users.xml +++ b/threema-connector-test/config/users.xml @@ -1,2 +1,2 @@ - + diff --git a/threema-connector-test/pom.xml b/threema-connector-test/pom.xml index f587f4c..cac22d0 100644 --- a/threema-connector-test/pom.xml +++ b/threema-connector-test/pom.xml @@ -1,14 +1,13 @@ - + 4.0.0 - threema.connector.test + com.axonivy.connector.threema threema-connector-test - 10.0.0-SNAPSHOT + 10.0.2-SNAPSHOT iar - threema.connector + com.axonivy.connector.threema threema-connector ${project.version} iar @@ -16,7 +15,7 @@ com.axonivy.ivy.test unit-tester - 11.1.0 + 10.0.14 test @@ -37,7 +36,7 @@ com.axonivy.ivy.ci project-build-plugin - 10.0.6 + 10.0.14 true diff --git a/threema-connector-test/src/ch/ivyteam/threema/mocks/ThreemaServiceMock.java b/threema-connector-test/src/ch/ivyteam/threema/mocks/ThreemaServiceMock.java new file mode 100644 index 0000000..860e3b8 --- /dev/null +++ b/threema-connector-test/src/ch/ivyteam/threema/mocks/ThreemaServiceMock.java @@ -0,0 +1,77 @@ +package ch.ivyteam.threema.mocks; + +import javax.annotation.security.PermitAll; +import javax.ws.rs.PathParam; +import javax.ws.rs.Consumes; +import javax.ws.rs.FormParam; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.ResponseBuilder; +import ch.ivyteam.ivy.environment.Ivy; +import ch.ivyteam.ivy.rest.client.config.IvyDefaultJaxRsTemplates; +import io.swagger.v3.oas.annotations.Hidden; + +@Path(ThreemaServiceMock.PATH_SUFFIX) +@PermitAll +@Hidden +@SuppressWarnings("all") +public class ThreemaServiceMock { + + static final String PATH_SUFFIX = "mock"; + private static final String THREEMA_ID = "validId"; + public static final String URI = "{" + IvyDefaultJaxRsTemplates.APP_URL + "}/api/" + PATH_SUFFIX; + // {ivy.app.baseurl}/api/mock + // https://msgapi.threema.ch + + @GET + @Path("/lookup/{type}/{id}") + @Produces(MediaType.TEXT_PLAIN) + public Response getThreemaIdByMail(@PathParam("type") String type, @PathParam("id") String id) { + Response resp; + if (id.equals("validId")) { + resp = Response.ok().entity(THREEMA_ID).build(); + } else { + resp = Response.status(404).build(); + } + return resp; + } + + @GET + @Path("/pubkeys/{id}") + @Produces(MediaType.TEXT_PLAIN) + public Response getPublicKey(@PathParam("id") String id) { + Response resp; + String pubKey = "ffbb40cfced42f75c4d83c7d35300c0698bf3ef1ab49ace323a1bbc38ee23f36"; + if (id.equals(THREEMA_ID)) { + resp = Response.ok().entity(pubKey).build(); + } else { + resp = Response.status(404).build(); + } + return resp; + } + + @POST + @Consumes(MediaType.APPLICATION_FORM_URLENCODED) + @Path("/send_e2e") + @Produces(MediaType.TEXT_PLAIN) + public Response sendMessage( + @FormParam("from") String from, + @FormParam("box") String box, + @FormParam("to") String to, + @FormParam("secret") String secret, + @FormParam("nonce") String nonce) { + String msgId = "b2885aa81e9b9c93"; + Response resp; + if (to.equals("validId")) { + resp = Response.ok().entity(msgId).build(); + } else { + resp = Response.status(404).build(); + } + return resp; + } +} diff --git a/threema-connector-test/src_test/threema/connector/test/process/GetReceiverInfoTest.java b/threema-connector-test/src_test/threema/connector/test/process/GetReceiverInfoTest.java index 8338c01..173f74f 100644 --- a/threema-connector-test/src_test/threema/connector/test/process/GetReceiverInfoTest.java +++ b/threema-connector-test/src_test/threema/connector/test/process/GetReceiverInfoTest.java @@ -1,82 +1,110 @@ package threema.connector.test.process; -import org.junit.jupiter.api.Test; - import static org.assertj.core.api.Assertions.assertThat; - +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import ch.ivyteam.ivy.bpm.engine.client.BpmClient; import ch.ivyteam.ivy.bpm.engine.client.ExecutionResult; import ch.ivyteam.ivy.bpm.engine.client.History; import ch.ivyteam.ivy.bpm.engine.client.element.BpmElement; import ch.ivyteam.ivy.bpm.engine.client.element.BpmProcess; import ch.ivyteam.ivy.bpm.exec.client.IvyProcessTest; -import threema.connector.receiverData; +import ch.ivyteam.ivy.environment.AppFixture; +import ch.ivyteam.threema.mocks.ThreemaServiceMock; +import threema.connector.ReceiverData; import util.LookupType; -@IvyProcessTest +@IvyProcessTest(enableWebServer = true) public class GetReceiverInfoTest { - - private static final BpmProcess RECEIVER_INFO_PROCESS = BpmProcess.name("getReceiverInfo"); - private static final String ECHO_PUBLIC_KEY = "4a6a1b34dcef15d43cb74de2fd36091be99fbbaf126d099d47d83d919712c72b"; - - @Test - void getIDByInvalidEmail(BpmClient bpmClient) { - BpmElement callable = RECEIVER_INFO_PROCESS.elementName("call(receiverData)"); - - String email = "invalid@email.com"; - receiverData recDatMail = new receiverData(); - recDatMail.setIdentifier(email); - recDatMail.setType(LookupType.EMAIL); - - ExecutionResult resultMail = bpmClient.start().subProcess(callable).execute(recDatMail); - receiverData resultDataMail = resultMail.data().last(); - History historyMail = resultMail.history(); - assertThat(resultDataMail.getApiResponse()).isEqualTo("404"); - assertThat(historyMail.elementNames()).contains("call(receiverData)"); - assertThat(historyMail.elementNames()).contains("LookupId"); - assertThat(historyMail.elementNames()).doesNotContain("LookupPubKey"); - - } - - @Test - void getPublicKeyByID(BpmClient bpmClient) { - BpmElement callable = RECEIVER_INFO_PROCESS.elementName("call(receiverData)"); - - String threemaId = "ECHOECHO"; - receiverData recDatId = new receiverData(); - recDatId.setIdentifier(threemaId); - recDatId.setType(LookupType.THREEMAID); - - ExecutionResult resultId = bpmClient.start().subProcess(callable).execute(recDatId); - receiverData resultDataId = resultId.data().last(); - History historyId = resultId.history(); - - assertThat(resultDataId.getApiResponse()).isEqualTo("200"); - assertThat(resultDataId.getPublicKey()).isEqualTo(ECHO_PUBLIC_KEY); - assertThat(historyId.elementNames()).contains("call(receiverData)"); - assertThat(historyId.elementNames()).contains("LookupPubKey"); - assertThat(historyId.elementNames()).doesNotContain("LookupId"); - } - - - @Test - void getPublicKeyByInvalidID(BpmClient bpmClient) { - BpmElement callable = RECEIVER_INFO_PROCESS.elementName("call(receiverData)"); - - String threemaId = "invalidID"; - receiverData recDatId = new receiverData(); - recDatId.setIdentifier(threemaId); - recDatId.setType(LookupType.THREEMAID); - - ExecutionResult resultId = bpmClient.start().subProcess(callable).execute(recDatId); - receiverData resultDataId = resultId.data().last(); - History historyId = resultId.history(); - - assertThat(resultDataId.getApiResponse()).isEqualTo("404"); - assertThat(historyId.elementNames()).contains("call(receiverData)"); - assertThat(historyId.elementNames()).contains("LookupPubKey"); - assertThat(historyId.elementNames()).doesNotContain("LookupId"); - } + private static final BpmProcess RECEIVER_INFO_PROCESS = BpmProcess.name("getReceiverInfo"); + private static final String VALID_ID = "validId"; + + @BeforeEach + void setup(AppFixture fixture) { + fixture.config("RestClients.ThreemaGateway.Url", ThreemaServiceMock.URI); + } + + @Test + void getIDByValidEmail(BpmClient bpmClient) { + BpmElement callable = RECEIVER_INFO_PROCESS.elementName("call(receiverData)"); + String email = VALID_ID; + ReceiverData recDatMail = new ReceiverData(); + recDatMail.setIdentifier(email); + recDatMail.setType(LookupType.EMAIL); + ExecutionResult resultMail = bpmClient.start().subProcess(callable).execute(recDatMail); + ReceiverData resultDataMail = resultMail.data().last(); + History historyMail = resultMail.history(); + assertThat(resultDataMail.getApiResponse()).contains("200"); + assertThat(historyMail.elementNames()) + .contains("call(receiverData)") + .contains("LookupId") + .contains("LookupPubKey"); + } + + @Test + void getIDByInvalidEmail(BpmClient bpmClient) { + BpmElement callable = RECEIVER_INFO_PROCESS.elementName("call(receiverData)"); + String email = "invalid@email.com"; + ReceiverData recDatMail = new ReceiverData(); + recDatMail.setIdentifier(email); + recDatMail.setType(LookupType.EMAIL); + ExecutionResult resultMail = bpmClient.start().subProcess(callable).execute(recDatMail); + ReceiverData resultDataMail = resultMail.data().last(); + History historyMail = resultMail.history(); + assertThat(resultDataMail.getApiResponse()).contains("404"); + assertThat(historyMail.elementNames()).contains("call(receiverData)") + .contains("LookupId") + .doesNotContain("LookupPubKey"); + } + + @Test + void getIDByValidPhone(BpmClient bpmClient) { + BpmElement callable = RECEIVER_INFO_PROCESS.elementName("call(receiverData)"); + String phone = VALID_ID; + ReceiverData recDatMail = new ReceiverData(); + recDatMail.setIdentifier(phone); + recDatMail.setType(LookupType.PHONE); + ExecutionResult resultMail = bpmClient.start().subProcess(callable).execute(recDatMail); + ReceiverData resultDataMail = resultMail.data().last(); + History historyMail = resultMail.history(); + assertThat(resultDataMail.getApiResponse()).contains("200"); + assertThat(historyMail.elementNames()).contains("call(receiverData)") + .contains("LookupId") + .contains("LookupPubKey"); + } + + @Test + void getPublicKeyByID(BpmClient bpmClient) { + BpmElement callable = RECEIVER_INFO_PROCESS.elementName("call(receiverData)"); + String threemaId = "validId"; + ReceiverData recDatId = new ReceiverData(); + recDatId.setIdentifier(threemaId); + recDatId.setType(LookupType.THREEMAID); + ExecutionResult resultId = bpmClient.start().subProcess(callable).execute(recDatId); + ReceiverData resultDataId = resultId.data().last(); + History historyId = resultId.history(); + assertThat(resultDataId.getApiResponse()).contains("200"); + assertThat(resultDataId.getPublicKey()) + .isEqualTo("ffbb40cfced42f75c4d83c7d35300c0698bf3ef1ab49ace323a1bbc38ee23f36"); + assertThat(historyId.elementNames()).contains("call(receiverData)") + .contains("LookupPubKey") + .doesNotContain("LookupId"); + } + @Test + void getPublicKeyByInvalidID(BpmClient bpmClient) { + BpmElement callable = RECEIVER_INFO_PROCESS.elementName("call(receiverData)"); + String threemaId = "invalidID"; + ReceiverData recDatId = new ReceiverData(); + recDatId.setIdentifier(threemaId); + recDatId.setType(LookupType.THREEMAID); + ExecutionResult resultId = bpmClient.start().subProcess(callable).execute(recDatId); + ReceiverData resultDataId = resultId.data().last(); + History historyId = resultId.history(); + assertThat(resultDataId.getApiResponse()).contains("404"); + assertThat(historyId.elementNames()).contains("call(receiverData)") + .contains("LookupPubKey") + .doesNotContain("LookupId"); + } } diff --git a/threema-connector-test/src_test/threema/connector/test/process/MessageEncryptionTest.java b/threema-connector-test/src_test/threema/connector/test/process/MessageEncryptionTest.java index 1bda79b..86c7844 100644 --- a/threema-connector-test/src_test/threema/connector/test/process/MessageEncryptionTest.java +++ b/threema-connector-test/src_test/threema/connector/test/process/MessageEncryptionTest.java @@ -1,10 +1,7 @@ package threema.connector.test.process; - +import static javax.xml.bind.DatatypeConverter.parseHexBinary; import static org.assertj.core.api.Assertions.assertThat; - -import static javax.xml.bind.DatatypeConverter.*; - import org.junit.jupiter.api.Test; import ch.ivyteam.ivy.bpm.engine.client.BpmClient; import ch.ivyteam.ivy.bpm.engine.client.ExecutionResult; @@ -12,39 +9,33 @@ import ch.ivyteam.ivy.bpm.engine.client.element.BpmProcess; import ch.ivyteam.ivy.bpm.exec.client.IvyProcessTest; import ch.ivyteam.ivy.environment.Ivy; -import threema.connector.receiverData; import ch.threema.apitool.CryptTool; +import threema.connector.ReceiverData; @IvyProcessTest public class MessageEncryptionTest { + private final static BpmProcess ENCRYPTION_PROCESS = BpmProcess.name("messageEncryption"); private final static String PUBLIC_KEY = "ffbb40cfced42f75c4d83c7d35300c0698bf3ef1ab49ace323a1bbc38ee23f36"; private final static String PRIVATE_KEY = "ff364c727068fd6e3e6a711918393fa37649d902402a8eb31af108e79f625d82"; - @Test void encryptMessage(BpmClient bpmClient) { BpmElement callable = ENCRYPTION_PROCESS.elementName("call(receiverData)"); - // set PrivateKey for this test - Ivy.var().set("connector.privateKey", PRIVATE_KEY); - + Ivy.var().set("threemaConnector.privateKey", PRIVATE_KEY); String plainMsg = "Hello World"; - receiverData recData = new receiverData(); + ReceiverData recData = new ReceiverData(); recData.setPlainMessage(plainMsg); recData.setPublicKey(PUBLIC_KEY); - ExecutionResult result = bpmClient.start().subProcess(callable).execute(recData); - receiverData resultData = result.data().last(); + ReceiverData resultData = result.data().last(); assertThat(resultData.getEncryptedMessage()).isNotEmpty(); - byte[] decryptedByte = CryptTool.decrypt( - parseHexBinary(resultData.getEncryptedMessage()), - parseHexBinary(PRIVATE_KEY), - parseHexBinary(PUBLIC_KEY), - parseHexBinary(resultData.getNonce()) - ); - + parseHexBinary(resultData.getEncryptedMessage()), + parseHexBinary(PRIVATE_KEY), + parseHexBinary(PUBLIC_KEY), + parseHexBinary(resultData.getNonce())); String decryptedMsg = new String(decryptedByte); assertThat(decryptedMsg).contains(plainMsg); } diff --git a/threema-connector-test/src_test/threema/connector/test/process/MultipleRecipientsTest.java b/threema-connector-test/src_test/threema/connector/test/process/MultipleRecipientsTest.java index d1b2558..8db51cd 100644 --- a/threema-connector-test/src_test/threema/connector/test/process/MultipleRecipientsTest.java +++ b/threema-connector-test/src_test/threema/connector/test/process/MultipleRecipientsTest.java @@ -1,47 +1,46 @@ package threema.connector.test.process; import static org.assertj.core.api.Assertions.assertThat; - +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; - import ch.ivyteam.ivy.bpm.engine.client.BpmClient; import ch.ivyteam.ivy.bpm.engine.client.ExecutionResult; import ch.ivyteam.ivy.bpm.engine.client.element.BpmElement; import ch.ivyteam.ivy.bpm.engine.client.element.BpmProcess; import ch.ivyteam.ivy.bpm.exec.client.IvyProcessTest; +import ch.ivyteam.ivy.environment.AppFixture; import ch.ivyteam.ivy.scripting.objects.List; -import threema.connector.receiverData; -import threema.connector.sendThreemaMessageData; +import ch.ivyteam.threema.mocks.ThreemaServiceMock; +import threema.connector.ReceiverData; +import threema.connector.SendThreemaMessageData; import util.LookupType; -@IvyProcessTest +@IvyProcessTest(enableWebServer = true) public class MultipleRecipientsTest { - private final static BpmProcess MULTIPLE_RECIPIENTS_PROCESS = BpmProcess.name("multipleRecipients"); - private final static String MESSAGE = "Hello World"; - - - @Test - void prepareMultipleRecipients(BpmClient bpmClient) { - List recipients = new List(); - recipients.add("invalidThreemaID"); - recipients.add("41000000000"); - recipients.add("invalid@email.ch"); - - BpmElement callable = MULTIPLE_RECIPIENTS_PROCESS.elementName("call(String,List)"); - ExecutionResult result = bpmClient.start().subProcess(callable).execute(MESSAGE, recipients); - sendThreemaMessageData msgData = result.data().last(); - List listReceiver = msgData.getReceiverData(); - - assertThat(listReceiver.size()).isEqualTo(recipients.size()); - assertThat(listReceiver.get(0).getType()).isEqualTo(LookupType.THREEMAID); - assertThat(listReceiver.get(1).getType()).isEqualTo(LookupType.PHONE); - assertThat(listReceiver.get(2).getType()).isEqualTo(LookupType.EMAIL); - - for(String status : msgData.getApiResponses()) { - assertThat(status).contains("404"); - } + private final static BpmProcess MULTIPLE_RECIPIENTS_PROCESS = BpmProcess.name("multipleRecipients"); + private final static String MESSAGE = "Hello World"; + + @BeforeEach + void setup(AppFixture fixture) { + fixture.config("RestClients.ThreemaGateway.Url", ThreemaServiceMock.URI); + } - } - + @Test + void prepareMultipleRecipients(BpmClient bpmClient) { + List recipients = new List(); + recipients.add("invalidThreemaID"); + recipients.add("41000000000"); + recipients.add("invalid@email.ch"); + BpmElement callable = MULTIPLE_RECIPIENTS_PROCESS.elementName("call(String,List)"); + ExecutionResult result = bpmClient.start().subProcess(callable).execute(MESSAGE, recipients); + SendThreemaMessageData msgData = result.data().last(); + List listReceiver = msgData.getReceiverData(); + assertThat(listReceiver.size()).isEqualTo(recipients.size()); + assertThat(listReceiver).extracting(ReceiverData::getType) + .containsExactly(LookupType.THREEMAID, LookupType.PHONE, LookupType.EMAIL); + for (String status : msgData.getApiResponses()) { + assertThat(status).contains("404"); + } + } } diff --git a/threema-connector-test/src_test/threema/connector/test/process/SendMessageTest.java b/threema-connector-test/src_test/threema/connector/test/process/SendMessageTest.java index 62584f5..77b5f6c 100644 --- a/threema-connector-test/src_test/threema/connector/test/process/SendMessageTest.java +++ b/threema-connector-test/src_test/threema/connector/test/process/SendMessageTest.java @@ -1,77 +1,74 @@ package threema.connector.test.process; import static org.assertj.core.api.Assertions.assertThat; - import javax.xml.bind.DatatypeConverter; - import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; - import ch.ivyteam.ivy.bpm.engine.client.BpmClient; import ch.ivyteam.ivy.bpm.engine.client.ExecutionResult; import ch.ivyteam.ivy.bpm.engine.client.element.BpmElement; import ch.ivyteam.ivy.bpm.engine.client.element.BpmProcess; import ch.ivyteam.ivy.bpm.exec.client.IvyProcessTest; +import ch.ivyteam.ivy.environment.AppFixture; +import ch.ivyteam.threema.mocks.ThreemaServiceMock; import ch.threema.apitool.CryptTool; import ch.threema.apitool.results.EncryptResult; -import threema.connector.receiverData; -import ch.ivyteam.ivy.environment.Ivy; +import threema.connector.ReceiverData; -@IvyProcessTest +@IvyProcessTest(enableWebServer = true) public class SendMessageTest { - private static final BpmProcess SEND_MESSAGE_PROCESS = BpmProcess.name("sendMessage"); - - private static final String ECHO_PUBLIC_KEY = "4a6a1b34dcef15d43cb74de2fd36091be99fbbaf126d099d47d83d919712c72b"; - private static final String INVALID_PUBLIC_KEY = "0000004dcef15d43cb74de2fd36091be99fbbaf126d099d47d83d919712c72b"; - private static final String ECHO_ID = "ECHOECHO"; - private static final String INVALID_ID = "INVALIDID"; - private static final String message = "Hello World"; - private static String encryptedMessage; - private static String nonce; - - - @BeforeAll - static void encryptMessage() { - byte[] privKey = DatatypeConverter.parseHexBinary(Ivy.var().get("connector.privatekey")); - EncryptResult encryptResult = CryptTool.encryptTextMessage(message, privKey, DatatypeConverter.parseHexBinary(ECHO_PUBLIC_KEY)); - encryptedMessage = DatatypeConverter.printHexBinary(encryptResult.getResult()); - nonce = DatatypeConverter.printHexBinary(encryptResult.getNonce()); - } - - @Test - void sendValidMessage(BpmClient bpmClient) { - BpmElement callable = SEND_MESSAGE_PROCESS.elementName("call(receiverData)"); - - receiverData recDat = new receiverData(); - recDat.setThreemaId(ECHO_ID); - recDat.setPublicKey(ECHO_PUBLIC_KEY); - recDat.setEncryptedMessage(encryptedMessage); - recDat.setNonce(nonce); - recDat.setApiResponse(""); - - ExecutionResult result = bpmClient.start().subProcess(callable).execute(recDat); - receiverData resultData = result.data().last(); - - assertThat(resultData.getApiResponse()).isEqualTo("Sent successfully (200)"); - } - - @Test - void sendInvalidMessage(BpmClient bpmClient) { - BpmElement callable = SEND_MESSAGE_PROCESS.elementName("call(receiverData)"); - - receiverData recDat = new receiverData(); - recDat.setThreemaId(INVALID_ID); - recDat.setPublicKey(INVALID_PUBLIC_KEY); - recDat.setEncryptedMessage(encryptedMessage); - recDat.setNonce(nonce); - recDat.setApiResponse(""); - - ExecutionResult result = bpmClient.start().subProcess(callable).execute(recDat); - receiverData resultData = result.data().last(); - - assertThat(resultData.getApiResponse()).contains("Error"); - - } - + private static final BpmProcess SEND_MESSAGE_PROCESS = BpmProcess.name("sendMessage"); + private static final String ECHO_PUBLIC_KEY = "4a6a1b34dcef15d43cb74de2fd36091be99fbbaf126d099d47d83d919712c72b"; + private static final String PRIVATE_KEY = "ff364c727068fd6e3e6a711918393fa37649d902402a8eb31af108e79f625d82"; + private static final String INVALID_PUBLIC_KEY = "0000004dcef15d43cb74de2fd36091be99fbbaf126d099d47d83d919712c72b"; + private static final String VALID_ID = "validId"; + private static final String INVALID_ID = "invalidId"; + private static final String message = "Hello World"; + private static String encryptedMessage; + private static String nonce; + + @BeforeAll + static void encryptMessage() { + EncryptResult encryptResult = CryptTool.encryptTextMessage( + message, + DatatypeConverter.parseHexBinary(PRIVATE_KEY), + DatatypeConverter.parseHexBinary(ECHO_PUBLIC_KEY)); + encryptedMessage = DatatypeConverter.printHexBinary(encryptResult.getResult()); + nonce = DatatypeConverter.printHexBinary(encryptResult.getNonce()); + } + + @BeforeEach + void setup(AppFixture fixture) { + fixture.config("RestClients.ThreemaGateway.Url", ThreemaServiceMock.URI); + } + + @Test + void sendValidMessage(BpmClient bpmClient) { + BpmElement callable = SEND_MESSAGE_PROCESS.elementName("call(receiverData)"); + ReceiverData recDat = new ReceiverData(); + recDat.setThreemaId(VALID_ID); + recDat.setPublicKey(ECHO_PUBLIC_KEY); + recDat.setEncryptedMessage(encryptedMessage); + recDat.setNonce(nonce); + recDat.setApiResponse(""); + ExecutionResult result = bpmClient.start().subProcess(callable).execute(recDat); + ReceiverData resultData = result.data().last(); + assertThat(resultData.getApiResponse()).contains("200"); + } + + @Test + void sendInvalidMessage(BpmClient bpmClient) { + BpmElement callable = SEND_MESSAGE_PROCESS.elementName("call(receiverData)"); + ReceiverData recDat = new ReceiverData(); + recDat.setThreemaId(INVALID_ID); + recDat.setPublicKey(INVALID_PUBLIC_KEY); + recDat.setEncryptedMessage(encryptedMessage); + recDat.setNonce(nonce); + recDat.setApiResponse(""); + ExecutionResult result = bpmClient.start().subProcess(callable).execute(recDat); + ReceiverData resultData = result.data().last(); + assertThat(resultData.getApiResponse()).contains("404"); + } } diff --git a/threema-connector-test/src_test/threema/connector/test/process/SingleRecipientTest.java b/threema-connector-test/src_test/threema/connector/test/process/SingleRecipientTest.java index 2995aef..60842db 100644 --- a/threema-connector-test/src_test/threema/connector/test/process/SingleRecipientTest.java +++ b/threema-connector-test/src_test/threema/connector/test/process/SingleRecipientTest.java @@ -1,55 +1,63 @@ package threema.connector.test.process; - - import static org.assertj.core.api.Assertions.assertThat; - +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; - import ch.ivyteam.ivy.bpm.engine.client.BpmClient; import ch.ivyteam.ivy.bpm.engine.client.ExecutionResult; import ch.ivyteam.ivy.bpm.engine.client.element.BpmElement; import ch.ivyteam.ivy.bpm.engine.client.element.BpmProcess; import ch.ivyteam.ivy.bpm.exec.client.IvyProcessTest; -import threema.connector.receiverData; +import ch.ivyteam.ivy.environment.AppFixture; +import ch.ivyteam.ivy.environment.Ivy; +import ch.ivyteam.threema.mocks.ThreemaServiceMock; +import threema.connector.ReceiverData; -@IvyProcessTest +@IvyProcessTest(enableWebServer = true) public class SingleRecipientTest { - private static final BpmProcess SINGLE_RECEIVER_PROCESS = BpmProcess.name("singleRecipient"); - private static final String VALID_ID = "ECHOECHO"; - private static final String INVALID_EMAIL = "invalid@mail.ch"; - private static final String INVALID_PHONE = "41000000000"; - private static final String MESSAGE = "Hello World"; - - @Test - void sendMessageToValidSingleRecipientById(BpmClient bpmClient) { - BpmElement callable = SINGLE_RECEIVER_PROCESS.elementName("call(String,String,LookupType)"); - ExecutionResult result = bpmClient.start().subProcess(callable).execute(MESSAGE, VALID_ID, util.LookupType.THREEMAID); - receiverData resultData = result.data().last(); - String apiStatus = resultData.getApiResponse(); - - assertThat(apiStatus).contains("200"); - } - - @Test - void sendMessageToInvalidSingleRecipientByEmail(BpmClient bpmClient) { - BpmElement callable = SINGLE_RECEIVER_PROCESS.elementName("call(String,String,LookupType)"); - ExecutionResult result = bpmClient.start().subProcess(callable).execute(MESSAGE, INVALID_EMAIL, util.LookupType.EMAIL); - receiverData resultData = result.data().last(); - String apiStatus = resultData.getApiResponse(); - - assertThat(apiStatus).contains("404"); - } - - @Test - void sendMessageToInvalidSingleRecipientByPhone(BpmClient bpmClient) { - BpmElement callable = SINGLE_RECEIVER_PROCESS.elementName("call(String,String,LookupType)"); - ExecutionResult result = bpmClient.start().subProcess(callable).execute(MESSAGE, INVALID_PHONE, util.LookupType.PHONE); - receiverData resultData = result.data().last(); - String apiStatus = resultData.getApiResponse(); - - assertThat(apiStatus).contains("404"); - } - + private static final BpmProcess SINGLE_RECEIVER_PROCESS = BpmProcess.name("singleRecipient"); + private static final String VALID_ID = "validId"; + private static final String INVALID_EMAIL = "invalid@mail.ch"; + private static final String INVALID_PHONE = "41000000000"; + private static final String MESSAGE = "Hello World"; + private static final String PRIVATE_KEY = "ff364c727068fd6e3e6a711918393fa37649d902402a8eb31af108e79f625d82"; + + @BeforeEach + void setup(AppFixture fixture) { + Ivy.var().set("threemaConnector.privateKey", PRIVATE_KEY); + Ivy.var().set("threemaConnector.secret", "secret"); + Ivy.var().set("threemaConnector.threemaId", "threemaId"); + fixture.config("RestClients.ThreemaGateway.Url", ThreemaServiceMock.URI); + } + + @Test + void sendMessageToValidSingleRecipientById(BpmClient bpmClient) { + BpmElement callable = SINGLE_RECEIVER_PROCESS.elementName("call(String,String,LookupType)"); + ExecutionResult result = bpmClient.start().subProcess(callable).execute(MESSAGE, VALID_ID, + util.LookupType.THREEMAID); + ReceiverData resultData = result.data().last(); + String apiStatus = resultData.getApiResponse(); + assertThat(apiStatus).contains("200"); + } + + @Test + void sendMessageToInvalidSingleRecipientByEmail(BpmClient bpmClient) { + BpmElement callable = SINGLE_RECEIVER_PROCESS.elementName("call(String,String,LookupType)"); + ExecutionResult result = bpmClient.start().subProcess(callable).execute(MESSAGE, INVALID_EMAIL, + util.LookupType.EMAIL); + ReceiverData resultData = result.data().last(); + String apiStatus = resultData.getApiResponse(); + assertThat(apiStatus).isEqualTo("ID-Lookup: 404"); + } + + @Test + void sendMessageToInvalidSingleRecipientByPhone(BpmClient bpmClient) { + BpmElement callable = SINGLE_RECEIVER_PROCESS.elementName("call(String,String,LookupType)"); + ExecutionResult result = bpmClient.start().subProcess(callable).execute(MESSAGE, INVALID_PHONE, + util.LookupType.PHONE); + ReceiverData resultData = result.data().last(); + String apiStatus = resultData.getApiResponse(); + assertThat(apiStatus).isEqualTo("ID-Lookup: 404"); + } } diff --git a/threema-connector-test/src_test/threema/connector/test/util/KeyPairGeneratorTest.java b/threema-connector-test/src_test/threema/connector/test/util/KeyPairGeneratorTest.java new file mode 100644 index 0000000..5bb233a --- /dev/null +++ b/threema-connector-test/src_test/threema/connector/test/util/KeyPairGeneratorTest.java @@ -0,0 +1,22 @@ +package threema.connector.test.util; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; + +import util.KeyPairGenerator; +import util.KeyPairGenerator.KeyPair; + +public class KeyPairGeneratorTest { + + @Test + void generateKeyPair() { + KeyPair keys = KeyPairGenerator.generate(); + assertThat(keys.publicKey()).isNotEmpty(); + assertThat(keys.privateKey()).isNotEmpty(); + + assertThat(keys.publicKey().length()).isEqualTo(64); + assertThat(keys.privateKey().length()).isEqualTo(64); + } + +} diff --git a/threema-connector-test/src_test/threema/connector/test/util/LookupTypeTest.java b/threema-connector-test/src_test/threema/connector/test/util/LookupTypeTest.java index 391a21e..7ce3758 100644 --- a/threema-connector-test/src_test/threema/connector/test/util/LookupTypeTest.java +++ b/threema-connector-test/src_test/threema/connector/test/util/LookupTypeTest.java @@ -13,39 +13,34 @@ void getTypeByString() { String threemaId = "threemaId"; String invalid1 = "invalidType1"; String invalid2 = "invalidType2"; - LookupType typeEmail = LookupType.getByString(email); assertThat(typeEmail).isEqualTo(LookupType.EMAIL); - LookupType typePhone = LookupType.getByString(phone); assertThat(typePhone).isEqualTo(LookupType.PHONE); - LookupType typeThreemaId = LookupType.getByString(threemaId); assertThat(typeThreemaId).isEqualTo(LookupType.THREEMAID); - LookupType typeInvalid1 = LookupType.getByString(invalid1); assertThat(typeInvalid1).isEqualTo(LookupType.INVALID); - LookupType typeInvalid2 = LookupType.getByString(invalid2); assertThat(typeInvalid2).isEqualTo(LookupType.INVALID); - } @Test void getTypebyPattern() { String email = "xyz@xyz.yz"; - String phone = "00000000000"; + String phoneSimple = "00000000000"; + String phoneComplete = "+00000000000"; + String phoneCompleteSpace = "+00 00 000 00 00"; String threemaId = "didegiasdfl"; - LookupType typeEmail = LookupType.getByPattern(email); assertThat(typeEmail).isEqualTo(LookupType.EMAIL); - - LookupType typePhone = LookupType.getByPattern(phone); + LookupType typePhone = LookupType.getByPattern(phoneSimple); + assertThat(typePhone).isEqualTo(LookupType.PHONE); + typePhone = LookupType.getByPattern(phoneComplete); + assertThat(typePhone).isEqualTo(LookupType.PHONE); + typePhone = LookupType.getByPattern(phoneCompleteSpace); assertThat(typePhone).isEqualTo(LookupType.PHONE); - LookupType typeThreemaId = LookupType.getByPattern(threemaId); assertThat(typeThreemaId).isEqualTo(LookupType.THREEMAID); - } - } diff --git a/threema-connector-webtest/.classpath b/threema-connector-webtest/.classpath new file mode 100644 index 0000000..26e6fb6 --- /dev/null +++ b/threema-connector-webtest/.classpath @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/threema-connector-webtest/.gitignore b/threema-connector-webtest/.gitignore new file mode 100644 index 0000000..1b2547b --- /dev/null +++ b/threema-connector-webtest/.gitignore @@ -0,0 +1,19 @@ +# general +Thumbs.db +.DS_Store +*~ +*.log + +# java +*.class +hs_err_pid* + +# maven +target/ +lib/mvn-deps/ + +# ivy +classes/ +src_dataClasses/ +src_wsproc/ +logs/ diff --git a/threema-connector-webtest/.project b/threema-connector-webtest/.project new file mode 100644 index 0000000..d8bca7c --- /dev/null +++ b/threema-connector-webtest/.project @@ -0,0 +1,49 @@ + + + threema-connector-webtest + + + + + + ch.ivyteam.ivy.designer.dataClasses.ui.ivyDataClassBuilder + + + + + ch.ivyteam.ivy.designer.process.ui.ivyWebServiceProcessClassBuilder + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + ch.ivyteam.ivy.designer.ide.ivyModelValidationBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + ch.ivyteam.ivy.project.IvyProjectNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + org.eclipse.jem.beaninfo.BeanInfoNature + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.wst.jsdt.core.jsNature + + diff --git a/threema-connector-webtest/.settings/.jsdtscope b/threema-connector-webtest/.settings/.jsdtscope new file mode 100644 index 0000000..e4ab59a --- /dev/null +++ b/threema-connector-webtest/.settings/.jsdtscope @@ -0,0 +1,17 @@ + + + + + + + + + + + + diff --git a/threema-connector-webtest/.settings/ch.ivyteam.ivy.designer.prefs b/threema-connector-webtest/.settings/ch.ivyteam.ivy.designer.prefs new file mode 100644 index 0000000..822cc6b --- /dev/null +++ b/threema-connector-webtest/.settings/ch.ivyteam.ivy.designer.prefs @@ -0,0 +1,5 @@ +ch.ivyteam.ivy.designer.preferences.DataClassPreferencePage\:DEFAULT_DATA_CLASS=threema.connector.webtest.Data +ch.ivyteam.ivy.designer.preferences.DataClassPreferencePage\:DEFAULT_NAMESPACE=threema.connector.webtest +ch.ivyteam.ivy.project.preferences\:PRIMEFACES_VERSION=11 +ch.ivyteam.ivy.project.preferences\:PROJECT_VERSION=100000 +eclipse.preferences.version=1 diff --git a/threema-connector-webtest/.settings/org.eclipse.jdt.core.prefs b/threema-connector-webtest/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..d4540a5 --- /dev/null +++ b/threema-connector-webtest/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,10 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 +org.eclipse.jdt.core.compiler.compliance=17 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=17 diff --git a/threema-connector-webtest/.settings/org.eclipse.wst.common.component b/threema-connector-webtest/.settings/org.eclipse.wst.common.component new file mode 100644 index 0000000..294e9ee --- /dev/null +++ b/threema-connector-webtest/.settings/org.eclipse.wst.common.component @@ -0,0 +1,20 @@ + + + + + + + + + + + + diff --git a/threema-connector-webtest/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml b/threema-connector-webtest/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml new file mode 100644 index 0000000..e725c8d --- /dev/null +++ b/threema-connector-webtest/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml @@ -0,0 +1,8 @@ + + + + + + + diff --git a/threema-connector-webtest/.settings/org.eclipse.wst.common.project.facet.core.xml b/threema-connector-webtest/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..3bb273d --- /dev/null +++ b/threema-connector-webtest/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/threema-connector-webtest/.settings/org.eclipse.wst.css.core.prefs b/threema-connector-webtest/.settings/org.eclipse.wst.css.core.prefs new file mode 100644 index 0000000..5ddc6bd --- /dev/null +++ b/threema-connector-webtest/.settings/org.eclipse.wst.css.core.prefs @@ -0,0 +1,2 @@ +css-profile/=org.eclipse.wst.css.core.cssprofile.css3 +eclipse.preferences.version=1 diff --git a/threema-connector-webtest/.settings/org.eclipse.wst.jsdt.ui.superType.container b/threema-connector-webtest/.settings/org.eclipse.wst.jsdt.ui.superType.container new file mode 100644 index 0000000..3bd5d0a --- /dev/null +++ b/threema-connector-webtest/.settings/org.eclipse.wst.jsdt.ui.superType.container @@ -0,0 +1 @@ +org.eclipse.wst.jsdt.launching.baseBrowserLibrary \ No newline at end of file diff --git a/threema-connector-webtest/.settings/org.eclipse.wst.jsdt.ui.superType.name b/threema-connector-webtest/.settings/org.eclipse.wst.jsdt.ui.superType.name new file mode 100644 index 0000000..05bd71b --- /dev/null +++ b/threema-connector-webtest/.settings/org.eclipse.wst.jsdt.ui.superType.name @@ -0,0 +1 @@ +Window \ No newline at end of file diff --git a/threema-connector-webtest/config/custom-fields.yaml b/threema-connector-webtest/config/custom-fields.yaml new file mode 100644 index 0000000..aa19ae0 --- /dev/null +++ b/threema-connector-webtest/config/custom-fields.yaml @@ -0,0 +1,20 @@ +# == Custom Fields Information == +# +# You can define here your project custom fields. +# Have a look at our documentation for more information. +# +CustomFields: +# Tasks: +# MyTaskCustomField: +# Label: My task custom field +# Description: This new task custom field can be used to ... +# Type: STRING +# Cases: +# MyCaseCustomField: +# Label: My case custom field +# Description: This new case custom field can be used to ... +# Type: STRING +# Starts: +# MyStartCustomField: +# Label: My start custom field +# Description: This new start custom field can be used to ... diff --git a/threema-connector-webtest/config/databases.yaml b/threema-connector-webtest/config/databases.yaml new file mode 100644 index 0000000..247b128 --- /dev/null +++ b/threema-connector-webtest/config/databases.yaml @@ -0,0 +1 @@ +Databases: diff --git a/threema-connector-webtest/config/overrides.any b/threema-connector-webtest/config/overrides.any new file mode 100644 index 0000000..f59ec20 --- /dev/null +++ b/threema-connector-webtest/config/overrides.any @@ -0,0 +1 @@ +* \ No newline at end of file diff --git a/threema-connector-webtest/config/persistence.xml b/threema-connector-webtest/config/persistence.xml new file mode 100644 index 0000000..3de1768 --- /dev/null +++ b/threema-connector-webtest/config/persistence.xml @@ -0,0 +1,4 @@ + + diff --git a/threema-connector-webtest/config/rest-clients.yaml b/threema-connector-webtest/config/rest-clients.yaml new file mode 100644 index 0000000..8e85296 --- /dev/null +++ b/threema-connector-webtest/config/rest-clients.yaml @@ -0,0 +1 @@ +RestClients: diff --git a/threema-connector-webtest/config/roles.xml b/threema-connector-webtest/config/roles.xml new file mode 100644 index 0000000..c7c6911 --- /dev/null +++ b/threema-connector-webtest/config/roles.xml @@ -0,0 +1,4 @@ + + + Everybody + diff --git a/threema-connector-webtest/config/users.xml b/threema-connector-webtest/config/users.xml new file mode 100644 index 0000000..1e173fa --- /dev/null +++ b/threema-connector-webtest/config/users.xml @@ -0,0 +1,2 @@ + + diff --git a/threema-connector-webtest/config/variables.yaml b/threema-connector-webtest/config/variables.yaml new file mode 100644 index 0000000..64c8fa0 --- /dev/null +++ b/threema-connector-webtest/config/variables.yaml @@ -0,0 +1,9 @@ +# == Variables == +# +# You can define here your project Variables. +# If you want to define/override a Variable for a specific Environment, +# add an additional ‘variables.yaml’ file in a subdirectory in the ‘Config’ folder: +# '/Config/_/variables.yaml +# +Variables: +# myVariable: value diff --git a/threema-connector-webtest/config/webservice-clients.yaml b/threema-connector-webtest/config/webservice-clients.yaml new file mode 100644 index 0000000..060b018 --- /dev/null +++ b/threema-connector-webtest/config/webservice-clients.yaml @@ -0,0 +1 @@ +WebServiceClients: diff --git a/threema-connector-webtest/dataclasses/threema/connector/webtest/Data.ivyClass b/threema-connector-webtest/dataclasses/threema/connector/webtest/Data.ivyClass new file mode 100644 index 0000000..34a701a --- /dev/null +++ b/threema-connector-webtest/dataclasses/threema/connector/webtest/Data.ivyClass @@ -0,0 +1,2 @@ +Data #class +threema.connector.webtest #namespace diff --git a/threema-connector-webtest/pom.xml b/threema-connector-webtest/pom.xml new file mode 100644 index 0000000..cfa091a --- /dev/null +++ b/threema-connector-webtest/pom.xml @@ -0,0 +1,39 @@ + + + 4.0.0 + com.axonivy.connector.threema + threema-connector-webtest + 10.0.2-SNAPSHOT + iar-integration-test + + + com.axonivy.connector.threema + threema-connector-demo + ${project.version} + iar + + + com.axonivy.connector.threema + threema-connector-test + ${project.version} + iar + + + com.axonivy.ivy.webtest + web-tester + 10.0.14 + test + + + + src_test + + + com.axonivy.ivy.ci + project-build-plugin + 10.0.14 + true + + + + diff --git a/threema-connector-webtest/src_test/threema/connector/webtest/MessageMultipleRecipientsTest.java b/threema-connector-webtest/src_test/threema/connector/webtest/MessageMultipleRecipientsTest.java new file mode 100644 index 0000000..ed26b67 --- /dev/null +++ b/threema-connector-webtest/src_test/threema/connector/webtest/MessageMultipleRecipientsTest.java @@ -0,0 +1,45 @@ +package threema.connector.webtest; + +import static com.codeborne.selenide.Condition.empty; +import static com.codeborne.selenide.Condition.value; +import static com.codeborne.selenide.Selenide.$; +import static com.codeborne.selenide.Selenide.$$; +import static com.codeborne.selenide.Selenide.open; +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; +import org.openqa.selenium.By; + +import com.axonivy.ivy.webtest.IvyWebTest; +import com.axonivy.ivy.webtest.engine.EngineUrl; +import com.axonivy.ivy.webtest.engine.WebAppFixture; +import com.codeborne.selenide.ElementsCollection; + +import ch.ivyteam.threema.mocks.ThreemaServiceMock; + +@IvyWebTest +public class MessageMultipleRecipientsTest { + + @Test + public void sendMessage(WebAppFixture fixture) { + String mockUrl = ThreemaServiceMock.URI.replaceAll("\\{", "%7B").replaceAll("\\}", "%7D").replaceAll("/", "%2F"); + fixture.config("RestClients.ThreemaGateway.Url", mockUrl); + open(EngineUrl.createProcessUrl("threema-connector-demo/18B8EEA3B9A84FAE/SendMessageToMultipleRecipients.ivp")); + String message = "Hello World"; + String recipients = "validId\ninvalidId"; + // Assert empty form + $(By.id("form:sendDemoMessageDataPlainMessage")).shouldBe(empty); + $(By.id("form:sendDemoMessageDataReceiver")).shouldBe(empty); + // Proceed without required fields + $(By.id("form:proceed")).click(); + // Assert all fields required + ElementsCollection errorMessages = $$(By.cssSelector(".ui-state-error")); + assertThat(errorMessages).hasSize(4); + // Fill out form + $(By.id("form:sendDemoMessageDataPlainMessage")).sendKeys(message); + $(By.id("form:sendDemoMessageDataReceiver")).sendKeys(recipients); + // Assert filled out form + $(By.id("form:sendDemoMessageDataPlainMessage")).shouldBe(value(message)); + $(By.id("form:sendDemoMessageDataReceiver")).shouldBe(value(recipients)); + } +} diff --git a/threema-connector-webtest/src_test/threema/connector/webtest/MessageSingleRecipientTest.java b/threema-connector-webtest/src_test/threema/connector/webtest/MessageSingleRecipientTest.java new file mode 100644 index 0000000..70c5537 --- /dev/null +++ b/threema-connector-webtest/src_test/threema/connector/webtest/MessageSingleRecipientTest.java @@ -0,0 +1,50 @@ +package threema.connector.webtest; + +import static com.codeborne.selenide.Condition.empty; +import static com.codeborne.selenide.Condition.selected; +import static com.codeborne.selenide.Condition.value; +import static com.codeborne.selenide.Selenide.$; +import static com.codeborne.selenide.Selenide.$$; +import static com.codeborne.selenide.Selenide.open; +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; +import org.openqa.selenium.By; + +import com.axonivy.ivy.webtest.IvyWebTest; +import com.axonivy.ivy.webtest.engine.EngineUrl; +import com.axonivy.ivy.webtest.engine.WebAppFixture; +import com.axonivy.ivy.webtest.primeui.PrimeUi; +import com.codeborne.selenide.ElementsCollection; + +import ch.ivyteam.threema.mocks.ThreemaServiceMock; + +@IvyWebTest +public class MessageSingleRecipientTest { + + @Test + public void sendMessage(WebAppFixture fixture) { + String mockUrl = ThreemaServiceMock.URI.replaceAll("\\{", "%7B").replaceAll("\\}", "%7D").replaceAll("/", "%2F"); + fixture.config("RestClients.ThreemaGateway.Url", mockUrl); + open(EngineUrl.createProcessUrl("threema-connector-demo/18B8EEA3B9A84FAE/SendMessageToSingleRecipient.ivp")); + String message = "Hello World"; + String validId = "validId"; + // Assert empty form + $(By.id("form:sendDemoMessageDataPlainMessage")).shouldBe(empty); + $(By.id("form:sendDemoMessageDataReceiver")).shouldBe(empty); + $(By.id("form:typeSelection:2")).shouldNotBe(selected); + // Proceed without required fields + $(By.id("form:proceed")).click(); + // Assert all fields required + ElementsCollection errorMessages = $$(By.cssSelector(".ui-state-error")); + assertThat(errorMessages).hasSize(8); + // Fill out form + $(By.id("form:sendDemoMessageDataPlainMessage")).sendKeys(message); + $(By.id("form:sendDemoMessageDataReceiver")).sendKeys(validId); + PrimeUi.selectOneRadio(By.id("form:typeSelection")).selectItemByValue("threemaid"); + // Assert filled out form + $(By.id("form:sendDemoMessageDataPlainMessage")).shouldBe(value(message)); + $(By.id("form:sendDemoMessageDataReceiver")).shouldBe(value(validId)); + $(By.id("form:typeSelection:2")).shouldBe(selected); + } +} diff --git a/threema-connector/.classpath b/threema-connector/.classpath index 92dce2f..37f38ba 100644 --- a/threema-connector/.classpath +++ b/threema-connector/.classpath @@ -1,33 +1,35 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/threema-connector/.project b/threema-connector/.project index 880014f..fd84dab 100644 --- a/threema-connector/.project +++ b/threema-connector/.project @@ -1,49 +1,49 @@ - threema-connector - - - - - - ch.ivyteam.ivy.designer.dataClasses.ui.ivyDataClassBuilder - - - - - ch.ivyteam.ivy.designer.process.ui.ivyWebServiceProcessClassBuilder - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.wst.common.project.facet.core.builder - - - - - ch.ivyteam.ivy.designer.ide.ivyModelValidationBuilder - - - - - org.eclipse.m2e.core.maven2Builder - - - - - - ch.ivyteam.ivy.project.IvyProjectNature - org.eclipse.wst.common.modulecore.ModuleCoreNature - org.eclipse.jem.workbench.JavaEMFNature - org.eclipse.jdt.core.javanature - org.eclipse.m2e.core.maven2Nature - org.eclipse.jem.beaninfo.BeanInfoNature - org.eclipse.wst.common.project.facet.core.nature - org.eclipse.wst.jsdt.core.jsNature - + threema-connector + + + + + + ch.ivyteam.ivy.designer.dataClasses.ui.ivyDataClassBuilder + + + + + ch.ivyteam.ivy.designer.process.ui.ivyWebServiceProcessClassBuilder + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + ch.ivyteam.ivy.designer.ide.ivyModelValidationBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + ch.ivyteam.ivy.project.IvyProjectNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + org.eclipse.jem.beaninfo.BeanInfoNature + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.wst.jsdt.core.jsNature + diff --git a/threema-connector/.settings/.jsdtscope b/threema-connector/.settings/.jsdtscope index 869c01d..e4ab59a 100644 --- a/threema-connector/.settings/.jsdtscope +++ b/threema-connector/.settings/.jsdtscope @@ -1,12 +1,17 @@ - - - - - - - - - + + + + + + + + + diff --git a/threema-connector/.settings/org.eclipse.wst.common.component b/threema-connector/.settings/org.eclipse.wst.common.component index 52f4a81..e3fa242 100644 --- a/threema-connector/.settings/org.eclipse.wst.common.component +++ b/threema-connector/.settings/org.eclipse.wst.common.component @@ -1,10 +1,17 @@ - - - - - - - - - + + + + + + + + + + diff --git a/threema-connector/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml b/threema-connector/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml index 9b4b9fc..e725c8d 100644 --- a/threema-connector/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml +++ b/threema-connector/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml @@ -1,7 +1,8 @@ - + diff --git a/threema-connector/.settings/org.eclipse.wst.common.project.facet.core.xml b/threema-connector/.settings/org.eclipse.wst.common.project.facet.core.xml index 156ecdb..3bb273d 100644 --- a/threema-connector/.settings/org.eclipse.wst.common.project.facet.core.xml +++ b/threema-connector/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -1,8 +1,8 @@ - - - - - + + + + + diff --git a/threema-connector/config/rest-clients.yaml b/threema-connector/config/rest-clients.yaml index c842ecc..0d96434 100644 --- a/threema-connector/config/rest-clients.yaml +++ b/threema-connector/config/rest-clients.yaml @@ -1,6 +1,7 @@ RestClients: ThreemaGateway: UUID: af315689-b538-4142-a823-0632d66754d7 - Url: https://msgapi.threema.ch/ + Url: https://msgapi.threema.ch + Icon: res:/webContent/icons/threema-icon_black.png Features: - ch.ivyteam.ivy.rest.client.mapper.JsonFeature diff --git a/threema-connector/config/roles.xml b/threema-connector/config/roles.xml index 59892fe..c7c6911 100644 --- a/threema-connector/config/roles.xml +++ b/threema-connector/config/roles.xml @@ -1,4 +1,4 @@ - Everybody + Everybody diff --git a/threema-connector/config/users.xml b/threema-connector/config/users.xml index 51a6906..1e173fa 100644 --- a/threema-connector/config/users.xml +++ b/threema-connector/config/users.xml @@ -1,2 +1,2 @@ - + diff --git a/threema-connector/config/variables.yaml b/threema-connector/config/variables.yaml new file mode 100644 index 0000000..e4fd1d0 --- /dev/null +++ b/threema-connector/config/variables.yaml @@ -0,0 +1,13 @@ +Variables: + threemaConnector: + + # Your Threema.Gateway ID + threemaId: '' + + # Your Threema.Gateway Secret + # [password] + secret: '' + + # Your private key associated with your Threema.Gateway ID + # [password] + privateKey: '' diff --git a/threema-connector/dataclasses/threema/connector/receiverData.ivyClass b/threema-connector/dataclasses/threema/connector/ReceiverData.ivyClass similarity index 96% rename from threema-connector/dataclasses/threema/connector/receiverData.ivyClass rename to threema-connector/dataclasses/threema/connector/ReceiverData.ivyClass index 5c04ddf..a03b5eb 100644 --- a/threema-connector/dataclasses/threema/connector/receiverData.ivyClass +++ b/threema-connector/dataclasses/threema/connector/ReceiverData.ivyClass @@ -1,4 +1,4 @@ -receiverData #class +ReceiverData #class threema.connector #namespace identifier String #field identifier PERSISTENT #fieldModifier diff --git a/threema-connector/dataclasses/threema/connector/sendThreemaMessageData.ivyClass b/threema-connector/dataclasses/threema/connector/SendThreemaMessageData.ivyClass similarity index 79% rename from threema-connector/dataclasses/threema/connector/sendThreemaMessageData.ivyClass rename to threema-connector/dataclasses/threema/connector/SendThreemaMessageData.ivyClass index a735433..7ffa4ff 100644 --- a/threema-connector/dataclasses/threema/connector/sendThreemaMessageData.ivyClass +++ b/threema-connector/dataclasses/threema/connector/SendThreemaMessageData.ivyClass @@ -1,10 +1,10 @@ -sendThreemaMessageData #class +SendThreemaMessageData #class threema.connector #namespace receiver List #field receiver PERSISTENT #fieldModifier plainMessage String #field plainMessage PERSISTENT #fieldModifier -receiverData List #field +receiverData List #field receiverData PERSISTENT #fieldModifier sendCount Number #field sendCount PERSISTENT #fieldModifier diff --git a/threema-connector/dataclasses/threema/connector/createKeyPairData.ivyClass b/threema-connector/dataclasses/threema/connector/createKeyPairData.ivyClass new file mode 100644 index 0000000..5e2b755 --- /dev/null +++ b/threema-connector/dataclasses/threema/connector/createKeyPairData.ivyClass @@ -0,0 +1,6 @@ +createKeyPairData #class +threema.connector #namespace +privateKey String #field +privateKey PERSISTENT #fieldModifier +publicKey String #field +publicKey PERSISTENT #fieldModifier diff --git a/threema-connector/pom.xml b/threema-connector/pom.xml index b83b9ee..f173cd3 100644 --- a/threema-connector/pom.xml +++ b/threema-connector/pom.xml @@ -1,30 +1,43 @@ - + 4.0.0 - threema.connector + com.axonivy.connector.threema threema-connector - 10.0.0-SNAPSHOT + 10.0.2-SNAPSHOT iar - - - + com.axonivy.ivy.ci project-build-plugin - 10.0.6 + 10.0.14 true + + org.apache.maven.plugins + maven-antrun-plugin + 3.1.0 + + + download-threema-msgapi-tool + validate + + run + + + + + + + + + + + + + + diff --git a/threema-connector/processes/multipleRecipients.p.json b/threema-connector/processes/multipleRecipients.p.json index 3a38680..5714346 100644 --- a/threema-connector/processes/multipleRecipients.p.json +++ b/threema-connector/processes/multipleRecipients.p.json @@ -3,7 +3,7 @@ "id" : "18B22DA4C8AA09A2", "kind" : "CALLABLE_SUB", "config" : { - "data" : "threema.connector.sendThreemaMessageData" + "data" : "threema.connector.SendThreemaMessageData" }, "elements" : [ { "id" : "f0", @@ -58,19 +58,19 @@ }, "code" : [ "import util.LookupType;", - "import threema.connector.receiverData;", + "import threema.connector.ReceiverData;", "", "import ch.ivyteam.ivy.environment.Ivy;", "", "for(String rec : in.receiver){", - " receiverData recDat = new receiverData();", + " ReceiverData recDat = new ReceiverData();", " recDat.plainMessage = in.plainMessage;", " recDat.identifier = rec;", " recDat.type = LookupType.getByPattern(rec);", " out.receiverData.add(recDat);", "}", "", - "for(receiverData rec : out.receiverData){", + "for(ReceiverData rec : out.receiverData){", " Ivy.log().debug(rec.identifier + \" \" + rec.type + \" \" + rec.plainMessage);", "}" ] diff --git a/threema-connector/processes/singleRecipient.p.json b/threema-connector/processes/singleRecipient.p.json index 4468de7..544ffa6 100644 --- a/threema-connector/processes/singleRecipient.p.json +++ b/threema-connector/processes/singleRecipient.p.json @@ -3,7 +3,7 @@ "id" : "18B22C8212D554A9", "kind" : "CALLABLE_SUB", "config" : { - "data" : "threema.connector.receiverData" + "data" : "threema.connector.ReceiverData" }, "elements" : [ { "id" : "f0", @@ -21,7 +21,16 @@ "out.identifier" : "param.receiverID", "out.plainMessage" : "param.plainMsg", "out.type" : "param.lookupType" - } + }, + "code" : [ + "import util.LookupType;", + "", + "if(param.lookupType == LookupType.PHONE){", + " out.identifier = param.receiverID.replaceAll(\" \",\"\").replaceAll(\"\\\\+\", \"\");", + "}else{", + " out.identifier = param.receiverID;", + "}" + ] }, "result" : { "params" : [ @@ -50,7 +59,7 @@ "type" : "SubProcessCall", "name" : "getReceiverInfo", "config" : { - "processCall" : "util/getReceiverInfo:call(threema.connector.receiverData)", + "processCall" : "util/getReceiverInfo:call(threema.connector.ReceiverData)", "output" : { "map" : { "out" : "result.receiverData" @@ -58,7 +67,7 @@ }, "call" : { "params" : [ - { "name" : "receiverData", "type" : "threema.connector.receiverData" } + { "name" : "receiverData", "type" : "threema.connector.ReceiverData" } ], "map" : { "param.receiverData" : "in" @@ -76,7 +85,7 @@ "type" : "SubProcessCall", "name" : "messageEncryption", "config" : { - "processCall" : "util/messageEncryption:call(threema.connector.receiverData)", + "processCall" : "util/messageEncryption:call(threema.connector.ReceiverData)", "output" : { "map" : { "out" : "result.receiverData" @@ -84,7 +93,7 @@ }, "call" : { "params" : [ - { "name" : "receiverData", "type" : "threema.connector.receiverData" } + { "name" : "receiverData", "type" : "threema.connector.ReceiverData" } ], "map" : { "param.receiverData" : "in" @@ -102,7 +111,7 @@ "type" : "SubProcessCall", "name" : "send", "config" : { - "processCall" : "util/sendMessage:call(threema.connector.receiverData)", + "processCall" : "util/sendMessage:call(threema.connector.ReceiverData)", "output" : { "map" : { "out" : "in", @@ -111,7 +120,7 @@ }, "call" : { "params" : [ - { "name" : "receiverData", "type" : "threema.connector.receiverData" } + { "name" : "receiverData", "type" : "threema.connector.ReceiverData" } ], "map" : { "param.receiverData" : "in" diff --git a/threema-connector/processes/util/getReceiverInfo.p.json b/threema-connector/processes/util/getReceiverInfo.p.json index f8b5e41..25a794d 100644 --- a/threema-connector/processes/util/getReceiverInfo.p.json +++ b/threema-connector/processes/util/getReceiverInfo.p.json @@ -3,7 +3,7 @@ "id" : "18B22C967B82A625", "kind" : "CALLABLE_SUB", "config" : { - "data" : "threema.connector.receiverData" + "data" : "threema.connector.ReceiverData" }, "elements" : [ { "id" : "f0", @@ -13,7 +13,7 @@ "callSignature" : "call", "input" : { "params" : [ - { "name" : "receiverData", "type" : "threema.connector.receiverData" } + { "name" : "receiverData", "type" : "threema.connector.ReceiverData" } ], "map" : { "out" : "param.receiverData", @@ -22,7 +22,7 @@ }, "result" : { "params" : [ - { "name" : "receiverData", "type" : "threema.connector.receiverData" } + { "name" : "receiverData", "type" : "threema.connector.ReceiverData" } ], "map" : { "result.receiverData" : "in" @@ -49,8 +49,8 @@ "clientId" : "af315689-b538-4142-a823-0632d66754d7", "clientErrorCode" : "ivy:error:rest:client", "queryParams" : { - "secret" : "ivy.var.connector_secret", - "from" : "ivy.var.connector_threemaId" + "secret" : "ivy.var.threemaConnector_secret", + "from" : "ivy.var.threemaConnector_threemaId" }, "statusErrorCode" : ">> Ignore status", "responseMapping" : { @@ -65,7 +65,7 @@ "resultType" : "java.lang.String" }, "visual" : { - "at" : { "x" : 320, "y" : 64 }, + "at" : { "x" : 336, "y" : 64 }, "icon" : "res:/webContent/icons/threema-icon_black.png" }, "connect" : { "id" : "f8", "to" : "f4" } @@ -78,8 +78,8 @@ "clientId" : "af315689-b538-4142-a823-0632d66754d7", "clientErrorCode" : "ivy:error:rest:client", "queryParams" : { - "from" : "ivy.var.connector_threemaId", - "secret" : "ivy.var.connector_secret" + "from" : "ivy.var.threemaConnector_threemaId", + "secret" : "ivy.var.threemaConnector_secret" }, "statusErrorCode" : ">> Ignore status", "responseMapping" : { diff --git a/threema-connector/processes/util/messageEncryption.p.json b/threema-connector/processes/util/messageEncryption.p.json index 2023394..88e014f 100644 --- a/threema-connector/processes/util/messageEncryption.p.json +++ b/threema-connector/processes/util/messageEncryption.p.json @@ -3,7 +3,7 @@ "id" : "18B22CD369A6089F", "kind" : "CALLABLE_SUB", "config" : { - "data" : "threema.connector.receiverData" + "data" : "threema.connector.ReceiverData" }, "elements" : [ { "id" : "f0", @@ -13,7 +13,7 @@ "callSignature" : "call", "input" : { "params" : [ - { "name" : "receiverData", "type" : "threema.connector.receiverData" } + { "name" : "receiverData", "type" : "threema.connector.ReceiverData" } ], "map" : { "out" : "param.receiverData" @@ -21,7 +21,7 @@ }, "result" : { "params" : [ - { "name" : "receiverData", "type" : "threema.connector.receiverData" } + { "name" : "receiverData", "type" : "threema.connector.ReceiverData" } ], "map" : { "result.receiverData" : "in" @@ -46,23 +46,12 @@ "config" : { "output" : { "code" : [ - "import ch.threema.apitool.results.EncryptResult;", - "import ch.threema.apitool.CryptTool;", - "import javax.xml.bind.DatatypeConverter;", + "import util.MessageEncryptor;", + "import util.MessageEncryptor.EncryptionResult;", "", - "String privateKey = ivy.var.connector_privateKey;", - "String publicKey = in.publicKey;", - "String msg = in.plainMessage;", - "", - "Array encPrivKey = DatatypeConverter.parseHexBinary(privateKey);", - "Array encPubKey = DatatypeConverter.parseHexBinary(publicKey);", - "", - "CryptTool tool = new CryptTool();", - "EncryptResult result = tool.encryptTextMessage(msg, encPrivKey, encPubKey);", - "", - "out = in;", - "out.encryptedMessage = DatatypeConverter.printHexBinary(result.getResult());", - "out.nonce = DatatypeConverter.printHexBinary(result.getNonce());" + "EncryptionResult result = MessageEncryptor.encrypt(in.publicKey, in.plainMessage);", + "out.encryptedMessage = result.encryptedMessage();", + "out.nonce = result.nonce();" ] } }, diff --git a/threema-connector/processes/util/sendMessage.p.json b/threema-connector/processes/util/sendMessage.p.json index 843a248..32439a5 100644 --- a/threema-connector/processes/util/sendMessage.p.json +++ b/threema-connector/processes/util/sendMessage.p.json @@ -3,7 +3,7 @@ "id" : "18B22CED0FA1555D", "kind" : "CALLABLE_SUB", "config" : { - "data" : "threema.connector.receiverData" + "data" : "threema.connector.ReceiverData" }, "elements" : [ { "id" : "f0", @@ -13,7 +13,7 @@ "callSignature" : "call", "input" : { "params" : [ - { "name" : "receiverData", "type" : "threema.connector.receiverData" } + { "name" : "receiverData", "type" : "threema.connector.ReceiverData" } ], "map" : { "out" : "param.receiverData" @@ -21,7 +21,7 @@ }, "result" : { "params" : [ - { "name" : "receiverData", "type" : "threema.connector.receiverData" } + { "name" : "receiverData", "type" : "threema.connector.ReceiverData" } ], "map" : { "result.receiverData" : "in" @@ -45,13 +45,18 @@ "name" : "sendMessage", "config" : { "bodyForm" : { - "from" : "ivy.var.connector_threemaId", + "from" : "ivy.var.threemaConnector_threemaId", "to" : "in.threemaId", "nonce" : "in.nonce", "box" : "in.encryptedMessage", - "secret" : "ivy.var.connector_secret" + "secret" : "ivy.var.threemaConnector_secret", + "" : "" }, "path" : "send_e2e", + "headers" : { + "Accept" : "*/*", + "X-Requested-By" : "\"ivy\"" + }, "clientId" : "af315689-b538-4142-a823-0632d66754d7", "clientErrorCode" : "ivy:error:rest:client", "method" : "POST", diff --git a/threema-connector/src/util/KeyPairGenerator.java b/threema-connector/src/util/KeyPairGenerator.java new file mode 100644 index 0000000..1b12c98 --- /dev/null +++ b/threema-connector/src/util/KeyPairGenerator.java @@ -0,0 +1,19 @@ +package util; + +import javax.xml.bind.DatatypeConverter; + +import ch.threema.apitool.CryptTool; + +public class KeyPairGenerator { + + public record KeyPair(String publicKey, String privateKey) {} + + public static KeyPair generate() { + byte[] publicKey = new byte[32]; + byte[] privateKey = new byte[32]; + + CryptTool.generateKeyPair(publicKey, privateKey); + return new KeyPair(DatatypeConverter.printHexBinary(publicKey), DatatypeConverter.printHexBinary(privateKey)); + } + +} diff --git a/threema-connector/src/util/LookupType.java b/threema-connector/src/util/LookupType.java index 4267ec9..d7a85c8 100644 --- a/threema-connector/src/util/LookupType.java +++ b/threema-connector/src/util/LookupType.java @@ -1,11 +1,7 @@ package util; - - public enum LookupType { - PHONE, - EMAIL, - THREEMAID, - INVALID; + + PHONE, EMAIL, THREEMAID, INVALID; @Override public String toString() { @@ -13,7 +9,7 @@ public String toString() { } public static LookupType getByString(String id) { - return switch(id) { + return switch (id.toLowerCase()) { case "phone" -> LookupType.PHONE; case "email" -> LookupType.EMAIL; case "threemaid" -> LookupType.THREEMAID; @@ -23,13 +19,14 @@ public static LookupType getByString(String id) { public static LookupType getByPattern(String id) { LookupType type = LookupType.INVALID; - if(id.lastIndexOf('@') < id.lastIndexOf('.')){ - type = LookupType.EMAIL; - }else if(id.matches("\\d{11}")) { - type = LookupType.PHONE; - }else { - type = LookupType.THREEMAID; - } + id = id.replaceAll(" ", ""); + if (id.lastIndexOf('@') < id.lastIndexOf('.')) { + type = LookupType.EMAIL; + } else if (id.matches("\\+?\\d{11}")) { + type = LookupType.PHONE; + } else { + type = LookupType.THREEMAID; + } return type; } } diff --git a/threema-connector/src/util/MessageEncryptor.java b/threema-connector/src/util/MessageEncryptor.java new file mode 100644 index 0000000..cf90394 --- /dev/null +++ b/threema-connector/src/util/MessageEncryptor.java @@ -0,0 +1,24 @@ +package util; + +import javax.xml.bind.DatatypeConverter; +import ch.ivyteam.ivy.environment.Ivy; +import ch.threema.apitool.CryptTool; +import ch.threema.apitool.results.EncryptResult; + + + +public class MessageEncryptor { + public record EncryptionResult(String encryptedMessage, String nonce) {} + public static EncryptionResult encrypt(String publicKey, String msg) { + + byte[] encPrivKey = DatatypeConverter.parseHexBinary(Ivy.var().get("threemaConnector.privateKey")); + byte[] encPubKey = DatatypeConverter.parseHexBinary(publicKey); + + EncryptResult result = CryptTool.encryptTextMessage(msg, encPrivKey, encPubKey); + + String encryptedMessage = DatatypeConverter.printHexBinary(result.getResult()); + String nonce = DatatypeConverter.printHexBinary(result.getNonce()); + return new EncryptionResult(encryptedMessage, nonce); + } + +} diff --git a/threema-connector-demo/webContent/layouts/basic-10.xhtml b/threema-connector/webContent/layouts/frame-10.xhtml similarity index 66% rename from threema-connector-demo/webContent/layouts/basic-10.xhtml rename to threema-connector/webContent/layouts/frame-10.xhtml index 2e4b7b8..936a73b 100644 --- a/threema-connector-demo/webContent/layouts/basic-10.xhtml +++ b/threema-connector/webContent/layouts/frame-10.xhtml @@ -2,14 +2,19 @@ - + xmlns:p="http://primefaces.org/ui" + xmlns:pe="http://primefaces.org/ui/extensions"> + - + @@ -35,33 +40,21 @@ and refence it below in the head part. - - - - -
+
default content - - -
-
- -
-
- + + + + \ No newline at end of file diff --git a/threema-connector/webContent/layouts/includes/exception-details.xhtml b/threema-connector/webContent/layouts/includes/exception-details.xhtml new file mode 100644 index 0000000..bbc3cce --- /dev/null +++ b/threema-connector/webContent/layouts/includes/exception-details.xhtml @@ -0,0 +1,109 @@ + + + + + + +

+ +

+ + +

Error id

+

#{errorPage.exceptionId}

+

Error Timestamp

+

#{errorPage.createdAt}

+
+ + + + +

Attributes

+
+ + + + + + + + + + + + + + + +
NameValue
+
+
+

Thrown by

+

Process: + +
Element: + +

+
+ + +

Process call stack

+ +
#{caller.callerElement}
+
+
+ +

Technical cause

+
#{causedBy.class.simpleName}: #{causedBy.message.trim()}
+
+
+ +

Request Uri

+

#{errorPage.getRequestUri()}

+
+

Servlet

+

#{errorPage.getServletName()}

+
+ +

Application

+

#{errorPage.applicationName}

+
+ + +

Thread local values

+
+ + + + + + + + + + + + + + + +
KeyValue
+
+
+
+ +

Stack-Trace

+
#{errorPage.getStackTrace()}
+
+ diff --git a/threema-connector/webContent/layouts/includes/exception.xhtml b/threema-connector/webContent/layouts/includes/exception.xhtml new file mode 100644 index 0000000..1b255a2 --- /dev/null +++ b/threema-connector/webContent/layouts/includes/exception.xhtml @@ -0,0 +1,47 @@ + + + + + + + + + +
+
+ + +
+ + + + + + + + + +
+ + \ No newline at end of file diff --git a/threema-connector/webContent/layouts/includes/footer.xhtml b/threema-connector/webContent/layouts/includes/footer.xhtml new file mode 100644 index 0000000..f21699e --- /dev/null +++ b/threema-connector/webContent/layouts/includes/footer.xhtml @@ -0,0 +1,18 @@ + + + +
+ + #{ivyAdvisor.applicationName} + + +
+
+ + \ No newline at end of file diff --git a/threema-connector/webContent/layouts/includes/progress-loader.xhtml b/threema-connector/webContent/layouts/includes/progress-loader.xhtml new file mode 100644 index 0000000..0d68a75 --- /dev/null +++ b/threema-connector/webContent/layouts/includes/progress-loader.xhtml @@ -0,0 +1,15 @@ + + + + +
+
+
Loading...
+
+
+ + + +
+
\ No newline at end of file