Skip to content

Commit

Permalink
Merge pull request #750 from ably/add-RSA4e
Browse files Browse the repository at this point in the history
Add rsa4e
  • Loading branch information
funkyboy authored Jul 26, 2018
2 parents 60f6cda + 33a9314 commit 6a0000b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Source/ARTAuth.m
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,11 @@ - (void)_requestToken:(ARTTokenParams *)tokenParams withOptions:(ARTAuthOptions

void (^checkerCallback)(ARTTokenDetails *_Nullable, NSError *_Nullable) = ^(ARTTokenDetails *tokenDetails, NSError *error) {
if (error) {
if (error.code == NSURLErrorTimedOut) {
ARTErrorInfo *ablyError = [ARTErrorInfo createWithCode:40170 message:@"Error in requesting auth token"];
callback(nil, ablyError);
return;
}
callback(nil, error);
return;
}
Expand Down
33 changes: 32 additions & 1 deletion Spec/RestClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1350,6 +1350,37 @@ class RestClient: QuickSpec {
}
}

} //RestClient
}

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()
})
})


}
}
}
}

0 comments on commit 6a0000b

Please sign in to comment.