From e5aaed4ee8c0f5ea8a43fc74a8e3f1b56a4dbdc4 Mon Sep 17 00:00:00 2001 From: Ricardo Pereira Date: Tue, 22 Mar 2016 22:23:04 +0000 Subject: [PATCH 1/4] RSA8f3 --- Spec/Auth.swift | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Spec/Auth.swift b/Spec/Auth.swift index 39290b30f..66e8cd164 100644 --- a/Spec/Auth.swift +++ b/Spec/Auth.swift @@ -891,6 +891,32 @@ class Auth : QuickSpec { } + // RSA8f3 + it("ensure the message published with a wildcard '*' does not have a clientId") { + let token = getTestToken() + let options = ARTClientOptions(token: token) + options.environment = "sandbox" + options.clientId = "john" + + let rest = ARTRest(options: options) + rest.httpExecutor = mockExecutor + let channel = rest.channels.get("test") + + waitUntil(timeout: testTimeout) { done in + channel.publish([ARTMessage(name: nil, data: "no client")]) { error in + expect(error).to(beNil()) + switch extractBodyAsJSON(mockExecutor.requests.first) { + case .Failure(let error): + fail(error) + case .Success(let httpBody): + expect(httpBody.unbox["clientId"]).to(beNil()) + } + done() + } + } + expect(rest.auth.clientId).to(equal("*")) + } + struct ExpectedTokenParams { static let clientId = "client_from_params" static let ttl = 5.0 From d6cc53ee59e2e314b6090ae90ab2a70da8676f7d Mon Sep 17 00:00:00 2001 From: Ricardo Pereira Date: Tue, 22 Mar 2016 22:23:26 +0000 Subject: [PATCH 2/4] RSA8f3: pending --- Spec/Auth.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Spec/Auth.swift b/Spec/Auth.swift index 66e8cd164..1953d6408 100644 --- a/Spec/Auth.swift +++ b/Spec/Auth.swift @@ -892,7 +892,7 @@ class Auth : QuickSpec { } // RSA8f3 - it("ensure the message published with a wildcard '*' does not have a clientId") { + pending("ensure the message published with a wildcard '*' does not have a clientId") { let token = getTestToken() let options = ARTClientOptions(token: token) options.environment = "sandbox" From e6072dc2b4e6fe46d9aa356772031fc9eda80d67 Mon Sep 17 00:00:00 2001 From: Ricardo Pereira Date: Tue, 5 Apr 2016 22:53:17 +0100 Subject: [PATCH 3/4] Test suite: extractBodyAsMessages --- Spec/TestUtilities.swift | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Spec/TestUtilities.swift b/Spec/TestUtilities.swift index 9c43f06dd..d9faa0ec1 100644 --- a/Spec/TestUtilities.swift +++ b/Spec/TestUtilities.swift @@ -479,6 +479,23 @@ func extractBodyAsJSON(request: NSMutableURLRequest?) -> Result { return Result.Success(Box(httpBody)) } +func extractBodyAsMessages(request: NSMutableURLRequest?) -> Result<[NSDictionary]> { + guard let request = request + else { return Result(error: "No request found") } + + guard let bodyData = request.HTTPBody + else { return Result(error: "No HTTPBody") } + + guard let json = try? NSJSONSerialization.JSONObjectWithData(bodyData, options: .MutableLeaves) + else { return Result(error: "Invalid json") } + + guard let httpBody = json as? NSArray + else { return Result(error: "HTTPBody has invalid format") } + + return Result.Success(Box(httpBody.map{$0 as! NSDictionary})) +} + + /// Records each request and response for test purpose. @objc class MockHTTPExecutor: NSObject, ARTHTTPExecutor { From 73c6c607d3467861599b973a211f895c91cdd891 Mon Sep 17 00:00:00 2001 From: Ricardo Pereira Date: Wed, 6 Apr 2016 15:21:59 +0100 Subject: [PATCH 4/4] Fix RSA8f3 --- Source/ARTAuth.m | 7 +------ Spec/Auth.swift | 38 ++++++++++++++++++++++++++------------ 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/Source/ARTAuth.m b/Source/ARTAuth.m index f7edc1867..568302115 100644 --- a/Source/ARTAuth.m +++ b/Source/ARTAuth.m @@ -342,12 +342,7 @@ - (void)setProtocolClientId:(NSString *)clientId { - (NSString *)getClientId { if (_protocolClientId) { - // Check wildcard - if ([_protocolClientId isEqual:@"*"]) - // Any client - return nil; - else - return _protocolClientId; + return _protocolClientId; } else if (self.tokenDetails) { // Check wildcard diff --git a/Spec/Auth.swift b/Spec/Auth.swift index 1953d6408..366509428 100644 --- a/Spec/Auth.swift +++ b/Spec/Auth.swift @@ -448,10 +448,19 @@ class Auth : QuickSpec { it("identity should be anonymous for all operations") { let options = AblyTests.commonAppSetup() options.autoConnect = false - let realtime = ARTRealtime(options: options) + let realtime = AblyTests.newRealtime(options) defer { realtime.close() } expect(realtime.auth.clientId).to(beNil()) + let transport = realtime.transport as! TestProxyTransport + transport.beforeProcessingReceivedMessage = { message in + if message.action == .Connected { + if let details = message.connectionDetails { + details.clientId = nil + } + } + } + waitUntil(timeout: testTimeout) { done in realtime.connection.once(.Connected) { stateChange in expect(stateChange!.reason).to(beNil()) @@ -892,29 +901,34 @@ class Auth : QuickSpec { } // RSA8f3 - pending("ensure the message published with a wildcard '*' does not have a clientId") { - let token = getTestToken() - let options = ARTClientOptions(token: token) - options.environment = "sandbox" - options.clientId = "john" - + it("ensure the message published with a wildcard '*' does not have a clientId") { + let options = AblyTests.commonAppSetup() + // Request a token with a wildcard '*' value clientId + options.token = getTestToken(clientId: "*") let rest = ARTRest(options: options) rest.httpExecutor = mockExecutor let channel = rest.channels.get("test") waitUntil(timeout: testTimeout) { done in - channel.publish([ARTMessage(name: nil, data: "no client")]) { error in + let message = ARTMessage(name: nil, data: "no client") + expect(message.clientId).to(beNil()) + channel.publish([message]) { error in expect(error).to(beNil()) - switch extractBodyAsJSON(mockExecutor.requests.first) { + switch extractBodyAsMessages(mockExecutor.requests.first) { case .Failure(let error): fail(error) case .Success(let httpBody): - expect(httpBody.unbox["clientId"]).to(beNil()) + expect(httpBody.unbox.first!["clientId"]).to(beNil()) + } + channel.history { page, error in + expect(error).to(beNil()) + expect(page!.items).to(haveCount(1)) + expect((page!.items[0] as! ARTMessage).clientId).to(beNil()) + done() } - done() } } - expect(rest.auth.clientId).to(equal("*")) + expect(rest.auth.clientId).to(beNil()) } struct ExpectedTokenParams {