Skip to content

Commit

Permalink
PubNub SDK v1.4.3 release.
Browse files Browse the repository at this point in the history
  • Loading branch information
client-engineering-bot committed Aug 5, 2020
1 parent 41160ad commit 149a65c
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 16 deletions.
12 changes: 11 additions & 1 deletion .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
---
changelog:
-
changes:
-
text: "Fixes issue of exception from server when publishKey os null with publish call."
type: bug
-
text: "Fixes missing url component in file publish message for sendFile and support for message encryption."
type: bug
date: Aug 5, 20
version: v1.4.3
-
changes:
-
Expand Down Expand Up @@ -256,4 +266,4 @@ supported-platforms:
platforms:
- "Dart SDK >=2.6.0 <3.0.0"
version: "PubNub Dart SDK"
version: "1.4.2"
version: "1.4.3"
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## [v1.4.3](https://github.com/pubnub/dart/releases/tag/v1.4.3)
August 5 2020

[Full Changelog](https://github.com/pubnub/dart/compare/v1.4.2...v1.4.3)

- 🐛 Fixes issue of exception from server when publishKey os null with publish call.
- 🐛 Fixes missing url component in file publish message for sendFile and support for message encryption.

## [v1.4.2](https://github.com/pubnub/dart/releases/tag/v1.4.2)
July 27 2020

Expand Down
2 changes: 1 addition & 1 deletion lib/src/core/core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Core {
ParserModule parser;
CryptoModule crypto;

static String version = '1.4.2';
static String version = '1.4.3';

Core(
{Keyset defaultKeyset,
Expand Down
15 changes: 11 additions & 4 deletions lib/src/dx/_endpoints/history.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'package:pubnub/src/core/core.dart';
import 'package:pubnub/src/dx/_utils/utils.dart';

typedef decryptFunction = List<int> Function(CipherKey key, String data);

class FetchHistoryParams extends Parameters {
Keyset keyset;
String channel;
Expand Down Expand Up @@ -113,10 +115,13 @@ class BatchHistoryResultEntry {

BatchHistoryResultEntry._();

factory BatchHistoryResultEntry.fromJson(Map<String, dynamic> object) {
factory BatchHistoryResultEntry.fromJson(Map<String, dynamic> object,
{CipherKey cipherKey, Function decryptFunction}) {
return BatchHistoryResultEntry._()
..timetoken = Timetoken(object['timestamp'] as int)
..message = object['message'];
..message = cipherKey == null
? object['message']
: decryptFunction(cipherKey, object['message']);
}
}

Expand All @@ -125,15 +130,17 @@ class BatchHistoryResult extends Result {

BatchHistoryResult._();

factory BatchHistoryResult.fromJson(Map<String, dynamic> object) {
factory BatchHistoryResult.fromJson(Map<String, dynamic> object,
{CipherKey cipherKey, Function decryptFunction}) {
var result = DefaultResult.fromJson(object);

return BatchHistoryResult._()
..channels = (result.otherKeys['channels'] as Map<String, dynamic>).map(
(key, value) => MapEntry(
key,
(value as List<dynamic>)
.map((entry) => BatchHistoryResultEntry.fromJson(entry))
.map((entry) => BatchHistoryResultEntry.fromJson(entry,
cipherKey: cipherKey, decryptFunction: decryptFunction))
.toList()));
}
}
Expand Down
4 changes: 3 additions & 1 deletion lib/src/dx/batch/batch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ class BatchDx {
end: end,
reverse: reverse,
includeMeta: includeMeta),
serialize: (object, [_]) => BatchHistoryResult.fromJson(object));
serialize: (object, [_]) => BatchHistoryResult.fromJson(object,
cipherKey: keyset.cipherKey,
decryptFunction: _core.crypto.decrypt));
}

/// Get multiple channels' message count using one REST call.
Expand Down
19 changes: 15 additions & 4 deletions lib/src/dx/file/file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class FileDx {
/// This method allows to send [file] to [channel]
/// If file upload operation , It also publish [fileMessage] along with file data `fileId` and `fileName`
///
/// Provide [cipherKey] to encrypt file content if you want to override default `cipherKey` of `Keyset`
/// Provide [cipherKey] to encrypt file content & fileEvent message if you want to override default `cipherKey` of `Keyset`
/// * It gives priority of [cipherKey] provided in method argument over `keyset`'s `cipherKey`
///
/// It retries for publishing [fileMessage] till default value of PubNub configuration value
Expand Down Expand Up @@ -51,6 +51,7 @@ class FileDx {
Keyset keyset,
String using}) async {
keyset ??= _core.keysets.get(using, defaultIfNameIsNull: true);

Ensure(keyset.publishKey).isNotNull('publish key for file upload message');
var requestPayload =
await _core.parser.encode(GenerateFileUploadUrlBody(fileName));
Expand All @@ -73,9 +74,11 @@ class FileDx {
form['file'] = _fileManager.createMultipartFile(_fileManager.read(file),
fileName: fileName);
}
var publishMessage = FileMessage(
fileUploadDetails.data.map((k, v) => MapEntry('$k', '$v')),
message: fileMessage);
var fileInfo = fileUploadDetails.data.map((k, v) => MapEntry('$k', '$v'));
fileInfo['url'] = getFileUrl(channel, '${fileUploadDetails.data['id']}',
'${fileUploadDetails.data['name']}')
.toString();
var publishMessage = FileMessage(fileInfo, message: fileMessage);
var publishFileResult = PublishFileMessageResult();
var retryCount = keyset.fileMessagePublishRetryLimit;
var s3Response = await customFlow<FileUploadParams, FileUploadResult>(
Expand All @@ -90,6 +93,7 @@ class FileDx {
ttl: fileMessageTtl,
storeMessage: storeFileMessage,
meta: fileMessageMeta,
cipherKey: cipherKey,
keyset: keyset,
using: using);
} catch (e) {
Expand All @@ -110,6 +114,8 @@ class FileDx {
/// In case `sendFile` method doesn't publish message to [channel], this method
/// can be used to explicitly publish message
///
/// Provide [cipherKey] to encrypt `message` it takes precedence over `keyset`'s cipherKey
///
/// You can override the default account configuration on message
/// saving using [storeMessage] flag - `true` to save and `false` to discard.
/// Leave this option unset if you want to use the default.
Expand All @@ -128,12 +134,17 @@ class FileDx {
{bool storeMessage,
int ttl,
dynamic meta,
CipherKey cipherKey,
Keyset keyset,
String using}) async {
keyset ??= _core.keysets.get(using, defaultIfNameIsNull: true);
Ensure(keyset.publishKey).isNotNull('publish key');

var messagePayload = await _core.parser.encode(message);
if (cipherKey != null || keyset.cipherKey != null) {
messagePayload = await _core.parser.encode(
_core.crypto.encrypt(cipherKey ?? keyset.cipherKey, messagePayload));
}
if (meta != null) meta = await _core.parser.encode(meta);
return defaultFlow(
logger: _logger,
Expand Down
1 change: 1 addition & 0 deletions lib/src/dx/publish/publish.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ mixin PublishDx on Core {
keyset ??= super.keysets.get(using, defaultIfNameIsNull: true);

Ensure(keyset).isNotNull('keyset');
Ensure(keyset.publishKey).isNotNull('publishKey');

var payload = await super.parser.encode(message);

Expand Down
4 changes: 3 additions & 1 deletion lib/src/dx/subscribe/subscription.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ class Subscription extends Disposable {
(presenceChannels.contains(envelope['c']) ||
presenceChannelGroups.contains(envelope['b'])));
}).asyncMap((envelope) async {
if (envelope['e'] == null && _keyset.cipherKey != null) {
if ((envelope['e'] == null || envelope['e'] == 4) &&
!envelope['b'].endsWith('-pnpres') &&
_keyset.cipherKey != null) {
envelope['d'] = await _core.parser
.decode(_core.crypto.decrypt(_keyset.cipherKey, envelope['d']));
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: pubnub
description: PubNub SDK v5 for Dart lang (with Flutter support) that allows you to create real-time applications
version: 1.4.2
version: 1.4.3
homepage: https://www.pubnub.com/docs

environment:
Expand Down
53 changes: 51 additions & 2 deletions test/dx/file_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,53 @@ void main() {
expect(result, isA<PublishFileMessageResult>());
});

test('#publishFileMessage withEncryption', () async {
when(
path: _publishFileMessageUrlEncryption,
method: 'GET',
).then(status: 200, body: _publishFileMessageSuccessResponse);
var message =
FileMessage({'id': 'some', 'name': 'cat_file.jpg'}, message: 'msg');
var result = await pubnub.files.publishFileMessage('channel', message,
cipherKey: CipherKey.fromUtf8('cipherKey'));
expect(result, isA<PublishFileMessageResult>());
});

test('#publishFileMessage withEncryption defaultKeyset', () async {
pubnub = PubNub(
networking: FakeNetworkingModule(),
defaultKeyset: Keyset(
subscribeKey: 'test',
publishKey: 'test',
cipherKey: CipherKey.fromUtf8('cipherKey')));
when(
path: _publishFileMessageUrlEncryption,
method: 'GET',
).then(status: 200, body: _publishFileMessageSuccessResponse);
var message =
FileMessage({'id': 'some', 'name': 'cat_file.jpg'}, message: 'msg');
var result = await pubnub.files.publishFileMessage('channel', message);
expect(result, isA<PublishFileMessageResult>());
});

test('#publishFileMessage cipherKey precedence', () async {
pubnub = PubNub(
networking: FakeNetworkingModule(),
defaultKeyset: Keyset(
subscribeKey: 'test',
publishKey: 'test',
cipherKey: CipherKey.fromUtf8('default_cipherKey')));
when(
path: _publishFileMessageUrlEncryption,
method: 'GET',
).then(status: 200, body: _publishFileMessageSuccessResponse);
var message =
FileMessage({'id': 'some', 'name': 'cat_file.jpg'}, message: 'msg');
var result = await pubnub.files.publishFileMessage('channel', message,
cipherKey: CipherKey.fromUtf8('cipherKey'));
expect(result, isA<PublishFileMessageResult>());
});

test('#publishFileMessage failure', () async {
when(
path: _publishFileMessageUrl1,
Expand All @@ -72,8 +119,9 @@ void main() {
expect(result, isA<DeleteFileResult>());
});
test('#SendFile', () async {
var pubnub = FakePubNub();
var keyset = Keyset(subscribeKey: 'test', publishKey: 'test');
var pubnub = FakePubNub()
..keysets.add(keyset, name: 'default', useAsDefault: true);
when(
path: _generateFileUploadUrl,
method: 'POST',
Expand All @@ -92,8 +140,9 @@ void main() {
});

test('#SendFile #FileMessagePublish retry', () async {
var pubnub = FakePubNub();
var keyset = Keyset(subscribeKey: 'test', publishKey: 'test');
var pubnub = FakePubNub()
..keysets.add(keyset, name: 'default', useAsDefault: true);
when(
path: _generateFileUploadUrl,
method: 'POST',
Expand Down
5 changes: 4 additions & 1 deletion test/dx/fixtures/file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,11 @@ final _generateFileUploadUrlResponse = '''
var _publishFileMessageUrl1 =
'v1/files/publish-file/test/test/0/channel/0/%7B%22message%22:%22msg%22,%22file%22:%7B%22id%22:%22some%22,%22name%22:%22cat_file.jpg%22%7D%7D?pnsdk=PubNub-Dart%2F${PubNub.version}';

var _publishFileMessageUrlEncryption =
'v1/files/publish-file/test/test/0/channel/0/%22X3LuZh36Z3vi4HFJSxdqD7XN%2FTsyUiPBmDfVaRipvaYs8wQE6OOloLTjGSTnZXIb0knFDIr8jPniWrnUYtdoTQ==%22?pnsdk=PubNub-Dart%2F${PubNub.version}';

var _publishFileMessageUrl2 =
'v1/files/publish-file/test/test/0/channel/0/%7B%22message%22:%22msg%22,%22file%22:%7B%22id%22:%225a3eb38c-483a-4b25-ac01-c4e20deba6d6%22,%22name%22:%22cat_file.jpg%22%7D%7D?pnsdk=PubNub-Dart%2F${PubNub.version}';
'v1/files/publish-file/test/test/0/channel/0/%7B%22message%22:%22msg%22,%22file%22:%7B%22id%22:%225a3eb38c-483a-4b25-ac01-c4e20deba6d6%22,%22name%22:%22cat_file.jpg%22,%22url%22:%22https:%2F%2Fps.pndsn.com%2Fv1%2Ffiles%2Ftest%2Fchannels%2Fchannel%2Ffiles%2F5a3eb38c-483a-4b25-ac01-c4e20deba6d6%2Fcat_file.jpg%3Fpnsdk=PubNub-Dart%252F1.4.2%22%7D%7D?pnsdk=PubNub-Dart%2F${PubNub.version}';

var _generateFileUploadUrl =
'v1/files/test/channels/channel/generate-upload-url?pnsdk=PubNub-Dart%2F${PubNub.version}';
Expand Down

0 comments on commit 149a65c

Please sign in to comment.