Skip to content

Commit 026be84

Browse files
committed
Fix test_post_buildReport_large
1 parent 68778a5 commit 026be84

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

Sources/App/Core/Authentication/User.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ extension User {
5555
static var builder: Self { .init(name: "builder", identifier: "builder") }
5656

5757
struct BuilderAuthenticator: AsyncBearerAuthenticator {
58+
@Dependency(\.environment) var environment
59+
5860
func authenticate(bearer: BearerAuthorization, for request: Request) async throws {
59-
@Dependency(\.environment) var environment
60-
if let builderToken = environment.builderToken(),
61-
bearer.token == builderToken {
61+
if let token = environment.builderToken(), bearer.token == token {
6262
request.auth.login(User.builder)
6363
}
6464
}

Tests/AppTests/AppTestCase.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
@testable import App
1616

17+
import Dependencies
1718
import NIOConcurrencyHelpers
1819
import PostgresNIO
1920
import SQLKit
@@ -35,8 +36,16 @@ class AppTestCase: XCTestCase {
3536
}
3637

3738
func setup(_ environment: Environment) async throws -> Application {
38-
try await Self.setupDb(environment)
39-
return try await Self.setupApp(environment)
39+
try await withDependencies {
40+
// Setting builderToken here when it's also set in all tests may seem redundant but it's
41+
// what allows test_post_buildReport_large to work.
42+
// See https://github.com/pointfreeco/swift-dependencies/discussions/300#discussioncomment-11252906
43+
// for details.
44+
$0.environment.builderToken = { "secr3t" }
45+
} operation: {
46+
try await Self.setupDb(environment)
47+
return try await Self.setupApp(environment)
48+
}
4049
}
4150

4251
override func tearDown() async throws {

0 commit comments

Comments
 (0)