From f58becc76810e18c5355f57bd009d88ff02276ad Mon Sep 17 00:00:00 2001 From: Ricardo Pereira Date: Mon, 21 Mar 2016 16:04:17 +0000 Subject: [PATCH 1/3] RTP10e --- Spec/RealtimeClientPresence.swift | 100 ++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) diff --git a/Spec/RealtimeClientPresence.swift b/Spec/RealtimeClientPresence.swift index f517956e6..b1063d10a 100644 --- a/Spec/RealtimeClientPresence.swift +++ b/Spec/RealtimeClientPresence.swift @@ -372,6 +372,106 @@ class RealtimeClientPresence: QuickSpec { } + // RTP10 + context("leave") { + + // RTP10e + it("should result in an error immediately if the client is anonymous") { + let client = ARTRealtime(options: AblyTests.commonAppSetup()) + defer { client.close() } + let channel = client.channels.get("test") + + waitUntil(timeout: testTimeout) { done in + channel.presence.leave(nil) { error in + expect(error!.message).to(contain("attempted to publish presence message without clientId")) + done() + } + } + } + + // RTP10e + it("should result in an error immediately if the channel is DETACHED") { + let options = AblyTests.commonAppSetup() + options.clientId = "john" + let client = ARTRealtime(options: options) + defer { client.close() } + let channel = client.channels.get("test") + + waitUntil(timeout: testTimeout) { done in + channel.presence.enter(nil) { error in + expect(error).to(beNil()) + done() + } + } + + channel.detach() + + waitUntil(timeout: testTimeout) { done in + channel.presence.leave(nil) { error in + expect(error!.message).to(contain("invalid channel state")) + done() + } + } + } + + // RTP10e + it("should result in an error immediately if the channel is FAILED") { + let options = AblyTests.commonAppSetup() + options.clientId = "john" + let client = ARTRealtime(options: options) + defer { client.close() } + let channel = client.channels.get("test") + + waitUntil(timeout: testTimeout) { done in + channel.presence.enter(nil) { error in + expect(error).to(beNil()) + done() + } + } + + channel.onError(AblyTests.newErrorProtocolMessage()) + + waitUntil(timeout: testTimeout) { done in + channel.presence.leave(nil) { error in + expect(error!.message).to(contain("invalid channel state")) + done() + } + } + } + + // RTP10e + it("should result in an error if the client does not have required presence permission") { + let options = AblyTests.clientOptions() + options.token = getTestToken(capability: "{ \"cannotpresence:john\":[\"publish\"] }") + options.clientId = "john" + let client = ARTRealtime(options: options) + defer { client.close() } + let channel = client.channels.get("cannotpresence") + + waitUntil(timeout: testTimeout) { done in + channel.presence.leave(nil) { error in + expect(error!.message).to(contain("no permission")) + done() + } + } + } + + // RTP10e + it("should result in an error if Ably service determines that the client is unidentified") { + let client = ARTRealtime(options: AblyTests.commonAppSetup()) + defer { client.close() } + let channel = client.channels.get("test") + + waitUntil(timeout: testTimeout) { done in + channel.presence.leave(nil) { error in + expect(error!.message).to(contain("presence message without clientId")) + done() + } + } + } + + } + // RTP15e let cases: [String:(ARTRealtimePresence, Optional<(ARTErrorInfo?)->Void>)->()] = [ "enterClient": { $0.enterClient("john", data: nil, callback: $1) }, From 283241ddea05c7b15f38e97a0d5884476c66e112 Mon Sep 17 00:00:00 2001 From: Ricardo Pereira Date: Mon, 21 Mar 2016 16:04:27 +0000 Subject: [PATCH 2/3] RTP10e: pending --- Spec/RealtimeClientPresence.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Spec/RealtimeClientPresence.swift b/Spec/RealtimeClientPresence.swift index b1063d10a..9b6a1238f 100644 --- a/Spec/RealtimeClientPresence.swift +++ b/Spec/RealtimeClientPresence.swift @@ -440,7 +440,7 @@ class RealtimeClientPresence: QuickSpec { } // RTP10e - it("should result in an error if the client does not have required presence permission") { + pending("should result in an error if the client does not have required presence permission") { let options = AblyTests.clientOptions() options.token = getTestToken(capability: "{ \"cannotpresence:john\":[\"publish\"] }") options.clientId = "john" From 7e1a38971128e94956c0847cc5eab94b7a050e65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toni=20C=C3=A1rdenas?= Date: Fri, 1 Apr 2016 17:10:22 +0200 Subject: [PATCH 3/3] Fix RTP10e. --- Source/ARTAuth.m | 4 ++-- Spec/RealtimeClientPresence.swift | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/ARTAuth.m b/Source/ARTAuth.m index 053400a1c..43c9e1892 100644 --- a/Source/ARTAuth.m +++ b/Source/ARTAuth.m @@ -336,10 +336,10 @@ - (NSString *)getClientId { if ([self.tokenDetails.clientId isEqual:@"*"]) // Any client return nil; - else + else if (self.tokenDetails.clientId) return self.tokenDetails.clientId; } - else if (self.options) { + if (self.options) { return self.options.clientId; } else { diff --git a/Spec/RealtimeClientPresence.swift b/Spec/RealtimeClientPresence.swift index 9b6a1238f..2d19e4d09 100644 --- a/Spec/RealtimeClientPresence.swift +++ b/Spec/RealtimeClientPresence.swift @@ -440,17 +440,17 @@ class RealtimeClientPresence: QuickSpec { } // RTP10e - pending("should result in an error if the client does not have required presence permission") { + it("should result in an error if the client does not have required presence permission") { let options = AblyTests.clientOptions() - options.token = getTestToken(capability: "{ \"cannotpresence:john\":[\"publish\"] }") + options.token = getTestToken(capability: "{ \"cannotpresence:other\":[\"publish\"] }") options.clientId = "john" let client = ARTRealtime(options: options) defer { client.close() } let channel = client.channels.get("cannotpresence") waitUntil(timeout: testTimeout) { done in - channel.presence.leave(nil) { error in - expect(error!.message).to(contain("no permission")) + channel.presence.leaveClient("other", data: nil) { error in + expect(error!.message).to(contain("Channel denied access based on given capability")) done() } }