mirror of
https://github.com/block/buzz.git
synced 2026-11-29 04:32:08 +00:00
Make the push gateway origin configurable across the relay, gateway, mobile client, and deployment chart. This is a fresh deployment. The gateway has only run on personal development infrastructure, and push has no existing enabled users. Legacy migration, configured-to-unconfigured mobile transitions, and rolling upgrades from pre-launch gateway binaries are not supported. Populated pre-launch databases are rejected with an informative error before migrations run; their data is untouched. Mobile builds may omit the gateway URL, leaving push unavailable. Once push is enabled, subsequent builds must retain that configuration. ### Validation - All applicable CI checks pass at `5f546cfaf403f0386f146d213adfb4392f4ec29c`, including Rust, mobile/Swift, desktop/integration, security, image builds, and Helm checks. An unrelated agent cancellation test passed on retry. - PostgreSQL CI passed 384 tests, including the production-entry-point regression for refusing populated pre-launch databases before migrations, fresh initialization, and subsequent initialized deployments. - Focused local validation passed all 10 gateway PostgreSQL tests under the CI discovery filter and all 3 unconfigured-mobile tests. Repository-wide PostgreSQL discovery validation and the complete pre-push hooks passed. - Physical-device APNs/App Attest behavior and deployment to a live cluster were not verified in this work. --------- Signed-off-by: Tom Brow <tomb@block.xyz> Co-authored-by: Codex <noreply@openai.com>
79 lines
3.0 KiB
Rust
79 lines
3.0 KiB
Rust
use super::*;
|
|
use sqlx::postgres::PgPoolOptions;
|
|
|
|
#[tokio::test]
|
|
#[ignore = "requires PostgreSQL"]
|
|
async fn bootstrap_refuses_legacy_data_before_migrations_and_allows_initialized_data() {
|
|
let url = std::env::var("BUZZ_TEST_DATABASE_URL").expect("test database URL");
|
|
let pool = PgPoolOptions::new()
|
|
.max_connections(1)
|
|
.connect(&url)
|
|
.await
|
|
.expect("connect test database");
|
|
let schema = format!("bootstrap_{}", Uuid::new_v4().simple());
|
|
sqlx::raw_sql(AssertSqlSafe(format!(
|
|
"CREATE SCHEMA {schema}; SET search_path TO {schema}"
|
|
)))
|
|
.execute(&pool)
|
|
.await
|
|
.expect("isolated schema");
|
|
|
|
// Legacy schema plus real authority data. The production entry point must
|
|
// refuse before SQLx can create its history or run destructive old steps.
|
|
for migration in GATEWAY_MIGRATOR.iter().take(3) {
|
|
sqlx::raw_sql(migration.sql.as_ref())
|
|
.execute(&pool)
|
|
.await
|
|
.expect("legacy schema");
|
|
}
|
|
sqlx::query("INSERT INTO push_gateway_challenges (id, challenge_hash, expires_at) VALUES ($1, $2, now() + interval '1 hour')")
|
|
.bind(Uuid::new_v4())
|
|
.bind(vec![1_u8; 32])
|
|
.execute(&pool)
|
|
.await
|
|
.expect("legacy challenge");
|
|
let error = PostgresAuthorityStore::apply_migrations_and_grants(&pool, "")
|
|
.await
|
|
.expect_err("populated legacy database must be refused");
|
|
assert!(error.to_string().contains("non-empty pre-launch database"));
|
|
let (count, history_missing): (i64, bool) = sqlx::query_as(
|
|
"SELECT count(*), to_regclass('_sqlx_migrations') IS NULL FROM push_gateway_challenges",
|
|
)
|
|
.fetch_one(&pool)
|
|
.await
|
|
.expect("unchanged legacy state");
|
|
assert_eq!(count, 1);
|
|
assert!(history_missing, "refusal must precede all SQLx migrations");
|
|
|
|
// Only the test discards its isolated fixture, never the gateway.
|
|
sqlx::raw_sql(AssertSqlSafe(format!(
|
|
"DROP SCHEMA {schema} CASCADE; CREATE SCHEMA {schema}; SET search_path TO {schema}"
|
|
)))
|
|
.execute(&pool)
|
|
.await
|
|
.expect("fresh fixture");
|
|
for populated in [false, true] {
|
|
if populated {
|
|
sqlx::query("INSERT INTO push_gateway_challenges (id, challenge_hash, expires_at) VALUES ($1, $2, now() + interval '1 hour')")
|
|
.bind(Uuid::new_v4())
|
|
.bind(vec![2_u8; 32])
|
|
.execute(&pool)
|
|
.await
|
|
.expect("initialized gateway data");
|
|
}
|
|
// An invalid role deliberately stops after migrations, avoiding grants
|
|
// against the shared test database's public schema.
|
|
let error = PostgresAuthorityStore::apply_migrations_and_grants(&pool, "")
|
|
.await
|
|
.expect_err("invalid role after successful initialization");
|
|
assert!(error.to_string().contains("runtime database role"));
|
|
}
|
|
sqlx::raw_sql(AssertSqlSafe(format!(
|
|
"SET search_path TO public; DROP SCHEMA {schema} CASCADE"
|
|
)))
|
|
.execute(&pool)
|
|
.await
|
|
.expect("remove isolated test fixture");
|
|
pool.close().await;
|
|
}
|