|
2 | 2 | mod tests { |
3 | 3 | use tracing::{debug, info}; |
4 | 4 |
|
5 | | - use crate::common::{clear, connect_with_tls, random_id, reset_schema, trace, PROXY}; |
| 5 | + use crate::common::{ |
| 6 | + clear, connect_with_tls, proxy_port, random_id, reset_schema, trace, PROXY, |
| 7 | + }; |
| 8 | + |
| 9 | + /// A statement that always fails inside the proxy, at Parse, in every |
| 10 | + /// configuration: the proxy's SQL parser rejects it before it reaches the |
| 11 | + /// server (same shape as [`invalid_sql_statement`]). |
| 12 | + /// |
| 13 | + /// A transformation failure (e.g. equality on the storage-only |
| 14 | + /// `eql_v3_boolean`) cannot be used here: type-check errors only surface |
| 15 | + /// when `CS_DEVELOPMENT__ENABLE_MAPPING_ERRORS` is on, and the CI proxy |
| 16 | + /// (like production) runs with it off, silently passing such statements |
| 17 | + /// through. A parse error takes the same failure path in the proxy |
| 18 | + /// (`handle_statement_error`) regardless of that flag. |
| 19 | + const FAILS_IN_PROXY: &str = "INSERT INTO encrypted id, encrypted_text VALUES ($1, $2)"; |
6 | 20 |
|
7 | 21 | struct Reset; |
8 | 22 |
|
@@ -108,6 +122,78 @@ mod tests { |
108 | 122 | } |
109 | 123 | } |
110 | 124 |
|
| 125 | + /// CIP-3678 regression: a statement that fails inside the proxy on a |
| 126 | + /// connection that has already run a MAPPED (encrypted) statement must |
| 127 | + /// surface the proxy's own error as a clean `db error` — not desync the |
| 128 | + /// extended-protocol stream into a client-side protocol error |
| 129 | + /// (`unexpected message from server`) — and the connection must remain |
| 130 | + /// usable afterwards. |
| 131 | + #[tokio::test] |
| 132 | + async fn proxy_error_after_mapped_statement() { |
| 133 | + trace(); |
| 134 | + |
| 135 | + let client = connect_with_tls(proxy_port()).await; |
| 136 | + |
| 137 | + // Mapped warm-up: an encrypted statement that parses, binds and |
| 138 | + // executes successfully. |
| 139 | + client |
| 140 | + .query( |
| 141 | + "SELECT id FROM encrypted WHERE encrypted_text = $1", |
| 142 | + &[&"cip-3678"], |
| 143 | + ) |
| 144 | + .await |
| 145 | + .unwrap(); |
| 146 | + |
| 147 | + // A statement that fails inside the proxy must return the proxy's |
| 148 | + // error, delivered as a database error. |
| 149 | + let err = client |
| 150 | + .query(FAILS_IN_PROXY, &[&random_id(), &"cip-3678"]) |
| 151 | + .await |
| 152 | + .unwrap_err(); |
| 153 | + let db_err = err.as_db_error().unwrap_or_else(|| { |
| 154 | + panic!("expected a db error carrying the proxy's message, got: {err:?}") |
| 155 | + }); |
| 156 | + assert!( |
| 157 | + db_err.message().contains("sql parser error"), |
| 158 | + "expected the proxy's parse error, got: {db_err:?}" |
| 159 | + ); |
| 160 | + |
| 161 | + // The connection must remain usable. |
| 162 | + let rows = client.query("SELECT 1::int4", &[]).await.unwrap(); |
| 163 | + let one: i32 = rows[0].get(0); |
| 164 | + assert_eq!(one, 1); |
| 165 | + } |
| 166 | + |
| 167 | + /// Companion to [`proxy_error_after_mapped_statement`]: the same failing |
| 168 | + /// statement on a connection that has only run passthrough statements. |
| 169 | + /// This path already worked; keep it covered. |
| 170 | + #[tokio::test] |
| 171 | + async fn proxy_error_after_passthrough_statement() { |
| 172 | + trace(); |
| 173 | + |
| 174 | + let client = connect_with_tls(proxy_port()).await; |
| 175 | + |
| 176 | + // Passthrough warm-up. |
| 177 | + client.query("SELECT 1::int4", &[]).await.unwrap(); |
| 178 | + |
| 179 | + let err = client |
| 180 | + .query(FAILS_IN_PROXY, &[&random_id(), &"cip-3678"]) |
| 181 | + .await |
| 182 | + .unwrap_err(); |
| 183 | + let db_err = err.as_db_error().unwrap_or_else(|| { |
| 184 | + panic!("expected a db error carrying the proxy's message, got: {err:?}") |
| 185 | + }); |
| 186 | + assert!( |
| 187 | + db_err.message().contains("sql parser error"), |
| 188 | + "expected the proxy's parse error, got: {db_err:?}" |
| 189 | + ); |
| 190 | + |
| 191 | + // The connection must remain usable. |
| 192 | + let rows = client.query("SELECT 1::int4", &[]).await.unwrap(); |
| 193 | + let one: i32 = rows[0].get(0); |
| 194 | + assert_eq!(one, 1); |
| 195 | + } |
| 196 | + |
111 | 197 | #[tokio::test] |
112 | 198 | async fn invalid_sql_statement() { |
113 | 199 | trace(); |
|
0 commit comments