Skip to content
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

RTL7e #211

Merged
merged 4 commits into from
Mar 2, 2016
Merged

RTL7e #211

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
51 changes: 51 additions & 0 deletions ablySpec/RealtimeClientChannel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1147,6 +1147,57 @@ class RealtimeClientChannel: QuickSpec {

}

context("message cannot be decoded or decrypted") {

// RTL7e
pending("should deliver with encoding attribute set indicating the residual encoding and error should be emitted") {
let options = AblyTests.commonAppSetup()
options.autoConnect = false
let client = ARTRealtime(options: options)
client.setTransportClass(TestProxyTransport.self)
client.connect()
defer { client.close() }

let channelOptions = ARTChannelOptions(cipher: ["key":ARTCrypto.generateRandomKey()])
let channel = client.channels.get("test", options: channelOptions)

let expectedMessage = ["key":1]
let expectedData = try! NSJSONSerialization.dataWithJSONObject(expectedMessage, options: NSJSONWritingOptions(rawValue: 0))

let transport = client.transport as! TestProxyTransport

transport.beforeProcessingReceivedMessage = { protocolMessage in
if protocolMessage.action == .Message {
let messageReceived = protocolMessage.messages![0]
// Replacement: `json/cipher+aes-128-cbc/base64` to `invalid/cipher+aes-128-cbc/base64`
let newEncoding = "invalid" + messageReceived.encoding!.substringFromIndex("json".endIndex)
messageReceived.encoding = newEncoding
}
}

waitUntil(timeout: testTimeout) { done in
let logTime = NSDate()

channel.subscribe { message in
// Last decoding failed: NSData -> JSON object, so...
expect(message.data as? NSData).to(equal(expectedData))
expect(message.encoding).to(equal("invalid"))

let logs = options.logHandler.captured
let line = logs.reduce("") { $0 + "; " + $1.toString() } //Reduce in one line
expect(line).to(contain("ERROR: Failed to decode data: unknown encoding: 'invalid'"))

expect(channel.errorReason!.message).to(contain("Failed to decode data: unknown encoding: 'invalid'"))

done()
}

channel.publish(nil, data: expectedMessage)
}
}

}

// RTL7f
it("should exist ensuring published messages are not echoed back to the subscriber when echoMessages is false") {
let options = AblyTests.commonAppSetup()
Expand Down