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

RTL7d #209

Merged
merged 5 commits into from
Feb 19, 2016
Merged

RTL7d #209

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

// RTL7d
pending("should deliver the message even if there is an error while decoding") {

for cryptoTest in [CryptoTest.aes128, CryptoTest.aes256] {
it("using \(cryptoTest) ") {
let options = AblyTests.commonAppSetup()
options.autoConnect = false
let client = ARTRealtime(options: options)
client.setTransportClass(TestProxyTransport.self)
client.connect()
defer { client.close() }

let (keyData, ivData, messages) = AblyTests.loadCryptoTestData(cryptoTest)
let testMessage = messages[0]

let cipherParams = ARTCrypto.defaultParamsWithKey(keyData, iv: ivData)
let channelOptions = ARTChannelOptions(encrypted: cipherParams)
let channel = client.channels.get("test", options: channelOptions)

let transport = client.transport as! TestProxyTransport

transport.beforeProcessingSentMessage = { protocolMessage in
if protocolMessage.action == .Message {
expect(protocolMessage.messages![0].data as? String).to(equal(testMessage.encrypted.data))
expect(protocolMessage.messages![0].encoding).to(equal(testMessage.encrypted.encoding))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failing because:

  • expected to equal <utf-8/cipher+aes-128-cbc/base64>, got <cipher+aes-128-cbc/base64>
  • expected to equal <utf-8/cipher+aes-256-cbc/base64>, got <cipher+aes-256-cbc/base64>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be passing after #217.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tcard Can you pick 236b3a9? Then I rebase this one after #217 has been merged.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ricardopereira Done, although I had to fix something in your 236b3a9 and now it is 9301ccb. You should replace 236b3a9 by 9301ccb in this PR.

}
}

transport.beforeProcessingReceivedMessage = { protocolMessage in
if protocolMessage.action == .Message {
expect(protocolMessage.messages![0].data as? String).to(equal(testMessage.encrypted.data))
expect(protocolMessage.messages![0].encoding).to(equal(testMessage.encrypted.encoding))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

// Force an error decoding a message
protocolMessage.messages![0].encoding = "bad_encoding_type"
}
}

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

channel.subscribe(testMessage.encoded.name) { message in
expect(message.data as? String).to(equal(testMessage.encrypted.data))

let logs = querySyslog(forLogsAfter: logTime)
let line = logs.reduce("") { $0 + "; " + $1 } //Reduce in one line
expect(line).to(contain("ERROR: Failed to decode data as 'bad_encoding_type' encoding is unknown"))

expect(channel.errorReason!.message).to(contain("Failed to decode data as 'bad_encoding_type' encoding is unknown"))

done()
}

channel.publish(testMessage.encoded.name, data: testMessage.encoded.data)
}
}
}

}

// RTL7f
it("should exist ensuring published messages are not echoed back to the subscriber when echoMessages is false") {
let options = AblyTests.commonAppSetup()
Expand Down
12 changes: 10 additions & 2 deletions ablySpec/TestUtilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ class AblyTests {
class func checkError(errorInfo: ARTErrorInfo?) {
checkError(errorInfo, withAlternative: "")
}
static let allDebug = true

class var jsonRestOptions: ARTClientOptions {
get {
Expand Down Expand Up @@ -114,7 +113,7 @@ class AblyTests {
class func clientOptions(debug debug: Bool = false, requestToken: Bool = false) -> ARTClientOptions {
let options = ARTClientOptions()
options.environment = "sandbox"
if debug || AblyTests.allDebug {
if debug {
options.logLevel = .Debug
}
if requestToken {
Expand Down Expand Up @@ -454,6 +453,9 @@ class TestProxyTransport: ARTWebSocketTransport {

private(set) var rawDataSent = [NSData]()
private(set) var rawDataReceived = [NSData]()

var beforeProcessingSentMessage: Optional<(ARTProtocolMessage)->()> = nil
var beforeProcessingReceivedMessage: Optional<(ARTProtocolMessage)->()> = nil

var actionsIgnored = [ARTProtocolMessageAction]()

Expand All @@ -465,6 +467,9 @@ class TestProxyTransport: ARTWebSocketTransport {

override func send(msg: ARTProtocolMessage) {
protocolMessagesSent.append(msg)
if let performEvent = beforeProcessingSentMessage {
performEvent(msg)
}
super.send(msg)
}

Expand All @@ -478,6 +483,9 @@ class TestProxyTransport: ARTWebSocketTransport {
if actionsIgnored.contains(msg.action) {
return
}
if let performEvent = beforeProcessingReceivedMessage {
performEvent(msg)
}
super.receive(msg)
}

Expand Down