this repo has no description
at oauth 91 lines 2.8 kB view raw
1import Testing 2import Foundation 3@testable import CoreATProtocol 4 5@Suite("CoreATProtocol Environment Tests", .serialized) 6struct CoreATProtocolTests { 7 8 @Test("Environment singleton is accessible") 9 func testEnvironmentSingleton() async { 10 // Clear state first 11 await clearAuthenticationContext() 12 13 // Just verify we can access the singleton 14 let host = await APEnvironment.current.host 15 #expect(host == nil) // Default state should have nil host 16 } 17 18 @Test("Setup configures environment correctly") 19 func testSetup() async { 20 // Clear previous state 21 await clearAuthenticationContext() 22 23 await setup( 24 hostURL: "https://bsky.social", 25 accessJWT: "test-access", 26 refreshJWT: "test-refresh" 27 ) 28 29 let host = await APEnvironment.current.host 30 let access = await APEnvironment.current.accessToken 31 let refresh = await APEnvironment.current.refreshToken 32 33 #expect(host == "https://bsky.social") 34 #expect(access == "test-access") 35 #expect(refresh == "test-refresh") 36 37 // Clean up 38 await clearAuthenticationContext() 39 } 40 41 @Test("Clear authentication context removes all tokens") 42 func testClearContext() async { 43 await setup( 44 hostURL: "https://test.social", 45 accessJWT: "access", 46 refreshJWT: "refresh" 47 ) 48 49 await clearAuthenticationContext() 50 51 let access = await APEnvironment.current.accessToken 52 let refresh = await APEnvironment.current.refreshToken 53 let login = await APEnvironment.current.login 54 55 #expect(access == nil) 56 #expect(refresh == nil) 57 #expect(login == nil) 58 } 59 60 @Test("Update tokens modifies existing tokens") 61 func testUpdateTokens() async { 62 await setup(hostURL: nil, accessJWT: "old-access", refreshJWT: "old-refresh") 63 await updateTokens(access: "new-access", refresh: "new-refresh") 64 65 let access = await APEnvironment.current.accessToken 66 let refresh = await APEnvironment.current.refreshToken 67 68 #expect(access == "new-access") 69 #expect(refresh == "new-refresh") 70 71 await clearAuthenticationContext() 72 } 73 74 @Test("DPoP nonce update works correctly") 75 func testDPoPNonceUpdate() async { 76 await updateResourceDPoPNonce("test-nonce-123") 77 78 let nonce = await APEnvironment.current.resourceServerNonce 79 80 #expect(nonce == "test-nonce-123") 81 82 await updateResourceDPoPNonce(nil) 83 } 84 85 @Test("hasValidSession returns false when no session") 86 func testNoValidSession() async { 87 await clearAuthenticationContext() 88 let valid = await hasValidSession 89 #expect(valid == false) 90 } 91}