Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update RSA10a for 0.9 #520

Merged
merged 2 commits into from
Nov 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Source/ARTAuth.m
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,6 @@ - (void)authorise:(ARTTokenParams *)tokenParams options:(ARTAuthOptions *)authOp
}

- (void)authorize:(ARTTokenParams *)tokenParams options:(ARTAuthOptions *)authOptions callback:(void (^)(ARTTokenDetails *, NSError *))callback {

ARTAuthOptions *replacedOptions = [authOptions copy] ? : [self.options copy];
[self storeOptions:replacedOptions];

Expand All @@ -351,6 +350,7 @@ - (void)authorize:(ARTTokenParams *)tokenParams options:(ARTAuthOptions *)authOp
}
} else {
_tokenDetails = tokenDetails;
_method = ARTAuthMethodToken;
[self.logger verbose:@"RS:%p ARTAuth: token request succeeded: %@", _rest, tokenDetails];
if (callback) {
callback(self.tokenDetails, nil);
Expand Down
50 changes: 50 additions & 0 deletions Spec/Auth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1728,6 +1728,56 @@ class Auth : QuickSpec {
}
}

// RSA10a
it("should create a new token if one already exist and ensure Token Auth is used for all future requests") {
let options = AblyTests.commonAppSetup()
let testToken = getTestToken()
options.token = testToken
let rest = ARTRest(options: options)

expect(rest.auth.tokenDetails?.token).toNot(beNil())
waitUntil(timeout: testTimeout) { done in
rest.auth.authorize(nil, options: nil, callback: { tokenDetails, error in
guard let tokenDetails = tokenDetails else {
XCTFail("TokenDetails is nil"); done(); return
}
expect(tokenDetails.token).toNot(equal(testToken))
expect(rest.auth.method).to(equal(ARTAuthMethod.Token))

publishTestMessage(rest, completion: { error in
expect(error).to(beNil())
expect(rest.auth.method).to(equal(ARTAuthMethod.Token))
expect(rest.auth.tokenDetails?.token).to(equal(tokenDetails.token))
done()
})
})
}
}

// RSA10a
it("should create a token immediately and ensures Token Auth is used for all future requests") {
let options = AblyTests.commonAppSetup()
let rest = ARTRest(options: options)

expect(rest.auth.tokenDetails?.token).to(beNil())
waitUntil(timeout: testTimeout) { done in
rest.auth.authorize(nil, options: nil, callback: { tokenDetails, error in
guard let tokenDetails = tokenDetails else {
XCTFail("TokenDetails is nil"); done(); return
}
expect(tokenDetails.token).toNot(beNil())
expect(rest.auth.method).to(equal(ARTAuthMethod.Token))

publishTestMessage(rest, completion: { error in
expect(error).to(beNil())
expect(rest.auth.method).to(equal(ARTAuthMethod.Token))
expect(rest.auth.tokenDetails?.token).to(equal(tokenDetails.token))
done()
})
})
}
}

// RSA10b
it("should supports all TokenParams and AuthOptions") {
let rest = ARTRest(options: AblyTests.commonAppSetup())
Expand Down