cc_lb_plugin_wire/v1/
mod.rs1pub mod build_signer;
2pub mod common;
3pub mod normalize_error;
4pub mod observe;
5pub mod on_unauthorized;
6pub mod shape;
7pub mod sign;
8
9pub use common::{
10 CandidateWire, DialectBinding, HeaderWire, ObserveEventWire, Principal,
11 RateLimitObservationWire, RequestWire, ShapedRequestWire,
12 SubscriptionQuotaCandidateSnapshotWire, UpstreamErrorCategory, UpstreamErrorWire, UpstreamWire,
13};
14
15#[cfg(test)]
16mod tests {
17 extern crate alloc;
18
19 use core::fmt::Debug;
20
21 use serde::{Serialize, de::DeserializeOwned};
22
23 use super::*;
24 use crate::wire_function::{FallbackPolicy, WireFunction};
25
26 fn round_trip<T>(value: T)
27 where
28 T: Serialize + DeserializeOwned + PartialEq + Debug,
29 {
30 let bytes = serde_json::to_vec(&value).unwrap();
31 let decoded: T = serde_json::from_slice(&bytes).unwrap();
32 assert_eq!(value, decoded);
33 }
34
35 fn assert_v1<F: WireFunction>() {
36 assert_eq!(F::SUPPORTED_VERSIONS, &[1]);
37 }
38
39 #[test]
40 fn six_impls() {
41 assert_eq!(<shape::ShapeFn as WireFunction>::NAME, "shape");
42 assert_eq!(
43 <normalize_error::NormalizeErrorFn as WireFunction>::NAME,
44 "normalize_error"
45 );
46 assert_eq!(
47 <build_signer::BuildSignerFn as WireFunction>::NAME,
48 "build_signer"
49 );
50 assert_eq!(<sign::SignFn as WireFunction>::NAME, "sign");
51 assert_eq!(
52 <on_unauthorized::OnUnauthorizedFn as WireFunction>::NAME,
53 "on_unauthorized"
54 );
55 assert_eq!(<observe::ObserveFn as WireFunction>::NAME, "observe");
56
57 assert_v1::<shape::ShapeFn>();
58 assert_v1::<normalize_error::NormalizeErrorFn>();
59 assert_v1::<build_signer::BuildSignerFn>();
60 assert_v1::<sign::SignFn>();
61 assert_v1::<on_unauthorized::OnUnauthorizedFn>();
62 assert_v1::<observe::ObserveFn>();
63 }
64
65 #[test]
66 fn dry_run_round_trip() {
67 round_trip(<shape::ShapeFn as WireFunction>::dry_run_request());
68 round_trip(<shape::ShapeFn as WireFunction>::dry_run_response());
69 round_trip(<normalize_error::NormalizeErrorFn as WireFunction>::dry_run_request());
70 round_trip(<normalize_error::NormalizeErrorFn as WireFunction>::dry_run_response());
71 round_trip(<build_signer::BuildSignerFn as WireFunction>::dry_run_request());
72 round_trip(<build_signer::BuildSignerFn as WireFunction>::dry_run_response());
73 round_trip(<sign::SignFn as WireFunction>::dry_run_request());
74 round_trip(<sign::SignFn as WireFunction>::dry_run_response());
75 round_trip(<on_unauthorized::OnUnauthorizedFn as WireFunction>::dry_run_request());
76 round_trip(<on_unauthorized::OnUnauthorizedFn as WireFunction>::dry_run_response());
77 round_trip(<observe::ObserveFn as WireFunction>::dry_run_request());
78 round_trip(<observe::ObserveFn as WireFunction>::dry_run_response());
79 }
80
81 #[test]
82 fn all_wire_types_have_dry_run_sample() {
83 round_trip(HeaderWire::dry_run_sample());
84 round_trip(Principal::dry_run_sample());
85 round_trip(RequestWire::dry_run_sample());
86 round_trip(RateLimitObservationWire::dry_run_sample());
87 round_trip(SubscriptionQuotaCandidateSnapshotWire::dry_run_sample());
88 round_trip(CandidateWire::dry_run_sample());
89 round_trip(UpstreamWire::dry_run_sample());
90 round_trip(DialectBinding::dry_run_sample());
91 round_trip(ShapedRequestWire::dry_run_sample());
92 round_trip(UpstreamErrorCategory::dry_run_sample());
93 round_trip(UpstreamErrorWire::dry_run_sample());
94 round_trip(ObserveEventWire::dry_run_sample());
95 round_trip(shape::ShapeRequest::dry_run_sample());
96 round_trip(shape::ShapeResponse::dry_run_sample());
97 round_trip(normalize_error::NormalizeErrorRequest::dry_run_sample());
98 round_trip(normalize_error::NormalizeErrorResponse::dry_run_sample());
99 round_trip(build_signer::BuildSignerRequest::dry_run_sample());
100 round_trip(build_signer::BuildSignerResponse::dry_run_sample());
101 round_trip(sign::SignRequest::dry_run_sample());
102 round_trip(sign::SignResponse::dry_run_sample());
103 round_trip(on_unauthorized::OnUnauthorizedRequest::dry_run_sample());
104 round_trip(on_unauthorized::OnUnauthorizedResponse::dry_run_sample());
105 round_trip(observe::ObserveRequest::dry_run_sample());
106 round_trip(observe::ObserveResponse::dry_run_sample());
107 }
108
109 #[test]
110 fn sign_build_signer_are_fail_request() {
111 assert_eq!(
112 <sign::SignFn as WireFunction>::FALLBACK,
113 FallbackPolicy::FailRequest
114 );
115 assert_eq!(
116 <build_signer::BuildSignerFn as WireFunction>::FALLBACK,
117 FallbackPolicy::FailRequest
118 );
119 }
120
121 #[test]
122 fn shape_is_fail_request() {
123 assert_eq!(
124 <shape::ShapeFn as WireFunction>::FALLBACK,
125 FallbackPolicy::FailRequest
126 );
127 }
128
129 #[test]
130 fn observe_is_silent_skip() {
131 assert_eq!(
132 <observe::ObserveFn as WireFunction>::FALLBACK,
133 FallbackPolicy::SilentSkip
134 );
135 }
136
137 #[test]
138 fn normalize_on_unauthorized_pass_through() {
139 assert_eq!(
140 <normalize_error::NormalizeErrorFn as WireFunction>::FALLBACK,
141 FallbackPolicy::PassThrough
142 );
143 assert_eq!(
144 <on_unauthorized::OnUnauthorizedFn as WireFunction>::FALLBACK,
145 FallbackPolicy::PassThrough
146 );
147 }
148
149 #[test]
150 fn deny_unknown_fields_on_wire_structs() {
151 let header = r#"{"name":"x-test","value_base64":"","extra":true}"#;
152 assert!(serde_json::from_str::<HeaderWire>(header).is_err());
153
154 let observe = r#"{"events":[],"extra":true}"#;
155 assert!(serde_json::from_str::<observe::ObserveRequest>(observe).is_err());
156 }
157}