Skip to content

Commit 63b196e

Browse files
committed
feat: basic fuzzing
1 parent ba5ef2f commit 63b196e

File tree

17 files changed

+5279
-12
lines changed

17 files changed

+5279
-12
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ lib/
44
target/
55
common/target/
66
codegen/target/
7+
fuzz/target/
78
docs/
89
Makefile.toml
910
dashboard/.nuxt/

.github/workflows/nightly.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- name: Install toolchain
14-
uses: actions-rs/toolchain@v1
14+
uses: actions-rust-lang/setup-rust-toolchain@v1
1515

1616
- name: Checkout Sources
1717
uses: actions/checkout@v4

Cargo.lock

Lines changed: 58 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ paste = "1.0.14"
7474
rand = "0.8.5"
7575
reqwest = { version = "0.12.3", features = ["json"] }
7676
test-log = "0.2.15"
77+
feedback_fusion_common = { path = "./common", features = ["arbitrary"] }
7778

7879
[features]
7980
default = ["all-databases", "otlp", "caching-skytable"]
@@ -95,3 +96,6 @@ mssql = ["rbdc-mssql"]
9596
[[bench]]
9697
name = "grpc"
9798
harness = false
99+
100+
[workspace]
101+
members = [".", "fuzz", "common", "codegen"]

Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
FROM rust:slim AS build
22

3+
COPY ./rust-toolchain.toml ./rust-toolchain.toml
4+
35
RUN apt-get update \
46
&& apt-get install libssl-dev protobuf-compiler libprotobuf-dev pkg-config -y --no-install-recommends \
57
&& apt-get clean \
6-
&& rustup toolchain install stable \
7-
&& rustup default stable
8+
&& rustup update
89

910
ARG features=all-databases,otlp
1011

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.PHONY: fuzz
2+
13
pnpm:
24
pnpm i -C lib
35
pnpm i -C docs
@@ -83,6 +85,9 @@ integration_test:
8385
OIDC_PROVIDER="http://localhost:5151" OIDC_CLIENT_ID="client" OIDC_CLIENT_SECRET="secret" RUST_LOG="INFO" GRPC_ENDPOINT="http://localhost:8000" \
8486
cargo test --no-fail-fast --test integration_test
8587

88+
fuzz:
89+
OIDC_PROVIDER="http://localhost:5151" OIDC_CLIENT_ID="client" OIDC_CLIENT_SECRET="secret" RUST_LOG="INFO" GRPC_ENDPOINT="http://localhost:8000" cargo fuzz run fuzz_create_and_export
90+
8691
cleanup:
8792
docker rm -f database;docker rm -f oidc-server-mock;docker rm -f feedback-fusion;docker rm -f skytable;docker network rm feedback-fusion; echo ""
8893

common/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@ edition = "2021"
66
[dependencies]
77
feedback_fusion_codegen = { path = "../codegen" }
88

9+
arbitrary = { version = "1.4.1", features = ["derive"], optional = true }
10+
lazy_static = { version = "1.5.0", optional = true }
911
rbatis = "4.5.21"
1012
tonic = "0.12.0"
13+
openidconnect = { version = "3.5.0", optional = true }
1114
prost = "0.13.0"
1215
prost-types = "0.13.0"
1316
validator = { version = "0.18.1", features = ["derive"] }
1417

1518
[build-dependencies]
1619
tonic-build = "0.12.0"
20+
21+
[features]
22+
arbitrary = ["dep:arbitrary", "dep:lazy_static", "dep:openidconnect"]

common/build.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,58 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
2626
let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());
2727

2828
tonic_build::configure()
29+
.type_attribute(
30+
"CreateTargetRequest",
31+
r#"#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]"#,
32+
)
33+
.type_attribute(
34+
"CreatePromptRequest",
35+
r#"#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]"#,
36+
)
37+
.type_attribute(
38+
"CreateFieldRequest",
39+
r#"#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]"#,
40+
)
41+
.type_attribute(
42+
"FieldOptions.options",
43+
r#"#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]"#,
44+
)
45+
.type_attribute(
46+
"FieldOptions",
47+
r#"#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]"#,
48+
)
49+
.type_attribute(
50+
"FieldType",
51+
r#"#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]"#,
52+
)
53+
.type_attribute(
54+
"TextOptions",
55+
r#"#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]"#,
56+
)
57+
.type_attribute(
58+
"RatingOptions",
59+
r#"#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]"#,
60+
)
61+
.type_attribute(
62+
"CheckboxOptions",
63+
r#"#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]"#,
64+
)
65+
.type_attribute(
66+
"SelectionOptions",
67+
r#"#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]"#,
68+
)
69+
.type_attribute(
70+
"RangeOptions",
71+
r#"#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]"#,
72+
)
73+
.type_attribute(
74+
"NumberOptions",
75+
r#"#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]"#,
76+
)
77+
.type_attribute(
78+
"CheckboxStyle",
79+
r#"#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]"#,
80+
)
2981
.type_attribute("CreateTargetRequest", "#[derive(validator::Validate)]")
3082
.field_attribute("CreateTargetRequest.name", "#[validate(length(max = 255))]")
3183
.type_attribute("UpdateTargetRequest", "#[derive(validator::Validate)]")

common/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
//DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2121
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2222

23+
#[cfg(feature = "arbitrary")]
24+
pub mod tests;
25+
2326
pub mod proto {
2427
tonic::include_proto!("feedback_fusion_v1");
2528
pub const FILE_DESCRIPTOR_SET: &[u8] =

tests/common.rs renamed to common/src/tests.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//SPDX-FileCopyrightText: 2024 OneLiteFeatherNet
1+
//SPDX-FileCopyrightText: 2025 OneLiteFeatherNet
22
//SPDX-License-Identifier: MIT
33

44
//MIT License
@@ -58,19 +58,19 @@ pub async fn authenticate() -> String {
5858
#[macro_export]
5959
macro_rules! connect {
6060
() => {{
61-
let channel = tonic::transport::Channel::from_static(&crate::common::GRPC_ENDPOINT).connect().await.unwrap();
62-
let token: tonic::metadata::MetadataValue<_> = format!("Bearer {}", crate::common::authenticate().await).parse().unwrap();
61+
let channel = tonic::transport::Channel::from_static(&$crate::tests::GRPC_ENDPOINT).connect().await.unwrap();
62+
let token: tonic::metadata::MetadataValue<_> = format!("Bearer {}", $crate::tests::authenticate().await).parse().unwrap();
6363

6464
let client =
65-
feedback_fusion_common::proto::feedback_fusion_v1_client::FeedbackFusionV1Client::with_interceptor(channel, move |mut request: tonic::Request<()>| {
65+
$crate::proto::feedback_fusion_v1_client::FeedbackFusionV1Client::with_interceptor(channel, move |mut request: tonic::Request<()>| {
6666
request
6767
.metadata_mut()
6868
.insert("authorization", token.clone());
6969

7070
Ok(request)
7171
});
7272

73-
let public_client = feedback_fusion_common::proto::public_feedback_fusion_v1_client::PublicFeedbackFusionV1Client::connect(crate::common::GRPC_ENDPOINT.as_str())
73+
let public_client = $crate::proto::public_feedback_fusion_v1_client::PublicFeedbackFusionV1Client::connect($crate::tests::GRPC_ENDPOINT.as_str())
7474
.await
7575
.unwrap();
7676

0 commit comments

Comments
 (0)