Skip to content

Commit

Permalink
fix throwing error when linking auth types due to missing sessionToken (
Browse files Browse the repository at this point in the history
  • Loading branch information
cbaker6 authored Apr 2, 2021
1 parent f3f2244 commit 7024222
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 22 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# Parse-Swift Changelog

### main
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.2.5...main)
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.2.6...main)
* _Contributing to this repo? Add info about your change here to be included in the next release_

### 1.2.6
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.2.5...1.2.6)

__Fixes__
- Crash when linking auth types due to server not sending sessionToken ([#109](https://github.com/parse-community/Parse-Swift/pull/109)), thanks to [Corey Baker](https://github.com/cbaker6).

### 1.2.5
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.2.4...1.2.5)

Expand Down
2 changes: 1 addition & 1 deletion ParseSwift.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "ParseSwift"
s.version = "1.2.5"
s.version = "1.2.6"
s.summary = "Parse Pure Swift SDK"
s.homepage = "https://github.com/parse-community/Parse-Swift"
s.authors = {
Expand Down
16 changes: 8 additions & 8 deletions ParseSwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2321,7 +2321,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 1.2.5;
MARKETING_VERSION = 1.2.6;
PRODUCT_BUNDLE_IDENTIFIER = com.parse.ParseSwift;
PRODUCT_NAME = ParseSwift;
SKIP_INSTALL = YES;
Expand All @@ -2345,7 +2345,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 1.2.5;
MARKETING_VERSION = 1.2.6;
PRODUCT_BUNDLE_IDENTIFIER = com.parse.ParseSwift;
PRODUCT_NAME = ParseSwift;
SKIP_INSTALL = YES;
Expand Down Expand Up @@ -2411,7 +2411,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.13;
MARKETING_VERSION = 1.2.5;
MARKETING_VERSION = 1.2.6;
PRODUCT_BUNDLE_IDENTIFIER = com.parse.ParseSwift;
PRODUCT_NAME = ParseSwift;
SDKROOT = macosx;
Expand All @@ -2437,7 +2437,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.13;
MARKETING_VERSION = 1.2.5;
MARKETING_VERSION = 1.2.6;
PRODUCT_BUNDLE_IDENTIFIER = com.parse.ParseSwift;
PRODUCT_NAME = ParseSwift;
SDKROOT = macosx;
Expand Down Expand Up @@ -2584,7 +2584,7 @@
INFOPLIST_FILE = "ParseSwift-watchOS/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 1.2.5;
MARKETING_VERSION = 1.2.6;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "com.parse.ParseSwift-watchOS";
Expand Down Expand Up @@ -2613,7 +2613,7 @@
INFOPLIST_FILE = "ParseSwift-watchOS/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 1.2.5;
MARKETING_VERSION = 1.2.6;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "com.parse.ParseSwift-watchOS";
PRODUCT_NAME = ParseSwift;
Expand All @@ -2640,7 +2640,7 @@
INFOPLIST_FILE = "ParseSwift-tvOS/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 1.2.5;
MARKETING_VERSION = 1.2.6;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "com.parse.ParseSwift-tvOS";
Expand Down Expand Up @@ -2668,7 +2668,7 @@
INFOPLIST_FILE = "ParseSwift-tvOS/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 1.2.5;
MARKETING_VERSION = 1.2.6;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "com.parse.ParseSwift-tvOS";
PRODUCT_NAME = ParseSwift;
Expand Down
2 changes: 1 addition & 1 deletion Scripts/jazzy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ bundle exec jazzy \
--author_url http://parseplatform.org \
--github_url https://github.com/parse-community/Parse-Swift \
--root-url http://parseplatform.org/Parse-Swift/api/ \
--module-version 1.2.5 \
--module-version 1.2.6 \
--theme fullwidth \
--skip-undocumented \
--output ./docs/api \
Expand Down
2 changes: 1 addition & 1 deletion Sources/ParseSwift/API/Responses.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal struct SaveResponse: Decodable {

internal struct UpdateSessionTokenResponse: Decodable {
var updatedAt: Date
let sessionToken: String
let sessionToken: String?
}

internal struct UpdateResponse: Decodable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,10 @@ public extension ParseUser {
guard let current = Self.current else {
throw ParseError(code: .unknownError, message: "Should have a current user.")
}
Self.currentUserContainer = .init(currentUser: current,
sessionToken: user.sessionToken)
if let sessionToken = user.sessionToken {
Self.currentUserContainer = .init(currentUser: current,
sessionToken: sessionToken)
}
Self.saveCurrentContainerToKeychain()
return current
}
Expand All @@ -432,8 +434,10 @@ public extension ParseUser {
guard let current = Self.current else {
throw ParseError(code: .unknownError, message: "Should have a current user.")
}
Self.currentUserContainer = .init(currentUser: current,
sessionToken: user.sessionToken)
if let sessionToken = user.sessionToken {
Self.currentUserContainer = .init(currentUser: current,
sessionToken: sessionToken)
}
Self.saveCurrentContainerToKeychain()
return current
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/ParseSwift/ParseConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation

enum ParseConstants {
static let parseVersion = "1.2.5"
static let parseVersion = "1.2.6"
static let hashingKey = "parseSwift"
static let fileManagementDirectory = "parse/"
static let fileManagementPrivateDocumentsDirectory = "Private Documents/"
Expand Down
2 changes: 1 addition & 1 deletion Tests/ParseSwiftTests/ParseAnonymousTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class ParseAnonymousTests: XCTestCase {

struct UpdateSessionTokenResponse: Codable {
var updatedAt: Date
let sessionToken: String
let sessionToken: String?
}

override func setUpWithError() throws {
Expand Down
6 changes: 5 additions & 1 deletion Tests/ParseSwiftTests/ParseAppleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ParseAppleTests: XCTestCase {

var objectId: String?
var createdAt: Date?
var sessionToken: String
var sessionToken: String?
var updatedAt: Date?
var ACL: ParseACL?

Expand Down Expand Up @@ -387,6 +387,7 @@ class ParseAppleTests: XCTestCase {
MockURLProtocol.removeAll()

var serverResponse = LoginSignupResponse()
serverResponse.sessionToken = nil
serverResponse.updatedAt = Date()

var userOnServer: User!
Expand Down Expand Up @@ -421,6 +422,7 @@ class ParseAppleTests: XCTestCase {
XCTAssertNil(user.password)
XCTAssertTrue(user.apple.isLinked)
XCTAssertFalse(user.anonymous.isLinked)
XCTAssertEqual(User.current?.sessionToken, "myToken")
case .failure(let error):
XCTFail(error.localizedDescription)
}
Expand All @@ -434,6 +436,7 @@ class ParseAppleTests: XCTestCase {
MockURLProtocol.removeAll()

var serverResponse = LoginSignupResponse()
serverResponse.sessionToken = nil
serverResponse.updatedAt = Date()

var userOnServer: User!
Expand Down Expand Up @@ -472,6 +475,7 @@ class ParseAppleTests: XCTestCase {
XCTAssertNil(user.password)
XCTAssertTrue(user.apple.isLinked)
XCTAssertFalse(user.anonymous.isLinked)
XCTAssertEqual(User.current?.sessionToken, "myToken")
case .failure(let error):
XCTFail(error.localizedDescription)
}
Expand Down
8 changes: 7 additions & 1 deletion Tests/ParseSwiftTests/ParseFacebookTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ParseFacebookTests: XCTestCase {

var objectId: String?
var createdAt: Date?
var sessionToken: String
var sessionToken: String?
var updatedAt: Date?
var ACL: ParseACL?

Expand Down Expand Up @@ -572,6 +572,7 @@ class ParseFacebookTests: XCTestCase {
MockURLProtocol.removeAll()
let expiresIn = 10
var serverResponse = LoginSignupResponse()
serverResponse.sessionToken = nil
serverResponse.updatedAt = Date()

var userOnServer: User!
Expand Down Expand Up @@ -602,6 +603,7 @@ class ParseFacebookTests: XCTestCase {
XCTAssertNil(user.password)
XCTAssertTrue(user.facebook.isLinked)
XCTAssertFalse(user.anonymous.isLinked)
XCTAssertEqual(User.current?.sessionToken, "myToken")
case .failure(let error):
XCTFail(error.localizedDescription)
}
Expand All @@ -615,6 +617,7 @@ class ParseFacebookTests: XCTestCase {
MockURLProtocol.removeAll()
let expiresIn = 10
var serverResponse = LoginSignupResponse()
serverResponse.sessionToken = nil
serverResponse.updatedAt = Date()

var userOnServer: User!
Expand Down Expand Up @@ -644,6 +647,7 @@ class ParseFacebookTests: XCTestCase {
XCTAssertNil(user.password)
XCTAssertTrue(user.facebook.isLinked)
XCTAssertFalse(user.anonymous.isLinked)
XCTAssertEqual(User.current?.sessionToken, "myToken")
case .failure(let error):
XCTFail(error.localizedDescription)
}
Expand All @@ -656,6 +660,7 @@ class ParseFacebookTests: XCTestCase {
_ = try loginNormally()
MockURLProtocol.removeAll()
var serverResponse = LoginSignupResponse()
serverResponse.sessionToken = nil
serverResponse.updatedAt = Date()

var userOnServer: User!
Expand Down Expand Up @@ -690,6 +695,7 @@ class ParseFacebookTests: XCTestCase {
XCTAssertNil(user.password)
XCTAssertTrue(user.facebook.isLinked)
XCTAssertFalse(user.anonymous.isLinked)
XCTAssertEqual(User.current?.sessionToken, "myToken")
case .failure(let error):
XCTFail(error.localizedDescription)
}
Expand Down
49 changes: 48 additions & 1 deletion Tests/ParseSwiftTests/ParseLDAPTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ParseLDAPTests: XCTestCase {

var objectId: String?
var createdAt: Date?
var sessionToken: String
var sessionToken: String?
var updatedAt: Date?
var ACL: ParseACL?

Expand Down Expand Up @@ -313,6 +313,7 @@ class ParseLDAPTests: XCTestCase {

var serverResponse = LoginSignupResponse()
serverResponse.updatedAt = Date()
serverResponse.sessionToken = nil

var userOnServer: User!

Expand Down Expand Up @@ -341,6 +342,52 @@ class ParseLDAPTests: XCTestCase {
XCTAssertNil(user.password)
XCTAssertTrue(user.ldap.isLinked)
XCTAssertFalse(user.anonymous.isLinked)
XCTAssertEqual(User.current?.sessionToken, "myToken")
case .failure(let error):
XCTFail(error.localizedDescription)
}
expectation1.fulfill()
}
wait(for: [expectation1], timeout: 20.0)
}

func testLinkLoggedInAuthData() throws {
_ = try loginNormally()
MockURLProtocol.removeAll()

var serverResponse = LoginSignupResponse()
serverResponse.updatedAt = Date()
serverResponse.sessionToken = nil

var userOnServer: User!

let encoded: Data!
do {
encoded = try serverResponse.getEncoder().encode(serverResponse, skipKeys: .none)
//Get dates in correct format from ParseDecoding strategy
userOnServer = try serverResponse.getDecoder().decode(User.self, from: encoded)
} catch {
XCTFail("Should encode/decode. Error \(error)")
return
}
MockURLProtocol.mockRequests { _ in
return MockURLResponse(data: encoded, statusCode: 200, delay: 0.0)
}

let expectation1 = XCTestExpectation(description: "Login")
let authData = ParseLDAP<User>
.AuthenticationKeys.id.makeDictionary(id: "testing", password: "authenticationToken")
User.ldap.link(authData: authData) { result in
switch result {

case .success(let user):
XCTAssertEqual(user, User.current)
XCTAssertEqual(user.updatedAt, userOnServer.updatedAt)
XCTAssertEqual(user.username, "parse")
XCTAssertNil(user.password)
XCTAssertTrue(user.ldap.isLinked)
XCTAssertFalse(user.anonymous.isLinked)
XCTAssertEqual(User.current?.sessionToken, "myToken")
case .failure(let error):
XCTFail(error.localizedDescription)
}
Expand Down
6 changes: 5 additions & 1 deletion Tests/ParseSwiftTests/ParseTwitterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ParseTwitterTests: XCTestCase {

var objectId: String?
var createdAt: Date?
var sessionToken: String
var sessionToken: String?
var updatedAt: Date?
var ACL: ParseACL?

Expand Down Expand Up @@ -402,6 +402,7 @@ class ParseTwitterTests: XCTestCase {
MockURLProtocol.removeAll()

var serverResponse = LoginSignupResponse()
serverResponse.sessionToken = nil
serverResponse.updatedAt = Date()

var userOnServer: User!
Expand Down Expand Up @@ -433,6 +434,7 @@ class ParseTwitterTests: XCTestCase {
XCTAssertNil(user.password)
XCTAssertTrue(user.twitter.isLinked)
XCTAssertFalse(user.anonymous.isLinked)
XCTAssertEqual(User.current?.sessionToken, "myToken")
case .failure(let error):
XCTFail(error.localizedDescription)
}
Expand All @@ -446,6 +448,7 @@ class ParseTwitterTests: XCTestCase {
MockURLProtocol.removeAll()

var serverResponse = LoginSignupResponse()
serverResponse.sessionToken = nil
serverResponse.updatedAt = Date()

var userOnServer: User!
Expand Down Expand Up @@ -482,6 +485,7 @@ class ParseTwitterTests: XCTestCase {
XCTAssertNil(user.password)
XCTAssertTrue(user.twitter.isLinked)
XCTAssertFalse(user.anonymous.isLinked)
XCTAssertEqual(User.current?.sessionToken, "myToken")
case .failure(let error):
XCTFail(error.localizedDescription)
}
Expand Down

0 comments on commit 7024222

Please sign in to comment.