Skip to content

Commit 07d66a4

Browse files
committed
Improve setupDb safeguard
1 parent c365440 commit 07d66a4

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

Tests/AppTests/AppTestCase.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,7 @@ extension AppTestCase {
5050

5151
static func setupApp(_ environment: Environment) async throws -> Application {
5252
let app = try await Application.make(environment)
53-
let host = try await configure(app)
54-
55-
// Ensure `.testing` refers to certain restricted db hostnames and nothing else
56-
precondition(["localhost", "postgres", "host.docker.internal"].contains(host),
57-
".testing must be a local db, was: \(host)")
53+
try await configure(app)
5854

5955
// Silence app logging
6056
app.logger = .init(label: "noop") { _ in SwiftLogNoOpLogHandler() }
@@ -65,6 +61,14 @@ extension AppTestCase {
6561

6662
static func setupDb(_ environment: Environment) async throws {
6763
await DotEnvFile.load(for: environment, fileio: .init(threadPool: .singleton))
64+
65+
// Ensure DATABASE_HOST is from a restricted set db hostnames and nothing else.
66+
// This is safeguard against accidental inheritance of setup in QueryPerformanceTests
67+
// and to ensure the database resetting cannot impact any other network hosts.
68+
let host = Environment.get("DATABASE_HOST")
69+
precondition(["localhost", "postgres", "host.docker.internal"].contains(host),
70+
"DATABASE_HOST must be a local db, was: \(host)")
71+
6872
let testDbName = Environment.get("DATABASE_NAME")!
6973
let snapshotName = testDbName + "_snapshot"
7074

0 commit comments

Comments
 (0)