@@ -43,11 +43,10 @@ class StorageAuthorizerTests: StorageTestHelpers {
43
43
let fetchRequest = URLRequest ( url: StorageTestHelpers ( ) . objectURL ( ) )
44
44
fetcher = GTMSessionFetcher ( request: fetchRequest)
45
45
46
- fetcherService = GTMSessionFetcherService ( )
47
46
auth = FIRAuthInteropFake ( token: StorageTestAuthToken, userID: nil , error: nil )
48
47
appCheck = FIRAppCheckFake ( )
49
48
fetcher? . authorizer = StorageTokenAuthorizer ( googleAppID: " dummyAppID " ,
50
- fetcherService : fetcherService! ,
49
+ callbackQueue : DispatchQueue . main ,
51
50
authProvider: auth, appCheck: appCheck)
52
51
}
53
52
@@ -60,130 +59,97 @@ class StorageAuthorizerTests: StorageTestHelpers {
60
59
super. tearDown ( )
61
60
}
62
61
63
- func testSuccessfulAuth( ) {
64
- let expectation = self . expectation ( description: #function)
62
+ func testSuccessfulAuth( ) async throws {
65
63
setFetcherTestBlock ( with: 200 ) { fetcher in
66
64
self . checkAuthorizer ( fetcher: fetcher, trueFalse: true )
67
65
}
68
- fetcher? . beginFetch { data, error in
69
- let headers = self . fetcher!. request? . allHTTPHeaderFields
70
- XCTAssertEqual ( headers![ " Authorization " ] , " Firebase \( self . StorageTestAuthToken) " )
71
- expectation. fulfill ( )
72
- }
73
- waitForExpectation ( test: self )
66
+ let _ = try await fetcher? . beginFetch ( )
67
+ let headers = fetcher!. request? . allHTTPHeaderFields
68
+ XCTAssertEqual ( headers![ " Authorization " ] , " Firebase \( StorageTestAuthToken) " )
74
69
}
75
70
76
- func testUnsuccessfulAuth( ) {
77
- let expectation = self . expectation ( description: #function)
71
+ func testUnsuccessfulAuth( ) async {
78
72
let authError = NSError ( domain: " FIRStorageErrorDomain " ,
79
73
code: StorageErrorCode . unauthenticated. rawValue, userInfo: nil )
80
74
let failedAuth = FIRAuthInteropFake ( token: nil , userID: nil , error: authError)
81
75
fetcher? . authorizer = StorageTokenAuthorizer (
82
76
googleAppID: " dummyAppID " ,
83
- fetcherService: fetcherService!,
84
77
authProvider: failedAuth,
85
78
appCheck: nil
86
79
)
87
80
setFetcherTestBlock ( with: 401 ) { fetcher in
88
81
self . checkAuthorizer ( fetcher: fetcher, trueFalse: false )
89
82
}
90
- fetcher ? . beginFetch { data , error in
91
- let headers = self . fetcher! . request ? . allHTTPHeaderFields
92
- XCTAssertNil ( headers )
93
- let nsError = error as? NSError
94
- XCTAssertEqual ( nsError? . domain, " FIRStorageErrorDomain " )
95
- XCTAssertEqual ( nsError? . code, StorageErrorCode . unauthenticated. rawValue)
96
- XCTAssertEqual ( nsError? . localizedDescription, " User is not authenticated, please " +
83
+ do {
84
+ let _ = try await fetcher? . beginFetch ( )
85
+ } catch {
86
+ let nsError = error as NSError
87
+ XCTAssertEqual ( nsError. domain, " FIRStorageErrorDomain " )
88
+ XCTAssertEqual ( nsError. code, StorageErrorCode . unauthenticated. rawValue)
89
+ XCTAssertEqual ( nsError. localizedDescription, " User is not authenticated, please " +
97
90
" authenticate using Firebase Authentication and try again. " )
98
- expectation. fulfill ( )
99
91
}
100
- waitForExpectation ( test: self )
101
92
}
102
93
103
- func testSuccessfulUnauthenticatedAuth( ) {
104
- let expectation = self . expectation ( description: #function)
105
-
94
+ func testSuccessfulUnauthenticatedAuth( ) async throws {
106
95
// Simulate Auth not being included at all
107
96
fetcher? . authorizer = StorageTokenAuthorizer (
108
97
googleAppID: " dummyAppID " ,
109
- fetcherService: fetcherService!,
110
98
authProvider: nil ,
111
99
appCheck: nil
112
100
)
113
101
114
102
setFetcherTestBlock ( with: 200 ) { fetcher in
115
103
self . checkAuthorizer ( fetcher: fetcher, trueFalse: false )
116
104
}
117
- fetcher? . beginFetch { data, error in
118
- let headers = self . fetcher!. request? . allHTTPHeaderFields
119
- XCTAssertNil ( headers![ " Authorization " ] )
120
- XCTAssertNil ( error)
121
- expectation. fulfill ( )
122
- }
123
- waitForExpectation ( test: self )
105
+ let _ = try await fetcher? . beginFetch ( )
106
+ let headers = fetcher!. request? . allHTTPHeaderFields
107
+ XCTAssertNil ( headers![ " Authorization " ] )
124
108
}
125
109
126
- func testSuccessfulAppCheckNoAuth( ) {
127
- let expectation = self . expectation ( description: #function)
110
+ func testSuccessfulAppCheckNoAuth( ) async throws {
128
111
appCheck? . tokenResult = appCheckTokenSuccess!
129
112
130
113
// Simulate Auth not being included at all
131
114
fetcher? . authorizer = StorageTokenAuthorizer (
132
115
googleAppID: " dummyAppID " ,
133
- fetcherService: fetcherService!,
134
116
authProvider: nil ,
135
117
appCheck: appCheck
136
118
)
137
119
138
120
setFetcherTestBlock ( with: 200 ) { fetcher in
139
121
self . checkAuthorizer ( fetcher: fetcher, trueFalse: false )
140
122
}
141
- fetcher? . beginFetch { data, error in
142
- let headers = self . fetcher!. request? . allHTTPHeaderFields
143
- XCTAssertEqual ( headers![ " X-Firebase-AppCheck " ] , self . appCheckTokenSuccess? . token)
144
- XCTAssertNil ( error)
145
- expectation. fulfill ( )
146
- }
147
- waitForExpectation ( test: self )
123
+ let _ = try await fetcher? . beginFetch ( )
124
+ let headers = fetcher!. request? . allHTTPHeaderFields
125
+ XCTAssertEqual ( headers![ " X-Firebase-AppCheck " ] , appCheckTokenSuccess? . token)
148
126
}
149
127
150
- func testSuccessfulAppCheckAndAuth( ) {
151
- let expectation = self . expectation ( description: #function)
128
+ func testSuccessfulAppCheckAndAuth( ) async throws {
152
129
appCheck? . tokenResult = appCheckTokenSuccess!
153
130
154
131
setFetcherTestBlock ( with: 200 ) { fetcher in
155
132
self . checkAuthorizer ( fetcher: fetcher, trueFalse: true )
156
133
}
157
- fetcher? . beginFetch { data, error in
158
- let headers = self . fetcher!. request? . allHTTPHeaderFields
159
- XCTAssertEqual ( headers![ " Authorization " ] , " Firebase \( self . StorageTestAuthToken) " )
160
- XCTAssertEqual ( headers![ " X-Firebase-AppCheck " ] , self . appCheckTokenSuccess? . token)
161
- XCTAssertNil ( error)
162
- expectation. fulfill ( )
163
- }
164
- waitForExpectation ( test: self )
134
+ let _ = try await fetcher? . beginFetch ( )
135
+ let headers = fetcher!. request? . allHTTPHeaderFields
136
+ XCTAssertEqual ( headers![ " Authorization " ] , " Firebase \( StorageTestAuthToken) " )
137
+ XCTAssertEqual ( headers![ " X-Firebase-AppCheck " ] , appCheckTokenSuccess? . token)
165
138
}
166
139
167
- func testAppCheckError( ) {
168
- let expectation = self . expectation ( description: #function)
140
+ func testAppCheckError( ) async throws {
169
141
appCheck? . tokenResult = appCheckTokenError!
170
142
171
143
setFetcherTestBlock ( with: 200 ) { fetcher in
172
144
self . checkAuthorizer ( fetcher: fetcher, trueFalse: true )
173
145
}
174
- fetcher? . beginFetch { data, error in
175
- let headers = self . fetcher!. request? . allHTTPHeaderFields
176
- XCTAssertEqual ( headers![ " Authorization " ] , " Firebase \( self . StorageTestAuthToken) " )
177
- XCTAssertEqual ( headers![ " X-Firebase-AppCheck " ] , self . appCheckTokenError? . token)
178
- XCTAssertNil ( error)
179
- expectation. fulfill ( )
180
- }
181
- waitForExpectation ( test: self )
146
+ let _ = try await fetcher? . beginFetch ( )
147
+ let headers = fetcher!. request? . allHTTPHeaderFields
148
+ XCTAssertEqual ( headers![ " Authorization " ] , " Firebase \( StorageTestAuthToken) " )
149
+ XCTAssertEqual ( headers![ " X-Firebase-AppCheck " ] , appCheckTokenError? . token)
182
150
}
183
151
184
- func testIsAuthorizing( ) {
185
- let expectation = self . expectation ( description: #function)
186
-
152
+ func testIsAuthorizing( ) async throws {
187
153
setFetcherTestBlock ( with: 200 ) { fetcher in
188
154
do {
189
155
let authorizer = try XCTUnwrap ( fetcher. authorizer)
@@ -192,16 +158,10 @@ class StorageAuthorizerTests: StorageTestHelpers {
192
158
XCTFail ( " Failed to get authorizer: \( error) " )
193
159
}
194
160
}
195
- fetcher? . beginFetch { data, error in
196
- XCTAssertNil ( error)
197
- expectation. fulfill ( )
198
- }
199
- waitForExpectation ( test: self )
161
+ let _ = try await fetcher? . beginFetch ( )
200
162
}
201
163
202
- func testStopAuthorizingNoop( ) {
203
- let expectation = self . expectation ( description: #function)
204
-
164
+ func testStopAuthorizingNoop( ) async throws {
205
165
setFetcherTestBlock ( with: 200 ) { fetcher in
206
166
do {
207
167
let authorizer = try XCTUnwrap ( fetcher. authorizer)
@@ -214,18 +174,12 @@ class StorageAuthorizerTests: StorageTestHelpers {
214
174
XCTFail ( " Failed to get authorizer: \( error) " )
215
175
}
216
176
}
217
- fetcher? . beginFetch { data, error in
218
- XCTAssertNil ( error)
219
- let headers = self . fetcher!. request? . allHTTPHeaderFields
220
- XCTAssertEqual ( headers![ " Authorization " ] , " Firebase \( self . StorageTestAuthToken) " )
221
- expectation. fulfill ( )
222
- }
223
- waitForExpectation ( test: self )
177
+ let _ = try await fetcher? . beginFetch ( )
178
+ let headers = fetcher!. request? . allHTTPHeaderFields
179
+ XCTAssertEqual ( headers![ " Authorization " ] , " Firebase \( StorageTestAuthToken) " )
224
180
}
225
181
226
- func testEmail( ) {
227
- let expectation = self . expectation ( description: #function)
228
-
182
+ func testEmail( ) async throws {
229
183
setFetcherTestBlock ( with: 200 ) { fetcher in
230
184
do {
231
185
let authorizer = try XCTUnwrap ( fetcher. authorizer)
@@ -234,11 +188,7 @@ class StorageAuthorizerTests: StorageTestHelpers {
234
188
XCTFail ( " Failed to get authorizer: \( error) " )
235
189
}
236
190
}
237
- fetcher? . beginFetch { data, error in
238
- XCTAssertNil ( error)
239
- expectation. fulfill ( )
240
- }
241
- waitForExpectation ( test: self )
191
+ let _ = try await fetcher? . beginFetch ( )
242
192
}
243
193
244
194
// MARK: Helpers
0 commit comments