Skip to content

Add error field to file result and set on decrypt error #294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: java
version: 6.4.2
version: 6.4.3
schema: 1
scm: github.com/pubnub/java
files:
- build/libs/pubnub-gson-6.4.2-all.jar
- build/libs/pubnub-gson-6.4.3-all.jar
sdks:
-
type: library
Expand All @@ -23,8 +23,8 @@ sdks:
-
distribution-type: library
distribution-repository: maven
package-name: pubnub-gson-6.4.2
location: https://repo.maven.apache.org/maven2/com/pubnub/pubnub-gson/6.4.2/pubnub-gson-6.4.2.jar
package-name: pubnub-gson-6.4.3
location: https://repo.maven.apache.org/maven2/com/pubnub/pubnub-gson/6.4.3/pubnub-gson-6.4.3.jar
supported-platforms:
supported-operating-systems:
Android:
Expand Down Expand Up @@ -115,6 +115,11 @@ sdks:
is-required: Required

changelog:
- date: 2023-11-28
version: v6.4.3
changes:
- type: feature
text: "Add `error` field to `PNFileEventResult` and set it in case of decryption failure."
- date: 2023-11-23
version: v6.4.2
changes:
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## v6.4.3
November 28 2023

#### Added
- Add `error` field to `PNFileEventResult` and set it in case of decryption failure.

## v6.4.2
November 23 2023

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ You will need the publish and subscribe keys to authenticate your app. Get your
<dependency>
<groupId>com.pubnub</groupId>
<artifactId>pubnub-gson</artifactId>
<version>6.4.2</version>
<version>6.4.3</version>
</dependency>
```

* for Gradle, add the following dependency in your `gradle.build`:
```groovy
implementation 'com.pubnub:pubnub-gson:6.4.2'
implementation 'com.pubnub:pubnub-gson:6.4.3'
```

2. Configure your keys:
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plugins {
}
group = 'com.pubnub'

version = '6.4.2'
version = '6.4.3'

description = """"""

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ SONATYPE_HOST=DEFAULT
SONATYPE_AUTOMATIC_RELEASE=true
GROUP=com.pubnub
POM_ARTIFACT_ID=pubnub-gson
VERSION_NAME=6.4.2
VERSION_NAME=6.4.3
POM_PACKAGING=jar

POM_NAME=PubNub Java SDK
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/pubnub/api/PubNub.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public class PubNub {
private static final int TIMESTAMP_DIVIDER = 1000;
private static final int MAX_SEQUENCE = 65535;

private static final String SDK_VERSION = "6.4.2";
private static final String SDK_VERSION = "6.4.3";
private final ListenerManager listenerManager;
private final StateManager stateManager;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ public final class PubNubErrorBuilder {

public static final PubNubError PNERROBJ_PNERR_CRYPTO_IS_CONFIGURED_BUT_MESSAGE_IS_NOT_ENCRYPTED = PubNubError.builder()
.errorCode(PNERR_CRYPTO_IS_CONFIGURED_BUT_MESSAGE_IS_NOT_ENCRYPTED)
.message("Crypto is configured but message is not encrypted.")
.message("Message decryption failed using the current crypto configuration.")
.build();

private PubNubErrorBuilder() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.pubnub.api.models.consumer.pubsub.files;

import com.google.gson.JsonElement;
import com.pubnub.api.PubNubError;
import com.pubnub.api.models.consumer.files.PNDownloadableFile;
import com.pubnub.api.models.consumer.pubsub.PNEvent;
import lombok.Builder;
Expand All @@ -19,4 +20,5 @@ public class PNFileEventResult implements PNEvent {
@NonNull
private final PNDownloadableFile file;
private final JsonElement jsonMessage;
private final PubNubError error;
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ PNEvent processIncomingPayload(SubscribeMessage message) throws PubNubException

if (message.getChannel().endsWith("-pnpres")) {
PresenceEnvelope presencePayload = mapper.convertValue(message.getPayload(), PresenceEnvelope.class);

String strippedPresenceChannel = null;
String strippedPresenceSubscription = null;

Expand Down Expand Up @@ -107,7 +106,6 @@ PNEvent processIncomingPayload(SubscribeMessage message) throws PubNubException
.timeout(getDelta(message.getPayload().getAsJsonObject().get("timeout")))
.hereNowRefresh(isHereNowRefresh != null && isHereNowRefresh.getAsBoolean())
.build();

return pnPresenceEventResult;
} else {
JsonElement extractedMessage;
Expand Down Expand Up @@ -202,6 +200,7 @@ PNEvent processIncomingPayload(SubscribeMessage message) throws PubNubException
.publisher(message.getIssuingClientId())
.timetoken(publishMetaData.getPublishTimetoken())
.jsonMessage(jsonMessage)
.error(error)
.build();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/pubnub/api/PubNubTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void getVersionAndTimeStamp() {
pubnub = new PubNub(pnConfiguration);
String version = pubnub.getVersion();
int timeStamp = pubnub.getTimestamp();
Assert.assertEquals("6.4.2", version);
Assert.assertEquals("6.4.3", version);
Assert.assertTrue(timeStamp > 0);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,24 @@ private void testDifferentJsonMessages(JsonElement jsonMessage) throws PubNubExc
assertThat(((PNFileEventResult) result).getJsonMessage(), is(jsonMessage));
}

@Test
public void testProcessFileUnencryptedWithCrypto() throws PubNubException {
//given
Gson gson = new Gson();
PNConfiguration config = config();
config.setCryptoModule(CryptoModule.createAesCbcCryptoModule("enigma", false));
SubscribeMessageProcessor subscribeMessageProcessor = subscribeMessageProcessor(config);
JsonElement jsonMessage = new JsonPrimitive("thisIsMessage");

//when
PNEvent result = subscribeMessageProcessor.processIncomingPayload(gson.fromJson(fileMessage(jsonMessage.toString()), SubscribeMessage.class));

//then
assertThat(result, is(instanceOf(PNFileEventResult.class)));
assertThat(((PNFileEventResult) result).getJsonMessage(), is(jsonMessage));
assertThat(((PNFileEventResult) result).getError(), is(PubNubErrorBuilder.PNERROBJ_PNERR_CRYPTO_IS_CONFIGURED_BUT_MESSAGE_IS_NOT_ENCRYPTED));
}

@Test
public void testProcessMessageEncryptedWithCrypto() throws PubNubException {
//given
Expand Down