Skip to content

Commit

Permalink
PubNub SDK v6.0.3 release.
Browse files Browse the repository at this point in the history
  • Loading branch information
client-engineering-bot committed Jul 27, 2021
1 parent 473a89a commit 611fc2e
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 15 deletions.
11 changes: 9 additions & 2 deletions .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: kotlin
version: 6.0.2
version: 6.0.3
schema: 1
scm: github.com/pubnub/kotlin
files:
- build/libs/pubnub-kotlin-6.0.2-all.jar
- build/libs/pubnub-kotlin-6.0.3-all.jar
sdks:
-
type: library
Expand Down Expand Up @@ -233,6 +233,13 @@ sdks:
license-url: https://github.com/stleary/JSON-java/blob/20210307/LICENSE
is-required: Required
changelog:
-
version: v6.0.3
date: 2021-07-26
changes:
-
type: bug
text: "Using random initialization vector according to 'useRandomInitializationVector' flag setting."
-
version: v6.0.2
date: 2021-07-06
Expand Down
8 changes: 4 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
## [v6.0.2](https://github.com/pubnub/kotlin/releases/tag/v6.0.2)
July 6 2021
## [v6.0.3](https://github.com/pubnub/kotlin/releases/tag/v6.0.3)
July 26 2021

[Full Changelog](https://github.com/pubnub/kotlin/compare/v6.0.1...v6.0.2)
[Full Changelog](https://github.com/pubnub/kotlin/compare/v6.0.2...v6.0.3)

- Handle socket exception causing crash while canceling the call.
- Using random initialization vector according to 'useRandomInitializationVector' flag setting.


2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ 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.0.2</version>
<version>6.0.3</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ plugins {
}

group = 'com.pubnub'
version = '6.0.2'
version = '6.0.3'

repositories {
mavenCentral()
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/pubnub/api/vendor/Crypto.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public Crypto(String cipherKey, String customInitializationVector) {
}
}

public Crypto(String cipherKey, boolean dynamicIV) { //TODO include necessary Crypto changes
public Crypto(String cipherKey, boolean dynamicIV) {
this.cipherKey = cipherKey;
this.dynamicIV = dynamicIV;
}
Expand Down
9 changes: 6 additions & 3 deletions src/main/kotlin/com/pubnub/api/PubNub.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class PubNub(val configuration: PNConfiguration) {

private companion object Constants {
private const val TIMESTAMP_DIVIDER = 1000
private const val SDK_VERSION = "6.0.2"
private const val SDK_VERSION = "6.0.3"
private const val MAX_SEQUENCE = 65535
}

Expand Down Expand Up @@ -549,6 +549,7 @@ class PubNub(val configuration: PNConfiguration) {
*
* @param channels Channels to return history messages from.
* @param page The paging object used for pagination. @see [PNBoundedPage]
* @param includeUUID Whether to include publisher uuid with each history message. Defaults to `true`.
* @param includeMeta Whether to include message metadata in response.
* Defaults to `false`.
* @param includeMessageActions Whether to include message actions in response.
Expand All @@ -557,12 +558,14 @@ class PubNub(val configuration: PNConfiguration) {
fun fetchMessages(
channels: List<String>,
page: PNBoundedPage = PNBoundedPage(),
includeUUID: Boolean = true,
includeMeta: Boolean = false,
includeMessageActions: Boolean = false
) = FetchMessages(
pubnub = this,
channels = channels,
page = page,
includeUUID = includeUUID,
includeMeta = includeMeta,
includeMessageActions = includeMessageActions
)
Expand Down Expand Up @@ -1772,7 +1775,7 @@ class PubNub(val configuration: PNConfiguration) {
* @throws PubNubException throws exception in case of failed decryption.
*/
fun decrypt(inputString: String, cipherKey: String = configuration.cipherKey): String =
Crypto(cipherKey).decrypt(inputString, Base64.DEFAULT)
Crypto(cipherKey, configuration.useRandomInitializationVector).decrypt(inputString, Base64.DEFAULT)

/**
* Perform Cryptographic decryption of an input stream using provided cipher key.
Expand All @@ -1798,7 +1801,7 @@ class PubNub(val configuration: PNConfiguration) {
* @throws PubNubException Throws exception in case of failed encryption.
*/
fun encrypt(inputString: String, cipherKey: String = configuration.cipherKey): String =
Crypto(cipherKey).encrypt(inputString, Base64.DEFAULT)
Crypto(cipherKey, configuration.useRandomInitializationVector).encrypt(inputString, Base64.DEFAULT)

/**
* Perform Cryptographic encryption of an input stream using provided cipher key.
Expand Down
5 changes: 4 additions & 1 deletion src/main/kotlin/com/pubnub/api/endpoints/FetchMessages.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class FetchMessages internal constructor(
pubnub: PubNub,
val channels: List<String>,
val page: PNBoundedPage,
val includeUUID: Boolean,
val includeMeta: Boolean,
val includeMessageActions: Boolean
) : Endpoint<FetchMessagesEnvelope, PNFetchMessagesResult>(pubnub) {
Expand Down Expand Up @@ -98,7 +99,9 @@ class FetchMessages internal constructor(
override fun operationType() = PNOperationType.PNFetchMessagesOperation

private fun addQueryParams(queryParams: MutableMap<String, String>) {
queryParams["max"] = effectiveMax(page.limit, includeMessageActions, channels.size).toString()
queryParams["max"] =
effectiveMax(page.limit, includeMessageActions, channels.size).toString()
queryParams["include_uuid"] = includeUUID.toString()

page.start?.run { queryParams["start"] = this.toString().toLowerCase(Locale.US) }
page.end?.run { queryParams["end"] = this.toString().toLowerCase(Locale.US) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ data class PNFetchMessagesResult(
/**
* Encapsulates a message in terms of a batch history entry.
*
* @property uuid Publisher uuid. Is `null` if not requested.
* @property message The actual message content.
* @property timetoken Publish timetoken of the message.
* @property meta Metadata of the message, if requested via [FetchMessages.includeMeta].
Expand All @@ -31,6 +32,7 @@ data class PNFetchMessagesResult(
* @see [Action]
*/
data class PNFetchMessageItem(
val uuid: String?,
val message: JsonElement,
val meta: JsonElement?,
val timetoken: Long,
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/pubnub/extension/JsonElement.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal fun JsonElement.processHistoryMessage(configuration: PNConfiguration, m
if (!configuration.isCipherKeyValid())
return this

val crypto = Crypto(configuration.cipherKey)
val crypto = Crypto(configuration.cipherKey, configuration.useRandomInitializationVector)

val inputText =
if (mapper.isJsonObject(this) && mapper.hasField(
Expand Down
6 changes: 5 additions & 1 deletion src/test/kotlin/com/pubnub/api/legacy/PubNubTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,31 @@ class PubNubTest : BaseTest() {
@Test
@Throws(PubNubException::class)
fun testEncryptCustomKey() {
config.useRandomInitializationVector = false
assertEquals("iALQtn3PfIXe74CT/wrS7g==", pubnub.encrypt("test1", "cipherKey").trim())
}

@Test
@Throws(PubNubException::class)
fun testEncryptConfigurationKey() {
config.cipherKey = "cipherKey"
config.useRandomInitializationVector = false
initPubNub()
assertEquals("iALQtn3PfIXe74CT/wrS7g==", pubnub.encrypt("test1").trim())
}

@Test
@Throws(PubNubException::class)
fun testDecryptCustomKey() {
config.useRandomInitializationVector = false
assertEquals("test1", pubnub.decrypt("iALQtn3PfIXe74CT/wrS7g==", "cipherKey").trim())
}

@Test
@Throws(PubNubException::class)
fun testDecryptConfigurationKey() {
config.cipherKey = "cipherKey"
config.useRandomInitializationVector = false
initPubNub()
assertEquals("test1", pubnub.decrypt("iALQtn3PfIXe74CT/wrS7g==").trim())
}
Expand All @@ -67,7 +71,7 @@ class PubNubTest : BaseTest() {
fun getVersionAndTimeStamp() {
val version = pubnub.version
val timeStamp = pubnub.timestamp()
assertEquals("6.0.2", version)
assertEquals("6.0.3", version)
assertTrue(timeStamp > 0)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,19 @@ class FetchMessagesEndpointTest : BaseTest() {
"my_channel": [
{
"message": "hihi",
"uuid": "my-uuid",
"timetoken": "14698320467224036"
},
{
"message": "Hey",
"uuid": "my-uuid",
"timetoken": "14698320468265639"
}
],
"mychannel": [
{
"message": "sample message",
"uuid": "my-uuid",
"timetoken": "14369823849575729"
}
]
Expand All @@ -72,11 +75,70 @@ class FetchMessagesEndpointTest : BaseTest() {
)
).sync()!!

assertEquals(response.channels.size, 2)

assertTrue(response.channels.containsKey("mychannel"))
assertTrue(response.channels.containsKey("my_channel"))

assertEquals(response.channels["mychannel"]!!.size, 1)
assertEquals(response.channels["my_channel"]!!.size, 2)

assertEquals(response.channels["mychannel"]!!.count { it.uuid == "my-uuid" }, 1)
assertEquals(response.channels["my_channel"]!!.count { it.uuid == "my-uuid" }, 2)
}

@Test
fun testSyncWithoutUUIDSuccess() {
stubFor(
get(urlPathEqualTo("/v3/history/sub-key/mySubscribeKey/channel/mychannel,my_channel"))
.willReturn(
aResponse().withBody(
"""
{
"status": 200,
"error": false,
"error_message": "",
"channels": {
"my_channel": [
{
"message": "hihi",
"timetoken": "14698320467224036"
},
{
"message": "Hey",
"timetoken": "14698320468265639"
}
],
"mychannel": [
{
"message": "sample message",
"timetoken": "14369823849575729"
}
]
}
}
""".trimIndent()
)
)
)

val response = pubnub.fetchMessages(
channels = listOf("mychannel", "my_channel"),
page = PNBoundedPage(
limit = 25
),
includeUUID = false
).sync()!!

assertEquals(response.channels.size, 2)
assertTrue(response.channels.containsKey("mychannel"))
assertTrue(response.channels.containsKey("my_channel"))

assertEquals(response.channels["mychannel"]!!.size, 1)
assertEquals(response.channels["my_channel"]!!.size, 2)

assertEquals(response.channels["mychannel"]!!.count { it.uuid == null }, 1)
assertEquals(response.channels["my_channel"]!!.count { it.uuid == null }, 2)
}

@Test
Expand Down Expand Up @@ -136,6 +198,7 @@ class FetchMessagesEndpointTest : BaseTest() {
@Test
fun testSyncEncryptedSuccess() {
pubnub.configuration.cipherKey = "testCipher"
pubnub.configuration.useRandomInitializationVector = false

stubFor(
get(urlPathEqualTo("/v3/history/sub-key/mySubscribeKey/channel/mychannel,my_channel"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ class HistoryEndpointTest : BaseTest() {
@Test
fun testSyncEncryptedSuccess() {
pubnub.configuration.cipherKey = "testCipher"
pubnub.configuration.useRandomInitializationVector = false

stubFor(
get(urlPathEqualTo("/v2/history/sub-key/mySubscribeKey/channel/niceChannel"))
Expand Down Expand Up @@ -231,6 +232,7 @@ class HistoryEndpointTest : BaseTest() {
@Test
fun testSyncEncryptedWithPNOtherSuccess() {
pubnub.configuration.cipherKey = "hello"
pubnub.configuration.useRandomInitializationVector = false

stubFor(
get(urlPathEqualTo("/v2/history/sub-key/mySubscribeKey/channel/niceChannel"))
Expand Down

0 comments on commit 611fc2e

Please sign in to comment.