Skip to content

Commit

Permalink
OKTA-214174-AuthN iOS SDK: Incorrect url link is used for skip passwo…
Browse files Browse the repository at this point in the history
…rd functionality
  • Loading branch information
IldarAbdullin-okta committed Mar 13, 2019
1 parent e9a6d6a commit 11c50d5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Source/AuthenticationClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,11 @@ public class AuthenticationClient {
case .passwordWarning:
delegate?.handleChangePassword(canSkip: true, callback: { [weak self] old, new, skip in
if skip {
guard let next = self?.links?.next else {
self?.delegate?.handleError(.wrongState("Can't find 'next' link in response"))
guard let skipLink = self?.links?.skip else {
self?.delegate?.handleError(.wrongState("Can't find 'skip' link in response"))
return
}
self?.perform(link: next)
self?.perform(link: skipLink)
} else {
self?.changePassword(oldPassword: old ?? "", newPassword: new ?? "")
}
Expand Down
4 changes: 3 additions & 1 deletion Tests/AuthenticationClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class AuthenticationClientTests: XCTestCase {
delegateVerifyer.handleChangePasswordCompletion?(nil, nil, true)
XCTAssertTrue(delegateVerifyer.handleErrorCalled, "Expected delegate method handleErrorCalled to be called")
XCTAssertNotNil(delegateVerifyer.error)
XCTAssertEqual(delegateVerifyer.error?.description, OktaError.wrongState("Can't find 'next' link in response").description)
XCTAssertEqual(delegateVerifyer.error?.description, OktaError.wrongState("Can't find 'skip' link in response").description)
}

func testPasswordWarningWithNoPasswordChangeSuccessFlow() {
Expand Down Expand Up @@ -180,6 +180,8 @@ class AuthenticationClientTests: XCTestCase {
delegateVerifyer.asyncExpectation = XCTestExpectation()
delegateVerifyer.handleChangePasswordCompletion?(nil, nil, true)
XCTAssertTrue(oktaApiMock!.performCalled)
XCTAssertNotNil(oktaApiMock!.performedLink)
XCTAssertEqual(client.links?.skip?.href, oktaApiMock!.performedLink?.href)

wait(for: [delegateVerifyer.asyncExpectation!], timeout: 1.0)

Expand Down
3 changes: 3 additions & 0 deletions Tests/Mocks/OktaAPIMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ class OktaAPIMock: OktaAPI {
}

self.performCalled = true
self.performedLink = link
let req = OktaAPIRequest(baseURL: URL(string: "https://dummy.url")!,
urlSession: URLSession(configuration: .default),
completion: { _ = $0; _ = $1})
Expand All @@ -189,4 +190,6 @@ class OktaAPIMock: OktaAPI {
var getTransactionStateCalled: Bool = false
var verifyFactorCalled: Bool = false
var performCalled: Bool = false

var performedLink: LinksResponse.Link?
}

0 comments on commit 11c50d5

Please sign in to comment.