Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: unsafe unwraps #2251

Merged
merged 6 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions quadratic-connection/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,6 @@ pub(crate) fn app(state: State) -> Result<Router> {
// unprotected routes without state
.route("/health", get(healthcheck))
//
// don't show authorization header in logs
.layer(SetSensitiveHeadersLayer::new(
sensitive_headers.iter().cloned(),
))
//
// cache control - disable client side caching
.layer(map_response(|mut response: Response| async move {
let headers = response.headers_mut();
Expand All @@ -160,7 +155,12 @@ pub(crate) fn app(state: State) -> Result<Router> {
.layer(
TraceLayer::new_for_http()
.make_span_with(DefaultMakeSpan::default().include_headers(true)),
);
)
//
// don't show authorization header in logs
.layer(SetSensitiveHeadersLayer::new(
sensitive_headers.iter().cloned(),
));

Ok(app)
}
Expand Down
2 changes: 1 addition & 1 deletion quadratic-files/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
tracing::info!(
r#"{{ "files_to_process_in_pubsub": "{:#?}", "last_processed_file_time": "{:#?}" }}"#,
stats.files_to_process_in_pubsub,
stats.last_processed_file_time,
stats.last_processed_file_time.unwrap_or_default(),

Check warning on line 189 in quadratic-files/src/server.rs

View check run for this annotation

Codecov / codecov/patch

quadratic-files/src/server.rs#L189

Added line #L189 was not covered by tests
);
}
}
Expand Down
8 changes: 6 additions & 2 deletions quadratic-rust-shared/src/sql/mssql_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@
if let Some(username) = &self.username {
config.authentication(AuthMethod::sql_server(
username,
self.password.as_ref().unwrap(),
self.password.as_deref().ok_or_else(|| {
SharedError::Sql(SqlError::Connect("Password is required".into()))

Check warning on line 105 in quadratic-rust-shared/src/sql/mssql_connection.rs

View check run for this annotation

Codecov / codecov/patch

quadratic-rust-shared/src/sql/mssql_connection.rs#L105

Added line #L105 was not covered by tests
})?,
));
}

Expand Down Expand Up @@ -242,7 +244,9 @@
ColumnData::F64(_) => convert_mssql_type::<f64, _>(column_data, ArrowType::Float64),
ColumnData::Numeric(_) => {
convert_mssql_type::<Decimal, _>(column_data, |decimal| {
ArrowType::BigDecimal(BigDecimal::from_str(&decimal.to_string()).unwrap())
ArrowType::BigDecimal(
BigDecimal::from_str(&decimal.to_string()).unwrap_or_default(),
)
})
}
ColumnData::Guid(_) => convert_mssql_type::<Uuid, _>(column_data, ArrowType::Uuid),
Expand Down
18 changes: 17 additions & 1 deletion quadratic-shared/typesAndSchemasConnections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,24 @@ export const ConnectionTypeDetailsPostgresSchema = z.object({
password: z.string().optional().transform(transformEmptyStringToUndefined),
});
export const ConnectionTypeDetailsMysqlSchema = ConnectionTypeDetailsPostgresSchema;
export const ConnectionTypeDetailsMssqlSchema = ConnectionTypeDetailsPostgresSchema.extend({
export const ConnectionTypeDetailsMssqlSchema = z.object({
host: z.string().min(1, { message: 'Required' }),
port: z
.string()
.min(1, { message: 'Required' })
.refine(
(port) => {
const portNumber = Number(port);
if (isNaN(portNumber)) return false;
return portNumber >= 0 && portNumber <= 65535;
},
{
message: 'Port must be a valid number between 0 and 65535',
}
),
database: z.string().optional(),
username: z.string().min(1, { message: 'Required' }),
password: z.string().min(1, { message: 'Required' }),
});
export const ConnectionTypeDetailsSnowflakeSchema = z.object({
account_identifier: z.string().min(1, { message: 'Required' }),
Expand Down
Loading