chore: fix rand upgrade

This commit is contained in:
Rob Ede 2025-02-09 02:13:11 +00:00
parent 79b2400849
commit a53f86190d
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
5 changed files with 25 additions and 54 deletions

View File

@ -16,6 +16,7 @@ use actix_utils::future::{err, ok, ready};
use bytes::Bytes;
use derive_more::derive::{Display, Error};
use futures_util::{stream::once, FutureExt as _, StreamExt as _};
use rand::Rng as _;
use regex::Regex;
#[actix_rt::test]
@ -164,7 +165,10 @@ async fn chunked_payload() {
for chunk_size in chunk_sizes.iter() {
let mut bytes = Vec::new();
let random_bytes: Vec<u8> = (0..*chunk_size).map(|_| rand::random::<u8>()).collect();
let random_bytes = rand::rng()
.sample_iter(rand::distr::StandardUniform)
.take(*chunk_size)
.collect::<Vec<_>>();
bytes.extend(format!("{:X}\r\n", chunk_size).as_bytes());
bytes.extend(&random_bytes[..]);

View File

@ -5,10 +5,7 @@ use actix_web::{
web::{BufMut as _, Bytes, BytesMut},
};
use mime::Mime;
use rand::{
distributions::{Alphanumeric, DistString as _},
thread_rng,
};
use rand::distr::{Alphanumeric, SampleString as _};
const CRLF: &[u8] = b"\r\n";
const CRLF_CRLF: &[u8] = b"\r\n\r\n";
@ -64,7 +61,7 @@ pub fn create_form_data_payload_and_headers(
content_type: Option<Mime>,
file: Bytes,
) -> (Bytes, HeaderMap) {
let boundary = Alphanumeric.sample_string(&mut thread_rng(), 32);
let boundary = Alphanumeric.sample_string(&mut rand::rng(), 32);
create_form_data_payload_and_headers_with_boundary(
&boundary,

View File

@ -25,7 +25,10 @@ use openssl::{
ssl::{SslAcceptor, SslMethod},
x509::X509,
};
use rand::{distributions::Alphanumeric, Rng as _};
use rand::{
distr::{Alphanumeric, SampleString as _},
Rng as _,
};
mod utils;
@ -188,11 +191,7 @@ async fn body_gzip_large() {
#[actix_rt::test]
async fn test_body_gzip_large_random() {
let data = rand::thread_rng()
.sample_iter(&Alphanumeric)
.take(70_000)
.map(char::from)
.collect::<String>();
let data = Alphanumeric.sample_string(&mut rand::rng(), 70_000);
let srv_data = data.clone();
let srv = actix_test::start_with(actix_test::config().h1(), move || {
@ -432,11 +431,7 @@ async fn test_zstd_encoding() {
#[actix_rt::test]
async fn test_zstd_encoding_large() {
let data = rand::thread_rng()
.sample_iter(&Alphanumeric)
.take(320_000)
.map(char::from)
.collect::<String>();
let data = Alphanumeric.sample_string(&mut rand::rng(), 320_000);
let srv = actix_test::start_with(actix_test::config().h1(), || {
App::new().service(
@ -529,11 +524,7 @@ async fn test_gzip_encoding_large() {
#[actix_rt::test]
async fn test_reading_gzip_encoding_large_random() {
let data = rand::thread_rng()
.sample_iter(&Alphanumeric)
.take(60_000)
.map(char::from)
.collect::<String>();
let data = Alphanumeric.sample_string(&mut rand::rng(), 60_000);
let srv = actix_test::start_with(actix_test::config().h1(), || {
App::new().service(web::resource("/").route(web::to(move |body: Bytes| async {
@ -599,11 +590,7 @@ async fn test_reading_deflate_encoding_large() {
#[actix_rt::test]
async fn test_reading_deflate_encoding_large_random() {
let data = rand::thread_rng()
.sample_iter(&Alphanumeric)
.take(160_000)
.map(char::from)
.collect::<String>();
let data = Alphanumeric.sample_string(&mut rand::rng(), 160_000);
let srv = actix_test::start_with(actix_test::config().h1(), || {
App::new().service(web::resource("/").route(web::to(move |body: Bytes| async {
@ -648,11 +635,7 @@ async fn test_brotli_encoding() {
#[actix_rt::test]
async fn test_brotli_encoding_large() {
let data = rand::thread_rng()
.sample_iter(&Alphanumeric)
.take(320_000)
.map(char::from)
.collect::<String>();
let data = Alphanumeric.sample_string(&mut rand::rng(), 320_000);
let srv = actix_test::start_with(actix_test::config().h1(), || {
App::new().service(
@ -737,11 +720,7 @@ mod plus_rustls {
#[actix_rt::test]
async fn test_reading_deflate_encoding_large_random_rustls() {
let data = rand::thread_rng()
.sample_iter(&Alphanumeric)
.take(160_000)
.map(char::from)
.collect::<String>();
let data = Alphanumeric.sample_string(&mut rand::rng(), 160_000);
let srv = actix_test::start_with(actix_test::config().rustls_0_23(tls_config()), || {
App::new().service(web::resource("/").route(web::to(|bytes: Bytes| async {

View File

@ -326,7 +326,7 @@ impl WebsocketsRequest {
// Generate a random key for the `Sec-WebSocket-Key` header which is a base64-encoded
// (see RFC 4648 §4) value that, when decoded, is 16 bytes in length (RFC 6455 §1.3).
let sec_key: [u8; 16] = rand::random();
let sec_key = rand::random::<[u8; 16]>();
let key = BASE64_STANDARD.encode(sec_key);
self.head.headers.insert(

View File

@ -20,7 +20,10 @@ use base64::prelude::*;
use bytes::Bytes;
use cookie::Cookie;
use futures_util::stream;
use rand::Rng;
use rand::{
distr::{Alphanumeric, SampleString as _},
Rng,
};
mod utils;
@ -516,11 +519,7 @@ async fn client_gzip_encoding_large() {
#[cfg(feature = "compress-gzip")]
#[actix_rt::test]
async fn client_gzip_encoding_large_random() {
let data = rand::thread_rng()
.sample_iter(&rand::distributions::Alphanumeric)
.take(100_000)
.map(char::from)
.collect::<String>();
let data = Alphanumeric.sample_string(&mut rand::rng(), 100_000);
let srv = actix_test::start(|| {
App::new().service(web::resource("/").route(web::to(|data: Bytes| async {
@ -562,11 +561,7 @@ async fn client_brotli_encoding() {
#[cfg(feature = "compress-brotli")]
#[actix_rt::test]
async fn client_brotli_encoding_large_random() {
let data = rand::thread_rng()
.sample_iter(&rand::distributions::Alphanumeric)
.take(70_000)
.map(char::from)
.collect::<String>();
let data = Alphanumeric.sample_string(&mut rand::rng(), 70_000);
let srv = actix_test::start(|| {
App::new().service(web::resource("/").route(web::to(|data: Bytes| async {
@ -607,11 +602,7 @@ async fn client_deflate_encoding() {
#[actix_rt::test]
async fn client_deflate_encoding_large_random() {
let data = rand::thread_rng()
.sample_iter(rand::distributions::Alphanumeric)
.map(char::from)
.take(70_000)
.collect::<String>();
let data = Alphanumeric.sample_string(&mut rand::rng(), 70_000);
let srv = actix_test::start(|| {
App::new().default_service(web::to(|body: Bytes| async {