Skip to content

Commit

Permalink
Merge pull request #16 from Web3Auth/fix_expired_session
Browse files Browse the repository at this point in the history
fix: check msgData is not empty for authorizeSession before attempting decryption
  • Loading branch information
chaitanyapotti authored Oct 25, 2024
2 parents 90afccc + 3d8eb03 commit d86cd2a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Sources/SessionManager/SessionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ public class SessionManager {
guard let msgData = msgData else {
throw SessionManagerError.dataNotFound
}

if msgData.isEmpty {
throw SessionManagerError.dataNotFound
}

let loginDetails = try decryptData(privKeyHex: sessionId, d: msgData)
return loginDetails
Expand Down
17 changes: 17 additions & 0 deletions Tests/SessionManagerTests/SessionManagementTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,21 @@ final class SessionManagementTest: XCTestCase {
SessionManager.saveSessionIdToStorage(created)
try await session.invalidateSession()
}

func test_session_expired_error() async throws {
var caughtCorrectError: Bool = false;
do {
let sessionId = try SessionManager.generateRandomSessionID();
let session = SessionManager(sessionTime: 1, sessionId: sessionId)
let (privKey, pubKey) = try generatePrivateandPublicKey()
let sfa = SFAModel(publicKey: pubKey, privateKey: privKey)
let created = try await session.createSession(data: sfa)
let _ = try await session.authorizeSession(origin: "origin")
sleep(2)
let _ = try await session.authorizeSession(origin: "origin")
} catch SessionManagerError.dataNotFound {
caughtCorrectError = true
}
XCTAssertTrue(caughtCorrectError)
}
}
2 changes: 1 addition & 1 deletion TorusSessionManager.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = "TorusSessionManager"
spec.version = "6.0.0"
spec.version = "6.0.1"
spec.platform = :ios, "14.0"
spec.summary = "SessionManagement SDK"
spec.homepage = "https://github.com/Web3Auth"
Expand Down

0 comments on commit d86cd2a

Please sign in to comment.