Skip to content

Commit

Permalink
Update RSA10a for 0.9 (#520)
Browse files Browse the repository at this point in the history
* Update RSA10a

* Fix: authorize should change auth method to Token for future requests
  • Loading branch information
ricardopereira committed Nov 30, 2016
1 parent 263c5a7 commit a8ec7cd
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Source/ARTAuth.m
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,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 @@ -357,6 +356,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

0 comments on commit a8ec7cd

Please sign in to comment.