From 09c428bd4c95afde03556e4caa8641f6d1b2780a Mon Sep 17 00:00:00 2001 From: Ricardo Pereira Date: Fri, 24 Aug 2018 15:35:09 +0100 Subject: [PATCH 1/2] Move RSL1i to RestClientChannel --- Spec/RestClient.swift | 90 +++++++++++------------------------- Spec/RestClientChannel.swift | 35 ++++++++++++++ 2 files changed, 62 insertions(+), 63 deletions(-) diff --git a/Spec/RestClient.swift b/Spec/RestClient.swift index a19074c37..209b9b820 100644 --- a/Spec/RestClient.swift +++ b/Spec/RestClient.swift @@ -1384,71 +1384,35 @@ class RestClient: QuickSpec { } } - } - - context("if in the course of a REST request an attempt to authenticate using authUrl fails due to a timeout") { - // RSA4e - it("the request should result in an error with code 40170, statusCode 401, and a suitable error message") { - let options = AblyTests.commonAppSetup() - let token = getTestToken() - options.httpRequestTimeout = 3 // short timeout to make it fail faster - options.authUrl = NSURL(string: "http://10.255.255.1")! as URL - options.authParams = [NSURLQueryItem]() as [URLQueryItem]? - options.authParams?.append(NSURLQueryItem(name: "type", value: "text") as URLQueryItem) - options.authParams?.append(NSURLQueryItem(name: "body", value: token) as URLQueryItem) - - let client = ARTRest(options: options) - waitUntil(timeout: testTimeout, action: { done in - let channel = client.channels.get("test-channel") - channel.publish("test", data: "test-data", callback: { error in - guard let error = error else { - fail("Error should not be empty") + context("if in the course of a REST request an attempt to authenticate using authUrl fails due to a timeout") { + // RSA4e + it("the request should result in an error with code 40170, statusCode 401, and a suitable error message") { + let options = AblyTests.commonAppSetup() + let token = getTestToken() + options.httpRequestTimeout = 3 // short timeout to make it fail faster + options.authUrl = NSURL(string: "http://10.255.255.1")! as URL + options.authParams = [NSURLQueryItem]() as [URLQueryItem]? + options.authParams?.append(NSURLQueryItem(name: "type", value: "text") as URLQueryItem) + options.authParams?.append(NSURLQueryItem(name: "body", value: token) as URLQueryItem) + + let client = ARTRest(options: options) + waitUntil(timeout: testTimeout, action: { done in + let channel = client.channels.get("test-channel") + channel.publish("test", data: "test-data", callback: { error in + guard let error = error else { + fail("Error should not be empty") + done() + return + } + expect(error.statusCode).to(equal(401)) + expect(error.code).to(equal(40170)) + expect(error.message).to(contain("Error in requesting auth token")) done() - return - } - expect(error.statusCode).to(equal(401)) - expect(error.code).to(equal(40170)) - expect(error.message).to(contain("Error in requesting auth token")) - done() - }) - }) - } - } - - // RSL1i - context("If the total size of message(s) exceeds the maxMessageSize") { - let channelName = "test-message-size" - it("the client library should reject the publish and indicate an error") { - let options = AblyTests.commonAppSetup() - let client = ARTRest(options: options) - let channel = client.channels.get(channelName) - let messages = buildMessagesThatExceedMaxMessageSize() - - waitUntil(timeout: testTimeout, action: { done in - channel.publish(messages, callback: { err in - expect(err?.code).to(equal(40009)) - expect(err?.message).to(contain("maximum message length exceeded")) - done() + }) }) - }) - } - - it("also when using publish:data:clientId:extras") { - let options = AblyTests.commonAppSetup() - let client = ARTRest(options: options) - let channel = client.channels.get(channelName) - let name = buildStringThatExceedMaxMessageSize() - - waitUntil(timeout: testTimeout, action: { done in - channel.publish(name, data: nil, extras: nil, callback: {err in - expect(err?.code).to(equal(40009)) - expect(err?.message).to(contain("maximum message length exceeded")) - done() - }) - - - }) + } } - } + + } // RestClient } } diff --git a/Spec/RestClientChannel.swift b/Spec/RestClientChannel.swift index 83e8e0a9f..fe856c808 100644 --- a/Spec/RestClientChannel.swift +++ b/Spec/RestClientChannel.swift @@ -371,6 +371,41 @@ class RestClientChannel: QuickSpec { } } } + + // RSL1i + context("If the total size of message(s) exceeds the maxMessageSize") { + let channelName = "test-message-size" + + it("the client library should reject the publish and indicate an error") { + let options = AblyTests.commonAppSetup() + let client = ARTRest(options: options) + let channel = client.channels.get(channelName) + let messages = buildMessagesThatExceedMaxMessageSize() + + waitUntil(timeout: testTimeout, action: { done in + channel.publish(messages, callback: { err in + expect(err?.code).to(equal(40009)) + expect(err?.message).to(contain("maximum message length exceeded")) + done() + }) + }) + } + + it("also when using publish:data:clientId:extras") { + let options = AblyTests.commonAppSetup() + let client = ARTRest(options: options) + let channel = client.channels.get(channelName) + let name = buildStringThatExceedMaxMessageSize() + + waitUntil(timeout: testTimeout, action: { done in + channel.publish(name, data: nil, extras: nil, callback: {err in + expect(err?.code).to(equal(40009)) + expect(err?.message).to(contain("maximum message length exceeded")) + done() + }) + }) + } + } } // RSL2 From a6d9ee70bfa91cced8725d72ccb5a15967aa9054 Mon Sep 17 00:00:00 2001 From: Cesare Rocchi Date: Wed, 5 Sep 2018 17:58:31 +0200 Subject: [PATCH 2/2] Improve RTN14b test --- Spec/RealtimeClientConnection.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Spec/RealtimeClientConnection.swift b/Spec/RealtimeClientConnection.swift index 4c1edebf5..f51837da4 100644 --- a/Spec/RealtimeClientConnection.swift +++ b/Spec/RealtimeClientConnection.swift @@ -1991,7 +1991,9 @@ class RealtimeClientConnection: QuickSpec { guard let reason = stateChange?.reason else { fail("Reason is nil"); done(); return; } - expect(reason.code) == 40142 + expect(reason.code).to(equal(40142)) + expect(reason.statusCode).to(equal(401)) + expect(reason.message).to(contain("Key/token status changed (expire)")) partialDone() } client.connect()