1
- @testable import Auth
2
1
import CustomDump
3
- @testable import Functions
4
2
import IssueReporting
3
+ import XCTest
4
+
5
+ @testable import Auth
6
+ @testable import Functions
5
7
@testable import Realtime
6
8
@testable import Supabase
7
- import XCTest
8
9
9
10
final class AuthLocalStorageMock : AuthLocalStorage {
10
11
func store( key _: String , value _: Data ) throws { }
@@ -17,6 +18,9 @@ final class AuthLocalStorageMock: AuthLocalStorage {
17
18
}
18
19
19
20
final class SupabaseClientTests : XCTestCase {
21
+ let jwt =
22
+ " eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c "
23
+
20
24
func testClientInitialization( ) async {
21
25
final class Logger : SupabaseLogger {
22
26
func log( message _: SupabaseLogMessage ) {
@@ -31,7 +35,7 @@ final class SupabaseClientTests: XCTestCase {
31
35
32
36
let client = SupabaseClient (
33
37
supabaseURL: URL ( string: " https://project-ref.supabase.co " ) !,
34
- supabaseKey: " ANON_KEY " ,
38
+ supabaseKey: jwt ,
35
39
options: SupabaseClientOptions (
36
40
db: SupabaseClientOptions . DatabaseOptions ( schema: customSchema) ,
37
41
auth: SupabaseClientOptions . AuthOptions (
@@ -53,7 +57,7 @@ final class SupabaseClientTests: XCTestCase {
53
57
)
54
58
55
59
XCTAssertEqual ( client. supabaseURL. absoluteString, " https://project-ref.supabase.co " )
56
- XCTAssertEqual ( client. supabaseKey, " ANON_KEY " )
60
+ XCTAssertEqual ( client. supabaseKey, jwt )
57
61
XCTAssertEqual ( client. storageURL. absoluteString, " https://project-ref.supabase.co/storage/v1 " )
58
62
XCTAssertEqual ( client. databaseURL. absoluteString, " https://project-ref.supabase.co/rest/v1 " )
59
63
XCTAssertEqual (
@@ -65,9 +69,9 @@ final class SupabaseClientTests: XCTestCase {
65
69
client. headers,
66
70
[
67
71
" X-Client-Info " : " supabase-swift/ \( Supabase . version) " ,
68
- " Apikey " : " ANON_KEY " ,
72
+ " Apikey " : jwt ,
69
73
" header_field " : " header_value " ,
70
- " Authorization " : " Bearer ANON_KEY " ,
74
+ " Authorization " : " Bearer \( jwt ) " ,
71
75
]
72
76
)
73
77
expectNoDifference ( client. _headers. dictionary, client. headers)
@@ -79,7 +83,8 @@ final class SupabaseClientTests: XCTestCase {
79
83
80
84
let realtimeOptions = client. realtimeV2. options
81
85
let expectedRealtimeHeader = client. _headers. merging ( with: [
82
- . init( " custom_realtime_header_key " ) !: " custom_realtime_header_value " ]
86
+ . init( " custom_realtime_header_key " ) !: " custom_realtime_header_value "
87
+ ]
83
88
)
84
89
expectNoDifference ( realtimeOptions. headers, expectedRealtimeHeader)
85
90
XCTAssertIdentical ( realtimeOptions. logger as? Logger , logger)
@@ -97,7 +102,7 @@ final class SupabaseClientTests: XCTestCase {
97
102
func testClientInitWithDefaultOptionsShouldBeAvailableInNonLinux( ) {
98
103
_ = SupabaseClient (
99
104
supabaseURL: URL ( string: " https://project-ref.supabase.co " ) !,
100
- supabaseKey: " ANON_KEY "
105
+ supabaseKey: jwt
101
106
)
102
107
}
103
108
#endif
@@ -107,7 +112,7 @@ final class SupabaseClientTests: XCTestCase {
107
112
108
113
let client = SupabaseClient (
109
114
supabaseURL: URL ( string: " https://project-ref.supabase.co " ) !,
110
- supabaseKey: " ANON_KEY " ,
115
+ supabaseKey: jwt ,
111
116
options: . init(
112
117
auth: . init(
113
118
storage: localStorage,
@@ -123,9 +128,31 @@ final class SupabaseClientTests: XCTestCase {
123
128
124
129
#if canImport(Darwin)
125
130
// withExpectedIssue is unavailable on non-Darwin platform.
126
- withExpectedIssue {
131
+ withExpectedIssue (
132
+ """
133
+ Supabase Client is configured with the auth.accessToken option,
134
+ accessing supabase.auth is not possible.
135
+ """
136
+ ) {
127
137
_ = client. auth
128
138
}
129
139
#endif
130
140
}
141
+
142
+ #if canImport(Darwin)
143
+ // withExpectedIssue is unavailable on non-Darwin platform.
144
+ func testClientInitWithNonJWTAPIKey( ) {
145
+ withExpectedIssue ( " Authorization header does not contain a JWT " ) {
146
+ _ = SupabaseClient (
147
+ supabaseURL: URL ( string: " https://project-ref.supabase.co " ) !,
148
+ supabaseKey: " invalid.token.format " ,
149
+ options: SupabaseClientOptions (
150
+ auth: . init(
151
+ storage: AuthLocalStorageMock ( )
152
+ )
153
+ )
154
+ )
155
+ }
156
+ }
157
+ #endif
131
158
}
0 commit comments