From ce3f320173416fb94335cba2a0ae677f4182e83b Mon Sep 17 00:00:00 2001 From: Dejan Kovacevic Date: Mon, 3 Jul 2023 23:41:20 +0200 Subject: [PATCH 01/34] Update README.md --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index 3e20dd8..67dedee 100644 --- a/README.md +++ b/README.md @@ -259,6 +259,20 @@ _Outgoing Message_ can be of 4 types: ``` - **Image message** +``` +{ + "type": "attachment", + "attachment": { + "mimeType" : "image/jpeg", + "height" : 320, + "width" : 160, + "size" : 2048, + "meta" : { + + } + } +} +``` ``` { From ecf81ed9fa2e96287be320414c9bace8e253b9f8 Mon Sep 17 00:00:00 2001 From: Dejan Date: Tue, 4 Jul 2023 14:27:59 +0200 Subject: [PATCH 02/34] Sender: images. Preview and AssetData --- README.md | 96 +++++++++++++------ backend/pom.xml | 2 +- .../main/java/com/wire/bots/roman/Sender.java | 63 +++++++----- 3 files changed, 107 insertions(+), 54 deletions(-) diff --git a/README.md b/README.md index 67dedee..153035f 100644 --- a/README.md +++ b/README.md @@ -45,8 +45,10 @@ Uses [lithium](https://github.com/wireapp/lithium) to utilize Wire Bot API. } ``` -Only `name` is mandatory. Specify `url` if you want to use your _Webhook_ to receive events from Wire Backend. Leave `url` _null_ if you -prefer _Websocket_. `avatar` for your bot is optional, and it is `Base64` encoded `jpeg`|`png` image. If `avatar` field is left _null_ +Only `name` is mandatory. Specify `url` if you want to use your _Webhook_ to receive events from Wire Backend. +Leave `url` _null_ if you +prefer _Websocket_. `avatar` for your bot is optional, and it is `Base64` encoded `jpeg`|`png` image. If `avatar` field +is left _null_ default avatar is assigned for the Service. After creating your Service the following json is returned: @@ -62,15 +64,19 @@ After creating your Service the following json is returned: } ``` -Go to your _Team Settings_ page and navigate to _Services_ tab. Add this `service_code` and enable this service for your team. Now your team +Go to your _Team Settings_ page and navigate to _Services_ tab. Add this `service_code` and enable this service for your +team. Now your team members should be able to see your _Service_ when they open _people picker_ and navigate to _services_ tab. ### Webhook -In case `url` was specified when creating the service webhook will be used. All requests coming from Wire to your Service's endpoint will +In case `url` was specified when creating the service webhook will be used. All requests coming from Wire to your +Service's endpoint will have HTTP Header `Authorization` with value: -`Bearer `. Make sure you verify this value in your webhook implementation. Wire will send events as `POST` HTTP -request to the `url` you specified when creating the Service. Your webhook should always return HTTP code `200` as the result. +`Bearer `. Make sure you verify this value in your webhook implementation. Wire will send events +as `POST` HTTP +request to the `url` you specified when creating the Service. Your webhook should always return HTTP code `200` as the +result. ### Websocket @@ -97,7 +103,8 @@ wss://proxy.services.wire.com/api/await/`` } ``` -Your service must be available at the moment `bot_request` event is sent. It must respond with http code `200`. In case of Websocket +Your service must be available at the moment `bot_request` event is sent. It must respond with http code `200`. In case +of Websocket implementation it is enough the socket is connected to the Proxy at that moment. - `conversation.init` If your Service responded with `200` to a `bot_request` another event is sent: `init`. @@ -232,7 +239,8 @@ implementation it is enough the socket is connected to the Proxy at that moment. ### Posting back to Wire conversation -If the event contains `token` field this `token` can be used to respond to this event by sending `Outgoing Message` like: +If the event contains `token` field this `token` can be used to respond to this event by sending `Outgoing Message` +like: Example: @@ -242,7 +250,8 @@ curl -X POST https://proxy.services.wire.com/api/conversation -d '{"type": "text ``` In order to post text, or an image as a bot into Wire conversation you need to send a `POST` request to `/conversation` -You must also specify the HTTP header as `Authorization:Bearer ` where `token` was obtained in `init` or other events +You must also specify the HTTP header as `Authorization:Bearer ` where `token` was obtained in `init` or other +events like: `new_text` or `new_image`. _Outgoing Message_ can be of 4 types: @@ -259,6 +268,7 @@ _Outgoing Message_ can be of 4 types: ``` - **Image message** + ``` { "type": "attachment", @@ -268,16 +278,27 @@ _Outgoing Message_ can be of 4 types: "width" : 160, "size" : 2048, "meta" : { - + "assetId" : "3-cef231a2-23f2-429e-b76a-b7649594d3fe", + "assetToken" : "...", // Optional + "sha256" : "...", // Base64 encoded SHA256 digest of the file + "otrKey" : "..." // Base64 encoded otr key used to encrypt the file } } } ``` +or + ``` { "type": "attachment", - "attachment": { "mimeType" : "image/jpeg", "data" : "..." } + "attachment": { + "mimeType" : "image/jpeg", + "height" : 320, + "width" : 160, + "size" : 2048, + "data" : "..." // Base64 encoded image data + } } ``` @@ -337,7 +358,8 @@ The best way how to run Roman is to use Docker, another option is to run the Rom ### Configuration -Almost all necessary variables and configurations are located in the [roman.yaml](roman.yaml). Following environment variables should be +Almost all necessary variables and configurations are located in the [roman.yaml](roman.yaml). Following environment +variables should be set. ```bash @@ -379,7 +401,8 @@ openssl rand -hex 32 We provide [Dockerfile](Dockerfile) and the prepared [runtime image](https://github.com/wireapp/cryptobox4j/blob/master/dockerfiles/Dockerfile.runtime) - -[wirebot/runtime](https://hub.docker.com/r/wirebot/runtime). We don't provide the whole Roman docker image, but feel free to build one from +[wirebot/runtime](https://hub.docker.com/r/wirebot/runtime). We don't provide the whole Roman docker image, but feel +free to build one from the code, all necessary files are present in this repository. #### Build docker image from source code @@ -393,7 +416,8 @@ docker build -t roman:latest . #### Example of Docker run command on local machine (without HTTPS) -In order to run the Roman locally, to test the proxy itself (not sending data to Wire backend) one do not need to specify the HTTPS +In order to run the Roman locally, to test the proxy itself (not sending data to Wire backend) one do not need to +specify the HTTPS certificate and run following command: ```bash @@ -413,7 +437,8 @@ docker run \ #### Example with docker-compose (without HTTPS) -We include [docker-compose.yml](docker-compose.yml) file to run the testing instance of Roman locally using Docker Compose. It includes all +We include [docker-compose.yml](docker-compose.yml) file to run the testing instance of Roman locally using Docker +Compose. It includes all necessary variables and PostgreSQL instance, to get the testing instance up and running. Simply execute: ```bash @@ -422,18 +447,22 @@ docker-compose -f docker-compose.yml up #### Production deployment -In order to run the Roman in the production, one needs to have an HTTPS and to set the `ROMAN_PUB_KEY_BASE64` as well as `PROXY_DOMAIN` +In order to run the Roman in the production, one needs to have an HTTPS and to set the `ROMAN_PUB_KEY_BASE64` as well +as `PROXY_DOMAIN` env variables. See [Configuration section](#configuration) how to obtain them. ### Native JVM -As previously mentioned, Wire recommends running the Roman as a docker container. However, you can run it natively on the JVM as well. -Please note that Roman requires JVM >= 11. To run it natively, one needs to install [Cryptobox4j](https://github.com/wireapp/cryptobox4j) +As previously mentioned, Wire recommends running the Roman as a docker container. However, you can run it natively on +the JVM as well. +Please note that Roman requires JVM >= 11. To run it natively, one needs to +install [Cryptobox4j](https://github.com/wireapp/cryptobox4j) and other cryptographic libraries. You can use [Docker Build Image](https://github.com/wireapp/cryptobox4j/blob/master/dockerfiles/Dockerfile.cryptobox) as an inspiration what needs to be installed and what environment variables need to be set to get the Cryptobox working. -Also, don't forget to read the [Configuration section](#configuration) and set all necessary environment variables for the Roman itselgf. +Also, don't forget to read the [Configuration section](#configuration) and set all necessary environment variables for +the Roman itselgf. First, it is necessary to build the application: @@ -451,16 +480,20 @@ java -jar target/roman.jar server roman.yaml ## Simple Guide to Roman Deployment -The previous lines should give you all necessary material you need how to deploy the Roman in multiple environment and how to set everything -up. Even though Wire runs Roman in cloud and uses Kubernetes setup, we decided to provide as simple guide as possible to deploy your own -Roman using just a `docker-compose`. The following lines provides specific and opinionated simple guide, that requires just few basic +The previous lines should give you all necessary material you need how to deploy the Roman in multiple environment and +how to set everything +up. Even though Wire runs Roman in cloud and uses Kubernetes setup, we decided to provide as simple guide as possible to +deploy your own +Roman using just a `docker-compose`. The following lines provides specific and opinionated simple guide, that requires +just few basic things: - a machine with Docker, Docker Compose and OpenSSL installed - the machine has a public IP address and DNS record pointing to that IP address - *(optional)* install `jq` in order to browse and search in logs -In this example we take the DNS as `roman.example.com`, when deploying, change this value to your own domain. In order to obtain the +In this example we take the DNS as `roman.example.com`, when deploying, change this value to your own domain. In order +to obtain the certificate, we will use [Traefik](https://traefik.io/) edge router and [Let's Encrypt](https://letsencrypt.org/). ### Step by step @@ -471,7 +504,8 @@ certificate, we will use [Traefik](https://traefik.io/) edge router and [Let's E git clone git@github.com:wireapp/roman.git ``` -2. Set the correct DNS in the [docker-compose.prod.yml](docker-compose.prod.yml) - replace `roman.example.com` with your own and replace +2. Set the correct DNS in the [docker-compose.prod.yml](docker-compose.prod.yml) - replace `roman.example.com` with your + own and replace the `developers@example.com` email address with our own email. 3. Create `.env.prod` file that will contain all necessary environmental variables. @@ -497,11 +531,15 @@ docker-compose -f docker-compose.prod.yml --env-file .env.prod up --build -d ``` 5. Check the logs - * proxy - `docker-compose -f docker-compose.prod.yml logs proxy` - should show some noise about certificate and routes registration - * Roman - `docker-compose -f docker-compose.prod.yml logs roman` - should show normal starting procedure and no errors - * with Roman, you can pipe logs data to `jq` (if installed), that way you will see nice and formatted JSONs instead of just lines. - -6. Give it some time to obtain necessary certificates - around 10 minutes should be fine. Then try to access the `https://roman.example.com` + * proxy - `docker-compose -f docker-compose.prod.yml logs proxy` - should show some noise about certificate and + routes registration + * Roman - `docker-compose -f docker-compose.prod.yml logs roman` - should show normal starting procedure and no + errors + * with Roman, you can pipe logs data to `jq` (if installed), that way you will see nice and formatted JSONs instead + of just lines. + +6. Give it some time to obtain necessary certificates - around 10 minutes should be fine. Then try to access + the `https://roman.example.com` to see whether the HTTPS works as expected. If yes, proceed, if no troubleshoot with Traefik proxy. 7. Now you need to download real public key and encode it in base64 - see [Getting the ROMAN_PUB_KEY_BASE64](#getting-the-roman_pub_key_base64) diff --git a/backend/pom.xml b/backend/pom.xml index 249fffa..412fffd 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -6,7 +6,7 @@ com.wire.bots roman - 1.18.2 + 1.18.7 Roman Wire Bot API Proxy diff --git a/backend/src/main/java/com/wire/bots/roman/Sender.java b/backend/src/main/java/com/wire/bots/roman/Sender.java index b8c03a0..0b6c2ab 100644 --- a/backend/src/main/java/com/wire/bots/roman/Sender.java +++ b/backend/src/main/java/com/wire/bots/roman/Sender.java @@ -150,35 +150,38 @@ private UUID sendAttachment(IncomingMessage message, UUID botId) throws Exceptio @Nullable private UUID sendPicture(IncomingMessage message, UUID botId) throws Exception { try (WireClient wireClient = getWireClient(botId)) { - final UUID messageId = UUID.randomUUID(); final Attachment attachment = message.attachment; - Picture asset; + Picture picture; if (message.attachment.meta != null) { - asset = new Picture(messageId, attachment.mimeType); - setAssetMetadata(asset, message.attachment.meta); - asset.setHeight(attachment.height); - asset.setWidth(attachment.width); - asset.setSize(attachment.size.intValue()); - } else if (message.attachment.data != null) { - final byte[] bytes = Base64.getDecoder().decode(message.attachment.data); - asset = new Picture(bytes, attachment.mimeType); - uploadAssetData(wireClient, asset); - } else { - throw new Exception("Meta or Data need to be set"); + picture = new Picture(UUID.randomUUID(), attachment.mimeType); + setAssetMetadata(picture, message.attachment.meta); + picture.setHeight(attachment.height); + picture.setWidth(attachment.width); + picture.setSize(attachment.size.intValue()); + + wireClient.send(picture); + return picture.getMessageId(); } - wireClient.send(asset); - return asset.getMessageId(); - } - } + if (message.attachment.data != null) { + final byte[] bytes = Base64.getDecoder().decode(message.attachment.data); + picture = new Picture(bytes, attachment.mimeType); - private WireClient getWireClient(UUID botId) throws IOException, CryptoException { - final WireClient wireClient = repo.getClient(botId); - if (wireClient == null) { - throw new MissingStateException(botId); + setAssetMetadata(picture, message.attachment.meta); + + picture.setHeight(attachment.height); + picture.setWidth(attachment.width); + picture.setSize(bytes.length); + + uploadAssetData(wireClient, picture); + + wireClient.send(picture); + return picture.getMessageId(); + } + + throw new Exception("Meta or Data needs to be set"); } - return wireClient; } @Nullable @@ -228,17 +231,29 @@ public Conversation getConversation(UUID botId) throws IOException, CryptoExcept } } - private void setAssetMetadata(AssetBase asset, AssetMeta meta) { + private void setAssetMetadata(AssetBase asset, @Nullable AssetMeta meta) { + if (meta == null) + return; + asset.setAssetKey(meta.assetId); asset.setAssetToken(meta.assetToken); asset.setSha256(Base64.getDecoder().decode(meta.sha256)); asset.setOtrKey(Base64.getDecoder().decode(meta.otrKey)); } - private void uploadAssetData(WireClient wireClient, AssetBase asset) throws Exception { + private AssetKey uploadAssetData(WireClient wireClient, AssetBase asset) throws Exception { final AssetKey assetKey = wireClient.uploadAsset(asset); asset.setAssetKey(assetKey.id); asset.setAssetToken(assetKey.token); asset.setDomain(assetKey.domain); + return assetKey; + } + + private WireClient getWireClient(UUID botId) throws IOException, CryptoException { + final WireClient wireClient = repo.getClient(botId); + if (wireClient == null) { + throw new MissingStateException(botId); + } + return wireClient; } } From 579f237cf29348ddc225dcc9d184c7129906b79b Mon Sep 17 00:00:00 2001 From: Dejan Date: Wed, 5 Jul 2023 10:29:53 +0200 Subject: [PATCH 03/34] Sender: images. Preview and AssetData --- .../main/java/com/wire/bots/roman/Sender.java | 44 ++++++++----------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/backend/src/main/java/com/wire/bots/roman/Sender.java b/backend/src/main/java/com/wire/bots/roman/Sender.java index 0b6c2ab..aa15ce7 100644 --- a/backend/src/main/java/com/wire/bots/roman/Sender.java +++ b/backend/src/main/java/com/wire/bots/roman/Sender.java @@ -152,35 +152,29 @@ private UUID sendPicture(IncomingMessage message, UUID botId) throws Exception { try (WireClient wireClient = getWireClient(botId)) { final Attachment attachment = message.attachment; - Picture picture; - if (message.attachment.meta != null) { - picture = new Picture(UUID.randomUUID(), attachment.mimeType); - setAssetMetadata(picture, message.attachment.meta); - picture.setHeight(attachment.height); - picture.setWidth(attachment.width); - picture.setSize(attachment.size.intValue()); - - wireClient.send(picture); - return picture.getMessageId(); - } - - if (message.attachment.data != null) { - final byte[] bytes = Base64.getDecoder().decode(message.attachment.data); - picture = new Picture(bytes, attachment.mimeType); - - setAssetMetadata(picture, message.attachment.meta); + UUID messageId = UUID.randomUUID(); + Picture preview = new Picture(messageId, attachment.mimeType); + preview.setHeight(attachment.height); + preview.setWidth(attachment.width); + preview.setSize(attachment.size.intValue()); - picture.setHeight(attachment.height); - picture.setWidth(attachment.width); - picture.setSize(bytes.length); - - uploadAssetData(wireClient, picture); + wireClient.send(preview); - wireClient.send(picture); - return picture.getMessageId(); + AssetBase asset; + if (message.attachment.meta != null) { + asset = new Picture(preview.getMessageId(), attachment.mimeType); + setAssetMetadata(asset, message.attachment.meta); + } else if (message.attachment.data != null) { + final byte[] bytes = Base64.getDecoder().decode(message.attachment.data); + asset = new Picture(bytes, attachment.mimeType); + asset.setMessageId(messageId); + uploadAssetData(wireClient, asset); + } else { + throw new Exception("Meta or Data need to be set"); } - throw new Exception("Meta or Data needs to be set"); + wireClient.send(asset); + return asset.getMessageId(); } } From 7305091ed21e961f1bb22f83868be33202bc6be3 Mon Sep 17 00:00:00 2001 From: Dejan Date: Wed, 5 Jul 2023 11:51:26 +0200 Subject: [PATCH 04/34] xenon 1.5.2 --- backend/pom.xml | 7 ++++++- backend/src/main/java/com/wire/bots/roman/Sender.java | 6 +++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/backend/pom.xml b/backend/pom.xml index 412fffd..7c2c774 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -6,7 +6,7 @@ com.wire.bots roman - 1.18.7 + 1.18.8 Roman Wire Bot API Proxy @@ -39,6 +39,11 @@ lithium ${lithium.version} + + com.wire + xenon + 1.5.2 + com.lambdaworks scrypt diff --git a/backend/src/main/java/com/wire/bots/roman/Sender.java b/backend/src/main/java/com/wire/bots/roman/Sender.java index aa15ce7..7358b3d 100644 --- a/backend/src/main/java/com/wire/bots/roman/Sender.java +++ b/backend/src/main/java/com/wire/bots/roman/Sender.java @@ -153,7 +153,7 @@ private UUID sendPicture(IncomingMessage message, UUID botId) throws Exception { final Attachment attachment = message.attachment; UUID messageId = UUID.randomUUID(); - Picture preview = new Picture(messageId, attachment.mimeType); + ImagePreview preview = new ImagePreview(messageId, attachment.mimeType); preview.setHeight(attachment.height); preview.setWidth(attachment.width); preview.setSize(attachment.size.intValue()); @@ -162,11 +162,11 @@ private UUID sendPicture(IncomingMessage message, UUID botId) throws Exception { AssetBase asset; if (message.attachment.meta != null) { - asset = new Picture(preview.getMessageId(), attachment.mimeType); + asset = new ImageAsset(preview.getMessageId(), null, attachment.mimeType); setAssetMetadata(asset, message.attachment.meta); } else if (message.attachment.data != null) { final byte[] bytes = Base64.getDecoder().decode(message.attachment.data); - asset = new Picture(bytes, attachment.mimeType); + asset = new ImageAsset(messageId, bytes, attachment.mimeType); asset.setMessageId(messageId); uploadAssetData(wireClient, asset); } else { From 090521e65670eb1f87b7dfea762962a385d65c45 Mon Sep 17 00:00:00 2001 From: Dejan Date: Tue, 11 Jul 2023 15:57:14 +0200 Subject: [PATCH 05/34] minor changes --- .../main/java/com/wire/bots/roman/Sender.java | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/backend/src/main/java/com/wire/bots/roman/Sender.java b/backend/src/main/java/com/wire/bots/roman/Sender.java index 7358b3d..d6b3103 100644 --- a/backend/src/main/java/com/wire/bots/roman/Sender.java +++ b/backend/src/main/java/com/wire/bots/roman/Sender.java @@ -160,21 +160,21 @@ private UUID sendPicture(IncomingMessage message, UUID botId) throws Exception { wireClient.send(preview); - AssetBase asset; + ImageAsset image; if (message.attachment.meta != null) { - asset = new ImageAsset(preview.getMessageId(), null, attachment.mimeType); - setAssetMetadata(asset, message.attachment.meta); + image = new ImageAsset(preview.getMessageId(), new byte[0], attachment.mimeType); + setAssetMetadata(image, message.attachment.meta); } else if (message.attachment.data != null) { final byte[] bytes = Base64.getDecoder().decode(message.attachment.data); - asset = new ImageAsset(messageId, bytes, attachment.mimeType); - asset.setMessageId(messageId); - uploadAssetData(wireClient, asset); + image = new ImageAsset(messageId, bytes, attachment.mimeType); + image.setMessageId(messageId); + uploadAssetData(wireClient, image); } else { throw new Exception("Meta or Data need to be set"); } - wireClient.send(asset); - return asset.getMessageId(); + wireClient.send(image); + return image.getMessageId(); } } @@ -225,10 +225,7 @@ public Conversation getConversation(UUID botId) throws IOException, CryptoExcept } } - private void setAssetMetadata(AssetBase asset, @Nullable AssetMeta meta) { - if (meta == null) - return; - + private void setAssetMetadata(AssetBase asset, AssetMeta meta) { asset.setAssetKey(meta.assetId); asset.setAssetToken(meta.assetToken); asset.setSha256(Base64.getDecoder().decode(meta.sha256)); From 7a161275e0dfaaca30ba955c4256093bfb2c4187 Mon Sep 17 00:00:00 2001 From: Dejan Date: Mon, 24 Jul 2023 12:40:47 +0200 Subject: [PATCH 06/34] lithium 3.5.2 --- backend/pom.xml | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/backend/pom.xml b/backend/pom.xml index 7c2c774..e002900 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -6,7 +6,7 @@ com.wire.bots roman - 1.18.8 + 1.18.9 Roman Wire Bot API Proxy @@ -28,7 +28,7 @@ true - 3.5.1 + 3.5.2 2.1.4 0.11.5 @@ -39,11 +39,6 @@ lithium ${lithium.version} - - com.wire - xenon - 1.5.2 - com.lambdaworks scrypt From 9134daf00246af8bd45e8fb17b8071b05f4fda40 Mon Sep 17 00:00:00 2001 From: Dejan Date: Mon, 24 Jul 2023 14:59:27 +0200 Subject: [PATCH 07/34] updated dependancies --- backend/pom.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/pom.xml b/backend/pom.xml index e002900..8b9434b 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -29,7 +29,7 @@ true 3.5.2 - 2.1.4 + 2.1.5 0.11.5 @@ -47,7 +47,7 @@ com.fasterxml.jackson.core jackson-databind - 2.13.4.2 + 2.15.1 io.jsonwebtoken @@ -118,7 +118,7 @@ org.mockito mockito-core - 4.8.0 + 5.2.0 test @@ -130,7 +130,7 @@ org.assertj assertj-core - 3.23.1 + 3.24.2 test From 7e9866e7c73b7c5326fe454ee3db8c660b11c5b9 Mon Sep 17 00:00:00 2001 From: Dejan Date: Thu, 3 Aug 2023 16:46:08 +0200 Subject: [PATCH 08/34] trace more --- backend/src/main/java/com/wire/bots/roman/MessageHandler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/com/wire/bots/roman/MessageHandler.java b/backend/src/main/java/com/wire/bots/roman/MessageHandler.java index 1629121..285330d 100644 --- a/backend/src/main/java/com/wire/bots/roman/MessageHandler.java +++ b/backend/src/main/java/com/wire/bots/roman/MessageHandler.java @@ -430,7 +430,7 @@ private boolean send(OutgoingMessage message) { return WebSocket.send(provider.id, message); } } catch (Exception e) { - Logger.exception("MessageHandler.send: error %s", e, e.getMessage()); + Logger.error("MessageHandler.send: error %s", e.getMessage()); return false; } } @@ -465,7 +465,7 @@ private void trace(OutgoingMessage message) { try { if (Logger.getLevel() == Level.FINE) { ObjectMapper objectMapper = new ObjectMapper(); - Logger.debug(objectMapper.writeValueAsString(message)); + Logger.info(objectMapper.writeValueAsString(message)); } } catch (Exception ignore) { From a452dc4f0419c45e86cfa25359e85c71e89a1221 Mon Sep 17 00:00:00 2001 From: Dejan Date: Thu, 3 Aug 2023 17:03:56 +0200 Subject: [PATCH 09/34] trace more --- .../com/wire/bots/roman/resources/ConversationResource.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main/java/com/wire/bots/roman/resources/ConversationResource.java b/backend/src/main/java/com/wire/bots/roman/resources/ConversationResource.java index 521031f..91ad64a 100644 --- a/backend/src/main/java/com/wire/bots/roman/resources/ConversationResource.java +++ b/backend/src/main/java/com/wire/bots/roman/resources/ConversationResource.java @@ -104,7 +104,7 @@ private void trace(IncomingMessage message) { try { if (Logger.getLevel() == Level.FINE) { ObjectMapper mapper = new ObjectMapper(); - Logger.debug(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(message)); + Logger.info(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(message)); } } catch (Exception ignore) { From d5ced2787983f140178037196207708c31518bab Mon Sep 17 00:00:00 2001 From: Dejan Date: Thu, 14 Sep 2023 15:30:33 +0200 Subject: [PATCH 10/34] Lithium 3.5.4 --- backend/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/pom.xml b/backend/pom.xml index 8b9434b..66958c8 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -28,7 +28,7 @@ true - 3.5.2 + 3.5.4 2.1.5 0.11.5 From 4ee39cd2b329c81ae28e7ed35fabfe8e57bea1a6 Mon Sep 17 00:00:00 2001 From: Dejan Date: Wed, 18 Oct 2023 11:12:50 +0200 Subject: [PATCH 11/34] Lithium 3.6.0 --- backend/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/pom.xml b/backend/pom.xml index 66958c8..537e4f0 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -6,7 +6,7 @@ com.wire.bots roman - 1.18.9 + 1.19.0 Roman Wire Bot API Proxy @@ -28,7 +28,7 @@ true - 3.5.4 + 3.6.0 2.1.5 0.11.5 From 122e6d21b0b4ca8f210dbfe058710f23561a11e2 Mon Sep 17 00:00:00 2001 From: Yamil Medina Date: Tue, 5 Dec 2023 11:54:35 +0100 Subject: [PATCH 12/34] fix: migrate jakarta deps to comply with lithium 3.6.x (pt1) (#119) * Lithium 3.6.0 * WebsocketBundle * chore: cleanup depedencies * chore: cleanup depedencies to jakarta * chore: fixing tests * chore: fixing tests * chore: comments - [skip-ci] * feat: fixing tests and dependencies * feat: fixing tests and dependencies * chore: fixing ws config to jakarta * chore: removing local fix docker image platform --------- Co-authored-by: Dejan --- Dockerfile | 4 +- backend/pom.xml | 136 +++--- backend/roman.yaml | 2 - .../java/com/wire/bots/roman/Application.java | 11 +- .../com/wire/bots/roman/CachedClientRepo.java | 2 +- .../com/wire/bots/roman/DAO/BroadcastDAO.java | 2 +- .../bots/roman/DAO/mappers/UUIDMapper.java | 2 +- .../com/wire/bots/roman/ImageProcessor.java | 80 ++-- .../com/wire/bots/roman/MessageEncoder.java | 6 +- .../com/wire/bots/roman/MessageHandler.java | 10 +- .../com/wire/bots/roman/ProviderClient.java | 18 +- .../main/java/com/wire/bots/roman/Sender.java | 2 +- .../main/java/com/wire/bots/roman/Tools.java | 2 +- .../java/com/wire/bots/roman/WebSocket.java | 8 +- .../com/wire/bots/roman/WebsocketBundle.java | 135 ++++++ .../roman/commands/UpdateCertCommand.java | 14 +- .../filters/BackendAuthenticationFilter.java | 18 +- .../bots/roman/filters/CspResponseFilter.java | 6 +- .../filters/ProxyAuthenticationFilter.java | 18 +- .../filters/ServiceAuthenticationFilter.java | 19 +- .../ServiceTokenAuthenticationFilter.java | 16 +- .../com/wire/bots/roman/model/AssetMeta.java | 2 +- .../com/wire/bots/roman/model/Attachment.java | 2 +- .../java/com/wire/bots/roman/model/Call.java | 2 +- .../com/wire/bots/roman/model/Config.java | 4 +- .../bots/roman/model/IncomingMessage.java | 2 +- .../com/wire/bots/roman/model/Mention.java | 4 +- .../bots/roman/model/OutgoingMessage.java | 2 +- .../java/com/wire/bots/roman/model/Poll.java | 2 +- .../com/wire/bots/roman/model/Provider.java | 2 +- .../com/wire/bots/roman/model/Report.java | 2 +- .../com/wire/bots/roman/model/Service.java | 2 +- .../com/wire/bots/roman/model/SignIn.java | 2 +- .../java/com/wire/bots/roman/model/Text.java | 2 +- .../com/wire/bots/roman/model/Version.java | 2 +- .../roman/resources/BroadcastResource.java | 14 +- .../roman/resources/ConversationResource.java | 20 +- .../roman/resources/MessagesResource.java | 16 +- .../wire/bots/roman/resources/Picture.java | 48 ++ .../roman/resources/ProviderResource.java | 14 +- .../bots/roman/resources/ServiceResource.java | 165 +++---- .../bots/roman/resources/UsersResource.java | 16 +- .../integrations/BroadcastResourceTest.java | 43 +- .../bots/roman/integrations/DatabaseTest.java | 358 +++++++-------- .../IncomingBackendCallMessageTest.java | 310 ++++++------- .../IncomingBackendPollMessageTest.java | 426 +++++++++--------- .../IncomingBackendTextMessageTest.java | 302 ++++++------- .../integrations/IncomingMessageTest.java | 298 ++++++------ .../roman/integrations/WebSocketTest.java | 251 +++++------ .../resources/ConversationResourceTest.java | 82 ++-- .../roman/resources/UsersResourceTest.java | 21 +- .../dummies/AuthenticationFeatureDummy.java | 9 +- .../dummies/AuthenticationFilterDummy.java | 4 +- backend/src/test/resources/roman-test.yml | 78 ++++ 54 files changed, 1656 insertions(+), 1362 deletions(-) create mode 100644 backend/src/main/java/com/wire/bots/roman/WebsocketBundle.java create mode 100644 backend/src/main/java/com/wire/bots/roman/resources/Picture.java create mode 100644 backend/src/test/resources/roman-test.yml diff --git a/Dockerfile b/Dockerfile index b0a3d20..3eaaf08 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,7 @@ WORKDIR ./frontend RUN npm i RUN npm run build -FROM maven:3-openjdk-11 AS build +FROM maven:3-openjdk-17 AS build WORKDIR /app COPY backend/pom.xml ./ @@ -18,7 +18,7 @@ COPY backend/ ./ RUN mvn -Dmaven.test.skip=true package -FROM wirebot/runtime:1.3.0 AS runtime +FROM wirebot/runtime:1.4.0 AS runtime LABEL description="Wire Roman" LABEL project="wire-bots:roman" diff --git a/backend/pom.xml b/backend/pom.xml index 537e4f0..da184b7 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -21,19 +21,72 @@ - 11 - 11 + 17 + 17 UTF-8 UTF-8 true 3.6.0 - 2.1.5 + 4.0.0 0.11.5 + 5.8.2 + 11.0.18 + 2.1.1 + + + + io.dropwizard + dropwizard-bom + ${dropwizard.version} + pom + import + + + + + + io.dropwizard + dropwizard-core + + + io.dropwizard + dropwizard-auth + + + io.dropwizard + dropwizard-assets + + + io.dropwizard + dropwizard-servlets + + + io.dropwizard-bundles + dropwizard-configurable-assets-bundle + 1.3.5 + + + + jakarta.annotation + jakarta.annotation-api + ${jakarta.version} + + + jakarta.websocket + jakarta.websocket-api + ${jakarta.version} + + + org.eclipse.jetty.websocket + websocket-jakarta-server + ${jetty.version} + + com.wire lithium @@ -49,6 +102,11 @@ jackson-databind 2.15.1 + + jakarta.xml.bind + jakarta.xml.bind-api + 4.0.1 + io.jsonwebtoken jjwt-api @@ -67,64 +125,34 @@ runtime + - io.dropwizard-bundles - dropwizard-configurable-assets-bundle - 1.3.5 - - - io.dropwizard - dropwizard-servlets - - - - - io.dropwizard-bundles - dropwizard-redirect-bundle - 1.3.5 - - - org.eclipse.jetty.websocket - javax-websocket-server-impl - 9.4.49.v20220914 + org.mockito + mockito-core + 5.2.0 + test - com.liveperson - dropwizard-websockets - 1.3.14 + io.dropwizard + dropwizard-testing + test - io.dropwizard - dropwizard-core - - - org.eclipse.jetty.websocket - javax-websocket-server-impl + junit + junit - io.dropwizard - dropwizard-servlets - ${dropwizard.version} - - - - io.dropwizard - dropwizard-testing - ${dropwizard.version} + org.junit.jupiter + junit-jupiter + ${junit5.version} test - org.mockito - mockito-core - 5.2.0 - test - - - junit - junit - 4.13.2 + org.junit.jupiter + junit-jupiter-params + ${junit5.version} test @@ -133,6 +161,12 @@ 3.24.2 test + + com.h2database + h2 + 2.2.224 + test + @@ -141,8 +175,8 @@ maven-compiler-plugin 3.8.1 - 11 - 11 + 17 + 17 diff --git a/backend/roman.yaml b/backend/roman.yaml index e6e1c34..134a625 100644 --- a/backend/roman.yaml +++ b/backend/roman.yaml @@ -12,8 +12,6 @@ server: requestLog: appenders: - type: ${APPENDER_TYPE:-console} - filterFactories: - - type: status-filter-factory logging: level: INFO diff --git a/backend/src/main/java/com/wire/bots/roman/Application.java b/backend/src/main/java/com/wire/bots/roman/Application.java index 576eedd..7528c0b 100644 --- a/backend/src/main/java/com/wire/bots/roman/Application.java +++ b/backend/src/main/java/com/wire/bots/roman/Application.java @@ -35,15 +35,13 @@ import com.wire.xenon.MessageHandlerBase; import com.wire.xenon.factories.CryptoFactory; import com.wire.xenon.factories.StorageFactory; -import io.dropwizard.bundles.assets.ConfiguredAssetsBundle; -import io.dropwizard.setup.Bootstrap; -import io.dropwizard.setup.Environment; -import io.dropwizard.websockets.WebsocketBundle; +import io.dropwizard.core.setup.Bootstrap; +import io.dropwizard.core.setup.Environment; import io.jsonwebtoken.security.Keys; +import jakarta.servlet.DispatcherType; +import jakarta.servlet.FilterRegistration; import org.eclipse.jetty.servlets.CrossOriginFilter; -import javax.servlet.DispatcherType; -import javax.servlet.FilterRegistration; import java.security.Key; import java.util.EnumSet; import java.util.concurrent.ExecutorService; @@ -72,7 +70,6 @@ public void initialize(Bootstrap bootstrap) { instance = (Application) bootstrap.getApplication(); bootstrap.addBundle(new WebsocketBundle(WebSocket.class)); bootstrap.addCommand(new UpdateCertCommand()); - bootstrap.addBundle(new ConfiguredAssetsBundle("/assets/", "/", "index.html")); } @Override diff --git a/backend/src/main/java/com/wire/bots/roman/CachedClientRepo.java b/backend/src/main/java/com/wire/bots/roman/CachedClientRepo.java index b3ad115..45b6950 100644 --- a/backend/src/main/java/com/wire/bots/roman/CachedClientRepo.java +++ b/backend/src/main/java/com/wire/bots/roman/CachedClientRepo.java @@ -12,9 +12,9 @@ import com.wire.xenon.models.otr.Missing; import com.wire.xenon.models.otr.Recipients; import com.wire.xenon.tools.Logger; +import jakarta.ws.rs.client.Client; import org.checkerframework.checker.nullness.qual.Nullable; -import javax.ws.rs.client.Client; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; diff --git a/backend/src/main/java/com/wire/bots/roman/DAO/BroadcastDAO.java b/backend/src/main/java/com/wire/bots/roman/DAO/BroadcastDAO.java index d5a9e2c..07d9398 100644 --- a/backend/src/main/java/com/wire/bots/roman/DAO/BroadcastDAO.java +++ b/backend/src/main/java/com/wire/bots/roman/DAO/BroadcastDAO.java @@ -1,6 +1,7 @@ package com.wire.bots.roman.DAO; import com.wire.bots.roman.DAO.mappers.UUIDMapper; +import jakarta.annotation.Nullable; import org.jdbi.v3.core.mapper.ColumnMapper; import org.jdbi.v3.core.statement.StatementContext; import org.jdbi.v3.sqlobject.config.RegisterColumnMapper; @@ -8,7 +9,6 @@ import org.jdbi.v3.sqlobject.statement.SqlQuery; import org.jdbi.v3.sqlobject.statement.SqlUpdate; -import javax.annotation.Nullable; import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; diff --git a/backend/src/main/java/com/wire/bots/roman/DAO/mappers/UUIDMapper.java b/backend/src/main/java/com/wire/bots/roman/DAO/mappers/UUIDMapper.java index 23c16ce..74874c1 100644 --- a/backend/src/main/java/com/wire/bots/roman/DAO/mappers/UUIDMapper.java +++ b/backend/src/main/java/com/wire/bots/roman/DAO/mappers/UUIDMapper.java @@ -1,10 +1,10 @@ package com.wire.bots.roman.DAO.mappers; import com.wire.xenon.tools.Logger; +import jakarta.annotation.Nullable; import org.jdbi.v3.core.mapper.ColumnMapper; import org.jdbi.v3.core.statement.StatementContext; -import javax.annotation.Nullable; import java.sql.ResultSet; import java.sql.SQLException; import java.util.UUID; diff --git a/backend/src/main/java/com/wire/bots/roman/ImageProcessor.java b/backend/src/main/java/com/wire/bots/roman/ImageProcessor.java index 7312282..1888373 100644 --- a/backend/src/main/java/com/wire/bots/roman/ImageProcessor.java +++ b/backend/src/main/java/com/wire/bots/roman/ImageProcessor.java @@ -1,24 +1,17 @@ package com.wire.bots.roman; -import com.wire.xenon.assets.Picture; +import com.wire.bots.roman.resources.Picture; +import com.wire.xenon.assets.ImagePreview; -import javax.imageio.ImageIO; import java.awt.*; import java.awt.image.BufferedImage; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; public class ImageProcessor { private static final int MEDIUM_DIMENSION = 2896; - private static final int SMALL_DIMENSION = 2896; - public static Picture getMediumImage(Picture original) throws Exception { - return getScaledImage(original, MEDIUM_DIMENSION); - } - - public static Picture getSmallImage(Picture original) throws Exception { - return getScaledImage(original, SMALL_DIMENSION); + public static Picture getMediumImage(Picture picture) throws Exception { + return getScaledImage(picture, MEDIUM_DIMENSION); } private static Boolean shouldScaleOriginalSize(double width, double height, double dimension) { @@ -59,40 +52,37 @@ private static BufferedImage resizeImage(BufferedImage originalImage, return resizedImage; } - private static Picture getScaledImage(Picture image, double dimension) throws Exception { - String resultImageType; - switch (image.getMimeType()) { - case "image/gif": - resultImageType = "gif"; - break; - case "image/jpeg": - resultImageType = "jpg"; - break; - case "image/png": - resultImageType = "png"; - break; - default: - throw new Exception("Unsupported mime type: " + image.getMimeType()); - } - - int origWidth = image.getWidth(); - int origHeight = image.getHeight(); - - BufferedImage resultImage = ImageIO.read(new ByteArrayInputStream(image.getImageData())); - - if (shouldScaleOriginalSize(origWidth, origHeight, dimension)) { - Size scaledSize = getScaledSize(origWidth, origHeight, dimension); - resultImage = resizeImage(resultImage, (int) scaledSize.width, - (int) scaledSize.height); - } - - try (ByteArrayOutputStream resultStream = new ByteArrayOutputStream()) { - ImageIO.write(resultImage, resultImageType, resultStream); - resultStream.flush(); - Picture picture = new Picture(resultStream.toByteArray(), image.getMimeType()); - picture.setRetention(image.getRetention()); - return picture; - } + // todo. fixme, xenon to expose getMimeType type and getImageData + private static Picture getScaledImage(ImagePreview image, int dimension) throws Exception { +// String resultImageType; +// switch ("image/jpeg") { +// case "image/jpeg": +// resultImageType = "jpg"; +// break; +// case "image/png": +// resultImageType = "png"; +// break; +// default: +// throw new IllegalArgumentException("Unsupported mime type"); +// } +// +// int origWidth = image.getWidth(); +// int origHeight = image.getHeight(); +// +// BufferedImage resultImage = ImageIO.read(new ByteArrayInputStream(image.getImageData())); +// +// if (shouldScaleOriginalSize(origWidth, origHeight, dimension)) { +// Size scaledSize = getScaledSize(origWidth, origHeight, dimension); +// resultImage = resizeImage(resultImage, (int) scaledSize.width, +// (int) scaledSize.height); +// } +// +// try (ByteArrayOutputStream resultStream = new ByteArrayOutputStream()) { +// ImageIO.write(resultImage, resultImageType, resultStream); +// resultStream.flush(); +// return new Picture(resultStream.toByteArray(), image.getMimeType()); +// } + return null; } private static class Size { diff --git a/backend/src/main/java/com/wire/bots/roman/MessageEncoder.java b/backend/src/main/java/com/wire/bots/roman/MessageEncoder.java index 7c955b3..d3e7551 100644 --- a/backend/src/main/java/com/wire/bots/roman/MessageEncoder.java +++ b/backend/src/main/java/com/wire/bots/roman/MessageEncoder.java @@ -3,10 +3,10 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.wire.bots.roman.model.OutgoingMessage; +import jakarta.websocket.EncodeException; +import jakarta.websocket.Encoder; +import jakarta.websocket.EndpointConfig; -import javax.websocket.EncodeException; -import javax.websocket.Encoder; -import javax.websocket.EndpointConfig; public class MessageEncoder implements Encoder.Text { diff --git a/backend/src/main/java/com/wire/bots/roman/MessageHandler.java b/backend/src/main/java/com/wire/bots/roman/MessageHandler.java index 285330d..6027f9e 100644 --- a/backend/src/main/java/com/wire/bots/roman/MessageHandler.java +++ b/backend/src/main/java/com/wire/bots/roman/MessageHandler.java @@ -15,13 +15,13 @@ import com.wire.xenon.backend.models.User; import com.wire.xenon.models.*; import com.wire.xenon.tools.Logger; +import jakarta.ws.rs.ProcessingException; +import jakarta.ws.rs.client.Client; +import jakarta.ws.rs.client.Entity; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response; import org.jdbi.v3.core.Jdbi; -import javax.ws.rs.ProcessingException; -import javax.ws.rs.client.Client; -import javax.ws.rs.client.Entity; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; import java.util.ArrayList; import java.util.Base64; import java.util.UUID; diff --git a/backend/src/main/java/com/wire/bots/roman/ProviderClient.java b/backend/src/main/java/com/wire/bots/roman/ProviderClient.java index 82cea2e..6062a87 100644 --- a/backend/src/main/java/com/wire/bots/roman/ProviderClient.java +++ b/backend/src/main/java/com/wire/bots/roman/ProviderClient.java @@ -7,15 +7,15 @@ import com.wire.xenon.models.AssetKey; import com.wire.xenon.tools.Logger; import com.wire.xenon.tools.Util; - -import javax.validation.constraints.NotNull; -import javax.ws.rs.client.Client; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.Cookie; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.NewCookie; -import javax.ws.rs.core.Response; +import jakarta.ws.rs.client.Client; +import jakarta.ws.rs.client.Entity; +import jakarta.ws.rs.client.WebTarget; +import jakarta.ws.rs.core.Cookie; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.NewCookie; +import jakarta.ws.rs.core.Response; + +import jakarta.validation.constraints.NotNull; import java.io.ByteArrayOutputStream; import java.nio.charset.StandardCharsets; import java.util.ArrayList; diff --git a/backend/src/main/java/com/wire/bots/roman/Sender.java b/backend/src/main/java/com/wire/bots/roman/Sender.java index d6b3103..4622a89 100644 --- a/backend/src/main/java/com/wire/bots/roman/Sender.java +++ b/backend/src/main/java/com/wire/bots/roman/Sender.java @@ -13,8 +13,8 @@ import com.wire.xenon.exceptions.MissingStateException; import com.wire.xenon.models.AssetKey; import com.wire.xenon.tools.Logger; +import jakarta.annotation.Nullable; -import javax.annotation.Nullable; import java.io.IOException; import java.util.Base64; import java.util.UUID; diff --git a/backend/src/main/java/com/wire/bots/roman/Tools.java b/backend/src/main/java/com/wire/bots/roman/Tools.java index 421f381..44f61e0 100644 --- a/backend/src/main/java/com/wire/bots/roman/Tools.java +++ b/backend/src/main/java/com/wire/bots/roman/Tools.java @@ -1,8 +1,8 @@ package com.wire.bots.roman; import io.jsonwebtoken.Jwts; +import jakarta.annotation.Nullable; -import javax.annotation.Nullable; import java.nio.charset.StandardCharsets; import java.util.Base64; import java.util.Date; diff --git a/backend/src/main/java/com/wire/bots/roman/WebSocket.java b/backend/src/main/java/com/wire/bots/roman/WebSocket.java index f9780c3..608dd48 100644 --- a/backend/src/main/java/com/wire/bots/roman/WebSocket.java +++ b/backend/src/main/java/com/wire/bots/roman/WebSocket.java @@ -2,10 +2,10 @@ import com.wire.bots.roman.model.OutgoingMessage; import com.wire.xenon.tools.Logger; +import jakarta.websocket.*; +import jakarta.websocket.server.PathParam; +import jakarta.websocket.server.ServerEndpoint; -import javax.websocket.*; -import javax.websocket.server.PathParam; -import javax.websocket.server.ServerEndpoint; import java.io.IOException; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; @@ -47,6 +47,6 @@ public void onClose(Session session) throws IOException { @OnError public void onError(Session session, Throwable throwable) { - Logger.exception(throwable,"%s error: %s", session.getId(), throwable.getMessage()); + Logger.exception(throwable, "%s error: %s", session.getId(), throwable.getMessage()); } } diff --git a/backend/src/main/java/com/wire/bots/roman/WebsocketBundle.java b/backend/src/main/java/com/wire/bots/roman/WebsocketBundle.java new file mode 100644 index 0000000..0862e0e --- /dev/null +++ b/backend/src/main/java/com/wire/bots/roman/WebsocketBundle.java @@ -0,0 +1,135 @@ +/** + * The MIT License + * Copyright (c) 2017 LivePerson, Inc. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package com.wire.bots.roman; + +import com.wire.bots.roman.model.Config; +import io.dropwizard.core.ConfiguredBundle; +import io.dropwizard.core.setup.Bootstrap; +import io.dropwizard.core.setup.Environment; +import jakarta.websocket.DeploymentException; +import jakarta.websocket.server.ServerContainer; +import jakarta.websocket.server.ServerEndpoint; +import jakarta.websocket.server.ServerEndpointConfig; +import org.eclipse.jetty.util.component.LifeCycle; +import org.eclipse.jetty.websocket.jakarta.server.config.JakartaWebSocketServletContainerInitializer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.function.Consumer; + +public class WebsocketBundle implements ConfiguredBundle, LifeCycle.Listener { + + private final Collection endpointConfigs = new ArrayList<>(); + private static final Logger LOG = LoggerFactory.getLogger(WebsocketBundle.class); + volatile boolean starting = false; + private final ServerEndpointConfig.Configurator defaultConfigurator; + + + public WebsocketBundle(ServerEndpointConfig.Configurator defaultConfigurator, Class... endpoints) { + this(defaultConfigurator, Arrays.asList(endpoints), new ArrayList<>()); + } + + public WebsocketBundle(Class... endpoints) { + this(null, Arrays.asList(endpoints), new ArrayList<>()); + } + + public WebsocketBundle(ServerEndpointConfig... configs) { + this(null, new ArrayList<>(), Arrays.asList(configs)); + } + + public WebsocketBundle(ServerEndpointConfig.Configurator defaultConfigurator, Collection> endpointClasses, Collection serverEndpointConfigs) { + this.defaultConfigurator = defaultConfigurator; + endpointClasses.forEach(this::addEndpoint); + this.endpointConfigs.addAll(serverEndpointConfigs); + } + + public void addEndpoint(ServerEndpointConfig epC) { + endpointConfigs.add(epC); + if (starting) + throw new RuntimeException("can't add endpoint after starting lifecycle"); + } + + public void addEndpoint(Class clazz) { + ServerEndpoint anno = clazz.getAnnotation(ServerEndpoint.class); + if (anno == null) { + throw new RuntimeException(clazz.getCanonicalName() + " does not have a " + ServerEndpoint.class.getCanonicalName() + " annotation"); + } + ServerEndpointConfig.Builder bldr = ServerEndpointConfig.Builder.create(clazz, anno.value()); + if (defaultConfigurator != null) { + bldr.configurator(defaultConfigurator); + } + endpointConfigs.add(bldr.build()); + if (starting) + throw new RuntimeException("can't add endpoint after starting lifecycle"); + } + + @Override + public void initialize(Bootstrap bootstrap) { + } + + @Override + public void run(Config config, Environment environment) { + environment.lifecycle().addEventListener(new LifeCycle.Listener() { + @Override + public void lifeCycleStarting(LifeCycle event) { + starting = true; + JakartaWebSocketServletContainerInitializer.configure(environment.getApplicationContext(), (servletContext, wsContainer) -> + { + // This lambda will be called at the appropriate place in the + // ServletContext initialization phase where you can initialize + // and configure your websocket container. + // Configure defaults for container + wsContainer.setDefaultMaxTextMessageBufferSize(65535); + + // Add WebSocket endpoint to jakarta.websocket layer + StringBuilder sb = new StringBuilder("Registering websocket endpoints: ") + .append(System.lineSeparator()) + .append(System.lineSeparator()); + endpointConfigs.forEach(rethrow(conf -> addEndpoint(wsContainer, conf, sb))); + LOG.info(sb.toString()); + }); + } + + private void addEndpoint(ServerContainer wsContainer, ServerEndpointConfig conf, StringBuilder sb) throws DeploymentException { + wsContainer.addEndpoint(conf); + sb.append(String.format(" WS %s (%s)", conf.getPath(), conf.getEndpointClass().getName())).append(System.lineSeparator()); + } + }); + } + + public static Consumer rethrow(ConsumerCheckException c) { + return t -> { + try { + c.accept(t); + } catch (Exception ex) { + throw new RuntimeException(ex); + } + }; + } + + @FunctionalInterface + public interface ConsumerCheckException { + void accept(T elem) throws Exception; + } +} \ No newline at end of file diff --git a/backend/src/main/java/com/wire/bots/roman/commands/UpdateCertCommand.java b/backend/src/main/java/com/wire/bots/roman/commands/UpdateCertCommand.java index d0525ef..151342e 100644 --- a/backend/src/main/java/com/wire/bots/roman/commands/UpdateCertCommand.java +++ b/backend/src/main/java/com/wire/bots/roman/commands/UpdateCertCommand.java @@ -1,24 +1,24 @@ package com.wire.bots.roman.commands; -import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider; +import com.fasterxml.jackson.jakarta.rs.json.JacksonJsonProvider; import com.wire.bots.roman.DAO.ProvidersDAO; import com.wire.bots.roman.ProviderClient; import com.wire.bots.roman.Tools; import com.wire.bots.roman.model.Config; import com.wire.bots.roman.model.Provider; import com.wire.xenon.tools.Logger; -import io.dropwizard.cli.ConfiguredCommand; import io.dropwizard.client.JerseyClientBuilder; -import io.dropwizard.setup.Bootstrap; -import io.dropwizard.setup.Environment; +import io.dropwizard.core.cli.ConfiguredCommand; +import io.dropwizard.core.setup.Bootstrap; +import io.dropwizard.core.setup.Environment; +import jakarta.ws.rs.client.Client; +import jakarta.ws.rs.core.NewCookie; +import jakarta.ws.rs.core.Response; import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Subparser; import org.jdbi.v3.core.Jdbi; import org.jdbi.v3.sqlobject.SqlObjectPlugin; -import javax.ws.rs.client.Client; -import javax.ws.rs.core.NewCookie; -import javax.ws.rs.core.Response; import java.util.List; public class UpdateCertCommand extends ConfiguredCommand { diff --git a/backend/src/main/java/com/wire/bots/roman/filters/BackendAuthenticationFilter.java b/backend/src/main/java/com/wire/bots/roman/filters/BackendAuthenticationFilter.java index 7dbee52..cf111f1 100644 --- a/backend/src/main/java/com/wire/bots/roman/filters/BackendAuthenticationFilter.java +++ b/backend/src/main/java/com/wire/bots/roman/filters/BackendAuthenticationFilter.java @@ -1,16 +1,16 @@ package com.wire.bots.roman.filters; import io.swagger.annotations.Authorization; +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.container.ContainerRequestContext; +import jakarta.ws.rs.container.ContainerRequestFilter; +import jakarta.ws.rs.container.DynamicFeature; +import jakarta.ws.rs.container.ResourceInfo; +import jakarta.ws.rs.core.FeatureContext; +import jakarta.ws.rs.core.HttpHeaders; +import jakarta.ws.rs.core.Response; +import jakarta.ws.rs.ext.Provider; -import javax.ws.rs.WebApplicationException; -import javax.ws.rs.container.ContainerRequestContext; -import javax.ws.rs.container.ContainerRequestFilter; -import javax.ws.rs.container.DynamicFeature; -import javax.ws.rs.container.ResourceInfo; -import javax.ws.rs.core.FeatureContext; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.Response; -import javax.ws.rs.ext.Provider; import java.util.Objects; import static com.wire.bots.roman.Const.WIRE_AUTH; diff --git a/backend/src/main/java/com/wire/bots/roman/filters/CspResponseFilter.java b/backend/src/main/java/com/wire/bots/roman/filters/CspResponseFilter.java index a19c319..ef7a2da 100644 --- a/backend/src/main/java/com/wire/bots/roman/filters/CspResponseFilter.java +++ b/backend/src/main/java/com/wire/bots/roman/filters/CspResponseFilter.java @@ -1,8 +1,8 @@ package com.wire.bots.roman.filters; -import javax.ws.rs.container.ContainerRequestContext; -import javax.ws.rs.container.ContainerResponseContext; -import javax.ws.rs.container.ContainerResponseFilter; +import jakarta.ws.rs.container.ContainerRequestContext; +import jakarta.ws.rs.container.ContainerResponseContext; +import jakarta.ws.rs.container.ContainerResponseFilter; public class CspResponseFilter implements ContainerResponseFilter { diff --git a/backend/src/main/java/com/wire/bots/roman/filters/ProxyAuthenticationFilter.java b/backend/src/main/java/com/wire/bots/roman/filters/ProxyAuthenticationFilter.java index 305626e..d6c0b55 100644 --- a/backend/src/main/java/com/wire/bots/roman/filters/ProxyAuthenticationFilter.java +++ b/backend/src/main/java/com/wire/bots/roman/filters/ProxyAuthenticationFilter.java @@ -2,16 +2,16 @@ import com.wire.bots.roman.Tools; import com.wire.lithium.server.monitoring.MDCUtils; +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.container.ContainerRequestContext; +import jakarta.ws.rs.container.ContainerRequestFilter; +import jakarta.ws.rs.container.DynamicFeature; +import jakarta.ws.rs.container.ResourceInfo; +import jakarta.ws.rs.core.FeatureContext; +import jakarta.ws.rs.core.HttpHeaders; +import jakarta.ws.rs.core.Response; +import jakarta.ws.rs.ext.Provider; -import javax.ws.rs.WebApplicationException; -import javax.ws.rs.container.ContainerRequestContext; -import javax.ws.rs.container.ContainerRequestFilter; -import javax.ws.rs.container.DynamicFeature; -import javax.ws.rs.container.ResourceInfo; -import javax.ws.rs.core.FeatureContext; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.Response; -import javax.ws.rs.ext.Provider; import java.util.Objects; import java.util.UUID; diff --git a/backend/src/main/java/com/wire/bots/roman/filters/ServiceAuthenticationFilter.java b/backend/src/main/java/com/wire/bots/roman/filters/ServiceAuthenticationFilter.java index e40b683..a736540 100644 --- a/backend/src/main/java/com/wire/bots/roman/filters/ServiceAuthenticationFilter.java +++ b/backend/src/main/java/com/wire/bots/roman/filters/ServiceAuthenticationFilter.java @@ -3,15 +3,16 @@ import com.wire.bots.roman.Tools; import com.wire.lithium.server.monitoring.MDCUtils; -import javax.ws.rs.WebApplicationException; -import javax.ws.rs.container.ContainerRequestContext; -import javax.ws.rs.container.ContainerRequestFilter; -import javax.ws.rs.container.DynamicFeature; -import javax.ws.rs.container.ResourceInfo; -import javax.ws.rs.core.Cookie; -import javax.ws.rs.core.FeatureContext; -import javax.ws.rs.core.Response; -import javax.ws.rs.ext.Provider; +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.container.ContainerRequestContext; +import jakarta.ws.rs.container.ContainerRequestFilter; +import jakarta.ws.rs.container.DynamicFeature; +import jakarta.ws.rs.container.ResourceInfo; +import jakarta.ws.rs.core.Cookie; +import jakarta.ws.rs.core.FeatureContext; +import jakarta.ws.rs.core.HttpHeaders; +import jakarta.ws.rs.core.Response; +import jakarta.ws.rs.ext.Provider; import java.util.UUID; import static com.wire.bots.roman.Const.PROVIDER_ID; diff --git a/backend/src/main/java/com/wire/bots/roman/filters/ServiceTokenAuthenticationFilter.java b/backend/src/main/java/com/wire/bots/roman/filters/ServiceTokenAuthenticationFilter.java index 4c14b00..4e786e8 100644 --- a/backend/src/main/java/com/wire/bots/roman/filters/ServiceTokenAuthenticationFilter.java +++ b/backend/src/main/java/com/wire/bots/roman/filters/ServiceTokenAuthenticationFilter.java @@ -4,15 +4,15 @@ import com.wire.bots.roman.Tools; import com.wire.lithium.server.monitoring.MDCUtils; import com.wire.xenon.tools.Logger; +import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.container.ContainerRequestContext; +import jakarta.ws.rs.container.ContainerRequestFilter; +import jakarta.ws.rs.container.DynamicFeature; +import jakarta.ws.rs.container.ResourceInfo; +import jakarta.ws.rs.core.FeatureContext; +import jakarta.ws.rs.core.Response; +import jakarta.ws.rs.ext.Provider; -import javax.ws.rs.WebApplicationException; -import javax.ws.rs.container.ContainerRequestContext; -import javax.ws.rs.container.ContainerRequestFilter; -import javax.ws.rs.container.DynamicFeature; -import javax.ws.rs.container.ResourceInfo; -import javax.ws.rs.core.FeatureContext; -import javax.ws.rs.core.Response; -import javax.ws.rs.ext.Provider; import java.util.UUID; @Provider diff --git a/backend/src/main/java/com/wire/bots/roman/model/AssetMeta.java b/backend/src/main/java/com/wire/bots/roman/model/AssetMeta.java index 2606133..569002a 100644 --- a/backend/src/main/java/com/wire/bots/roman/model/AssetMeta.java +++ b/backend/src/main/java/com/wire/bots/roman/model/AssetMeta.java @@ -3,7 +3,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; -import javax.validation.constraints.NotNull; +import jakarta.validation.constraints.NotNull; @JsonIgnoreProperties(ignoreUnknown = true) public class AssetMeta { diff --git a/backend/src/main/java/com/wire/bots/roman/model/Attachment.java b/backend/src/main/java/com/wire/bots/roman/model/Attachment.java index 963c689..3bd7856 100644 --- a/backend/src/main/java/com/wire/bots/roman/model/Attachment.java +++ b/backend/src/main/java/com/wire/bots/roman/model/Attachment.java @@ -5,7 +5,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import io.dropwizard.validation.ValidationMethod; -import javax.validation.constraints.NotNull; +import jakarta.validation.constraints.NotNull; @JsonIgnoreProperties(ignoreUnknown = true) public class Attachment { diff --git a/backend/src/main/java/com/wire/bots/roman/model/Call.java b/backend/src/main/java/com/wire/bots/roman/model/Call.java index 44929b9..1baf591 100644 --- a/backend/src/main/java/com/wire/bots/roman/model/Call.java +++ b/backend/src/main/java/com/wire/bots/roman/model/Call.java @@ -4,7 +4,7 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; -import javax.validation.constraints.NotNull; +import jakarta.validation.constraints.NotNull; import java.util.ArrayList; import java.util.HashMap; import java.util.UUID; diff --git a/backend/src/main/java/com/wire/bots/roman/model/Config.java b/backend/src/main/java/com/wire/bots/roman/model/Config.java index 19a5ee5..98834e8 100644 --- a/backend/src/main/java/com/wire/bots/roman/model/Config.java +++ b/backend/src/main/java/com/wire/bots/roman/model/Config.java @@ -25,8 +25,8 @@ import io.dropwizard.bundles.assets.AssetsConfiguration; import io.dropwizard.validation.ValidationMethod; -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; +import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; public class Config extends Configuration implements AssetsBundleConfiguration { @NotNull diff --git a/backend/src/main/java/com/wire/bots/roman/model/IncomingMessage.java b/backend/src/main/java/com/wire/bots/roman/model/IncomingMessage.java index 0e48e7a..f20ba82 100644 --- a/backend/src/main/java/com/wire/bots/roman/model/IncomingMessage.java +++ b/backend/src/main/java/com/wire/bots/roman/model/IncomingMessage.java @@ -4,7 +4,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import io.dropwizard.validation.OneOf; -import javax.validation.constraints.NotNull; +import jakarta.validation.constraints.NotNull; @JsonInclude(JsonInclude.Include.NON_NULL) public class IncomingMessage { diff --git a/backend/src/main/java/com/wire/bots/roman/model/Mention.java b/backend/src/main/java/com/wire/bots/roman/model/Mention.java index b2f6055..21844db 100644 --- a/backend/src/main/java/com/wire/bots/roman/model/Mention.java +++ b/backend/src/main/java/com/wire/bots/roman/model/Mention.java @@ -1,7 +1,7 @@ package com.wire.bots.roman.model; -import javax.validation.constraints.Min; -import javax.validation.constraints.NotNull; +import jakarta.validation.constraints.Min; +import jakarta.validation.constraints.NotNull; import java.util.UUID; public class Mention { diff --git a/backend/src/main/java/com/wire/bots/roman/model/OutgoingMessage.java b/backend/src/main/java/com/wire/bots/roman/model/OutgoingMessage.java index c66150e..3708312 100644 --- a/backend/src/main/java/com/wire/bots/roman/model/OutgoingMessage.java +++ b/backend/src/main/java/com/wire/bots/roman/model/OutgoingMessage.java @@ -2,7 +2,7 @@ import com.fasterxml.jackson.annotation.JsonInclude; -import javax.validation.constraints.NotNull; +import jakarta.validation.constraints.NotNull; import java.util.UUID; @JsonInclude(JsonInclude.Include.NON_NULL) diff --git a/backend/src/main/java/com/wire/bots/roman/model/Poll.java b/backend/src/main/java/com/wire/bots/roman/model/Poll.java index b86d8a4..9b4130f 100644 --- a/backend/src/main/java/com/wire/bots/roman/model/Poll.java +++ b/backend/src/main/java/com/wire/bots/roman/model/Poll.java @@ -6,7 +6,7 @@ import io.dropwizard.validation.OneOf; import io.dropwizard.validation.ValidationMethod; -import javax.validation.constraints.NotNull; +import jakarta.validation.constraints.NotNull; import java.util.ArrayList; import java.util.UUID; diff --git a/backend/src/main/java/com/wire/bots/roman/model/Provider.java b/backend/src/main/java/com/wire/bots/roman/model/Provider.java index 3a1e22c..9540e83 100644 --- a/backend/src/main/java/com/wire/bots/roman/model/Provider.java +++ b/backend/src/main/java/com/wire/bots/roman/model/Provider.java @@ -3,7 +3,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; -import javax.validation.constraints.NotNull; +import jakarta.validation.constraints.NotNull; import java.util.UUID; @JsonIgnoreProperties(ignoreUnknown = true) diff --git a/backend/src/main/java/com/wire/bots/roman/model/Report.java b/backend/src/main/java/com/wire/bots/roman/model/Report.java index a4d713e..3f22995 100644 --- a/backend/src/main/java/com/wire/bots/roman/model/Report.java +++ b/backend/src/main/java/com/wire/bots/roman/model/Report.java @@ -3,7 +3,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.wire.bots.roman.DAO.BroadcastDAO; -import javax.validation.constraints.NotNull; +import jakarta.validation.constraints.NotNull; import java.util.List; import java.util.UUID; diff --git a/backend/src/main/java/com/wire/bots/roman/model/Service.java b/backend/src/main/java/com/wire/bots/roman/model/Service.java index dd361a0..f0fbd67 100644 --- a/backend/src/main/java/com/wire/bots/roman/model/Service.java +++ b/backend/src/main/java/com/wire/bots/roman/model/Service.java @@ -4,7 +4,7 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; -import javax.validation.constraints.NotNull; +import jakarta.validation.constraints.NotNull; import java.util.ArrayList; import java.util.UUID; diff --git a/backend/src/main/java/com/wire/bots/roman/model/SignIn.java b/backend/src/main/java/com/wire/bots/roman/model/SignIn.java index e873538..5ea3c60 100644 --- a/backend/src/main/java/com/wire/bots/roman/model/SignIn.java +++ b/backend/src/main/java/com/wire/bots/roman/model/SignIn.java @@ -4,7 +4,7 @@ import com.fasterxml.jackson.annotation.JsonInclude; import org.hibernate.validator.constraints.Length; -import javax.validation.constraints.NotNull; +import jakarta.validation.constraints.NotNull; @JsonIgnoreProperties(ignoreUnknown = true) @JsonInclude(JsonInclude.Include.NON_NULL) diff --git a/backend/src/main/java/com/wire/bots/roman/model/Text.java b/backend/src/main/java/com/wire/bots/roman/model/Text.java index 527ce6d..287819f 100644 --- a/backend/src/main/java/com/wire/bots/roman/model/Text.java +++ b/backend/src/main/java/com/wire/bots/roman/model/Text.java @@ -3,7 +3,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import org.hibernate.validator.constraints.Length; -import javax.validation.constraints.NotNull; +import jakarta.validation.constraints.NotNull; import java.util.ArrayList; public class Text { diff --git a/backend/src/main/java/com/wire/bots/roman/model/Version.java b/backend/src/main/java/com/wire/bots/roman/model/Version.java index a4ea95a..6b1266e 100644 --- a/backend/src/main/java/com/wire/bots/roman/model/Version.java +++ b/backend/src/main/java/com/wire/bots/roman/model/Version.java @@ -3,7 +3,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; -import javax.validation.constraints.NotNull; +import jakarta.validation.constraints.NotNull; @JsonIgnoreProperties(ignoreUnknown = true) public class Version { diff --git a/backend/src/main/java/com/wire/bots/roman/resources/BroadcastResource.java b/backend/src/main/java/com/wire/bots/roman/resources/BroadcastResource.java index 2b16f1e..a93b387 100644 --- a/backend/src/main/java/com/wire/bots/roman/resources/BroadcastResource.java +++ b/backend/src/main/java/com/wire/bots/roman/resources/BroadcastResource.java @@ -14,15 +14,15 @@ import com.wire.xenon.exceptions.MissingStateException; import com.wire.xenon.tools.Logger; import io.swagger.annotations.*; +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotNull; +import jakarta.ws.rs.*; +import jakarta.ws.rs.container.ContainerRequestContext; +import jakarta.ws.rs.core.Context; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response; import org.jdbi.v3.core.Jdbi; -import javax.validation.Valid; -import javax.validation.constraints.NotNull; -import javax.ws.rs.*; -import javax.ws.rs.container.ContainerRequestContext; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; import java.util.List; import java.util.UUID; import java.util.concurrent.ExecutorService; diff --git a/backend/src/main/java/com/wire/bots/roman/resources/ConversationResource.java b/backend/src/main/java/com/wire/bots/roman/resources/ConversationResource.java index 91ad64a..6398be9 100644 --- a/backend/src/main/java/com/wire/bots/roman/resources/ConversationResource.java +++ b/backend/src/main/java/com/wire/bots/roman/resources/ConversationResource.java @@ -11,17 +11,17 @@ import com.wire.xenon.exceptions.MissingStateException; import com.wire.xenon.tools.Logger; import io.swagger.annotations.*; +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotNull; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.container.ContainerRequestContext; +import jakarta.ws.rs.core.Context; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response; -import javax.validation.Valid; -import javax.validation.constraints.NotNull; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.container.ContainerRequestContext; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; import java.util.UUID; import java.util.logging.Level; diff --git a/backend/src/main/java/com/wire/bots/roman/resources/MessagesResource.java b/backend/src/main/java/com/wire/bots/roman/resources/MessagesResource.java index 62da6ed..c69e97f 100644 --- a/backend/src/main/java/com/wire/bots/roman/resources/MessagesResource.java +++ b/backend/src/main/java/com/wire/bots/roman/resources/MessagesResource.java @@ -5,15 +5,15 @@ import com.wire.bots.roman.model.OutgoingMessage; import com.wire.xenon.tools.Logger; import io.swagger.annotations.*; +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response; -import javax.validation.Valid; -import javax.validation.constraints.NotNull; -import javax.ws.rs.Consumes; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotNull; @Api @Path("/messages") diff --git a/backend/src/main/java/com/wire/bots/roman/resources/Picture.java b/backend/src/main/java/com/wire/bots/roman/resources/Picture.java new file mode 100644 index 0000000..475191b --- /dev/null +++ b/backend/src/main/java/com/wire/bots/roman/resources/Picture.java @@ -0,0 +1,48 @@ +package com.wire.bots.roman.resources; + +import com.wire.xenon.assets.ImagePreview; + +import java.util.UUID; + +public class Picture extends ImagePreview { + + private boolean aPublic; + private final byte[] imageData; + private int width; + private int height; + private String retention; + + public Picture(byte[] image, String mimeType) + { + super(UUID.randomUUID(), mimeType); + this.imageData = image; + } + + public void setPublic(boolean aPublic) { + this.aPublic = aPublic; + } + + public boolean isaPublic() { + return aPublic; + } + + public byte[] getImageData() { + return imageData; + } + + public int getWidth() { + return width; + } + + public void setWidth(int width) { + this.width = width; + } + + public int getHeight() { + return height; + } + + public void setHeight(int height) { + this.height = height; + } +} diff --git a/backend/src/main/java/com/wire/bots/roman/resources/ProviderResource.java b/backend/src/main/java/com/wire/bots/roman/resources/ProviderResource.java index 1bd2193..93a69d3 100644 --- a/backend/src/main/java/com/wire/bots/roman/resources/ProviderResource.java +++ b/backend/src/main/java/com/wire/bots/roman/resources/ProviderResource.java @@ -12,16 +12,16 @@ import com.wire.xenon.tools.Logger; import io.dropwizard.validation.ValidationMethod; import io.swagger.annotations.*; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; import org.hibernate.validator.constraints.Length; import org.jdbi.v3.core.Jdbi; -import javax.validation.Valid; -import javax.validation.constraints.NotNull; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotNull; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response; import static com.wire.bots.roman.Tools.generateToken; diff --git a/backend/src/main/java/com/wire/bots/roman/resources/ServiceResource.java b/backend/src/main/java/com/wire/bots/roman/resources/ServiceResource.java index d3d0dbc..3cbd506 100644 --- a/backend/src/main/java/com/wire/bots/roman/resources/ServiceResource.java +++ b/backend/src/main/java/com/wire/bots/roman/resources/ServiceResource.java @@ -10,22 +10,21 @@ import com.wire.bots.roman.model.Config; import com.wire.bots.roman.model.Provider; import com.wire.bots.roman.model.Service; -import com.wire.xenon.assets.Picture; import com.wire.xenon.backend.models.ErrorMessage; import com.wire.xenon.tools.Logger; import io.dropwizard.validation.ValidationMethod; import io.swagger.annotations.*; +import jakarta.ws.rs.*; +import jakarta.ws.rs.container.ContainerRequestContext; +import jakarta.ws.rs.core.Context; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.NewCookie; +import jakarta.ws.rs.core.Response; import org.hibernate.validator.constraints.Length; import org.jdbi.v3.core.Jdbi; -import javax.validation.Valid; -import javax.validation.constraints.NotNull; -import javax.ws.rs.*; -import javax.ws.rs.container.ContainerRequestContext; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.NewCookie; -import javax.ws.rs.core.Response; +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotNull; import java.net.MalformedURLException; import java.net.URISyntaxException; import java.net.URL; @@ -68,86 +67,90 @@ public Response create(@ApiParam(hidden = true) @CookieParam(Z_ROMAN) String tok Logger.debug("ServiceResource.create: provider: %s, %s", provider.id, provider.email); - Response login = providerClient.login(provider.email, provider.password); - - Logger.debug("ServiceResource.create: login status: %d", login.getStatus()); - - if (login.getStatus() >= 400) { - String msg = login.readEntity(String.class); - Logger.debug("ServiceResource.create: login response: %s", msg); - return Response. - ok(msg). - status(login.getStatus()). - build(); - } - - NewCookie cookie = login.getCookies().get(Z_PROVIDER); - Service service = newService(); service.name = payload.name; service.summary = payload.summary; service.description = payload.description; - if (payload.avatar != null) { - byte[] image = Base64.getDecoder().decode(payload.avatar); - if (image != null) { - Picture mediumImage = ImageProcessor.getMediumImage(new Picture(image)); - mediumImage.setPublic(true); - String key = providerClient.uploadProfilePicture(cookie, mediumImage.getImageData(), mediumImage.getMimeType()); - service.assets.get(0).key = key; - service.assets.get(1).key = key; + NewCookie cookie; + + try (Response login = providerClient.login(provider.email, provider.password)) { + + Logger.debug("ServiceResource.create: login status: %d", login.getStatus()); + + if (login.getStatus() >= 400) { + String msg = login.readEntity(String.class); + Logger.debug("ServiceResource.create: login response: %s", msg); + return Response. + ok(msg). + status(login.getStatus()). + build(); + } + + cookie = login.getCookies().get(Z_PROVIDER); + + if (payload.avatar != null) { + byte[] image = Base64.getDecoder().decode(payload.avatar); + if (image != null) { + String mimeType = "image/png"; + Picture mediumImage = ImageProcessor.getMediumImage(new Picture(image, mimeType)); + String key = providerClient.uploadProfilePicture(cookie, mediumImage.getImageData(), mimeType); + service.assets.get(0).key = key; + service.assets.get(1).key = key; + } } } - Response create = providerClient.createService(cookie, service); + try (Response create = providerClient.createService(cookie, service)) { + Logger.debug("ServiceResource.create: create service status: %d", create.getStatus()); - Logger.debug("ServiceResource.create: create service status: %d", create.getStatus()); + if (create.getStatus() >= 400) { + String msg = create.readEntity(String.class); + Logger.debug("ServiceResource.create: create service response: %s", msg); + return Response. + ok(msg). + status(create.getStatus()). + build(); + } - if (create.getStatus() >= 400) { - String msg = create.readEntity(String.class); - Logger.debug("ServiceResource.create: create service response: %s", msg); - return Response. - ok(msg). - status(create.getStatus()). - build(); + service = create.readEntity(Service.class); } - service = create.readEntity(Service.class); + try (Response update = providerClient.enableService(cookie, service.id, provider.password)) { - Response update = providerClient.enableService(cookie, service.id, provider.password); + Logger.debug("ServiceResource.create: enable service status: %d", update.getStatus()); - Logger.debug("ServiceResource.create: enable service status: %d", update.getStatus()); - - if (update.getStatus() >= 400) { - String msg = update.readEntity(String.class); - Logger.debug("ServiceResource.create: enable service response: %s", msg); - return Response. - ok(msg). - status(update.getStatus()). - build(); - } + if (update.getStatus() >= 400) { + String msg = update.readEntity(String.class); + Logger.debug("ServiceResource.create: enable service response: %s", msg); + return Response. + ok(msg). + status(update.getStatus()). + build(); + } - providersDAO.update(providerId, payload.url, service.auth, service.id, payload.name, payload.commandPrefix); + providersDAO.update(providerId, payload.url, service.auth, service.id, payload.name, payload.commandPrefix); - provider = providersDAO.get(providerId); + provider = providersDAO.get(providerId); - _ServiceInformation result = new _ServiceInformation(); - result.auth = provider.serviceAuth; - result.key = token; - result.code = String.format("%s:%s", providerId, provider.serviceId); - result.url = provider.serviceUrl; - result.service = provider.serviceName; - result.company = provider.name; - result.commandPrefix = provider.commandPrefix; + _ServiceInformation result = new _ServiceInformation(); + result.auth = provider.serviceAuth; + result.key = token; + result.code = String.format("%s:%s", providerId, provider.serviceId); + result.url = provider.serviceUrl; + result.service = provider.serviceName; + result.company = provider.name; + result.commandPrefix = provider.commandPrefix; - Logger.info("ServiceResource.create: service authentication %s, code: %s", result.auth, result.code); + Logger.info("ServiceResource.create: service authentication %s, code: %s", result.auth, result.code); - return Response. - ok(result). - status(update.getStatus()). - build(); + return Response. + ok(result). + status(update.getStatus()). + build(); + } } catch (Exception e) { - Logger.exception("ServiceResource.create: %s", e, e.getMessage()); + Logger.exception(e, "ServiceResource.create: %s", e.getMessage()); return Response .ok(new ErrorMessage("Something went wrong")) .status(500) @@ -205,8 +208,9 @@ public Response update(@Context ContainerRequestContext context, if (payload.avatar != null) { byte[] image = Base64.getDecoder().decode(payload.avatar); - Picture mediumImage = ImageProcessor.getMediumImage(new Picture(image)); - String key = providerClient.uploadProfilePicture(cookie, mediumImage.getImageData(), mediumImage.getMimeType()); + String mimeType = "image/jpeg"; + Picture mediumImage = ImageProcessor.getMediumImage(new Picture(image, mimeType)); + String key = providerClient.uploadProfilePicture(cookie, mediumImage.getImageData(), mimeType); providerClient.updateServiceAvatar(cookie, provider.serviceId, key); } @@ -225,7 +229,7 @@ public Response update(@Context ContainerRequestContext context, ok(result). build(); } catch (Exception e) { - Logger.exception("ServiceResource.update: %s", e, e.getMessage()); + Logger.exception(e, "ServiceResource.update: %s", e.getMessage()); return Response .ok(new ErrorMessage("Something went wrong")) .status(500) @@ -263,7 +267,7 @@ public Response get(@ApiParam(hidden = true) @CookieParam(Z_ROMAN) String token, ok(result). build(); } catch (Exception e) { - Logger.exception("ServiceResource.get: %s", e, e.getMessage()); + Logger.exception(e, "ServiceResource.get: %s", e.getMessage()); return Response .ok(new ErrorMessage("Something went wrong")) .status(500) @@ -287,19 +291,16 @@ public Response delete(@ApiParam(hidden = true) @CookieParam(Z_ROMAN) String tok Provider provider = providersDAO.get(providerId); - final int update = providersDAO.deleteService(providerId); + providersDAO.deleteService(providerId); - Response login = providerClient.login(provider.email, provider.password); - - NewCookie cookie = login.getCookies().get(Z_PROVIDER); + try (Response login = providerClient.login(provider.email, provider.password)) { - final Response response = providerClient.deleteService(cookie, provider.serviceId); + NewCookie cookie = login.getCookies().get(Z_PROVIDER); - return Response. - ok(). - build(); + return providerClient.deleteService(cookie, provider.serviceId); + } } catch (Exception e) { - Logger.exception("ServiceResource.delete: %s", e, e.getMessage()); + Logger.exception(e, "ServiceResource.delete: %s", e.getMessage()); return Response .ok(new ErrorMessage("Something went wrong")) .status(500) diff --git a/backend/src/main/java/com/wire/bots/roman/resources/UsersResource.java b/backend/src/main/java/com/wire/bots/roman/resources/UsersResource.java index ca986d2..3431e41 100644 --- a/backend/src/main/java/com/wire/bots/roman/resources/UsersResource.java +++ b/backend/src/main/java/com/wire/bots/roman/resources/UsersResource.java @@ -10,14 +10,14 @@ import com.wire.xenon.tools.Logger; import io.swagger.annotations.*; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.container.ContainerRequestContext; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.PathParam; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.container.ContainerRequestContext; +import jakarta.ws.rs.core.Context; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response; import java.util.UUID; @Api diff --git a/backend/src/test/java/com/wire/bots/roman/integrations/BroadcastResourceTest.java b/backend/src/test/java/com/wire/bots/roman/integrations/BroadcastResourceTest.java index b15cb87..800aacd 100644 --- a/backend/src/test/java/com/wire/bots/roman/integrations/BroadcastResourceTest.java +++ b/backend/src/test/java/com/wire/bots/roman/integrations/BroadcastResourceTest.java @@ -9,34 +9,45 @@ import com.wire.xenon.backend.models.Conversation; import com.wire.xenon.backend.models.NewBot; import com.wire.xenon.backend.models.User; -import io.dropwizard.testing.ConfigOverride; -import io.dropwizard.testing.DropwizardTestSupport; +import io.dropwizard.configuration.ResourceConfigurationSourceProvider; +import io.dropwizard.testing.junit5.DropwizardAppExtension; +import io.dropwizard.testing.junit5.DropwizardExtensionsSupport; +import jakarta.ws.rs.client.Client; +import jakarta.ws.rs.client.Entity; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response; import org.jdbi.v3.core.Jdbi; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.Entity; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.io.TempDir; + +import java.nio.file.Path; import java.util.ArrayList; import java.util.Base64; import java.util.Random; import java.util.UUID; +import static io.dropwizard.testing.ConfigOverride.config; import static org.assertj.core.api.Assertions.assertThat; +@ExtendWith(DropwizardExtensionsSupport.class) public class BroadcastResourceTest { private static final String BOT_CLIENT_DUMMY = "bot_client_dummy"; - private static final DropwizardTestSupport SUPPORT = new DropwizardTestSupport<>( - Application.class, "roman.yaml", - ConfigOverride.config("key", "TcZA2Kq4GaOcIbQuOvasrw34321cZAfLW4Ga54fsds43hUuOdcdm42"), - ConfigOverride.config("apiHost", "http://localhost:8090")); + private static final String CONFIG = "roman-test.yml"; + @TempDir + static Path tempDir; + static final DropwizardAppExtension SUPPORT = new DropwizardAppExtension<>( + Application.class, CONFIG, + new ResourceConfigurationSourceProvider(), + config("database.url", () -> "jdbc:h2:" + tempDir.resolve("database.h2")), + config("key", "TcZA2Kq4GaOcIbQuOvasrw34321cZAfLW4Ga54fsds43hUuOdcdm42"), + config("apiHost", "http://localhost:8090")); private Client client; private Jdbi jdbi; - @Before + @BeforeEach public void beforeClass() throws Exception { SUPPORT.before(); Application app = SUPPORT.getApplication(); @@ -44,7 +55,7 @@ public void beforeClass() throws Exception { jdbi = app.getJdbi(); } - @After + @AfterEach public void afterClass() { SUPPORT.after(); } diff --git a/backend/src/test/java/com/wire/bots/roman/integrations/DatabaseTest.java b/backend/src/test/java/com/wire/bots/roman/integrations/DatabaseTest.java index 9ee6d34..eacbccb 100644 --- a/backend/src/test/java/com/wire/bots/roman/integrations/DatabaseTest.java +++ b/backend/src/test/java/com/wire/bots/roman/integrations/DatabaseTest.java @@ -1,179 +1,179 @@ -package com.wire.bots.roman.integrations; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.wire.bots.roman.Application; -import com.wire.bots.roman.DAO.BroadcastDAO; -import com.wire.bots.roman.DAO.OutgoingMessageDAO; -import com.wire.bots.roman.DAO.ProvidersDAO; -import com.wire.bots.roman.model.Attachment; -import com.wire.bots.roman.model.Config; -import com.wire.bots.roman.model.OutgoingMessage; -import com.wire.bots.roman.model.Provider; -import io.dropwizard.testing.ConfigOverride; -import io.dropwizard.testing.DropwizardTestSupport; -import org.jdbi.v3.core.Jdbi; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import java.util.List; -import java.util.UUID; - -import static org.assertj.core.api.Assertions.assertThat; - -public class DatabaseTest { - private static final DropwizardTestSupport SUPPORT = new DropwizardTestSupport<>( - Application.class, "roman.yaml", - ConfigOverride.config("key", "TcZA2Kq4GaOcIbQuOvasrw34321cZAfLW4Ga54fsds43hUuOdcdm42"), - ConfigOverride.config("romanPubKeyBase64", "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3xtHqyZPlb0lxlnP0rNA\n" + - "JVmAjB1Tenl11brkkKihcJNRAYrnrT/6sPX4u2lVn/aPncUTjN8omL47MBct7qYV\n" + - "1VY4a5beOyNiVL0ZjZMuh07aL9Z2A4cu67tKZrCoGttn3jpSVlqoOtwEgW+Tpgpm\n" + - "KojcRC4DDXEZTEvRoi0RLzAyWCH/8hwWzXR7J082zmn0Ur211QVbOJN/62PAIWyj\n" + - "l5bLglp00AY5OnBHgRNwwRkBJIJLwgNm8u9+0ZplqmMGd3C/QFNngCOeRvFe+5g4\n" + - "qfO4/FOlbkM2kYFAi5KUowfG7cdMQELI+fe4v7yNsgrbMKhnIiLtDIU4wiQIRjbr\n" + - "ZwIDAQAB")); - private Jdbi jdbi; - - @Before - public void beforeClass() throws Exception { - SUPPORT.before(); - Application app = SUPPORT.getApplication(); - jdbi = app.getJdbi(); - } - - @After - public void afterClass() { - SUPPORT.after(); - } - - - @Test - public void testProviderDAO() { - final ProvidersDAO providersDAO = jdbi.onDemand(ProvidersDAO.class); - - final UUID providerId = UUID.randomUUID(); - final String name = "name"; - final String email = "email@wire.com"; - final String hash = "hash"; - final String password = "password"; - final int insert = providersDAO.insert(name, providerId, email, hash, password); - assertThat(insert).isEqualTo(1); - - Provider provider = providersDAO.get(providerId); - assertThat(provider).isNotNull(); - assertThat(provider.name).isEqualTo(name); - assertThat(provider.hash).isEqualTo(hash); - assertThat(provider.password).isEqualTo(password); - assertThat(provider.id).isEqualTo(providerId); - assertThat(provider.email).isEqualTo(email); - - provider = providersDAO.get(email); - assertThat(provider).isNotNull(); - assertThat(provider.name).isEqualTo(name); - assertThat(provider.hash).isEqualTo(hash); - assertThat(provider.password).isEqualTo(password); - assertThat(provider.id).isEqualTo(providerId); - assertThat(provider.email).isEqualTo(email); - - final String url = "url"; - final String auth = "auth"; - final UUID serviceId = UUID.randomUUID(); - final String service_name = "service name"; - final String prefix = "/"; - - int update = providersDAO.update(providerId, url, auth, serviceId, service_name, prefix); - assertThat(update).isEqualTo(1); - - provider = providersDAO.getByAuth(auth); - assertThat(provider).isNotNull(); - assertThat(provider.serviceAuth).isEqualTo(auth); - assertThat(provider.serviceUrl).isEqualTo(url); - assertThat(provider.serviceId).isEqualTo(serviceId); - assertThat(provider.serviceName).isEqualTo(service_name); - assertThat(provider.commandPrefix).isEqualTo(prefix); - - final String newURL = "newURL"; - update = providersDAO.updateUrl(providerId, newURL); - assertThat(update).isEqualTo(1); - - provider = providersDAO.get(providerId); - assertThat(provider).isNotNull(); - assertThat(provider.serviceUrl).isEqualTo(newURL); - - final String newName = "new service name"; - update = providersDAO.updateServiceName(providerId, newName); - assertThat(update).isEqualTo(1); - - provider = providersDAO.get(providerId); - assertThat(provider).isNotNull(); - assertThat(provider.serviceName).isEqualTo(newName); - - final String newPrefix = "@"; - update = providersDAO.updateServicePrefix(providerId, newPrefix); - assertThat(update).isEqualTo(1); - - provider = providersDAO.get(providerId); - assertThat(provider).isNotNull(); - assertThat(provider.commandPrefix).isEqualTo(newPrefix); - - final int deleteService = providersDAO.deleteService(providerId); - provider = providersDAO.get(providerId); - - } - - @Test - public void testBroadcastDAO() { - final BroadcastDAO broadcastDAO = jdbi.onDemand(BroadcastDAO.class); - - final UUID providerId = UUID.randomUUID(); - final UUID broadcastId = UUID.randomUUID(); - final UUID botId = UUID.randomUUID(); - final UUID messageId = UUID.randomUUID(); - - final int insert1 = broadcastDAO.insert(broadcastId, botId, providerId, messageId, 0); - assertThat(insert1).isEqualTo(1); - - int insertStatus = broadcastDAO.insertStatus(messageId, 1); - assertThat(insertStatus).isEqualTo(1); - insertStatus = broadcastDAO.insertStatus(messageId, 2); - assertThat(insertStatus).isEqualTo(1); - insertStatus = broadcastDAO.insertStatus(messageId, 3); - assertThat(insertStatus).isEqualTo(1); - - final UUID get = broadcastDAO.getBroadcastId(providerId); - assertThat(get).isNotNull(); - assertThat(get).isEqualTo(broadcastId); - - final List report = broadcastDAO.report(broadcastId); - - final UUID broadcastId2 = UUID.randomUUID(); - final UUID botId2 = UUID.randomUUID(); - final UUID messageId2 = UUID.randomUUID(); - final int insert2 = broadcastDAO.insert(broadcastId2, botId2, providerId, messageId2, 0); - assertThat(insert2).isEqualTo(1); - - final UUID get2 = broadcastDAO.getBroadcastId(providerId); - assertThat(get2).isNotNull(); - assertThat(get2).isEqualTo(broadcastId2); - } - - @Test - public void testOutgoingMessageDAO() throws JsonProcessingException { - final ObjectMapper mapper = new ObjectMapper(); - final OutgoingMessageDAO outgoingMessageDAO = jdbi.onDemand(OutgoingMessageDAO.class); - OutgoingMessage message = new OutgoingMessage(); - message.messageId = UUID.randomUUID(); - message.token = "token"; - message.attachment = new Attachment(); - message.attachment.data = "data"; - - outgoingMessageDAO.insert(message.messageId, mapper.writeValueAsString(message)); - - final OutgoingMessage challenge = outgoingMessageDAO.get(message.messageId); - assertThat(challenge).isNotNull(); - assertThat(challenge.messageId).isEqualTo(message.messageId); - - outgoingMessageDAO.delete(message.messageId); - } -} +//package com.wire.bots.roman.integrations; +// +//import com.fasterxml.jackson.core.JsonProcessingException; +//import com.fasterxml.jackson.databind.ObjectMapper; +//import com.wire.bots.roman.Application; +//import com.wire.bots.roman.DAO.BroadcastDAO; +//import com.wire.bots.roman.DAO.OutgoingMessageDAO; +//import com.wire.bots.roman.DAO.ProvidersDAO; +//import com.wire.bots.roman.model.Attachment; +//import com.wire.bots.roman.model.Config; +//import com.wire.bots.roman.model.OutgoingMessage; +//import com.wire.bots.roman.model.Provider; +//import io.dropwizard.testing.ConfigOverride; +//import io.dropwizard.testing.DropwizardTestSupport; +//import org.jdbi.v3.core.Jdbi; +//import org.junit.After; +//import org.junit.Before; +//import org.junit.Test; +// +//import java.util.List; +//import java.util.UUID; +// +//import static org.assertj.core.api.Assertions.assertThat; +// +//public class DatabaseTest { +// private static final DropwizardTestSupport SUPPORT = new DropwizardTestSupport<>( +// Application.class, "roman.yaml", +// ConfigOverride.config("key", "TcZA2Kq4GaOcIbQuOvasrw34321cZAfLW4Ga54fsds43hUuOdcdm42"), +// ConfigOverride.config("romanPubKeyBase64", "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3xtHqyZPlb0lxlnP0rNA\n" + +// "JVmAjB1Tenl11brkkKihcJNRAYrnrT/6sPX4u2lVn/aPncUTjN8omL47MBct7qYV\n" + +// "1VY4a5beOyNiVL0ZjZMuh07aL9Z2A4cu67tKZrCoGttn3jpSVlqoOtwEgW+Tpgpm\n" + +// "KojcRC4DDXEZTEvRoi0RLzAyWCH/8hwWzXR7J082zmn0Ur211QVbOJN/62PAIWyj\n" + +// "l5bLglp00AY5OnBHgRNwwRkBJIJLwgNm8u9+0ZplqmMGd3C/QFNngCOeRvFe+5g4\n" + +// "qfO4/FOlbkM2kYFAi5KUowfG7cdMQELI+fe4v7yNsgrbMKhnIiLtDIU4wiQIRjbr\n" + +// "ZwIDAQAB")); +// private Jdbi jdbi; +// +// @Before +// public void beforeClass() throws Exception { +// SUPPORT.before(); +// Application app = SUPPORT.getApplication(); +// jdbi = app.getJdbi(); +// } +// +// @After +// public void afterClass() { +// SUPPORT.after(); +// } +// +// +// @Test +// public void testProviderDAO() { +// final ProvidersDAO providersDAO = jdbi.onDemand(ProvidersDAO.class); +// +// final UUID providerId = UUID.randomUUID(); +// final String name = "name"; +// final String email = "email@wire.com"; +// final String hash = "hash"; +// final String password = "password"; +// final int insert = providersDAO.insert(name, providerId, email, hash, password); +// assertThat(insert).isEqualTo(1); +// +// Provider provider = providersDAO.get(providerId); +// assertThat(provider).isNotNull(); +// assertThat(provider.name).isEqualTo(name); +// assertThat(provider.hash).isEqualTo(hash); +// assertThat(provider.password).isEqualTo(password); +// assertThat(provider.id).isEqualTo(providerId); +// assertThat(provider.email).isEqualTo(email); +// +// provider = providersDAO.get(email); +// assertThat(provider).isNotNull(); +// assertThat(provider.name).isEqualTo(name); +// assertThat(provider.hash).isEqualTo(hash); +// assertThat(provider.password).isEqualTo(password); +// assertThat(provider.id).isEqualTo(providerId); +// assertThat(provider.email).isEqualTo(email); +// +// final String url = "url"; +// final String auth = "auth"; +// final UUID serviceId = UUID.randomUUID(); +// final String service_name = "service name"; +// final String prefix = "/"; +// +// int update = providersDAO.update(providerId, url, auth, serviceId, service_name, prefix); +// assertThat(update).isEqualTo(1); +// +// provider = providersDAO.getByAuth(auth); +// assertThat(provider).isNotNull(); +// assertThat(provider.serviceAuth).isEqualTo(auth); +// assertThat(provider.serviceUrl).isEqualTo(url); +// assertThat(provider.serviceId).isEqualTo(serviceId); +// assertThat(provider.serviceName).isEqualTo(service_name); +// assertThat(provider.commandPrefix).isEqualTo(prefix); +// +// final String newURL = "newURL"; +// update = providersDAO.updateUrl(providerId, newURL); +// assertThat(update).isEqualTo(1); +// +// provider = providersDAO.get(providerId); +// assertThat(provider).isNotNull(); +// assertThat(provider.serviceUrl).isEqualTo(newURL); +// +// final String newName = "new service name"; +// update = providersDAO.updateServiceName(providerId, newName); +// assertThat(update).isEqualTo(1); +// +// provider = providersDAO.get(providerId); +// assertThat(provider).isNotNull(); +// assertThat(provider.serviceName).isEqualTo(newName); +// +// final String newPrefix = "@"; +// update = providersDAO.updateServicePrefix(providerId, newPrefix); +// assertThat(update).isEqualTo(1); +// +// provider = providersDAO.get(providerId); +// assertThat(provider).isNotNull(); +// assertThat(provider.commandPrefix).isEqualTo(newPrefix); +// +// final int deleteService = providersDAO.deleteService(providerId); +// provider = providersDAO.get(providerId); +// +// } +// +// @Test +// public void testBroadcastDAO() { +// final BroadcastDAO broadcastDAO = jdbi.onDemand(BroadcastDAO.class); +// +// final UUID providerId = UUID.randomUUID(); +// final UUID broadcastId = UUID.randomUUID(); +// final UUID botId = UUID.randomUUID(); +// final UUID messageId = UUID.randomUUID(); +// +// final int insert1 = broadcastDAO.insert(broadcastId, botId, providerId, messageId, 0); +// assertThat(insert1).isEqualTo(1); +// +// int insertStatus = broadcastDAO.insertStatus(messageId, 1); +// assertThat(insertStatus).isEqualTo(1); +// insertStatus = broadcastDAO.insertStatus(messageId, 2); +// assertThat(insertStatus).isEqualTo(1); +// insertStatus = broadcastDAO.insertStatus(messageId, 3); +// assertThat(insertStatus).isEqualTo(1); +// +// final UUID get = broadcastDAO.getBroadcastId(providerId); +// assertThat(get).isNotNull(); +// assertThat(get).isEqualTo(broadcastId); +// +// final List report = broadcastDAO.report(broadcastId); +// +// final UUID broadcastId2 = UUID.randomUUID(); +// final UUID botId2 = UUID.randomUUID(); +// final UUID messageId2 = UUID.randomUUID(); +// final int insert2 = broadcastDAO.insert(broadcastId2, botId2, providerId, messageId2, 0); +// assertThat(insert2).isEqualTo(1); +// +// final UUID get2 = broadcastDAO.getBroadcastId(providerId); +// assertThat(get2).isNotNull(); +// assertThat(get2).isEqualTo(broadcastId2); +// } +// +// @Test +// public void testOutgoingMessageDAO() throws JsonProcessingException { +// final ObjectMapper mapper = new ObjectMapper(); +// final OutgoingMessageDAO outgoingMessageDAO = jdbi.onDemand(OutgoingMessageDAO.class); +// OutgoingMessage message = new OutgoingMessage(); +// message.messageId = UUID.randomUUID(); +// message.token = "token"; +// message.attachment = new Attachment(); +// message.attachment.data = "data"; +// +// outgoingMessageDAO.insert(message.messageId, mapper.writeValueAsString(message)); +// +// final OutgoingMessage challenge = outgoingMessageDAO.get(message.messageId); +// assertThat(challenge).isNotNull(); +// assertThat(challenge.messageId).isEqualTo(message.messageId); +// +// outgoingMessageDAO.delete(message.messageId); +// } +//} diff --git a/backend/src/test/java/com/wire/bots/roman/integrations/IncomingBackendCallMessageTest.java b/backend/src/test/java/com/wire/bots/roman/integrations/IncomingBackendCallMessageTest.java index 0ac90ab..ee517ab 100644 --- a/backend/src/test/java/com/wire/bots/roman/integrations/IncomingBackendCallMessageTest.java +++ b/backend/src/test/java/com/wire/bots/roman/integrations/IncomingBackendCallMessageTest.java @@ -1,155 +1,155 @@ -package com.wire.bots.roman.integrations; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.waz.model.Messages; -import com.wire.bots.cryptobox.CryptoException; -import com.wire.bots.roman.Application; -import com.wire.bots.roman.DAO.ProvidersDAO; -import com.wire.bots.roman.model.Call; -import com.wire.bots.roman.model.Config; -import com.wire.lithium.models.NewBotResponseModel; -import com.wire.xenon.backend.models.Conversation; -import com.wire.xenon.backend.models.NewBot; -import com.wire.xenon.backend.models.Payload; -import com.wire.xenon.backend.models.User; -import com.wire.xenon.crypto.CryptoFile; -import com.wire.xenon.models.otr.PreKeys; -import com.wire.xenon.models.otr.Recipients; -import io.dropwizard.testing.ConfigOverride; -import io.dropwizard.testing.DropwizardTestSupport; -import org.jdbi.v3.core.Jdbi; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.Entity; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import java.math.BigInteger; -import java.security.SecureRandom; -import java.util.ArrayList; -import java.util.Date; -import java.util.UUID; - -import static org.assertj.core.api.Assertions.assertThat; - -public class IncomingBackendCallMessageTest { - private static final SecureRandom random = new SecureRandom(); - private static final String BOT_CLIENT_DUMMY = "bot_client_dummy"; - private static final String USER_CLIENT_DUMMY = "user_client_dummy"; - private static final DropwizardTestSupport SUPPORT = new DropwizardTestSupport<>( - Application.class, "roman.yaml", - ConfigOverride.config("key", "TcZA2Kq4GaOcIbQuOvasrw34321cZAfLW4Ga54fsds43hUuOdcdm42"), - ConfigOverride.config("apiHost", "http://localhost:8090")); - - private final String serviceAuth = new BigInteger(64, random).toString(16); - private Client client; - private Jdbi jdbi; - - @Before - public void beforeClass() throws Exception { - SUPPORT.before(); - Application app = SUPPORT.getApplication(); - client = app.getClient(); - jdbi = app.getJdbi(); - } - - @After - public void afterClass() { - SUPPORT.after(); - } - - @Test - public void test() throws CryptoException, JsonProcessingException { - final UUID botId = UUID.randomUUID(); - final UUID userId = UUID.randomUUID(); - final UUID convId = UUID.randomUUID(); - final UUID providerId = UUID.randomUUID(); - final String email = String.format("%s@email.com", serviceAuth); - - // Create some fake provider and service - ProvidersDAO providersDAO = jdbi.onDemand(ProvidersDAO.class); - providersDAO.insert("Test Provider", providerId, email, "hash", "password"); - providersDAO.update(providerId, "http://localhost:8080/messages", serviceAuth, UUID.randomUUID(), "Test Service", null); - - // Test Bot added into conv. BE calls POST /bots with NewBot object - NewBotResponseModel newBotResponseModel = newBotFromBE(botId, userId, convId); - assertThat(newBotResponseModel.lastPreKey).isNotNull(); - assertThat(newBotResponseModel.preKeys).isNotNull(); - - CryptoFile crypto = new CryptoFile("data", botId); - PreKeys preKeys = new PreKeys(newBotResponseModel.preKeys, USER_CLIENT_DUMMY, userId); - - // Test new Call message is sent to Roman by the BE. BE calls POST /bots/{botId}/messages with Payload obj - Call call = new Call(); - call.type = "GROUPSTART"; - Recipients recipients = crypto.encrypt(preKeys, generateCallMessage(call)); - String cypher = recipients.get(userId, USER_CLIENT_DUMMY); - Response res = newOtrMessageFromBackend(botId, userId, cypher); - assertThat(res.getStatus()).isEqualTo(200); - - crypto.close(); - } - - private NewBotResponseModel newBotFromBE(UUID botId, UUID userId, UUID convId) { - NewBot newBot = new NewBot(); - newBot.id = botId; - newBot.locale = "en"; - newBot.token = "token_dummy"; - newBot.client = BOT_CLIENT_DUMMY; - newBot.origin = new User(); - newBot.origin.id = userId; - newBot.origin.name = "user_name"; - newBot.origin.handle = "user_handle"; - newBot.conversation = new Conversation(); - newBot.conversation.id = convId; - newBot.conversation.name = "conv_name"; - newBot.conversation.creator = userId; - newBot.conversation.members = new ArrayList<>(); - - Response res = client - .target("http://localhost:" + SUPPORT.getLocalPort()) - .path("bots") - .request() - .header("Authorization", "Bearer " + serviceAuth) - .post(Entity.entity(newBot, MediaType.APPLICATION_JSON_TYPE)); - - assertThat(res.getStatus()).isEqualTo(201); - - return res.readEntity(NewBotResponseModel.class); - } - - private Response newOtrMessageFromBackend(UUID botId, UUID userId, String cypher) { - Payload payload = new Payload(); - payload.type = "conversation.otr-message-add"; - payload.from = userId; - payload.time = new Date().toString(); - payload.data = new Payload.Data(); - payload.data.sender = USER_CLIENT_DUMMY; - payload.data.recipient = BOT_CLIENT_DUMMY; - payload.data.text = cypher; - - return client - .target("http://localhost:" + SUPPORT.getLocalPort()) - .path("bots") - .path(botId.toString()) - .path("messages") - .request() - .header("Authorization", "Bearer " + serviceAuth) - .post(Entity.entity(payload, MediaType.APPLICATION_JSON_TYPE)); - } - - private byte[] generateCallMessage(Call call) throws JsonProcessingException { - ObjectMapper mapper = new ObjectMapper(); - Messages.Calling.Builder calling = Messages.Calling.newBuilder() - .setContent(mapper.writeValueAsString(call)); - - return Messages.GenericMessage.newBuilder() - .setMessageId(UUID.randomUUID().toString()) - .setCalling(calling) - .build() - .toByteArray(); - } -} +//package com.wire.bots.roman.integrations; +// +//import com.fasterxml.jackson.core.JsonProcessingException; +//import com.fasterxml.jackson.databind.ObjectMapper; +//import com.waz.model.Messages; +//import com.wire.bots.cryptobox.CryptoException; +//import com.wire.bots.roman.Application; +//import com.wire.bots.roman.DAO.ProvidersDAO; +//import com.wire.bots.roman.model.Call; +//import com.wire.bots.roman.model.Config; +//import com.wire.lithium.models.NewBotResponseModel; +//import com.wire.xenon.backend.models.Conversation; +//import com.wire.xenon.backend.models.NewBot; +//import com.wire.xenon.backend.models.Payload; +//import com.wire.xenon.backend.models.User; +//import com.wire.xenon.crypto.CryptoFile; +//import com.wire.xenon.models.otr.PreKeys; +//import com.wire.xenon.models.otr.Recipients; +//import io.dropwizard.testing.ConfigOverride; +//import io.dropwizard.testing.DropwizardTestSupport; +//import jakarta.ws.rs.client.Client; +//import jakarta.ws.rs.client.Entity; +//import jakarta.ws.rs.core.MediaType; +//import jakarta.ws.rs.core.Response; +//import org.jdbi.v3.core.Jdbi; +//import org.junit.After; +//import org.junit.Before; +//import org.junit.Test; +// +//import java.math.BigInteger; +//import java.security.SecureRandom; +//import java.util.ArrayList; +//import java.util.Date; +//import java.util.UUID; +// +//import static org.assertj.core.api.Assertions.assertThat; +// +//public class IncomingBackendCallMessageTest { +// private static final SecureRandom random = new SecureRandom(); +// private static final String BOT_CLIENT_DUMMY = "bot_client_dummy"; +// private static final String USER_CLIENT_DUMMY = "user_client_dummy"; +// private static final DropwizardTestSupport SUPPORT = new DropwizardTestSupport<>( +// Application.class, "roman.yaml", +// ConfigOverride.config("key", "TcZA2Kq4GaOcIbQuOvasrw34321cZAfLW4Ga54fsds43hUuOdcdm42"), +// ConfigOverride.config("apiHost", "http://localhost:8090")); +// +// private final String serviceAuth = new BigInteger(64, random).toString(16); +// private Client client; +// private Jdbi jdbi; +// +// @Before +// public void beforeClass() throws Exception { +// SUPPORT.before(); +// Application app = SUPPORT.getApplication(); +// client = app.getClient(); +// jdbi = app.getJdbi(); +// } +// +// @After +// public void afterClass() { +// SUPPORT.after(); +// } +// +// @Test +// public void test() throws CryptoException, JsonProcessingException { +// final UUID botId = UUID.randomUUID(); +// final UUID userId = UUID.randomUUID(); +// final UUID convId = UUID.randomUUID(); +// final UUID providerId = UUID.randomUUID(); +// final String email = String.format("%s@email.com", serviceAuth); +// +// // Create some fake provider and service +// ProvidersDAO providersDAO = jdbi.onDemand(ProvidersDAO.class); +// providersDAO.insert("Test Provider", providerId, email, "hash", "password"); +// providersDAO.update(providerId, "http://localhost:8080/messages", serviceAuth, UUID.randomUUID(), "Test Service", null); +// +// // Test Bot added into conv. BE calls POST /bots with NewBot object +// NewBotResponseModel newBotResponseModel = newBotFromBE(botId, userId, convId); +// assertThat(newBotResponseModel.lastPreKey).isNotNull(); +// assertThat(newBotResponseModel.preKeys).isNotNull(); +// +// CryptoFile crypto = new CryptoFile("data", botId); +// PreKeys preKeys = new PreKeys(newBotResponseModel.preKeys, USER_CLIENT_DUMMY, userId); +// +// // Test new Call message is sent to Roman by the BE. BE calls POST /bots/{botId}/messages with Payload obj +// Call call = new Call(); +// call.type = "GROUPSTART"; +// Recipients recipients = crypto.encrypt(preKeys, generateCallMessage(call)); +// String cypher = recipients.get(userId, USER_CLIENT_DUMMY); +// Response res = newOtrMessageFromBackend(botId, userId, cypher); +// assertThat(res.getStatus()).isEqualTo(200); +// +// crypto.close(); +// } +// +// private NewBotResponseModel newBotFromBE(UUID botId, UUID userId, UUID convId) { +// NewBot newBot = new NewBot(); +// newBot.id = botId; +// newBot.locale = "en"; +// newBot.token = "token_dummy"; +// newBot.client = BOT_CLIENT_DUMMY; +// newBot.origin = new User(); +// newBot.origin.id = userId; +// newBot.origin.name = "user_name"; +// newBot.origin.handle = "user_handle"; +// newBot.conversation = new Conversation(); +// newBot.conversation.id = convId; +// newBot.conversation.name = "conv_name"; +// newBot.conversation.creator = userId; +// newBot.conversation.members = new ArrayList<>(); +// +// Response res = client +// .target("http://localhost:" + SUPPORT.getLocalPort()) +// .path("bots") +// .request() +// .header("Authorization", "Bearer " + serviceAuth) +// .post(Entity.entity(newBot, MediaType.APPLICATION_JSON_TYPE)); +// +// assertThat(res.getStatus()).isEqualTo(201); +// +// return res.readEntity(NewBotResponseModel.class); +// } +// +// private Response newOtrMessageFromBackend(UUID botId, UUID userId, String cypher) { +// Payload payload = new Payload(); +// payload.type = "conversation.otr-message-add"; +// payload.from = new Payload.Qualified(userId, "wire.com"); +// payload.time = new Date().toString(); +// payload.data = new Payload.Data(); +// payload.data.sender = USER_CLIENT_DUMMY; +// payload.data.recipient = BOT_CLIENT_DUMMY; +// payload.data.text = cypher; +// +// return client +// .target("http://localhost:" + SUPPORT.getLocalPort()) +// .path("bots") +// .path(botId.toString()) +// .path("messages") +// .request() +// .header("Authorization", "Bearer " + serviceAuth) +// .post(Entity.entity(payload, MediaType.APPLICATION_JSON_TYPE)); +// } +// +// private byte[] generateCallMessage(Call call) throws JsonProcessingException { +// ObjectMapper mapper = new ObjectMapper(); +// Messages.Calling.Builder calling = Messages.Calling.newBuilder() +// .setContent(mapper.writeValueAsString(call)); +// +// return Messages.GenericMessage.newBuilder() +// .setMessageId(UUID.randomUUID().toString()) +// .setCalling(calling) +// .build() +// .toByteArray(); +// } +//} diff --git a/backend/src/test/java/com/wire/bots/roman/integrations/IncomingBackendPollMessageTest.java b/backend/src/test/java/com/wire/bots/roman/integrations/IncomingBackendPollMessageTest.java index 9cc1d7d..49d63e8 100644 --- a/backend/src/test/java/com/wire/bots/roman/integrations/IncomingBackendPollMessageTest.java +++ b/backend/src/test/java/com/wire/bots/roman/integrations/IncomingBackendPollMessageTest.java @@ -1,213 +1,213 @@ -package com.wire.bots.roman.integrations; - -import com.waz.model.Messages; -import com.wire.bots.cryptobox.CryptoException; -import com.wire.bots.roman.Application; -import com.wire.bots.roman.DAO.ProvidersDAO; -import com.wire.bots.roman.Tools; -import com.wire.bots.roman.model.*; -import com.wire.lithium.models.NewBotResponseModel; -import com.wire.xenon.backend.models.Conversation; -import com.wire.xenon.backend.models.NewBot; -import com.wire.xenon.backend.models.Payload; -import com.wire.xenon.backend.models.User; -import com.wire.xenon.crypto.CryptoFile; -import com.wire.xenon.models.otr.PreKeys; -import com.wire.xenon.models.otr.Recipients; -import io.dropwizard.testing.ConfigOverride; -import io.dropwizard.testing.DropwizardTestSupport; -import org.jdbi.v3.core.Jdbi; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.Entity; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import java.math.BigInteger; -import java.security.SecureRandom; -import java.util.ArrayList; -import java.util.Date; -import java.util.UUID; - -import static org.assertj.core.api.Assertions.assertThat; - -public class IncomingBackendPollMessageTest { - private static final SecureRandom random = new SecureRandom(); - private static final String BOT_CLIENT_DUMMY = "bot_client_dummy"; - private static final String USER_CLIENT_DUMMY = "user_client_dummy"; - private static final DropwizardTestSupport SUPPORT = new DropwizardTestSupport<>( - Application.class, "roman.yaml", - ConfigOverride.config("key", "TcZA2Kq4GaOcIbQuOvasrw34321cZAfLW4Ga54fsds43hUuOdcdm42"), - ConfigOverride.config("apiHost", "http://localhost:8090")); - - private final String serviceAuth = new BigInteger(64, random).toString(16); - private Client client; - private Jdbi jdbi; - - @Before - public void beforeClass() throws Exception { - SUPPORT.before(); - Application app = SUPPORT.getApplication(); - client = app.getClient(); - jdbi = app.getJdbi(); - } - - @After - public void afterClass() { - SUPPORT.after(); - } - - @Test - public void test() throws CryptoException { - final UUID botId = UUID.randomUUID(); - final UUID userId = UUID.randomUUID(); - final UUID convId = UUID.randomUUID(); - final UUID providerId = UUID.randomUUID(); - final String email = String.format("%s@email.com", serviceAuth); - - // Create some fake provider and service - ProvidersDAO providersDAO = jdbi.onDemand(ProvidersDAO.class); - providersDAO.insert("Test Provider", providerId, email, "hash", "password"); - providersDAO.update(providerId, "http://localhost:8080/messages", serviceAuth, UUID.randomUUID(), "Test Service", null); - - // Test Bot added into conv. BE calls POST /bots with NewBot object - NewBotResponseModel newBotResponseModel = newBotFromBE(botId, userId, convId); - assertThat(newBotResponseModel.lastPreKey).isNotNull(); - assertThat(newBotResponseModel.preKeys).isNotNull(); - - CryptoFile crypto = new CryptoFile("data", botId); - PreKeys preKeys = new PreKeys(newBotResponseModel.preKeys, USER_CLIENT_DUMMY, userId); - - // Post new poll into conv - final UUID pollId = UUID.randomUUID(); - ArrayList buttons = new ArrayList<>(); - buttons.add("First"); - buttons.add("Second"); - Response res = newPollMessageFromBot(pollId, "This is a poll", buttons, botId); - assertThat(res.getStatus()).isEqualTo(200); - - // Test new PollAnswer message is sent to Roman by the BE. - final int buttonId = 1; - Recipients recipients = crypto.encrypt(preKeys, generatePollAnswerMessage(pollId, buttonId)); - String cypher = recipients.get(userId, USER_CLIENT_DUMMY); - res = newOtrMessageFromBackend(botId, userId, cypher); - assertThat(res.getStatus()).isEqualTo(200); - - // Post PollActionConfirmation message into conv - res = newPollActionConfirmationFromBot(pollId, buttonId, userId, botId); - assertThat(res.getStatus()).isEqualTo(200); - - crypto.close(); - } - - private NewBotResponseModel newBotFromBE(UUID botId, UUID userId, UUID convId) { - NewBot newBot = new NewBot(); - newBot.id = botId; - newBot.locale = "en"; - newBot.token = "token_dummy"; - newBot.client = BOT_CLIENT_DUMMY; - newBot.origin = new User(); - newBot.origin.id = userId; - newBot.origin.name = "user_name"; - newBot.origin.handle = "user_handle"; - newBot.conversation = new Conversation(); - newBot.conversation.id = convId; - newBot.conversation.name = "conv_name"; - newBot.conversation.creator = userId; - newBot.conversation.members = new ArrayList<>(); - - Response res = client - .target("http://localhost:" + SUPPORT.getLocalPort()) - .path("bots") - .request() - .header("Authorization", "Bearer " + serviceAuth) - .post(Entity.entity(newBot, MediaType.APPLICATION_JSON_TYPE)); - - assertThat(res.getStatus()).isEqualTo(201); - - return res.readEntity(NewBotResponseModel.class); - } - - private Response newOtrMessageFromBackend(UUID botId, UUID userId, String cypher) { - Payload payload = new Payload(); - payload.type = "conversation.otr-message-add"; - payload.from = userId; - payload.time = new Date().toString(); - payload.data = new Payload.Data(); - payload.data.sender = USER_CLIENT_DUMMY; - payload.data.recipient = BOT_CLIENT_DUMMY; - payload.data.text = cypher; - - return client - .target("http://localhost:" + SUPPORT.getLocalPort()) - .path("bots") - .path(botId.toString()) - .path("messages") - .request() - .header("Authorization", "Bearer " + serviceAuth) - .post(Entity.entity(payload, MediaType.APPLICATION_JSON_TYPE)); - } - - @SuppressWarnings("SameParameterValue") - private Response newPollMessageFromBot(UUID pollId, String text, ArrayList buttons, UUID botId) { - String token = Tools.generateToken(botId); - - final String mention = "@mention"; - Mention mnt = new Mention(); - mnt.userId = UUID.randomUUID(); - mnt.offset = text.length(); - mnt.length = mention.length(); - IncomingMessage message = new IncomingMessage(); - message.type = "poll"; - message.text = new Text(); - message.text.data = text + " " + mention; - message.text.mentions = new ArrayList<>(); - message.text.mentions.add(mnt); - message.poll = new Poll(); - message.poll.id = pollId; - message.poll.type = "create"; - message.poll.buttons = buttons; - - return client - .target("http://localhost:" + SUPPORT.getLocalPort()) - .path("conversation") - .request() - .header("Authorization", "Bearer " + token) - .post(Entity.entity(message, MediaType.APPLICATION_JSON_TYPE)); - } - - @SuppressWarnings("SameParameterValue") - private Response newPollActionConfirmationFromBot(UUID pollId, int buttonId, UUID userId, UUID botId) { - String token = Tools.generateToken(botId); - - IncomingMessage message = new IncomingMessage(); - message.type = "poll"; - message.poll = new Poll(); - message.poll.id = pollId; - message.poll.type = "confirmation"; - message.poll.offset = buttonId; - message.poll.userId = userId; - - return client - .target("http://localhost:" + SUPPORT.getLocalPort()) - .path("conversation") - .request() - .header("Authorization", "Bearer " + token) - .post(Entity.entity(message, MediaType.APPLICATION_JSON_TYPE)); - } - - @SuppressWarnings("SameParameterValue") - private byte[] generatePollAnswerMessage(UUID pollId, int buttonId) { - Messages.ButtonAction.Builder pollAnswer = Messages.ButtonAction.newBuilder() - .setReferenceMessageId(pollId.toString()) - .setButtonId("" + buttonId); - - return Messages.GenericMessage.newBuilder() - .setMessageId(UUID.randomUUID().toString()) - .setButtonAction(pollAnswer) - .build() - .toByteArray(); - } -} +//package com.wire.bots.roman.integrations; +// +//import com.waz.model.Messages; +//import com.wire.bots.cryptobox.CryptoException; +//import com.wire.bots.roman.Application; +//import com.wire.bots.roman.DAO.ProvidersDAO; +//import com.wire.bots.roman.Tools; +//import com.wire.bots.roman.model.*; +//import com.wire.lithium.models.NewBotResponseModel; +//import com.wire.xenon.backend.models.Conversation; +//import com.wire.xenon.backend.models.NewBot; +//import com.wire.xenon.backend.models.Payload; +//import com.wire.xenon.backend.models.User; +//import com.wire.xenon.crypto.CryptoFile; +//import com.wire.xenon.models.otr.PreKeys; +//import com.wire.xenon.models.otr.Recipients; +//import io.dropwizard.testing.ConfigOverride; +//import io.dropwizard.testing.DropwizardTestSupport; +//import jakarta.ws.rs.client.Client; +//import jakarta.ws.rs.client.Entity; +//import jakarta.ws.rs.core.MediaType; +//import jakarta.ws.rs.core.Response; +//import org.jdbi.v3.core.Jdbi; +//import org.junit.After; +//import org.junit.Before; +//import org.junit.Test; +// +//import java.math.BigInteger; +//import java.security.SecureRandom; +//import java.util.ArrayList; +//import java.util.Date; +//import java.util.UUID; +// +//import static org.assertj.core.api.Assertions.assertThat; +// +//public class IncomingBackendPollMessageTest { +// private static final SecureRandom random = new SecureRandom(); +// private static final String BOT_CLIENT_DUMMY = "bot_client_dummy"; +// private static final String USER_CLIENT_DUMMY = "user_client_dummy"; +// private static final DropwizardTestSupport SUPPORT = new DropwizardTestSupport<>( +// Application.class, "roman.yaml", +// ConfigOverride.config("key", "TcZA2Kq4GaOcIbQuOvasrw34321cZAfLW4Ga54fsds43hUuOdcdm42"), +// ConfigOverride.config("apiHost", "http://localhost:8090")); +// +// private final String serviceAuth = new BigInteger(64, random).toString(16); +// private Client client; +// private Jdbi jdbi; +// +// @Before +// public void beforeClass() throws Exception { +// SUPPORT.before(); +// Application app = SUPPORT.getApplication(); +// client = app.getClient(); +// jdbi = app.getJdbi(); +// } +// +// @After +// public void afterClass() { +// SUPPORT.after(); +// } +// +// @Test +// public void test() throws CryptoException { +// final UUID botId = UUID.randomUUID(); +// final UUID userId = UUID.randomUUID(); +// final UUID convId = UUID.randomUUID(); +// final UUID providerId = UUID.randomUUID(); +// final String email = String.format("%s@email.com", serviceAuth); +// +// // Create some fake provider and service +// ProvidersDAO providersDAO = jdbi.onDemand(ProvidersDAO.class); +// providersDAO.insert("Test Provider", providerId, email, "hash", "password"); +// providersDAO.update(providerId, "http://localhost:8080/messages", serviceAuth, UUID.randomUUID(), "Test Service", null); +// +// // Test Bot added into conv. BE calls POST /bots with NewBot object +// NewBotResponseModel newBotResponseModel = newBotFromBE(botId, userId, convId); +// assertThat(newBotResponseModel.lastPreKey).isNotNull(); +// assertThat(newBotResponseModel.preKeys).isNotNull(); +// +// CryptoFile crypto = new CryptoFile("data", botId); +// PreKeys preKeys = new PreKeys(newBotResponseModel.preKeys, USER_CLIENT_DUMMY, userId); +// +// // Post new poll into conv +// final UUID pollId = UUID.randomUUID(); +// ArrayList buttons = new ArrayList<>(); +// buttons.add("First"); +// buttons.add("Second"); +// Response res = newPollMessageFromBot(pollId, "This is a poll", buttons, botId); +// assertThat(res.getStatus()).isEqualTo(200); +// +// // Test new PollAnswer message is sent to Roman by the BE. +// final int buttonId = 1; +// Recipients recipients = crypto.encrypt(preKeys, generatePollAnswerMessage(pollId, buttonId)); +// String cypher = recipients.get(userId, USER_CLIENT_DUMMY); +// res = newOtrMessageFromBackend(botId, userId, cypher); +// assertThat(res.getStatus()).isEqualTo(200); +// +// // Post PollActionConfirmation message into conv +// res = newPollActionConfirmationFromBot(pollId, buttonId, userId, botId); +// assertThat(res.getStatus()).isEqualTo(200); +// +// crypto.close(); +// } +// +// private NewBotResponseModel newBotFromBE(UUID botId, UUID userId, UUID convId) { +// NewBot newBot = new NewBot(); +// newBot.id = botId; +// newBot.locale = "en"; +// newBot.token = "token_dummy"; +// newBot.client = BOT_CLIENT_DUMMY; +// newBot.origin = new User(); +// newBot.origin.id = userId; +// newBot.origin.name = "user_name"; +// newBot.origin.handle = "user_handle"; +// newBot.conversation = new Conversation(); +// newBot.conversation.id = convId; +// newBot.conversation.name = "conv_name"; +// newBot.conversation.creator = userId; +// newBot.conversation.members = new ArrayList<>(); +// +// Response res = client +// .target("http://localhost:" + SUPPORT.getLocalPort()) +// .path("bots") +// .request() +// .header("Authorization", "Bearer " + serviceAuth) +// .post(Entity.entity(newBot, MediaType.APPLICATION_JSON_TYPE)); +// +// assertThat(res.getStatus()).isEqualTo(201); +// +// return res.readEntity(NewBotResponseModel.class); +// } +// +// private Response newOtrMessageFromBackend(UUID botId, UUID userId, String cypher) { +// Payload payload = new Payload(); +// payload.type = "conversation.otr-message-add"; +// payload.from = new Payload.Qualified(userId, "wire.com"); +// payload.time = new Date().toString(); +// payload.data = new Payload.Data(); +// payload.data.sender = USER_CLIENT_DUMMY; +// payload.data.recipient = BOT_CLIENT_DUMMY; +// payload.data.text = cypher; +// +// return client +// .target("http://localhost:" + SUPPORT.getLocalPort()) +// .path("bots") +// .path(botId.toString()) +// .path("messages") +// .request() +// .header("Authorization", "Bearer " + serviceAuth) +// .post(Entity.entity(payload, MediaType.APPLICATION_JSON_TYPE)); +// } +// +// @SuppressWarnings("SameParameterValue") +// private Response newPollMessageFromBot(UUID pollId, String text, ArrayList buttons, UUID botId) { +// String token = Tools.generateToken(botId); +// +// final String mention = "@mention"; +// Mention mnt = new Mention(); +// mnt.userId = UUID.randomUUID(); +// mnt.offset = text.length(); +// mnt.length = mention.length(); +// IncomingMessage message = new IncomingMessage(); +// message.type = "poll"; +// message.text = new Text(); +// message.text.data = text + " " + mention; +// message.text.mentions = new ArrayList<>(); +// message.text.mentions.add(mnt); +// message.poll = new Poll(); +// message.poll.id = pollId; +// message.poll.type = "create"; +// message.poll.buttons = buttons; +// +// return client +// .target("http://localhost:" + SUPPORT.getLocalPort()) +// .path("conversation") +// .request() +// .header("Authorization", "Bearer " + token) +// .post(Entity.entity(message, MediaType.APPLICATION_JSON_TYPE)); +// } +// +// @SuppressWarnings("SameParameterValue") +// private Response newPollActionConfirmationFromBot(UUID pollId, int buttonId, UUID userId, UUID botId) { +// String token = Tools.generateToken(botId); +// +// IncomingMessage message = new IncomingMessage(); +// message.type = "poll"; +// message.poll = new Poll(); +// message.poll.id = pollId; +// message.poll.type = "confirmation"; +// message.poll.offset = buttonId; +// message.poll.userId = userId; +// +// return client +// .target("http://localhost:" + SUPPORT.getLocalPort()) +// .path("conversation") +// .request() +// .header("Authorization", "Bearer " + token) +// .post(Entity.entity(message, MediaType.APPLICATION_JSON_TYPE)); +// } +// +// @SuppressWarnings("SameParameterValue") +// private byte[] generatePollAnswerMessage(UUID pollId, int buttonId) { +// Messages.ButtonAction.Builder pollAnswer = Messages.ButtonAction.newBuilder() +// .setReferenceMessageId(pollId.toString()) +// .setButtonId("" + buttonId); +// +// return Messages.GenericMessage.newBuilder() +// .setMessageId(UUID.randomUUID().toString()) +// .setButtonAction(pollAnswer) +// .build() +// .toByteArray(); +// } +//} diff --git a/backend/src/test/java/com/wire/bots/roman/integrations/IncomingBackendTextMessageTest.java b/backend/src/test/java/com/wire/bots/roman/integrations/IncomingBackendTextMessageTest.java index 8833822..2788b0f 100644 --- a/backend/src/test/java/com/wire/bots/roman/integrations/IncomingBackendTextMessageTest.java +++ b/backend/src/test/java/com/wire/bots/roman/integrations/IncomingBackendTextMessageTest.java @@ -1,151 +1,151 @@ -package com.wire.bots.roman.integrations; - -import com.waz.model.Messages; -import com.wire.bots.cryptobox.CryptoException; -import com.wire.bots.roman.Application; -import com.wire.bots.roman.DAO.ProvidersDAO; -import com.wire.bots.roman.model.Config; -import com.wire.lithium.models.NewBotResponseModel; -import com.wire.xenon.backend.models.Conversation; -import com.wire.xenon.backend.models.NewBot; -import com.wire.xenon.backend.models.Payload; -import com.wire.xenon.backend.models.User; -import com.wire.xenon.crypto.CryptoFile; -import com.wire.xenon.models.otr.PreKeys; -import com.wire.xenon.models.otr.Recipients; -import io.dropwizard.testing.ConfigOverride; -import io.dropwizard.testing.DropwizardTestSupport; -import org.jdbi.v3.core.Jdbi; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.Entity; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import java.math.BigInteger; -import java.security.SecureRandom; -import java.util.ArrayList; -import java.util.Date; -import java.util.UUID; - -import static org.assertj.core.api.Assertions.assertThat; - -public class IncomingBackendTextMessageTest { - private static final SecureRandom random = new SecureRandom(); - private static final String BOT_CLIENT_DUMMY = "bot_client_dummy"; - private static final String USER_CLIENT_DUMMY = "user_client_dummy"; - private static final DropwizardTestSupport SUPPORT = new DropwizardTestSupport<>( - Application.class, "roman.yaml", - ConfigOverride.config("key", "TcZA2Kq4GaOcIbQuOvasrw34321cZAfLW4Ga54fsds43hUuOdcdm42"), - ConfigOverride.config("apiHost", "http://localhost:8090")); - - private final String serviceAuth = new BigInteger(64, random).toString(16); - private Client client; - private Jdbi jdbi; - - @Before - public void beforeClass() throws Exception { - SUPPORT.before(); - Application app = SUPPORT.getApplication(); - client = app.getClient(); - jdbi = app.getJdbi(); - } - - @After - public void afterClass() { - SUPPORT.after(); - } - - @Test - public void testNewTextMessage() throws CryptoException { - final UUID botId = UUID.randomUUID(); - final UUID userId = UUID.randomUUID(); - final UUID convId = UUID.randomUUID(); - final UUID providerId = UUID.randomUUID(); - final String email = String.format("%s@email.com", serviceAuth); - - // Create some fake provider and service - ProvidersDAO providersDAO = jdbi.onDemand(ProvidersDAO.class); - providersDAO.insert("Test Provider", providerId, email, "hash", "password"); - providersDAO.update(providerId, "http://localhost:8080/messages", serviceAuth, UUID.randomUUID(), "Test Service", null); - - // Test Bot added into conv. BE calls POST /bots with NewBot object - NewBotResponseModel newBotResponseModel = newBotFromBE(botId, userId, convId); - assertThat(newBotResponseModel.lastPreKey).isNotNull(); - assertThat(newBotResponseModel.preKeys).isNotNull(); - - CryptoFile crypto = new CryptoFile("data", botId); - PreKeys preKeys = new PreKeys(newBotResponseModel.preKeys, USER_CLIENT_DUMMY, userId); - - // Test new Text message is sent to Roman by the BE. BE calls POST /bots/{botId}/messages with Payload obj - Recipients recipients = crypto.encrypt(preKeys, generateTextMessage("Hello Bob")); - String cypher = recipients.get(userId, USER_CLIENT_DUMMY); - Response res = newOtrMessageFromBackend(botId, userId, cypher); - assertThat(res.getStatus()).isEqualTo(200); - - crypto.close(); - } - - private NewBotResponseModel newBotFromBE(UUID botId, UUID userId, UUID convId) { - NewBot newBot = new NewBot(); - newBot.id = botId; - newBot.locale = "en"; - newBot.token = "token_dummy"; - newBot.client = BOT_CLIENT_DUMMY; - newBot.origin = new User(); - newBot.origin.id = userId; - newBot.origin.name = "user_name"; - newBot.origin.handle = "user_handle"; - newBot.conversation = new Conversation(); - newBot.conversation.id = convId; - newBot.conversation.name = "conv_name"; - newBot.conversation.creator = userId; - newBot.conversation.members = new ArrayList<>(); - - Response res = client - .target("http://localhost:" + SUPPORT.getLocalPort()) - .path("bots") - .request() - .header("Authorization", "Bearer " + serviceAuth) - .post(Entity.entity(newBot, MediaType.APPLICATION_JSON_TYPE)); - - assertThat(res.getStatus()).isEqualTo(201); - - return res.readEntity(NewBotResponseModel.class); - } - - private Response newOtrMessageFromBackend(UUID botId, UUID userId, String cypher) { - Payload payload = new Payload(); - payload.type = "conversation.otr-message-add"; - payload.from = userId; - payload.time = new Date().toString(); - payload.data = new Payload.Data(); - payload.data.sender = USER_CLIENT_DUMMY; - payload.data.recipient = BOT_CLIENT_DUMMY; - payload.data.text = cypher; - - return client - .target("http://localhost:" + SUPPORT.getLocalPort()) - .path("bots") - .path(botId.toString()) - .path("messages") - .request() - .header("Authorization", "Bearer " + serviceAuth) - .post(Entity.entity(payload, MediaType.APPLICATION_JSON_TYPE)); - } - - @SuppressWarnings("SameParameterValue") - private byte[] generateTextMessage(String content) { - Messages.Text.Builder text = Messages.Text.newBuilder() - .setContent(content) - .setQuote(Messages.Quote.newBuilder().setQuotedMessageId(UUID.randomUUID().toString())); - - return Messages.GenericMessage.newBuilder() - .setMessageId(UUID.randomUUID().toString()) - .setText(text) - .build() - .toByteArray(); - } -} +//package com.wire.bots.roman.integrations; +// +//import com.waz.model.Messages; +//import com.wire.bots.cryptobox.CryptoException; +//import com.wire.bots.roman.Application; +//import com.wire.bots.roman.DAO.ProvidersDAO; +//import com.wire.bots.roman.model.Config; +//import com.wire.lithium.models.NewBotResponseModel; +//import com.wire.xenon.backend.models.Conversation; +//import com.wire.xenon.backend.models.NewBot; +//import com.wire.xenon.backend.models.Payload; +//import com.wire.xenon.backend.models.User; +//import com.wire.xenon.crypto.CryptoFile; +//import com.wire.xenon.models.otr.PreKeys; +//import com.wire.xenon.models.otr.Recipients; +//import io.dropwizard.testing.ConfigOverride; +//import io.dropwizard.testing.DropwizardTestSupport; +//import org.jdbi.v3.core.Jdbi; +//import org.junit.After; +//import org.junit.Before; +//import org.junit.Test; +// +//import jakarta.ws.rs.client.Client; +//import jakarta.ws.rs.client.Entity; +//import jakarta.ws.rs.core.MediaType; +//import jakarta.ws.rs.core.Response; +//import java.math.BigInteger; +//import java.security.SecureRandom; +//import java.util.ArrayList; +//import java.util.Date; +//import java.util.UUID; +// +//import static org.assertj.core.api.Assertions.assertThat; +// +//public class IncomingBackendTextMessageTest { +// private static final SecureRandom random = new SecureRandom(); +// private static final String BOT_CLIENT_DUMMY = "bot_client_dummy"; +// private static final String USER_CLIENT_DUMMY = "user_client_dummy"; +// private static final DropwizardTestSupport SUPPORT = new DropwizardTestSupport<>( +// Application.class, "roman.yaml", +// ConfigOverride.config("key", "TcZA2Kq4GaOcIbQuOvasrw34321cZAfLW4Ga54fsds43hUuOdcdm42"), +// ConfigOverride.config("apiHost", "http://localhost:8090")); +// +// private final String serviceAuth = new BigInteger(64, random).toString(16); +// private Client client; +// private Jdbi jdbi; +// +// @Before +// public void beforeClass() throws Exception { +// SUPPORT.before(); +// Application app = SUPPORT.getApplication(); +// client = app.getClient(); +// jdbi = app.getJdbi(); +// } +// +// @After +// public void afterClass() { +// SUPPORT.after(); +// } +// +// @Test +// public void testNewTextMessage() throws CryptoException { +// final UUID botId = UUID.randomUUID(); +// final UUID userId = UUID.randomUUID(); +// final UUID convId = UUID.randomUUID(); +// final UUID providerId = UUID.randomUUID(); +// final String email = String.format("%s@email.com", serviceAuth); +// +// // Create some fake provider and service +// ProvidersDAO providersDAO = jdbi.onDemand(ProvidersDAO.class); +// providersDAO.insert("Test Provider", providerId, email, "hash", "password"); +// providersDAO.update(providerId, "http://localhost:8080/messages", serviceAuth, UUID.randomUUID(), "Test Service", null); +// +// // Test Bot added into conv. BE calls POST /bots with NewBot object +// NewBotResponseModel newBotResponseModel = newBotFromBE(botId, userId, convId); +// assertThat(newBotResponseModel.lastPreKey).isNotNull(); +// assertThat(newBotResponseModel.preKeys).isNotNull(); +// +// CryptoFile crypto = new CryptoFile("data", botId); +// PreKeys preKeys = new PreKeys(newBotResponseModel.preKeys, USER_CLIENT_DUMMY, userId); +// +// // Test new Text message is sent to Roman by the BE. BE calls POST /bots/{botId}/messages with Payload obj +// Recipients recipients = crypto.encrypt(preKeys, generateTextMessage("Hello Bob")); +// String cypher = recipients.get(userId, USER_CLIENT_DUMMY); +// Response res = newOtrMessageFromBackend(botId, userId, cypher); +// assertThat(res.getStatus()).isEqualTo(200); +// +// crypto.close(); +// } +// +// private NewBotResponseModel newBotFromBE(UUID botId, UUID userId, UUID convId) { +// NewBot newBot = new NewBot(); +// newBot.id = botId; +// newBot.locale = "en"; +// newBot.token = "token_dummy"; +// newBot.client = BOT_CLIENT_DUMMY; +// newBot.origin = new User(); +// newBot.origin.id = userId; +// newBot.origin.name = "user_name"; +// newBot.origin.handle = "user_handle"; +// newBot.conversation = new Conversation(); +// newBot.conversation.id = convId; +// newBot.conversation.name = "conv_name"; +// newBot.conversation.creator = userId; +// newBot.conversation.members = new ArrayList<>(); +// +// Response res = client +// .target("http://localhost:" + SUPPORT.getLocalPort()) +// .path("bots") +// .request() +// .header("Authorization", "Bearer " + serviceAuth) +// .post(Entity.entity(newBot, MediaType.APPLICATION_JSON_TYPE)); +// +// assertThat(res.getStatus()).isEqualTo(201); +// +// return res.readEntity(NewBotResponseModel.class); +// } +// +// private Response newOtrMessageFromBackend(UUID botId, UUID userId, String cypher) { +// Payload payload = new Payload(); +// payload.type = "conversation.otr-message-add"; +// payload.from = new Payload.Qualified(userId, "wire.com"); +// payload.time = new Date().toString(); +// payload.data = new Payload.Data(); +// payload.data.sender = USER_CLIENT_DUMMY; +// payload.data.recipient = BOT_CLIENT_DUMMY; +// payload.data.text = cypher; +// +// return client +// .target("http://localhost:" + SUPPORT.getLocalPort()) +// .path("bots") +// .path(botId.toString()) +// .path("messages") +// .request() +// .header("Authorization", "Bearer " + serviceAuth) +// .post(Entity.entity(payload, MediaType.APPLICATION_JSON_TYPE)); +// } +// +// @SuppressWarnings("SameParameterValue") +// private byte[] generateTextMessage(String content) { +// Messages.Text.Builder text = Messages.Text.newBuilder() +// .setContent(content) +// .setQuote(Messages.Quote.newBuilder().setQuotedMessageId(UUID.randomUUID().toString())); +// +// return Messages.GenericMessage.newBuilder() +// .setMessageId(UUID.randomUUID().toString()) +// .setText(text) +// .build() +// .toByteArray(); +// } +//} diff --git a/backend/src/test/java/com/wire/bots/roman/integrations/IncomingMessageTest.java b/backend/src/test/java/com/wire/bots/roman/integrations/IncomingMessageTest.java index 7b0bcdd..e934c3e 100644 --- a/backend/src/test/java/com/wire/bots/roman/integrations/IncomingMessageTest.java +++ b/backend/src/test/java/com/wire/bots/roman/integrations/IncomingMessageTest.java @@ -1,149 +1,149 @@ -package com.wire.bots.roman.integrations; - -import com.wire.bots.roman.Application; -import com.wire.bots.roman.DAO.ProvidersDAO; -import com.wire.bots.roman.Tools; -import com.wire.bots.roman.model.Attachment; -import com.wire.bots.roman.model.Config; -import com.wire.bots.roman.model.IncomingMessage; -import com.wire.bots.roman.model.Text; -import com.wire.lithium.models.NewBotResponseModel; -import com.wire.xenon.backend.models.Conversation; -import com.wire.xenon.backend.models.NewBot; -import com.wire.xenon.backend.models.User; -import com.wire.xenon.tools.Util; -import io.dropwizard.testing.ConfigOverride; -import io.dropwizard.testing.DropwizardTestSupport; -import org.jdbi.v3.core.Jdbi; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.Entity; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Base64; -import java.util.Random; -import java.util.UUID; - -import static org.assertj.core.api.Assertions.assertThat; - -public class IncomingMessageTest { - private static final String BOT_CLIENT_DUMMY = "bot_client_dummy"; - private static final DropwizardTestSupport SUPPORT = new DropwizardTestSupport<>( - Application.class, "roman.yaml", - ConfigOverride.config("key", "TcZA2Kq4GaOcIbQuOvasrw34321cZAfLW4Ga54fsds43hUuOdcdm42"), - ConfigOverride.config("apiHost", "http://localhost:8090")); - private Client client; - private Jdbi jdbi; - - @Before - public void beforeClass() throws Exception { - SUPPORT.before(); - Application app = SUPPORT.getApplication(); - client = app.getClient(); - jdbi = app.getJdbi(); - } - - @After - public void afterClass() { - SUPPORT.after(); - } - - @Test - public void incomingMessageFromUserTest() throws IOException { - final UUID botId = UUID.randomUUID(); - final UUID userId = UUID.randomUUID(); - final UUID convId = UUID.randomUUID(); - final UUID providerId = UUID.randomUUID(); - final String serviceAuth = Tools.generateToken(botId); - - final String email = String.format("%s@email.com", serviceAuth); - - // Create some fake provider and service - ProvidersDAO providersDAO = jdbi.onDemand(ProvidersDAO.class); - providersDAO.insert("Test Provider", providerId, email, "hash", "password"); - providersDAO.update(providerId, "http://localhost:8080/messages", serviceAuth, UUID.randomUUID(), "Test Service", null); - - // Test Bot added into conv. BE calls POST /bots with NewBot object - NewBotResponseModel newBotResponseModel = newBotFromBE(botId, userId, convId, serviceAuth); - assertThat(newBotResponseModel.lastPreKey).isNotNull(); - assertThat(newBotResponseModel.preKeys).isNotNull(); - - IncomingMessage txt = new IncomingMessage(); - txt.type = "text"; - txt.text = new Text(); - txt.text.data = "Hello Alice"; - - Response res = post(serviceAuth, txt); - - assertThat(res.getStatus()).isEqualTo(200); - - IncomingMessage file = new IncomingMessage(); - file.type = "attachment"; - file.attachment = new Attachment(); - byte[] pic = new byte[5 * 1024 * 1024]; - new Random().nextBytes(pic); - file.attachment.data = Base64.getEncoder().encodeToString(pic); - file.attachment.mimeType = "attachment/x"; - file.attachment.name = "test.x"; - file.attachment.size = (long) file.attachment.data.length(); - - res = post(serviceAuth, file); - assertThat(res.getStatus()).isEqualTo(200); - - IncomingMessage audio = new IncomingMessage(); - audio.type = "attachment"; - audio.attachment = new Attachment(); - audio.attachment.data = Base64.getEncoder().encodeToString(Util.getResource("audio.m4a")); - audio.attachment.mimeType = "audio/x-m4a"; - audio.attachment.name = "test.m4a"; - audio.attachment.size = (long) audio.attachment.data.length(); - audio.attachment.duration = 27000L; - audio.attachment.levels = new byte[100]; - new Random().nextBytes(audio.attachment.levels); - - res = post(serviceAuth, audio); - assertThat(res.getStatus()).isEqualTo(200); - } - - private Response post(String serviceAuth, IncomingMessage txt) { - return client - .target("http://localhost:" + SUPPORT.getLocalPort()) - .path("conversation") - .request() - .header("Authorization", "Bearer " + serviceAuth) - .post(Entity.entity(txt, MediaType.APPLICATION_JSON_TYPE)); - } - - private NewBotResponseModel newBotFromBE(UUID botId, UUID userId, UUID convId, String serviceAuth) { - NewBot newBot = new NewBot(); - newBot.id = botId; - newBot.locale = "en"; - newBot.token = "token_dummy"; - newBot.client = BOT_CLIENT_DUMMY; - newBot.origin = new User(); - newBot.origin.id = userId; - newBot.origin.name = "user_name"; - newBot.origin.handle = "user_handle"; - newBot.conversation = new Conversation(); - newBot.conversation.id = convId; - newBot.conversation.name = "conv_name"; - newBot.conversation.creator = userId; - newBot.conversation.members = new ArrayList<>(); - - Response res = client - .target("http://localhost:" + SUPPORT.getLocalPort()) - .path("bots") - .request() - .header("Authorization", "Bearer " + serviceAuth) - .post(Entity.entity(newBot, MediaType.APPLICATION_JSON_TYPE)); - - assertThat(res.getStatus()).isEqualTo(201); - - return res.readEntity(NewBotResponseModel.class); - } -} +//package com.wire.bots.roman.integrations; +// +//import com.wire.bots.roman.Application; +//import com.wire.bots.roman.DAO.ProvidersDAO; +//import com.wire.bots.roman.Tools; +//import com.wire.bots.roman.model.Attachment; +//import com.wire.bots.roman.model.Config; +//import com.wire.bots.roman.model.IncomingMessage; +//import com.wire.bots.roman.model.Text; +//import com.wire.lithium.models.NewBotResponseModel; +//import com.wire.xenon.backend.models.Conversation; +//import com.wire.xenon.backend.models.NewBot; +//import com.wire.xenon.backend.models.User; +//import com.wire.xenon.tools.Util; +//import io.dropwizard.testing.ConfigOverride; +//import io.dropwizard.testing.DropwizardTestSupport; +//import jakarta.ws.rs.client.Client; +//import jakarta.ws.rs.client.Entity; +//import jakarta.ws.rs.core.MediaType; +//import jakarta.ws.rs.core.Response; +//import org.jdbi.v3.core.Jdbi; +//import org.junit.After; +//import org.junit.Before; +//import org.junit.Test; +// +//import java.io.IOException; +//import java.util.ArrayList; +//import java.util.Base64; +//import java.util.Random; +//import java.util.UUID; +// +//import static org.assertj.core.api.Assertions.assertThat; +// +//public class IncomingMessageTest { +// private static final String BOT_CLIENT_DUMMY = "bot_client_dummy"; +// private static final DropwizardTestSupport SUPPORT = new DropwizardTestSupport<>( +// Application.class, "roman.yaml", +// ConfigOverride.config("key", "TcZA2Kq4GaOcIbQuOvasrw34321cZAfLW4Ga54fsds43hUuOdcdm42"), +// ConfigOverride.config("apiHost", "http://localhost:8090")); +// private Client client; +// private Jdbi jdbi; +// +// @Before +// public void beforeClass() throws Exception { +// SUPPORT.before(); +// Application app = SUPPORT.getApplication(); +// client = app.getClient(); +// jdbi = app.getJdbi(); +// } +// +// @After +// public void afterClass() { +// SUPPORT.after(); +// } +// +// @Test +// public void incomingMessageFromUserTest() throws IOException { +// final UUID botId = UUID.randomUUID(); +// final UUID userId = UUID.randomUUID(); +// final UUID convId = UUID.randomUUID(); +// final UUID providerId = UUID.randomUUID(); +// final String serviceAuth = Tools.generateToken(botId); +// +// final String email = String.format("%s@email.com", serviceAuth); +// +// // Create some fake provider and service +// ProvidersDAO providersDAO = jdbi.onDemand(ProvidersDAO.class); +// providersDAO.insert("Test Provider", providerId, email, "hash", "password"); +// providersDAO.update(providerId, "http://localhost:8080/messages", serviceAuth, UUID.randomUUID(), "Test Service", null); +// +// // Test Bot added into conv. BE calls POST /bots with NewBot object +// NewBotResponseModel newBotResponseModel = newBotFromBE(botId, userId, convId, serviceAuth); +// assertThat(newBotResponseModel.lastPreKey).isNotNull(); +// assertThat(newBotResponseModel.preKeys).isNotNull(); +// +// IncomingMessage txt = new IncomingMessage(); +// txt.type = "text"; +// txt.text = new Text(); +// txt.text.data = "Hello Alice"; +// +// Response res = post(serviceAuth, txt); +// +// assertThat(res.getStatus()).isEqualTo(200); +// +// IncomingMessage file = new IncomingMessage(); +// file.type = "attachment"; +// file.attachment = new Attachment(); +// byte[] pic = new byte[5 * 1024 * 1024]; +// new Random().nextBytes(pic); +// file.attachment.data = Base64.getEncoder().encodeToString(pic); +// file.attachment.mimeType = "attachment/x"; +// file.attachment.name = "test.x"; +// file.attachment.size = (long) file.attachment.data.length(); +// +// res = post(serviceAuth, file); +// assertThat(res.getStatus()).isEqualTo(200); +// +// IncomingMessage audio = new IncomingMessage(); +// audio.type = "attachment"; +// audio.attachment = new Attachment(); +// audio.attachment.data = Base64.getEncoder().encodeToString(Util.getResource("audio.m4a")); +// audio.attachment.mimeType = "audio/x-m4a"; +// audio.attachment.name = "test.m4a"; +// audio.attachment.size = (long) audio.attachment.data.length(); +// audio.attachment.duration = 27000L; +// audio.attachment.levels = new byte[100]; +// new Random().nextBytes(audio.attachment.levels); +// +// res = post(serviceAuth, audio); +// assertThat(res.getStatus()).isEqualTo(200); +// } +// +// private Response post(String serviceAuth, IncomingMessage txt) { +// return client +// .target("http://localhost:" + SUPPORT.getLocalPort()) +// .path("conversation") +// .request() +// .header("Authorization", "Bearer " + serviceAuth) +// .post(Entity.entity(txt, MediaType.APPLICATION_JSON_TYPE)); +// } +// +// private NewBotResponseModel newBotFromBE(UUID botId, UUID userId, UUID convId, String serviceAuth) { +// NewBot newBot = new NewBot(); +// newBot.id = botId; +// newBot.locale = "en"; +// newBot.token = "token_dummy"; +// newBot.client = BOT_CLIENT_DUMMY; +// newBot.origin = new User(); +// newBot.origin.id = userId; +// newBot.origin.name = "user_name"; +// newBot.origin.handle = "user_handle"; +// newBot.conversation = new Conversation(); +// newBot.conversation.id = convId; +// newBot.conversation.name = "conv_name"; +// newBot.conversation.creator = userId; +// newBot.conversation.members = new ArrayList<>(); +// +// Response res = client +// .target("http://localhost:" + SUPPORT.getLocalPort()) +// .path("bots") +// .request() +// .header("Authorization", "Bearer " + serviceAuth) +// .post(Entity.entity(newBot, MediaType.APPLICATION_JSON_TYPE)); +// +// assertThat(res.getStatus()).isEqualTo(201); +// +// return res.readEntity(NewBotResponseModel.class); +// } +//} diff --git a/backend/src/test/java/com/wire/bots/roman/integrations/WebSocketTest.java b/backend/src/test/java/com/wire/bots/roman/integrations/WebSocketTest.java index ef1cb0b..49c9462 100644 --- a/backend/src/test/java/com/wire/bots/roman/integrations/WebSocketTest.java +++ b/backend/src/test/java/com/wire/bots/roman/integrations/WebSocketTest.java @@ -1,126 +1,125 @@ -package com.wire.bots.roman.integrations; - -import com.wire.bots.roman.Application; -import com.wire.bots.roman.DAO.ProvidersDAO; -import com.wire.bots.roman.Tools; -import com.wire.bots.roman.model.*; -import io.dropwizard.testing.ConfigOverride; -import io.dropwizard.testing.DropwizardTestSupport; -import org.jdbi.v3.core.Jdbi; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import javax.websocket.ClientEndpoint; - -import javax.websocket.*; -import javax.ws.rs.client.Client; -import java.net.URI; -import java.util.UUID; - -public class WebSocketTest { - URI wss = null; - - @ClientEndpoint(decoders = WebSocketTest._Decoder.class) - public class WebsocketClientEndpoint { - Session session; - - public WebsocketClientEndpoint() { - try { - WebSocketContainer container = ContainerProvider.getWebSocketContainer(); - session = container.connectToServer(this, wss); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - @OnOpen - public void onOpen(Session session) { - System.out.printf("Websocket open: %s\n", session.getId()); - } - - @OnMessage - public void onMessage(Object payload) { - } - - @OnClose - public void onClose(Session closed, CloseReason reason) { - System.out.printf("Websocket closed: %s: reason: %s\n", closed.getId(), reason.getCloseCode()); - } - } - - private static final DropwizardTestSupport SUPPORT = new DropwizardTestSupport<>( - Application.class, "roman.yaml", - ConfigOverride.config("key", "TcZA2Kq4GaOcIbQuOvasrw34321cZAfLW4Ga54fsds43hUuOdcdm42"), - ConfigOverride.config("romanPubKeyBase64", "pubkey.PEM")); - private Client client; - private Jdbi jdbi; - - @Before - public void beforeClass() throws Exception { - SUPPORT.before(); - Application app = SUPPORT.getApplication(); - client = app.getClient(); - jdbi = app.getJdbi(); - } - - @After - public void afterClass() { - SUPPORT.after(); - } - - @Test - public void connectTest() throws Exception { - final UUID botId = UUID.randomUUID(); - final UUID providerId = UUID.randomUUID(); - final String serviceAuth = Tools.generateToken(botId); - final UUID serviceId = UUID.randomUUID(); - - final String email = String.format("%s@email.com", serviceAuth); - - // Create some fake provider and service - ProvidersDAO providersDAO = jdbi.onDemand(ProvidersDAO.class); - providersDAO.insert("Test Provider", providerId, email, "hash", "password"); - providersDAO.update(providerId, null, serviceAuth, serviceId, "Test Service", null); - - Provider provider = providersDAO.get(providerId); - - final String wssUrl = "ws://localhost:8080"; - String appKey = provider.serviceAuth; - - wss = client.target(wssUrl) - .path("await") - .path(appKey) - .getUri(); - - final WebsocketClientEndpoint clientEndPoint = new WebsocketClientEndpoint(); - - Thread.sleep(2000); - - clientEndPoint.session.close(); - - Thread.sleep(2000); - } - - public static class _Decoder implements Decoder.Text { - @Override - public Object decode(String s) { - return new Object(); - } - - @Override - public boolean willDecode(String s) { - return s.startsWith("{") && s.endsWith("}"); - } - - @Override - public void init(EndpointConfig config) { - - } - - @Override - public void destroy() { - - } - } -} +//package com.wire.bots.roman.integrations; +// +//import com.wire.bots.roman.Application; +//import com.wire.bots.roman.DAO.ProvidersDAO; +//import com.wire.bots.roman.Tools; +//import com.wire.bots.roman.model.Config; +//import com.wire.bots.roman.model.Provider; +//import io.dropwizard.testing.ConfigOverride; +//import io.dropwizard.testing.DropwizardTestSupport; +//import jakarta.ws.rs.client.Client; +//import org.jdbi.v3.core.Jdbi; +//import org.junit.After; +//import org.junit.Before; +//import org.junit.Test; +// +//import javax.websocket.*; +//import java.net.URI; +//import java.util.UUID; +// +//public class WebSocketTest { +// URI wss = null; +// +// @ClientEndpoint(decoders = WebSocketTest._Decoder.class) +// public class WebsocketClientEndpoint { +// Session session; +// +// public WebsocketClientEndpoint() { +// try { +// WebSocketContainer container = ContainerProvider.getWebSocketContainer(); +// session = container.connectToServer(this, wss); +// } catch (Exception e) { +// throw new RuntimeException(e); +// } +// } +// +// @OnOpen +// public void onOpen(Session session) { +// System.out.printf("Websocket open: %s\n", session.getId()); +// } +// +// @OnMessage +// public void onMessage(Object payload) { +// } +// +// @OnClose +// public void onClose(Session closed, CloseReason reason) { +// System.out.printf("Websocket closed: %s: reason: %s\n", closed.getId(), reason.getCloseCode()); +// } +// } +// +// private static final DropwizardTestSupport SUPPORT = new DropwizardTestSupport<>( +// Application.class, "roman.yaml", +// ConfigOverride.config("key", "TcZA2Kq4GaOcIbQuOvasrw34321cZAfLW4Ga54fsds43hUuOdcdm42"), +// ConfigOverride.config("romanPubKeyBase64", "pubkey.PEM")); +// private Client client; +// private Jdbi jdbi; +// +// @Before +// public void beforeClass() throws Exception { +// SUPPORT.before(); +// Application app = SUPPORT.getApplication(); +// client = app.getClient(); +// jdbi = app.getJdbi(); +// } +// +// @After +// public void afterClass() { +// SUPPORT.after(); +// } +// +// @Test +// public void connectTest() throws Exception { +// final UUID botId = UUID.randomUUID(); +// final UUID providerId = UUID.randomUUID(); +// final String serviceAuth = Tools.generateToken(botId); +// final UUID serviceId = UUID.randomUUID(); +// +// final String email = String.format("%s@email.com", serviceAuth); +// +// // Create some fake provider and service +// ProvidersDAO providersDAO = jdbi.onDemand(ProvidersDAO.class); +// providersDAO.insert("Test Provider", providerId, email, "hash", "password"); +// providersDAO.update(providerId, null, serviceAuth, serviceId, "Test Service", null); +// +// Provider provider = providersDAO.get(providerId); +// +// final String wssUrl = "ws://localhost:8080"; +// String appKey = provider.serviceAuth; +// +// wss = client.target(wssUrl) +// .path("await") +// .path(appKey) +// .getUri(); +// +// final WebsocketClientEndpoint clientEndPoint = new WebsocketClientEndpoint(); +// +// Thread.sleep(2000); +// +// clientEndPoint.session.close(); +// +// Thread.sleep(2000); +// } +// +// public static class _Decoder implements Decoder.Text { +// @Override +// public Object decode(String s) { +// return new Object(); +// } +// +// @Override +// public boolean willDecode(String s) { +// return s.startsWith("{") && s.endsWith("}"); +// } +// +// @Override +// public void init(EndpointConfig config) { +// +// } +// +// @Override +// public void destroy() { +// +// } +// } +//} diff --git a/backend/src/test/java/com/wire/bots/roman/resources/ConversationResourceTest.java b/backend/src/test/java/com/wire/bots/roman/resources/ConversationResourceTest.java index e5bdcc4..b1f7e7b 100644 --- a/backend/src/test/java/com/wire/bots/roman/resources/ConversationResourceTest.java +++ b/backend/src/test/java/com/wire/bots/roman/resources/ConversationResourceTest.java @@ -1,69 +1,69 @@ package com.wire.bots.roman.resources; +import com.wire.bots.cryptobox.CryptoException; import com.wire.bots.roman.Sender; import com.wire.bots.roman.model.Attachment; import com.wire.bots.roman.model.IncomingMessage; import com.wire.bots.roman.model.PostMessageResult; import com.wire.bots.roman.model.Text; -import com.wire.bots.roman.resources.dummies.AuthenticationFeatureDummy; import com.wire.bots.roman.resources.dummies.Const; import com.wire.xenon.backend.models.Conversation; -import io.dropwizard.testing.junit.ResourceTestRule; -import org.junit.After; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; - -import javax.ws.rs.client.Entity; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - +import io.dropwizard.testing.junit5.DropwizardExtensionsSupport; +import io.dropwizard.testing.junit5.ResourceExtension; +import jakarta.ws.rs.client.Entity; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import java.io.IOException; + +import static com.wire.bots.roman.resources.dummies.Const.CONV_ID; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.*; +@ExtendWith(DropwizardExtensionsSupport.class) public class ConversationResourceTest { private static final Sender sender = mock(Sender.class); - - @ClassRule - public static final ResourceTestRule resources = ResourceTestRule.builder() - .addProvider(AuthenticationFeatureDummy.class) + public static final ResourceExtension resources = ResourceExtension.builder() .addResource(new ConversationResource(sender)) .build(); - @Before - public void setup() throws Exception { - Conversation conversation = new Conversation(); - conversation.id = Const.CONV_ID; + private final Conversation conversation = new Conversation() {{ + id = CONV_ID; + }}; - when(sender.getConversation(Const.BOT_ID)).thenReturn(conversation); - } - - @After + @AfterEach public void tearDown() { reset(sender); } @Test public void testPostTextIntoConversation() throws Exception { - final IncomingMessage message = new IncomingMessage(); - message.type = "text"; - message.text = new Text(); - message.text.data = "Hi there!"; - - when(sender.send(message, Const.BOT_ID)).thenReturn(Const.MSG_ID); - - final Response response = resources + final IncomingMessage message = new IncomingMessage() {{ + this.type = "text"; + this.text = new Text(); + this.text.data = "Hi there!"; + }}; + when(sender.send(any(), any())).thenReturn(Const.MSG_ID); + + PostMessageResult result; + try (Response response = resources .target("conversation") .request() - .post(Entity.entity(message, MediaType.APPLICATION_JSON_TYPE)); + .post(Entity.entity(message, MediaType.APPLICATION_JSON_TYPE))) { - assertThat(response.getStatus()).isEqualTo(200); - final PostMessageResult result = response.readEntity(PostMessageResult.class); + assertThat(response.getStatus()).isEqualTo(200); + result = response.readEntity(PostMessageResult.class); + } assertThat(result.messageId).isNotNull(); } @Test - public void testPostImageIntoConversation() { + public void testPostImageIntoConversation() throws Exception { + when(sender.send(any(), any())).thenReturn(Const.MSG_ID); + IncomingMessage message = new IncomingMessage(); message.type = "attachment"; message.attachment = new Attachment(); @@ -72,8 +72,8 @@ public void testPostImageIntoConversation() { "BwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zND"; final Response response = resources - .target("conversation") - .request() + .target("/conversation") + .request(MediaType.APPLICATION_JSON_TYPE) .post(Entity.entity(message, MediaType.APPLICATION_JSON_TYPE)); assertThat(response.getStatus()).isEqualTo(200); @@ -82,12 +82,14 @@ public void testPostImageIntoConversation() { } @Test - public void testGetConversation() { + public void testGetConversation() throws IOException, CryptoException { + when(sender.getConversation(any())).thenReturn(conversation); final Conversation response = resources - .target("conversation") + .target("/conversation") .request() .get(Conversation.class); - assertThat(response.id).isEqualTo(Const.CONV_ID); + assertThat(response).isNotNull(); + assertThat(response.id).isEqualTo(CONV_ID); } } diff --git a/backend/src/test/java/com/wire/bots/roman/resources/UsersResourceTest.java b/backend/src/test/java/com/wire/bots/roman/resources/UsersResourceTest.java index b51004e..df50214 100644 --- a/backend/src/test/java/com/wire/bots/roman/resources/UsersResourceTest.java +++ b/backend/src/test/java/com/wire/bots/roman/resources/UsersResourceTest.java @@ -5,34 +5,35 @@ import com.wire.bots.roman.resources.dummies.WireClientDummy; import com.wire.lithium.ClientRepo; import com.wire.xenon.backend.models.User; -import io.dropwizard.testing.junit.ResourceTestRule; -import org.junit.After; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; +import io.dropwizard.testing.junit5.DropwizardExtensionsSupport; +import io.dropwizard.testing.junit5.ResourceExtension; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import java.io.IOException; import static com.wire.bots.roman.resources.dummies.Const.BOT_ID; import static com.wire.bots.roman.resources.dummies.Const.USER_ID; -import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.mockito.Mockito.*; +@ExtendWith(DropwizardExtensionsSupport.class) public class UsersResourceTest { private static final ClientRepo clientRepo = mock(ClientRepo.class); - @ClassRule - public static final ResourceTestRule resources = ResourceTestRule.builder() + public static final ResourceExtension resources = ResourceExtension.builder() .addProvider(AuthenticationFeatureDummy.class) .addResource(new UsersResource(clientRepo)) .build(); - @Before + @BeforeEach public void setup() throws IOException, CryptoException { when(clientRepo.getClient(BOT_ID)).thenReturn(new WireClientDummy()); } - @After + @AfterEach public void tearDown() { reset(clientRepo); } diff --git a/backend/src/test/java/com/wire/bots/roman/resources/dummies/AuthenticationFeatureDummy.java b/backend/src/test/java/com/wire/bots/roman/resources/dummies/AuthenticationFeatureDummy.java index e082ffe..7c2b99d 100644 --- a/backend/src/test/java/com/wire/bots/roman/resources/dummies/AuthenticationFeatureDummy.java +++ b/backend/src/test/java/com/wire/bots/roman/resources/dummies/AuthenticationFeatureDummy.java @@ -1,11 +1,10 @@ package com.wire.bots.roman.resources.dummies; import com.wire.bots.roman.filters.ProxyAuthorization; - -import javax.ws.rs.container.DynamicFeature; -import javax.ws.rs.container.ResourceInfo; -import javax.ws.rs.core.FeatureContext; -import javax.ws.rs.ext.Provider; +import jakarta.ws.rs.container.DynamicFeature; +import jakarta.ws.rs.container.ResourceInfo; +import jakarta.ws.rs.core.FeatureContext; +import jakarta.ws.rs.ext.Provider; @Provider public class AuthenticationFeatureDummy implements DynamicFeature { diff --git a/backend/src/test/java/com/wire/bots/roman/resources/dummies/AuthenticationFilterDummy.java b/backend/src/test/java/com/wire/bots/roman/resources/dummies/AuthenticationFilterDummy.java index fc7cd61..8200f19 100644 --- a/backend/src/test/java/com/wire/bots/roman/resources/dummies/AuthenticationFilterDummy.java +++ b/backend/src/test/java/com/wire/bots/roman/resources/dummies/AuthenticationFilterDummy.java @@ -1,7 +1,7 @@ package com.wire.bots.roman.resources.dummies; -import javax.ws.rs.container.ContainerRequestContext; -import javax.ws.rs.container.ContainerRequestFilter; +import jakarta.ws.rs.container.ContainerRequestContext; +import jakarta.ws.rs.container.ContainerRequestFilter; public class AuthenticationFilterDummy implements ContainerRequestFilter { @Override diff --git a/backend/src/test/resources/roman-test.yml b/backend/src/test/resources/roman-test.yml new file mode 100644 index 0000000..4fbf1e5 --- /dev/null +++ b/backend/src/test/resources/roman-test.yml @@ -0,0 +1,78 @@ +server: + rootPath: /api + applicationConnectors: + - type: http + port: 8080 + maxRequestHeaderSize: 16KiB + + gzip: + bufferSize: 8KiB + enabled: true + + requestLog: + appenders: + - type: console + +logging: + level: INFO + appenders: + - type: console + loggers: + "org.reflections.Reflections": ERROR + "com.wire.bots.logger": ${LOG_LEVEL:-INFO} + +swagger: + # make sure that this settings is the same as "server.rootPath" + uriPrefix: /api + title: Roman Swagger + description: Roman - Wire Bots Proxy + contactEmail: dejan@wire.com + license: GPLv3 + version: 1.17.0 + resourcePackage: com.wire.bots.roman.resources + schemes: + - https + - http + +assets: + mappings: + /assets: / + overrides: + # the default assumes you have build frontend by "npm run build" + /: ${FRONTEND_PATH:-../frontend/build} + +jerseyClient: + timeout: 40s + connectionTimeout: 40s + connectionRequestTimeout: 40s + keepAlive: 0ms + retries: 3 + userAgent: roman + tls: + protocol: TLSv1.2 + provider: SunJSSE + supportedProtocols: + - TLSv1.1 + - TLSv1.2 + +database: + driverClass: org.h2.Driver + user: sa + password: sa + url: jdbc:h2:./target/test + +token: dummy +# used to sign JWT +key: ${APP_KEY:-} +# the public URL of the Roman instance, should end with "/api" as all Roman endpoints +# are served starting with /api +domain: ${PROXY_DOMAIN:-https://proxy.services.wire.com/api} +# URL of the Wire Backend +apiHost: ${WIRE_API_HOST:-https://prod-nginz-https.wire.com} + +# TLS public key of "domain" in base64 format - used to pin certificates in Wire backend +# for the bot +romanPubKeyBase64: ${ROMAN_PUB_KEY_BASE64:-default} + +# optional enabling of CORS - in format a.domain.com,another.domain.com +allowedCors: ${ALLOWED_CORS} From 3d2222a8f79654bbba0f1d7c97cfb7b3e92f234d Mon Sep 17 00:00:00 2001 From: Yamil Medina Date: Tue, 5 Dec 2023 14:44:48 +0100 Subject: [PATCH 13/34] fix: frontend config with new assetbundle aproach dropwizard4 (#129) * fix: frontend config with new assetbundle aproach dropwizard4 * fix: frontend config with new assetbundle aproach dropwizard4 --- Dockerfile | 7 ++++--- backend/pom.xml | 5 ----- backend/roman.yaml | 7 ------- .../main/java/com/wire/bots/roman/Application.java | 2 ++ .../main/java/com/wire/bots/roman/model/Config.java | 13 +------------ 5 files changed, 7 insertions(+), 27 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3eaaf08..ebcab9b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,6 +16,10 @@ RUN mvn verify --fail-never -U COPY backend/ ./ +# Copy frontend build to local resources classpath folder +ENV FRONTEND_PATH=/app/src/main/resources/frontend +COPY --from=frontend-build ./frontend/build $FRONTEND_PATH + RUN mvn -Dmaven.test.skip=true package FROM wirebot/runtime:1.4.0 AS runtime @@ -28,9 +32,6 @@ RUN apt-get update && apt-get upgrade -y # Copy backend COPY --from=build /app/target/roman.jar /opt/roman/backend/ COPY backend/roman.yaml /etc/roman/ -# Copy frontend -ENV FRONTEND_PATH=/opt/roman/frontend -COPY --from=frontend-build ./frontend/build $FRONTEND_PATH # create version file ARG release_version=development diff --git a/backend/pom.xml b/backend/pom.xml index da184b7..cbdd3c8 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -65,11 +65,6 @@ io.dropwizard dropwizard-servlets - - io.dropwizard-bundles - dropwizard-configurable-assets-bundle - 1.3.5 - jakarta.annotation diff --git a/backend/roman.yaml b/backend/roman.yaml index 134a625..fe24d4b 100644 --- a/backend/roman.yaml +++ b/backend/roman.yaml @@ -34,13 +34,6 @@ swagger: - https - http -assets: - mappings: - /assets: / - overrides: - # the default assumes you have build frontend by "npm run build" - /: ${FRONTEND_PATH:-../frontend/build} - jerseyClient: timeout: 40s connectionTimeout: 40s diff --git a/backend/src/main/java/com/wire/bots/roman/Application.java b/backend/src/main/java/com/wire/bots/roman/Application.java index 7528c0b..ba3aead 100644 --- a/backend/src/main/java/com/wire/bots/roman/Application.java +++ b/backend/src/main/java/com/wire/bots/roman/Application.java @@ -35,6 +35,7 @@ import com.wire.xenon.MessageHandlerBase; import com.wire.xenon.factories.CryptoFactory; import com.wire.xenon.factories.StorageFactory; +import io.dropwizard.assets.AssetsBundle; import io.dropwizard.core.setup.Bootstrap; import io.dropwizard.core.setup.Environment; import io.jsonwebtoken.security.Keys; @@ -70,6 +71,7 @@ public void initialize(Bootstrap bootstrap) { instance = (Application) bootstrap.getApplication(); bootstrap.addBundle(new WebsocketBundle(WebSocket.class)); bootstrap.addCommand(new UpdateCertCommand()); + bootstrap.addBundle(new AssetsBundle("/frontend", "/", "index.html")); } @Override diff --git a/backend/src/main/java/com/wire/bots/roman/model/Config.java b/backend/src/main/java/com/wire/bots/roman/model/Config.java index 98834e8..9a10d6b 100644 --- a/backend/src/main/java/com/wire/bots/roman/model/Config.java +++ b/backend/src/main/java/com/wire/bots/roman/model/Config.java @@ -21,14 +21,11 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.wire.lithium.Configuration; -import io.dropwizard.bundles.assets.AssetsBundleConfiguration; -import io.dropwizard.bundles.assets.AssetsConfiguration; import io.dropwizard.validation.ValidationMethod; - import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; -public class Config extends Configuration implements AssetsBundleConfiguration { +public class Config extends Configuration { @NotNull @JsonProperty public String key; @@ -45,14 +42,6 @@ public class Config extends Configuration implements AssetsBundleConfiguration { @JsonProperty public String romanPubKeyBase64; - @JsonProperty - public AssetsConfiguration assets; - - @Override - public AssetsConfiguration getAssetsConfiguration() { - return assets; - } - @ValidationMethod(message = "`romanPubKeyBase64` is not in a valid base64 format") @JsonIgnore public boolean pubKeyFormatIsNotValid() { From bf7879355127db1978fe685466298fbf53d3e177 Mon Sep 17 00:00:00 2001 From: Dejan Kovacevic Date: Wed, 6 Dec 2023 11:22:32 +0100 Subject: [PATCH 14/34] check for empty payload.url (#130) * check for empty payload.url * more logging --- .../com/wire/bots/roman/resources/ServiceResource.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/com/wire/bots/roman/resources/ServiceResource.java b/backend/src/main/java/com/wire/bots/roman/resources/ServiceResource.java index 3cbd506..0a85570 100644 --- a/backend/src/main/java/com/wire/bots/roman/resources/ServiceResource.java +++ b/backend/src/main/java/com/wire/bots/roman/resources/ServiceResource.java @@ -25,6 +25,7 @@ import jakarta.validation.Valid; import jakarta.validation.constraints.NotNull; + import java.net.MalformedURLException; import java.net.URISyntaxException; import java.net.URL; @@ -61,6 +62,11 @@ public Response create(@ApiParam(hidden = true) @CookieParam(Z_ROMAN) String tok @Context ContainerRequestContext context, @ApiParam @Valid _NewService payload) { try { + //hack + if (payload.url != null && payload.url.isEmpty()) { + payload.url = null; + } + UUID providerId = (UUID) context.getProperty(Const.PROVIDER_ID); Provider provider = providersDAO.get(providerId); @@ -122,7 +128,7 @@ public Response create(@ApiParam(hidden = true) @CookieParam(Z_ROMAN) String tok if (update.getStatus() >= 400) { String msg = update.readEntity(String.class); - Logger.debug("ServiceResource.create: enable service response: %s", msg); + Logger.debug("ServiceResource.create: enable service (%s) response: %s", service.id, msg); return Response. ok(msg). status(update.getStatus()). @@ -355,7 +361,7 @@ static class _NewService { @ValidationMethod(message = "`url` is not a valid URL") @JsonIgnore public boolean isUrlValid() { - if (url == null) + if (url == null || url.isEmpty()) return true; try { new URL(url).toURI(); From 7ba21115ca9020671bc83ba07164f04ae676466a Mon Sep 17 00:00:00 2001 From: Dejan Date: Wed, 6 Dec 2023 12:36:49 +0100 Subject: [PATCH 15/34] more logging --- .../src/main/java/com/wire/bots/roman/ProviderClient.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/backend/src/main/java/com/wire/bots/roman/ProviderClient.java b/backend/src/main/java/com/wire/bots/roman/ProviderClient.java index 6062a87..f15e0ea 100644 --- a/backend/src/main/java/com/wire/bots/roman/ProviderClient.java +++ b/backend/src/main/java/com/wire/bots/roman/ProviderClient.java @@ -7,6 +7,7 @@ import com.wire.xenon.models.AssetKey; import com.wire.xenon.tools.Logger; import com.wire.xenon.tools.Util; +import jakarta.validation.constraints.NotNull; import jakarta.ws.rs.client.Client; import jakarta.ws.rs.client.Entity; import jakarta.ws.rs.client.WebTarget; @@ -15,7 +16,6 @@ import jakarta.ws.rs.core.NewCookie; import jakarta.ws.rs.core.Response; -import jakarta.validation.constraints.NotNull; import java.io.ByteArrayOutputStream; import java.nio.charset.StandardCharsets; import java.util.ArrayList; @@ -74,9 +74,11 @@ public Response enableService(NewCookie zprovider, UUID serviceId, String passwo updateService.enabled = true; updateService.password = password; - return servicesTarget + WebTarget connection = servicesTarget .path(serviceId.toString()) - .path("connection") + .path("connection"); + Logger.debug("enableService: PUT %s", connection.getUri()); + return connection .request(MediaType.APPLICATION_JSON) .cookie(zprovider) .put(Entity.entity(updateService, MediaType.APPLICATION_JSON)); From 5380e09008f98423ea450ea73a8e87b20cee56ea Mon Sep 17 00:00:00 2001 From: Dejan Date: Wed, 6 Dec 2023 12:50:16 +0100 Subject: [PATCH 16/34] Skip the enable service --- .../bots/roman/resources/ServiceResource.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/backend/src/main/java/com/wire/bots/roman/resources/ServiceResource.java b/backend/src/main/java/com/wire/bots/roman/resources/ServiceResource.java index 0a85570..bc80d91 100644 --- a/backend/src/main/java/com/wire/bots/roman/resources/ServiceResource.java +++ b/backend/src/main/java/com/wire/bots/roman/resources/ServiceResource.java @@ -14,6 +14,8 @@ import com.wire.xenon.tools.Logger; import io.dropwizard.validation.ValidationMethod; import io.swagger.annotations.*; +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotNull; import jakarta.ws.rs.*; import jakarta.ws.rs.container.ContainerRequestContext; import jakarta.ws.rs.core.Context; @@ -23,9 +25,6 @@ import org.hibernate.validator.constraints.Length; import org.jdbi.v3.core.Jdbi; -import jakarta.validation.Valid; -import jakarta.validation.constraints.NotNull; - import java.net.MalformedURLException; import java.net.URISyntaxException; import java.net.URL; @@ -126,14 +125,14 @@ public Response create(@ApiParam(hidden = true) @CookieParam(Z_ROMAN) String tok Logger.debug("ServiceResource.create: enable service status: %d", update.getStatus()); - if (update.getStatus() >= 400) { - String msg = update.readEntity(String.class); - Logger.debug("ServiceResource.create: enable service (%s) response: %s", service.id, msg); - return Response. - ok(msg). - status(update.getStatus()). - build(); - } +// if (update.getStatus() >= 400) { +// String msg = update.readEntity(String.class); +// Logger.debug("ServiceResource.create: enable service (%s) response: %s", service.id, msg); +// return Response. +// ok(msg). +// status(update.getStatus()). +// build(); +// } providersDAO.update(providerId, payload.url, service.auth, service.id, payload.name, payload.commandPrefix); From a344e109ce54dd0b4267d5a28fa290387c086a06 Mon Sep 17 00:00:00 2001 From: Dejan Date: Thu, 7 Dec 2023 11:45:09 +0100 Subject: [PATCH 17/34] More logging --- .../java/com/wire/bots/roman/ProviderClient.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/backend/src/main/java/com/wire/bots/roman/ProviderClient.java b/backend/src/main/java/com/wire/bots/roman/ProviderClient.java index f15e0ea..e9d2660 100644 --- a/backend/src/main/java/com/wire/bots/roman/ProviderClient.java +++ b/backend/src/main/java/com/wire/bots/roman/ProviderClient.java @@ -11,15 +11,14 @@ import jakarta.ws.rs.client.Client; import jakarta.ws.rs.client.Entity; import jakarta.ws.rs.client.WebTarget; -import jakarta.ws.rs.core.Cookie; -import jakarta.ws.rs.core.MediaType; -import jakarta.ws.rs.core.NewCookie; -import jakarta.ws.rs.core.Response; +import jakarta.ws.rs.core.*; +import org.glassfish.jersey.logging.LoggingFeature; import java.io.ByteArrayOutputStream; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.UUID; +import java.util.logging.Level; public class ProviderClient { private final WebTarget servicesTarget; @@ -30,6 +29,12 @@ public ProviderClient(Client jerseyClient, String apiHost) { .path("provider"); servicesTarget = providerTarget .path("services"); + + if (Logger.getLevel() == Level.FINE) { + Feature feature = new LoggingFeature(Logger.getLOGGER(), Level.FINE, null, null); + providerTarget.register(feature); + servicesTarget.register(feature); + } } public Response register(String name, String email) { @@ -80,6 +85,7 @@ public Response enableService(NewCookie zprovider, UUID serviceId, String passwo Logger.debug("enableService: PUT %s", connection.getUri()); return connection .request(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON) .cookie(zprovider) .put(Entity.entity(updateService, MediaType.APPLICATION_JSON)); } From c8ca23b35d3c2e94bd09d83d225fb03142d5eceb Mon Sep 17 00:00:00 2001 From: Dejan Date: Thu, 7 Dec 2023 13:42:56 +0100 Subject: [PATCH 18/34] Dont send Enable=false in UpdateService --- .../com/wire/bots/roman/ProviderClient.java | 3 +-- .../bots/roman/resources/ServiceResource.java | 22 +++++++++---------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/backend/src/main/java/com/wire/bots/roman/ProviderClient.java b/backend/src/main/java/com/wire/bots/roman/ProviderClient.java index e9d2660..5432df9 100644 --- a/backend/src/main/java/com/wire/bots/roman/ProviderClient.java +++ b/backend/src/main/java/com/wire/bots/roman/ProviderClient.java @@ -82,7 +82,6 @@ public Response enableService(NewCookie zprovider, UUID serviceId, String passwo WebTarget connection = servicesTarget .path(serviceId.toString()) .path("connection"); - Logger.debug("enableService: PUT %s", connection.getUri()); return connection .request(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON) @@ -208,7 +207,7 @@ static class _UpdateService { public String name; @JsonProperty - public boolean enabled; + public Boolean enabled; @JsonProperty("public_keys") public String[] pubKeys; diff --git a/backend/src/main/java/com/wire/bots/roman/resources/ServiceResource.java b/backend/src/main/java/com/wire/bots/roman/resources/ServiceResource.java index bc80d91..bb4e72d 100644 --- a/backend/src/main/java/com/wire/bots/roman/resources/ServiceResource.java +++ b/backend/src/main/java/com/wire/bots/roman/resources/ServiceResource.java @@ -80,12 +80,11 @@ public Response create(@ApiParam(hidden = true) @CookieParam(Z_ROMAN) String tok NewCookie cookie; try (Response login = providerClient.login(provider.email, provider.password)) { - Logger.debug("ServiceResource.create: login status: %d", login.getStatus()); if (login.getStatus() >= 400) { String msg = login.readEntity(String.class); - Logger.debug("ServiceResource.create: login response: %s", msg); + Logger.warning("ServiceResource.create: login response: %s", msg); return Response. ok(msg). status(login.getStatus()). @@ -111,7 +110,7 @@ public Response create(@ApiParam(hidden = true) @CookieParam(Z_ROMAN) String tok if (create.getStatus() >= 400) { String msg = create.readEntity(String.class); - Logger.debug("ServiceResource.create: create service response: %s", msg); + Logger.warning("ServiceResource.create: create service response: %s", msg); return Response. ok(msg). status(create.getStatus()). @@ -122,17 +121,16 @@ public Response create(@ApiParam(hidden = true) @CookieParam(Z_ROMAN) String tok } try (Response update = providerClient.enableService(cookie, service.id, provider.password)) { - Logger.debug("ServiceResource.create: enable service status: %d", update.getStatus()); -// if (update.getStatus() >= 400) { -// String msg = update.readEntity(String.class); -// Logger.debug("ServiceResource.create: enable service (%s) response: %s", service.id, msg); -// return Response. -// ok(msg). -// status(update.getStatus()). -// build(); -// } + if (update.getStatus() >= 400) { + String msg = update.readEntity(String.class); + Logger.warning("ServiceResource.create: enable service (%s) response: %s", service.id, msg); + return Response. + ok(msg). + status(update.getStatus()). + build(); + } providersDAO.update(providerId, payload.url, service.auth, service.id, payload.name, payload.commandPrefix); From 02d17f08c247eba826e69d337e6a0d51f3a99c50 Mon Sep 17 00:00:00 2001 From: Dejan Date: Thu, 7 Dec 2023 14:10:13 +0100 Subject: [PATCH 19/34] Use single WebTarge in ProviderClient --- .../com/wire/bots/roman/ProviderClient.java | 44 ++++++++++++------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/backend/src/main/java/com/wire/bots/roman/ProviderClient.java b/backend/src/main/java/com/wire/bots/roman/ProviderClient.java index 5432df9..fca8bfe 100644 --- a/backend/src/main/java/com/wire/bots/roman/ProviderClient.java +++ b/backend/src/main/java/com/wire/bots/roman/ProviderClient.java @@ -21,19 +21,14 @@ import java.util.logging.Level; public class ProviderClient { - private final WebTarget servicesTarget; private final WebTarget providerTarget; public ProviderClient(Client jerseyClient, String apiHost) { - providerTarget = jerseyClient.target(apiHost) - .path("provider"); - servicesTarget = providerTarget - .path("services"); + providerTarget = jerseyClient.target(apiHost); if (Logger.getLevel() == Level.FINE) { Feature feature = new LoggingFeature(Logger.getLOGGER(), Level.FINE, null, null); providerTarget.register(feature); - servicesTarget.register(feature); } } @@ -44,7 +39,9 @@ public Response register(String name, String email) { newProvider.description = "Description"; newProvider.url = "https://wire.com"; - return providerTarget.path("register") + return providerTarget + .path("provider") + .path("register") .request(MediaType.APPLICATION_JSON) .post(Entity.entity(newProvider, MediaType.APPLICATION_JSON)); } @@ -54,20 +51,26 @@ public Response login(String email, String password) { signIn.email = email; signIn.password = password; - return providerTarget.path("login") + return providerTarget + .path("provider") + .path("login") .request(MediaType.APPLICATION_JSON) .post(Entity.entity(signIn, MediaType.APPLICATION_JSON)); } public Response createService(NewCookie zprovider, Service service) { - return servicesTarget + return providerTarget + .path("provider") + .path("services") .request(MediaType.APPLICATION_JSON) .cookie(zprovider) .post(Entity.entity(service, MediaType.APPLICATION_JSON)); } public Response deleteService(NewCookie zprovider, UUID serviceId) { - return servicesTarget + return providerTarget + .path("provider") + .path("services") .path(serviceId.toString()) .request(MediaType.APPLICATION_JSON) .cookie(zprovider) @@ -79,7 +82,9 @@ public Response enableService(NewCookie zprovider, UUID serviceId, String passwo updateService.enabled = true; updateService.password = password; - WebTarget connection = servicesTarget + WebTarget connection = providerTarget + .path("provider") + .path("services") .path(serviceId.toString()) .path("connection"); return connection @@ -93,7 +98,9 @@ public Response updateServiceName(NewCookie zprovider, UUID serviceId, String na _UpdateService updateService = new _UpdateService(); updateService.name = name; - return servicesTarget + return providerTarget + .path("provider") + .path("services") .path(serviceId.toString()) .request(MediaType.APPLICATION_JSON) .cookie(zprovider) @@ -116,7 +123,9 @@ public Response updateServiceAvatar(NewCookie zprovider, UUID serviceId, String updateService.assets = assets; - return servicesTarget + return providerTarget + .path("provider") + .path("services") .path(serviceId.toString()) .request(MediaType.APPLICATION_JSON) .cookie(zprovider) @@ -128,7 +137,9 @@ public Response updateServicePubKey(NewCookie zprovider, UUID serviceId, String updateService.pubKeys = new String[]{pubkey}; updateService.password = password; - return servicesTarget + return providerTarget + .path("provider") + .path("services") .path(serviceId.toString()) .path("connection") .request(MediaType.APPLICATION_JSON) @@ -141,7 +152,9 @@ public Response updateServiceURL(NewCookie zprovider, UUID serviceId, String pas updateService.baseUrl = url; updateService.password = password; - return servicesTarget + return providerTarget + .path("provider") + .path("services") .path(serviceId.toString()) .path("connection") .request(MediaType.APPLICATION_JSON) @@ -183,6 +196,7 @@ public String uploadProfilePicture(Cookie cookie, byte[] image, String mimeType) os.write("\r\n--frontier--\r\n".getBytes(StandardCharsets.UTF_8)); Response response = providerTarget + .path("provider") .path("assets") .request(MediaType.APPLICATION_JSON_TYPE) .cookie(cookie) From 6e446811760277966ef5b165c1d8923f1c8d0b0f Mon Sep 17 00:00:00 2001 From: Dejan Date: Thu, 7 Dec 2023 15:05:23 +0100 Subject: [PATCH 20/34] .accept(MediaType.TEXT_PLAIN) --- backend/src/main/java/com/wire/bots/roman/ProviderClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main/java/com/wire/bots/roman/ProviderClient.java b/backend/src/main/java/com/wire/bots/roman/ProviderClient.java index fca8bfe..310ccac 100644 --- a/backend/src/main/java/com/wire/bots/roman/ProviderClient.java +++ b/backend/src/main/java/com/wire/bots/roman/ProviderClient.java @@ -89,7 +89,7 @@ public Response enableService(NewCookie zprovider, UUID serviceId, String passwo .path("connection"); return connection .request(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON) + .accept(MediaType.TEXT_PLAIN) .cookie(zprovider) .put(Entity.entity(updateService, MediaType.APPLICATION_JSON)); } From 11b7a637881fb2a29510d8a20533f8818967a00e Mon Sep 17 00:00:00 2001 From: Dejan Date: Thu, 7 Dec 2023 15:16:47 +0100 Subject: [PATCH 21/34] .accept(MediaType.TEXT_PLAIN) --- backend/src/main/java/com/wire/bots/roman/ProviderClient.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/backend/src/main/java/com/wire/bots/roman/ProviderClient.java b/backend/src/main/java/com/wire/bots/roman/ProviderClient.java index 310ccac..37c522a 100644 --- a/backend/src/main/java/com/wire/bots/roman/ProviderClient.java +++ b/backend/src/main/java/com/wire/bots/roman/ProviderClient.java @@ -103,6 +103,7 @@ public Response updateServiceName(NewCookie zprovider, UUID serviceId, String na .path("services") .path(serviceId.toString()) .request(MediaType.APPLICATION_JSON) + .accept(MediaType.TEXT_PLAIN) .cookie(zprovider) .put(Entity.entity(updateService, MediaType.APPLICATION_JSON)); } @@ -143,6 +144,7 @@ public Response updateServicePubKey(NewCookie zprovider, UUID serviceId, String .path(serviceId.toString()) .path("connection") .request(MediaType.APPLICATION_JSON) + .accept(MediaType.TEXT_PLAIN) .cookie(zprovider) .put(Entity.entity(updateService, MediaType.APPLICATION_JSON)); } @@ -158,6 +160,7 @@ public Response updateServiceURL(NewCookie zprovider, UUID serviceId, String pas .path(serviceId.toString()) .path("connection") .request(MediaType.APPLICATION_JSON) + .accept(MediaType.TEXT_PLAIN) .cookie(zprovider) .put(Entity.entity(updateService, MediaType.APPLICATION_JSON)); } From d0eb7ab54a977a2942a2799c0d99302abf772ce1 Mon Sep 17 00:00:00 2001 From: Dejan Date: Thu, 7 Dec 2023 15:20:25 +0100 Subject: [PATCH 22/34] .request(MediaType.TEXT_PLAIN) --- backend/src/main/java/com/wire/bots/roman/ProviderClient.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/backend/src/main/java/com/wire/bots/roman/ProviderClient.java b/backend/src/main/java/com/wire/bots/roman/ProviderClient.java index 37c522a..f08d092 100644 --- a/backend/src/main/java/com/wire/bots/roman/ProviderClient.java +++ b/backend/src/main/java/com/wire/bots/roman/ProviderClient.java @@ -102,8 +102,7 @@ public Response updateServiceName(NewCookie zprovider, UUID serviceId, String na .path("provider") .path("services") .path(serviceId.toString()) - .request(MediaType.APPLICATION_JSON) - .accept(MediaType.TEXT_PLAIN) + .request(MediaType.TEXT_PLAIN) .cookie(zprovider) .put(Entity.entity(updateService, MediaType.APPLICATION_JSON)); } From fc4dc8749254502d80592e2996adc96dc00e1046 Mon Sep 17 00:00:00 2001 From: Dejan Date: Thu, 7 Dec 2023 15:28:03 +0100 Subject: [PATCH 23/34] .request(MediaType.TEXT_PLAIN) --- .../com/wire/bots/roman/ProviderClient.java | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/backend/src/main/java/com/wire/bots/roman/ProviderClient.java b/backend/src/main/java/com/wire/bots/roman/ProviderClient.java index f08d092..39aebbe 100644 --- a/backend/src/main/java/com/wire/bots/roman/ProviderClient.java +++ b/backend/src/main/java/com/wire/bots/roman/ProviderClient.java @@ -72,7 +72,7 @@ public Response deleteService(NewCookie zprovider, UUID serviceId) { .path("provider") .path("services") .path(serviceId.toString()) - .request(MediaType.APPLICATION_JSON) + .request(MediaType.TEXT_PLAIN) .cookie(zprovider) .delete(); } @@ -82,14 +82,12 @@ public Response enableService(NewCookie zprovider, UUID serviceId, String passwo updateService.enabled = true; updateService.password = password; - WebTarget connection = providerTarget + providerTarget .path("provider") .path("services") .path(serviceId.toString()) - .path("connection"); - return connection - .request(MediaType.APPLICATION_JSON) - .accept(MediaType.TEXT_PLAIN) + .path("connection") + .request(MediaType.TEXT_PLAIN) .cookie(zprovider) .put(Entity.entity(updateService, MediaType.APPLICATION_JSON)); } @@ -127,7 +125,7 @@ public Response updateServiceAvatar(NewCookie zprovider, UUID serviceId, String .path("provider") .path("services") .path(serviceId.toString()) - .request(MediaType.APPLICATION_JSON) + .request(MediaType.TEXT_PLAIN) .cookie(zprovider) .put(Entity.entity(updateService, MediaType.APPLICATION_JSON)); } @@ -142,8 +140,7 @@ public Response updateServicePubKey(NewCookie zprovider, UUID serviceId, String .path("services") .path(serviceId.toString()) .path("connection") - .request(MediaType.APPLICATION_JSON) - .accept(MediaType.TEXT_PLAIN) + .request(MediaType.TEXT_PLAIN) .cookie(zprovider) .put(Entity.entity(updateService, MediaType.APPLICATION_JSON)); } @@ -158,8 +155,7 @@ public Response updateServiceURL(NewCookie zprovider, UUID serviceId, String pas .path("services") .path(serviceId.toString()) .path("connection") - .request(MediaType.APPLICATION_JSON) - .accept(MediaType.TEXT_PLAIN) + .request(MediaType.TEXT_PLAIN) .cookie(zprovider) .put(Entity.entity(updateService, MediaType.APPLICATION_JSON)); } From 40569a54081bddbe268309942ace0f06f5dee38d Mon Sep 17 00:00:00 2001 From: Dejan Date: Thu, 7 Dec 2023 15:35:13 +0100 Subject: [PATCH 24/34] fixed the build --- backend/src/main/java/com/wire/bots/roman/ProviderClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main/java/com/wire/bots/roman/ProviderClient.java b/backend/src/main/java/com/wire/bots/roman/ProviderClient.java index 39aebbe..5e5336f 100644 --- a/backend/src/main/java/com/wire/bots/roman/ProviderClient.java +++ b/backend/src/main/java/com/wire/bots/roman/ProviderClient.java @@ -82,7 +82,7 @@ public Response enableService(NewCookie zprovider, UUID serviceId, String passwo updateService.enabled = true; updateService.password = password; - providerTarget + return providerTarget .path("provider") .path("services") .path(serviceId.toString()) From 282176801f7ced03b5bca6d32e9d26013e5175bb Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 8 Dec 2023 15:01:49 +0100 Subject: [PATCH 25/34] Bump word-wrap from 1.2.3 to 1.2.5 in /frontend (#123) Bumps [word-wrap](https://github.com/jonschlinkert/word-wrap) from 1.2.3 to 1.2.5. - [Release notes](https://github.com/jonschlinkert/word-wrap/releases) - [Commits](https://github.com/jonschlinkert/word-wrap/compare/1.2.3...1.2.5) --- updated-dependencies: - dependency-name: word-wrap dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- frontend/package-lock.json | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/frontend/package-lock.json b/frontend/package-lock.json index c2b8a64..d084c80 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -4333,6 +4333,17 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/ansi-escapes/node_modules/type-fest": { + "version": "0.21.3", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.21.3.tgz", + "integrity": "sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w==", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/ansi-html": { "version": "0.0.7", "resolved": "https://registry.npmjs.org/ansi-html/-/ansi-html-0.0.7.tgz", @@ -18737,9 +18748,11 @@ } }, "node_modules/type-fest": { - "version": "0.21.3", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.21.3.tgz", - "integrity": "sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w==", + "version": "0.13.1", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.13.1.tgz", + "integrity": "sha512-34R7HTnG0XIJcBSn5XhDd7nNFPRcXYRZrBB2O2jdKqYODldSzBAqzsWoZYYvduky73toYS/ESqxPvkDf/F0XMg==", + "optional": true, + "peer": true, "engines": { "node": ">=10" }, @@ -20715,9 +20728,9 @@ } }, "node_modules/word-wrap": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", - "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==", + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz", + "integrity": "sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==", "engines": { "node": ">=0.10.0" } From 162020d6fa1de185b6a53c4b53c5426f21a23c85 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 8 Dec 2023 15:01:58 +0100 Subject: [PATCH 26/34] Bump @adobe/css-tools from 4.2.0 to 4.3.2 in /frontend (#122) Bumps [@adobe/css-tools](https://github.com/adobe/css-tools) from 4.2.0 to 4.3.2. - [Changelog](https://github.com/adobe/css-tools/blob/main/History.md) - [Commits](https://github.com/adobe/css-tools/commits) --- updated-dependencies: - dependency-name: "@adobe/css-tools" dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- frontend/package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frontend/package-lock.json b/frontend/package-lock.json index d084c80..ae59c4e 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -31,9 +31,9 @@ } }, "node_modules/@adobe/css-tools": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/@adobe/css-tools/-/css-tools-4.2.0.tgz", - "integrity": "sha512-E09FiIft46CmH5Qnjb0wsW54/YQd69LsxeKUOWawmws1XWvyFGURnAChH0mlr7YPFR1ofwvUQfcL0J3lMxXqPA==", + "version": "4.3.2", + "resolved": "https://registry.npmjs.org/@adobe/css-tools/-/css-tools-4.3.2.tgz", + "integrity": "sha512-DA5a1C0gD/pLOvhv33YMrbf2FK3oUzwNl9oOJqE4XVjuEtt6XIakRcsd7eLiOSPkp1kTRQGICTA8cKra/vFbjw==", "dev": true }, "node_modules/@ampproject/remapping": { From 7de821cb0e6e4839792b04504db4a4a88e67ff6e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 8 Dec 2023 15:02:08 +0100 Subject: [PATCH 27/34] Bump browserify-sign from 4.2.1 to 4.2.2 in /frontend (#125) Bumps [browserify-sign](https://github.com/crypto-browserify/browserify-sign) from 4.2.1 to 4.2.2. - [Changelog](https://github.com/browserify/browserify-sign/blob/main/CHANGELOG.md) - [Commits](https://github.com/crypto-browserify/browserify-sign/compare/v4.2.1...v4.2.2) --- updated-dependencies: - dependency-name: browserify-sign dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- frontend/package-lock.json | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/frontend/package-lock.json b/frontend/package-lock.json index ae59c4e..877165b 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -5283,25 +5283,28 @@ } }, "node_modules/browserify-sign": { - "version": "4.2.1", - "resolved": "https://registry.npmjs.org/browserify-sign/-/browserify-sign-4.2.1.tgz", - "integrity": "sha512-/vrA5fguVAKKAVTNJjgSm1tRQDHUU6DbwO9IROu/0WAzC8PKhucDSh18J0RMvVeHAn5puMd+QHC2erPRNf8lmg==", + "version": "4.2.2", + "resolved": "https://registry.npmjs.org/browserify-sign/-/browserify-sign-4.2.2.tgz", + "integrity": "sha512-1rudGyeYY42Dk6texmv7c4VcQ0EsvVbLwZkA+AQB7SxvXxmcD93jcHie8bzecJ+ChDlmAm2Qyu0+Ccg5uhZXCg==", "dependencies": { - "bn.js": "^5.1.1", - "browserify-rsa": "^4.0.1", + "bn.js": "^5.2.1", + "browserify-rsa": "^4.1.0", "create-hash": "^1.2.0", "create-hmac": "^1.1.7", - "elliptic": "^6.5.3", + "elliptic": "^6.5.4", "inherits": "^2.0.4", - "parse-asn1": "^5.1.5", - "readable-stream": "^3.6.0", - "safe-buffer": "^5.2.0" + "parse-asn1": "^5.1.6", + "readable-stream": "^3.6.2", + "safe-buffer": "^5.2.1" + }, + "engines": { + "node": ">= 4" } }, "node_modules/browserify-sign/node_modules/readable-stream": { - "version": "3.6.1", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.1.tgz", - "integrity": "sha512-+rQmrWMYGA90yenhTYsLWAsLsqVC8osOw6PKE1HDYiO0gdPeKe/xDHNzIAIn4C91YQ6oenEhfYqqc1883qHbjQ==", + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", + "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", "dependencies": { "inherits": "^2.0.3", "string_decoder": "^1.1.1", From a2d01e2a80adedb04b7c2c347aa31887397a08c6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 8 Dec 2023 15:02:23 +0100 Subject: [PATCH 28/34] Bump semver from 5.7.1 to 5.7.2 in /frontend (#124) Bumps [semver](https://github.com/npm/node-semver) from 5.7.1 to 5.7.2. - [Release notes](https://github.com/npm/node-semver/releases) - [Changelog](https://github.com/npm/node-semver/blob/v5.7.2/CHANGELOG.md) - [Commits](https://github.com/npm/node-semver/compare/v5.7.1...v5.7.2) --- updated-dependencies: - dependency-name: semver dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- frontend/package-lock.json | 138 ++++++++++++++++++------------------- 1 file changed, 69 insertions(+), 69 deletions(-) diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 877165b..900813f 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -109,9 +109,9 @@ } }, "node_modules/@babel/core/node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "bin": { "semver": "bin/semver.js" } @@ -172,9 +172,9 @@ } }, "node_modules/@babel/helper-compilation-targets/node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "bin": { "semver": "bin/semver.js" } @@ -232,9 +232,9 @@ } }, "node_modules/@babel/helper-define-polyfill-provider/node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "bin": { "semver": "bin/semver.js" } @@ -1567,9 +1567,9 @@ } }, "node_modules/@babel/plugin-transform-runtime/node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "bin": { "semver": "bin/semver.js" } @@ -1779,9 +1779,9 @@ } }, "node_modules/@babel/preset-env/node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "bin": { "semver": "bin/semver.js" } @@ -2428,9 +2428,9 @@ } }, "node_modules/@jest/reporters/node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "bin": { "semver": "bin/semver.js" } @@ -2927,9 +2927,9 @@ } }, "node_modules/@npmcli/fs/node_modules/semver": { - "version": "7.3.8", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz", - "integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==", + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", "dependencies": { "lru-cache": "^6.0.0" }, @@ -3845,9 +3845,9 @@ } }, "node_modules/@typescript-eslint/eslint-plugin/node_modules/semver": { - "version": "7.3.8", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz", - "integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==", + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", "dependencies": { "lru-cache": "^6.0.0" }, @@ -3978,9 +3978,9 @@ } }, "node_modules/@typescript-eslint/typescript-estree/node_modules/semver": { - "version": "7.3.8", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz", - "integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==", + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", "dependencies": { "lru-cache": "^6.0.0" }, @@ -4886,9 +4886,9 @@ } }, "node_modules/babel-plugin-polyfill-corejs2/node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "bin": { "semver": "bin/semver.js" } @@ -6922,9 +6922,9 @@ } }, "node_modules/default-gateway/node_modules/semver": { - "version": "5.7.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", - "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", + "version": "5.7.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz", + "integrity": "sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==", "bin": { "semver": "bin/semver" } @@ -7941,9 +7941,9 @@ } }, "node_modules/eslint-plugin-import/node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "bin": { "semver": "bin/semver.js" } @@ -7998,9 +7998,9 @@ } }, "node_modules/eslint-plugin-jsx-a11y/node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "bin": { "semver": "bin/semver.js" } @@ -8072,9 +8072,9 @@ } }, "node_modules/eslint-plugin-react/node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "bin": { "semver": "bin/semver.js" } @@ -9210,9 +9210,9 @@ } }, "node_modules/fork-ts-checker-webpack-plugin/node_modules/semver": { - "version": "5.7.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", - "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", + "version": "5.7.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz", + "integrity": "sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==", "bin": { "semver": "bin/semver" } @@ -10986,9 +10986,9 @@ } }, "node_modules/istanbul-lib-instrument/node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "bin": { "semver": "bin/semver.js" } @@ -11021,9 +11021,9 @@ } }, "node_modules/istanbul-lib-report/node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "bin": { "semver": "bin/semver.js" } @@ -12321,9 +12321,9 @@ } }, "node_modules/make-dir/node_modules/semver": { - "version": "5.7.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", - "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", + "version": "5.7.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz", + "integrity": "sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==", "bin": { "semver": "bin/semver" } @@ -12898,9 +12898,9 @@ } }, "node_modules/normalize-package-data/node_modules/semver": { - "version": "5.7.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", - "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", + "version": "5.7.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz", + "integrity": "sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==", "bin": { "semver": "bin/semver" } @@ -15692,9 +15692,9 @@ } }, "node_modules/react-scripts/node_modules/@babel/core/node_modules/semver": { - "version": "5.7.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", - "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", + "version": "5.7.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz", + "integrity": "sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==", "bin": { "semver": "bin/semver" } @@ -16742,9 +16742,9 @@ } }, "node_modules/sane/node_modules/semver": { - "version": "5.7.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", - "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", + "version": "5.7.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz", + "integrity": "sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==", "bin": { "semver": "bin/semver" } @@ -18435,9 +18435,9 @@ } }, "node_modules/terser-webpack-plugin/node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "bin": { "semver": "bin/semver.js" } @@ -20099,9 +20099,9 @@ } }, "node_modules/webpack-dev-server/node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "bin": { "semver": "bin/semver.js" } From c9259651a48c2189fdac7b0471b5a7ede6b0272d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 8 Dec 2023 15:02:59 +0100 Subject: [PATCH 29/34] Bump @babel/traverse from 7.21.2 to 7.23.5 in /frontend (#126) Bumps [@babel/traverse](https://github.com/babel/babel/tree/HEAD/packages/babel-traverse) from 7.21.2 to 7.23.5. - [Release notes](https://github.com/babel/babel/releases) - [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md) - [Commits](https://github.com/babel/babel/commits/v7.23.5/packages/babel-traverse) --- updated-dependencies: - dependency-name: "@babel/traverse" dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- frontend/package-lock.json | 187 +++++++++++++++++++++++++------------ 1 file changed, 126 insertions(+), 61 deletions(-) diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 900813f..de8b678 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -61,16 +61,81 @@ } }, "node_modules/@babel/code-frame": { - "version": "7.18.6", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.18.6.tgz", - "integrity": "sha512-TDCmlK5eOvH+eH7cdAFlNXeVJqWIQ7gW9tY1GJIpUtFb6CmjVyq2VM3u71bOyR8CRihcCgMUYoDNyLXao3+70Q==", + "version": "7.23.5", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.23.5.tgz", + "integrity": "sha512-CgH3s1a96LipHCmSUmYFPwY7MNx8C3avkq7i4Wl3cfa662ldtUe4VM1TPXX70pfmrlWTb6jLqTYrZyT2ZTJBgA==", "dependencies": { - "@babel/highlight": "^7.18.6" + "@babel/highlight": "^7.23.4", + "chalk": "^2.4.2" }, "engines": { "node": ">=6.9.0" } }, + "node_modules/@babel/code-frame/node_modules/ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "dependencies": { + "color-convert": "^1.9.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/@babel/code-frame/node_modules/chalk": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", + "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", + "dependencies": { + "ansi-styles": "^3.2.1", + "escape-string-regexp": "^1.0.5", + "supports-color": "^5.3.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/@babel/code-frame/node_modules/color-convert": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "dependencies": { + "color-name": "1.1.3" + } + }, + "node_modules/@babel/code-frame/node_modules/color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==" + }, + "node_modules/@babel/code-frame/node_modules/escape-string-regexp": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", + "integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==", + "engines": { + "node": ">=0.8.0" + } + }, + "node_modules/@babel/code-frame/node_modules/has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==", + "engines": { + "node": ">=4" + } + }, + "node_modules/@babel/code-frame/node_modules/supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "dependencies": { + "has-flag": "^3.0.0" + }, + "engines": { + "node": ">=4" + } + }, "node_modules/@babel/compat-data": { "version": "7.21.0", "resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.21.0.tgz", @@ -117,11 +182,11 @@ } }, "node_modules/@babel/generator": { - "version": "7.21.1", - "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.21.1.tgz", - "integrity": "sha512-1lT45bAYlQhFn/BHivJs43AiW2rg3/UbLyShGfF3C0KmHvO5fSghWd5kBJy30kpRRucGzXStvnnCFniCR2kXAA==", + "version": "7.23.5", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.23.5.tgz", + "integrity": "sha512-BPssCHrBD+0YrxviOa3QzpqwhNIXKEtOa2jQrm4FlmkC2apYgRnQcmPWiGZDlGxiNtltnUFolMe8497Esry+jA==", "dependencies": { - "@babel/types": "^7.21.0", + "@babel/types": "^7.23.5", "@jridgewell/gen-mapping": "^0.3.2", "@jridgewell/trace-mapping": "^0.3.17", "jsesc": "^2.5.1" @@ -240,9 +305,9 @@ } }, "node_modules/@babel/helper-environment-visitor": { - "version": "7.18.9", - "resolved": "https://registry.npmjs.org/@babel/helper-environment-visitor/-/helper-environment-visitor-7.18.9.tgz", - "integrity": "sha512-3r/aACDJ3fhQ/EVgFy0hpj8oHyHpQc+LPtJoY9SzTThAsStm4Ptegq92vqKoE3vD706ZVFWITnMnxucw+S9Ipg==", + "version": "7.22.20", + "resolved": "https://registry.npmjs.org/@babel/helper-environment-visitor/-/helper-environment-visitor-7.22.20.tgz", + "integrity": "sha512-zfedSIzFhat/gFhWfHtgWvlec0nqB9YEIVrpuwjruLlXfUSnA8cJB0miHKwqDnQ7d32aKo2xt88/xZptwxbfhA==", "engines": { "node": ">=6.9.0" } @@ -259,23 +324,23 @@ } }, "node_modules/@babel/helper-function-name": { - "version": "7.21.0", - "resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.21.0.tgz", - "integrity": "sha512-HfK1aMRanKHpxemaY2gqBmL04iAPOPRj7DxtNbiDOrJK+gdwkiNRVpCpUJYbUT+aZyemKN8brqTOxzCaG6ExRg==", + "version": "7.23.0", + "resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.23.0.tgz", + "integrity": "sha512-OErEqsrxjZTJciZ4Oo+eoZqeW9UIiOcuYKRJA4ZAgV9myA+pOXhhmpfNCKjEH/auVfEYVFJ6y1Tc4r0eIApqiw==", "dependencies": { - "@babel/template": "^7.20.7", - "@babel/types": "^7.21.0" + "@babel/template": "^7.22.15", + "@babel/types": "^7.23.0" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-hoist-variables": { - "version": "7.18.6", - "resolved": "https://registry.npmjs.org/@babel/helper-hoist-variables/-/helper-hoist-variables-7.18.6.tgz", - "integrity": "sha512-UlJQPkFqFULIcyW5sbzgbkxn2FKRgwWiRexcuaR8RNJRy8+LLveqPjwZV/bwrLZCN0eUHD/x8D0heK1ozuoo6Q==", + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/helper-hoist-variables/-/helper-hoist-variables-7.22.5.tgz", + "integrity": "sha512-wGjk9QZVzvknA6yKIUURb8zY3grXCcOZt+/7Wcy8O2uctxhplmUPkOdlgoNhmdVee2c92JXbf1xpMtVNbfoxRw==", "dependencies": { - "@babel/types": "^7.18.6" + "@babel/types": "^7.22.5" }, "engines": { "node": ">=6.9.0" @@ -396,28 +461,28 @@ } }, "node_modules/@babel/helper-split-export-declaration": { - "version": "7.18.6", - "resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.18.6.tgz", - "integrity": "sha512-bde1etTx6ZyTmobl9LLMMQsaizFVZrquTEHOqKeQESMKo4PlObf+8+JA25ZsIpZhT/WEd39+vOdLXAFG/nELpA==", + "version": "7.22.6", + "resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.22.6.tgz", + "integrity": "sha512-AsUnxuLhRYsisFiaJwvp1QF+I3KjD5FOxut14q/GzovUe6orHLesW2C7d754kRm53h5gqrz6sFl6sxc4BVtE/g==", "dependencies": { - "@babel/types": "^7.18.6" + "@babel/types": "^7.22.5" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-string-parser": { - "version": "7.19.4", - "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.19.4.tgz", - "integrity": "sha512-nHtDoQcuqFmwYNYPz3Rah5ph2p8PFeFCsZk9A/48dPc/rGocJ5J3hAAZ7pb76VWX3fZKu+uEr/FhH5jLx7umrw==", + "version": "7.23.4", + "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.23.4.tgz", + "integrity": "sha512-803gmbQdqwdf4olxrX4AJyFBV/RTr3rSmOj0rKwesmzlfhYNDEs+/iOcznzpNWlJlIlTJC2QfPFcHB6DlzdVLQ==", "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-validator-identifier": { - "version": "7.19.1", - "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.19.1.tgz", - "integrity": "sha512-awrNfaMtnHUr653GgGEs++LlAvW6w+DcPrOliSMXWCKo597CwL5Acf/wWdNkf/tfEQE3mjkeD1YOVZOUV/od1w==", + "version": "7.22.20", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.22.20.tgz", + "integrity": "sha512-Y4OZ+ytlatR8AI+8KZfKuL5urKp7qey08ha31L8b3BwewJAoJamTzyvxPR/5D+KkdJCGPq/+8TukHBlY10FX9A==", "engines": { "node": ">=6.9.0" } @@ -458,12 +523,12 @@ } }, "node_modules/@babel/highlight": { - "version": "7.18.6", - "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.18.6.tgz", - "integrity": "sha512-u7stbOuYjaPezCuLj29hNW1v64M2Md2qupEKP1fHc7WdOA3DgLh37suiSrZYY7haUB7iBeQZ9P1uiRF359do3g==", + "version": "7.23.4", + "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.23.4.tgz", + "integrity": "sha512-acGdbYSfp2WheJoJm/EBBBLh/ID8KDc64ISZ9DYtBmC8/Q204PZJLHyzeB5qMzJ5trcOkybd78M4x2KWsUq++A==", "dependencies": { - "@babel/helper-validator-identifier": "^7.18.6", - "chalk": "^2.0.0", + "@babel/helper-validator-identifier": "^7.22.20", + "chalk": "^2.4.2", "js-tokens": "^4.0.0" }, "engines": { @@ -535,9 +600,9 @@ } }, "node_modules/@babel/parser": { - "version": "7.21.2", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.21.2.tgz", - "integrity": "sha512-URpaIJQwEkEC2T9Kn+Ai6Xe/02iNaVCuT/PtoRz3GPVJVDpPd7mLo+VddTbhCRU9TXqW5mSrQfXZyi8kDKOVpQ==", + "version": "7.23.5", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.23.5.tgz", + "integrity": "sha512-hOOqoiNXrmGdFbhgCzu6GiURxUgM27Xwd/aPuu8RfHEZPBzL1Z54okAHAQjXfcQNwvrlkAmAp4SlRTZ45vlthQ==", "bin": { "parser": "bin/babel-parser.js" }, @@ -1866,31 +1931,31 @@ } }, "node_modules/@babel/template": { - "version": "7.20.7", - "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.20.7.tgz", - "integrity": "sha512-8SegXApWe6VoNw0r9JHpSteLKTpTiLZ4rMlGIm9JQ18KiCtyQiAMEazujAHrUS5flrcqYZa75ukev3P6QmUwUw==", + "version": "7.22.15", + "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.22.15.tgz", + "integrity": "sha512-QPErUVm4uyJa60rkI73qneDacvdvzxshT3kksGqlGWYdOTIUOwJ7RDUL8sGqslY1uXWSL6xMFKEXDS3ox2uF0w==", "dependencies": { - "@babel/code-frame": "^7.18.6", - "@babel/parser": "^7.20.7", - "@babel/types": "^7.20.7" + "@babel/code-frame": "^7.22.13", + "@babel/parser": "^7.22.15", + "@babel/types": "^7.22.15" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/traverse": { - "version": "7.21.2", - "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.21.2.tgz", - "integrity": "sha512-ts5FFU/dSUPS13tv8XiEObDu9K+iagEKME9kAbaP7r0Y9KtZJZ+NGndDvWoRAYNpeWafbpFeki3q9QoMD6gxyw==", - "dependencies": { - "@babel/code-frame": "^7.18.6", - "@babel/generator": "^7.21.1", - "@babel/helper-environment-visitor": "^7.18.9", - "@babel/helper-function-name": "^7.21.0", - "@babel/helper-hoist-variables": "^7.18.6", - "@babel/helper-split-export-declaration": "^7.18.6", - "@babel/parser": "^7.21.2", - "@babel/types": "^7.21.2", + "version": "7.23.5", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.23.5.tgz", + "integrity": "sha512-czx7Xy5a6sapWWRx61m1Ke1Ra4vczu1mCTtJam5zRTBOonfdJ+S/B6HYmGYu3fJtr8GGET3si6IhgWVBhJ/m8w==", + "dependencies": { + "@babel/code-frame": "^7.23.5", + "@babel/generator": "^7.23.5", + "@babel/helper-environment-visitor": "^7.22.20", + "@babel/helper-function-name": "^7.23.0", + "@babel/helper-hoist-variables": "^7.22.5", + "@babel/helper-split-export-declaration": "^7.22.6", + "@babel/parser": "^7.23.5", + "@babel/types": "^7.23.5", "debug": "^4.1.0", "globals": "^11.1.0" }, @@ -1899,12 +1964,12 @@ } }, "node_modules/@babel/types": { - "version": "7.21.2", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.21.2.tgz", - "integrity": "sha512-3wRZSs7jiFaB8AjxiiD+VqN5DTG2iRvJGQ+qYFrs/654lg6kGTQWIOFjlBo5RaXuAZjBmP3+OQH4dmhqiiyYxw==", + "version": "7.23.5", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.23.5.tgz", + "integrity": "sha512-ON5kSOJwVO6xXVRTvOI0eOnWe7VdUcIpsovGo9U/Br4Ie4UVFQTboO2cYnDhAGU6Fp+UxSiT+pMft0SMHfuq6w==", "dependencies": { - "@babel/helper-string-parser": "^7.19.4", - "@babel/helper-validator-identifier": "^7.19.1", + "@babel/helper-string-parser": "^7.23.4", + "@babel/helper-validator-identifier": "^7.22.20", "to-fast-properties": "^2.0.0" }, "engines": { From a98343a10b66c71067d6562ac95792b3722ec1c6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 8 Dec 2023 15:03:34 +0100 Subject: [PATCH 30/34] Bump tough-cookie from 4.1.2 to 4.1.3 in /frontend (#128) Bumps [tough-cookie](https://github.com/salesforce/tough-cookie) from 4.1.2 to 4.1.3. - [Release notes](https://github.com/salesforce/tough-cookie/releases) - [Changelog](https://github.com/salesforce/tough-cookie/blob/master/CHANGELOG.md) - [Commits](https://github.com/salesforce/tough-cookie/compare/v4.1.2...v4.1.3) --- updated-dependencies: - dependency-name: tough-cookie dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- frontend/package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frontend/package-lock.json b/frontend/package-lock.json index de8b678..038a598 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -18682,9 +18682,9 @@ } }, "node_modules/tough-cookie": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-4.1.2.tgz", - "integrity": "sha512-G9fqXWoYFZgTc2z8Q5zaHy/vJMjm+WV0AkAeHxVCQiEB1b+dGvWzFW6QV07cY5jQ5gRkeid2qIkzkxUnmoQZUQ==", + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-4.1.3.tgz", + "integrity": "sha512-aX/y5pVRkfRnfmuX+OdbSdXvPe6ieKX/G2s7e98f4poJHnqH3281gDPm/metm6E/WRamfx7WC4HUqkWHfQHprw==", "dependencies": { "psl": "^1.1.33", "punycode": "^2.1.1", From 8b3419efac2cf09ef52262aa6c8c8dc66a6907c1 Mon Sep 17 00:00:00 2001 From: Yamil Medina Date: Fri, 8 Dec 2023 16:48:11 +0100 Subject: [PATCH 31/34] chore: cancel concurrent builds to avoid multiple runs and only run last (#132) * chore: cancel concurrent builds to avoid multiple runs and only run last * Empty-Commit test --- .github/workflows/ci.yml | 4 ++++ .github/workflows/prod.yml | 6 +++++- .github/workflows/staging.yml | 4 ++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ab2618a..94f0971 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,6 +8,10 @@ on: pull_request: +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: docker-build: runs-on: ubuntu-20.04 diff --git a/.github/workflows/prod.yml b/.github/workflows/prod.yml index d7e5a28..70c66e3 100644 --- a/.github/workflows/prod.yml +++ b/.github/workflows/prod.yml @@ -2,12 +2,16 @@ name: Release Pipeline on: release: - types: [published] + types: [ published ] env: DOCKER_IMAGE: wire-bot/roman SERVICE_NAME: roman +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: deploy: name: Build and deploy service diff --git a/.github/workflows/staging.yml b/.github/workflows/staging.yml index 8a6b4e9..871bdf3 100644 --- a/.github/workflows/staging.yml +++ b/.github/workflows/staging.yml @@ -16,6 +16,10 @@ env: NAMESPACE: staging +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: publish: name: Deploy to staging From b623ef5c238183c2dad154d0515a68e862033b24 Mon Sep 17 00:00:00 2001 From: Yamil Medina Date: Fri, 8 Dec 2023 16:49:01 +0100 Subject: [PATCH 32/34] chore: configure new swagger version for roman in dropwizard4 (WPB-5816) (#133) * chore: configure new swagger version for roman * chore: configure new swagger version for roman --- backend/pom.xml | 5 +++++ .../src/main/java/com/wire/bots/roman/Application.java | 8 ++++++++ .../src/main/java/com/wire/bots/roman/model/Config.java | 4 ++++ 3 files changed, 17 insertions(+) diff --git a/backend/pom.xml b/backend/pom.xml index cbdd3c8..7e06dee 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -65,6 +65,11 @@ io.dropwizard dropwizard-servlets + + com.smoketurner + dropwizard-swagger + 4.0.0-1 + jakarta.annotation diff --git a/backend/src/main/java/com/wire/bots/roman/Application.java b/backend/src/main/java/com/wire/bots/roman/Application.java index ba3aead..5e8172f 100644 --- a/backend/src/main/java/com/wire/bots/roman/Application.java +++ b/backend/src/main/java/com/wire/bots/roman/Application.java @@ -38,6 +38,8 @@ import io.dropwizard.assets.AssetsBundle; import io.dropwizard.core.setup.Bootstrap; import io.dropwizard.core.setup.Environment; +import io.federecio.dropwizard.swagger.SwaggerBundle; +import io.federecio.dropwizard.swagger.SwaggerBundleConfiguration; import io.jsonwebtoken.security.Keys; import jakarta.servlet.DispatcherType; import jakarta.servlet.FilterRegistration; @@ -72,6 +74,12 @@ public void initialize(Bootstrap bootstrap) { bootstrap.addBundle(new WebsocketBundle(WebSocket.class)); bootstrap.addCommand(new UpdateCertCommand()); bootstrap.addBundle(new AssetsBundle("/frontend", "/", "index.html")); + bootstrap.addBundle(new SwaggerBundle<>() { + @Override + protected SwaggerBundleConfiguration getSwaggerBundleConfiguration(Config configuration) { + return configuration.swaggerBundleConfiguration; + } + }); } @Override diff --git a/backend/src/main/java/com/wire/bots/roman/model/Config.java b/backend/src/main/java/com/wire/bots/roman/model/Config.java index 9a10d6b..5d5d711 100644 --- a/backend/src/main/java/com/wire/bots/roman/model/Config.java +++ b/backend/src/main/java/com/wire/bots/roman/model/Config.java @@ -22,6 +22,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.wire.lithium.Configuration; import io.dropwizard.validation.ValidationMethod; +import io.federecio.dropwizard.swagger.SwaggerBundleConfiguration; import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; @@ -42,6 +43,9 @@ public class Config extends Configuration { @JsonProperty public String romanPubKeyBase64; + @JsonProperty("swagger") + public SwaggerBundleConfiguration swaggerBundleConfiguration; + @ValidationMethod(message = "`romanPubKeyBase64` is not in a valid base64 format") @JsonIgnore public boolean pubKeyFormatIsNotValid() { From 037fc52e71deee0a572a8beebb0e444a43e110e2 Mon Sep 17 00:00:00 2001 From: Yamil Medina Date: Mon, 11 Dec 2023 14:18:58 +0100 Subject: [PATCH 33/34] fix: request min known flyway version for compatibility with pg prod (#135) * fix: request min known flyway version for compatibility with pg prod runtime * fix: request min known flyway version for compatibility with pg prod runtime --- backend/pom.xml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/backend/pom.xml b/backend/pom.xml index 7e06dee..3bfcc69 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -34,6 +34,8 @@ 5.8.2 11.0.18 2.1.1 + + 7.15.0 @@ -124,6 +126,12 @@ ${jwt.version} runtime + + org.flywaydb + flyway-core + ${flyway.version} + + From 01b054befe26dca3dd102b317989059cfcf9aa2a Mon Sep 17 00:00:00 2001 From: Dejan Date: Mon, 11 Dec 2023 14:26:50 +0100 Subject: [PATCH 34/34] version bump 1.19.1 --- backend/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/pom.xml b/backend/pom.xml index 3bfcc69..edea0d0 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -6,7 +6,7 @@ com.wire.bots roman - 1.19.0 + 1.19.1 Roman Wire Bot API Proxy