Skip to content

Commit

Permalink
When setting realtime channel options, pass through to REST channel
Browse files Browse the repository at this point in the history
When calling -[ARTRealtimeChannel setOptions:callback:], the passed
options are not used to update the options of this instance’s REST
channel. This means that, for example, if we update the realtime
channel’s cipher options, these options will not be used to decrypt
messages subsequently fetched using the -history:* methods.

I think this is something we missed when fixing #1207 (34d68ec).

This issue is causing ably/ably-flutter#296.

Closes #1265.
  • Loading branch information
lawrence-forooghian committed Jan 19, 2022
1 parent dd272cf commit 71250a0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions Source/ARTRealtimeChannel.m
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,7 @@ - (void)setOptions:(ARTRealtimeChannelOptions *_Nullable)options callback:(nulla

- (void)setOptions_nosync:(ARTRealtimeChannelOptions *_Nullable)options callback:(nullable ARTCallback)callback {
[self setOptions_nosync:options];
[self.restChannel setOptions_nosync:options];

if (!options.modes && !options.params) {
if (callback)
Expand Down
33 changes: 33 additions & 0 deletions Spec/Tests/RealtimeClientChannelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4188,6 +4188,39 @@ class RealtimeClientChannelTests: XCTestCase {
expect(lastAttach.flags & subscribeFlag).to(equal(subscribeFlag))
expect(lastAttach.params).to(equal(channelOptions.params))
}

func test__Channel_options__setOptions__shouldUpdateOptionsOfRestChannel() {
let client = AblyTests.newRealtime(AblyTests.commonAppSetup())
defer { client.dispose(); client.close() }
let channel = client.channels.get("foo")

waitUntil(timeout: testTimeout) { done in
client.connection.once(.connected) { _ in
done()
}
}

var restChannelSetOptions: ARTChannelOptions?
let token = channel.internal.restChannel.testSuite_getArgument(from: #selector(ARTRestChannelInternal.setOptions_nosync(_:)), at: 0) { arg in
guard let optionsArg = arg as? ARTChannelOptions else {
XCTFail("Expected setOptions: to have been called with an ARTChannelOptions instance")
return
}
restChannelSetOptions = optionsArg
}
defer { token.remove() }

let channelOptions = ARTRealtimeChannelOptions(cipherKey: ARTCrypto.generateRandomKey() as NSData)

waitUntil(timeout: testTimeout) { done in
channel.setOptions(channelOptions) { error in
XCTAssertNil(error)
done()
}
}

expect(restChannelSetOptions).to(beIdenticalTo(channelOptions))
}

// RTL17
func test__122__Channel__history__should_not_emit_messages_to_subscribers_if_the_channel_is_in_any_state_other_than_ATTACHED() {
Expand Down

0 comments on commit 71250a0

Please sign in to comment.