From 4755f16d0feb9f8c35eb5fef482a73b2bc52ba6c Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Wed, 12 Apr 2023 14:33:58 +0200 Subject: [PATCH 1/9] wip: Restrict the form operations --- examples/thing.rs | 4 ++++ src/servient/builder.rs | 7 ++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/examples/thing.rs b/examples/thing.rs index aa0f56e..e5ce3e5 100644 --- a/examples/thing.rs +++ b/examples/thing.rs @@ -54,6 +54,10 @@ async fn main() { .href("/say_hello/{action_id}") .http_get(|| async { "Checking ..." }) .op(wot_td::thing::FormOperation::QueryAction) + }) + .form(|b| { + b.ext(()) + .href("/say_hello/{action_id}") .http_delete(|| async { "Canceling ..." }) .op(wot_td::thing::FormOperation::CancelAction) }) diff --git a/src/servient/builder.rs b/src/servient/builder.rs index ad63e03..57eff0a 100644 --- a/src/servient/builder.rs +++ b/src/servient/builder.rs @@ -12,7 +12,7 @@ use datta::{Operator, UriTemplate}; use serde::{Deserialize, Serialize}; use uuid::Uuid; use wot_td::{ - builder::{FormBuilder, ThingBuilder}, + builder::{FormBuilder, FormBuilderInner, ThingBuilder, CAN_ADD_ANY_OPS}, extend::ExtendableThing, }; @@ -274,12 +274,13 @@ pub trait HttpRouter { T: 'static; } -impl HttpRouter for FormBuilder +impl HttpRouter + for FormBuilderInner where Other: ExtendableThing + Holder, OtherForm: Holder
, { - type Target = FormBuilder; + type Target = FormBuilderInner; /// Route GET requests to the given handler. fn http_get(mut self, handler: H) -> Self::Target From 1c8656371125b9f814a084b01bb20e726159bcdb Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Wed, 12 Apr 2023 14:57:03 +0200 Subject: [PATCH 2/9] wip: Set the method name --- examples/thing.rs | 1 + src/servient/builder.rs | 32 ++++++++++++++++++++------------ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/examples/thing.rs b/examples/thing.rs index e5ce3e5..d1f8a5f 100644 --- a/examples/thing.rs +++ b/examples/thing.rs @@ -68,6 +68,7 @@ async fn main() { eprintln!("Listening to 127.0.0.1:8080"); dbg!(&servient.router); + dbg!(&servient.thing); println!("Running the servient for 10 seconds."); let _ = tokio::time::timeout(Duration::from_secs(10), async { diff --git a/src/servient/builder.rs b/src/servient/builder.rs index 57eff0a..c3a0bf4 100644 --- a/src/servient/builder.rs +++ b/src/servient/builder.rs @@ -12,8 +12,9 @@ use datta::{Operator, UriTemplate}; use serde::{Deserialize, Serialize}; use uuid::Uuid; use wot_td::{ - builder::{FormBuilder, FormBuilderInner, ThingBuilder, CAN_ADD_ANY_OPS}, + builder::{FormBuilderInner, ThingBuilder, CAN_ADD_ANY_OPS}, extend::ExtendableThing, + protocol::http, }; #[doc(hidden)] @@ -49,12 +50,9 @@ impl Default for ServientExtension { pub struct Form { #[serde(skip)] method_router: MethodRouter, -} -impl From for Form { - fn from(method_router: MethodRouter) -> Self { - Self { method_router } - } + #[serde(flatten)] + htv: http::Form, } impl ExtendableThing for ServientExtension { @@ -63,7 +61,7 @@ impl ExtendableThing for ServientExtension { type ActionAffordance = (); type EventAffordance = (); type Form = Form; - type ExpectedResponse = (); + type ExpectedResponse = http::Response; type DataSchema = (); type ObjectSchema = (); type ArraySchema = (); @@ -289,7 +287,9 @@ where T: 'static, { let method_router = std::mem::take(&mut self.other.field_mut().method_router); - self.other.field_mut().method_router = method_router.get(handler); + let f = self.other.field_mut(); + f.method_router = method_router.get(handler); + f.htv.method_name = Some(http::Method::Get); self } /// Route PUT requests to the given handler. @@ -299,7 +299,9 @@ where T: 'static, { let method_router = std::mem::take(&mut self.other.field_mut().method_router); - self.other.field_mut().method_router = method_router.put(handler); + let f = self.other.field_mut(); + f.method_router = method_router.put(handler); + f.htv.method_name = Some(http::Method::Put); self } /// Route POST requests to the given handler. @@ -309,7 +311,9 @@ where T: 'static, { let method_router = std::mem::take(&mut self.other.field_mut().method_router); - self.other.field_mut().method_router = method_router.post(handler); + let f = self.other.field_mut(); + f.method_router = method_router.post(handler); + f.htv.method_name = Some(http::Method::Post); self } /// Route PATCH requests to the given handler. @@ -319,7 +323,9 @@ where T: 'static, { let method_router = std::mem::take(&mut self.other.field_mut().method_router); - self.other.field_mut().method_router = method_router.patch(handler); + let f: &mut Form = self.other.field_mut(); + f.method_router = method_router.patch(handler); + f.htv.method_name = Some(http::Method::Patch); self } /// Route DELETE requests to the given handler. @@ -329,7 +335,9 @@ where T: 'static, { let method_router = std::mem::take(&mut self.other.field_mut().method_router); - self.other.field_mut().method_router = method_router.delete(handler); + let f: &mut Form = self.other.field_mut(); + f.method_router = method_router.delete(handler); + f.htv.method_name = Some(http::Method::Delete); self } } From a09131c9704ae6257a781b19af2bdfd04f2fec8d Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Thu, 13 Apr 2023 10:21:17 +0200 Subject: [PATCH 3/9] wip: Restrict further op --- src/servient.rs | 19 ++++++++++++------- src/servient/builder.rs | 17 ++++++++--------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/servient.rs b/src/servient.rs index e578539..6b0bde1 100644 --- a/src/servient.rs +++ b/src/servient.rs @@ -111,13 +111,18 @@ mod test { let servient = Servient::builder("test") .finish_extend() .property("hello", |b| { - b.finish_extend_data_schema().null().form(|f| { - f.href("/hello") - .http_get(|| async { "Reading Hello, World!" }) - .http_put(|| async { "Writing Hello, World!" }) - .op(FormOperation::ReadProperty) - .op(FormOperation::WriteProperty) - }) + b.finish_extend_data_schema() + .null() + .form(|f| { + f.href("/hello") + .http_get(|| async { "Reading Hello, World!" }) + .op(FormOperation::ReadProperty) + }) + .form(|f| { + f.href("/hello") + .http_put(|| async { "Writing Hello, World!" }) + .op(FormOperation::WriteProperty) + }) }) .build_servient() .unwrap(); diff --git a/src/servient/builder.rs b/src/servient/builder.rs index c3a0bf4..e03d689 100644 --- a/src/servient/builder.rs +++ b/src/servient/builder.rs @@ -12,7 +12,7 @@ use datta::{Operator, UriTemplate}; use serde::{Deserialize, Serialize}; use uuid::Uuid; use wot_td::{ - builder::{FormBuilderInner, ThingBuilder, CAN_ADD_ANY_OPS}, + builder::{FormBuilder, ThingBuilder, CAN_ADD_ANY_OPS, CAN_ADD_ONE_OP}, extend::ExtendableThing, protocol::http, }; @@ -272,13 +272,12 @@ pub trait HttpRouter { T: 'static; } -impl HttpRouter - for FormBuilderInner +impl HttpRouter for FormBuilder where Other: ExtendableThing + Holder, OtherForm: Holder, { - type Target = FormBuilderInner; + type Target = FormBuilder; /// Route GET requests to the given handler. fn http_get(mut self, handler: H) -> Self::Target @@ -290,7 +289,7 @@ where let f = self.other.field_mut(); f.method_router = method_router.get(handler); f.htv.method_name = Some(http::Method::Get); - self + self.into() } /// Route PUT requests to the given handler. fn http_put(mut self, handler: H) -> Self::Target @@ -302,7 +301,7 @@ where let f = self.other.field_mut(); f.method_router = method_router.put(handler); f.htv.method_name = Some(http::Method::Put); - self + self.into() } /// Route POST requests to the given handler. fn http_post(mut self, handler: H) -> Self::Target @@ -314,7 +313,7 @@ where let f = self.other.field_mut(); f.method_router = method_router.post(handler); f.htv.method_name = Some(http::Method::Post); - self + self.into() } /// Route PATCH requests to the given handler. fn http_patch(mut self, handler: H) -> Self::Target @@ -326,7 +325,7 @@ where let f: &mut Form = self.other.field_mut(); f.method_router = method_router.patch(handler); f.htv.method_name = Some(http::Method::Patch); - self + self.into() } /// Route DELETE requests to the given handler. fn http_delete(mut self, handler: H) -> Self::Target @@ -338,7 +337,7 @@ where let f: &mut Form = self.other.field_mut(); f.method_router = method_router.delete(handler); f.htv.method_name = Some(http::Method::Delete); - self + self.into() } } From 24bb3cf86842fa6f0f50a61c8ca46e05d8a0e631 Mon Sep 17 00:00:00 2001 From: Edoardo Morandi Date: Fri, 14 Apr 2023 10:31:56 +0200 Subject: [PATCH 4/9] feat!: impl restricted ops with stable wot-td --- examples/thing.rs | 4 ++ src/servient.rs | 42 ++++++++++++++++ src/servient/builder.rs | 103 ++++++++++++++++++++++++++++++++++++---- 3 files changed, 139 insertions(+), 10 deletions(-) diff --git a/examples/thing.rs b/examples/thing.rs index d1f8a5f..0f50e6d 100644 --- a/examples/thing.rs +++ b/examples/thing.rs @@ -37,6 +37,7 @@ async fn main() { b.ext(()) .http_get(|| async { "Hello World!" }) .href("/hello") + .into() }) .string() }) @@ -47,6 +48,7 @@ async fn main() { b.ext(()) .http_post(|| async { "I'm saying hello" }) .href("/say_hello") + .into() }) .input(|b| b.ext(()).finish_extend().null()) .form(|b| { @@ -54,12 +56,14 @@ async fn main() { .href("/say_hello/{action_id}") .http_get(|| async { "Checking ..." }) .op(wot_td::thing::FormOperation::QueryAction) + .into() }) .form(|b| { b.ext(()) .href("/say_hello/{action_id}") .http_delete(|| async { "Canceling ..." }) .op(wot_td::thing::FormOperation::CancelAction) + .into() }) .uri_variable("action_id", |b| b.ext(()).finish_extend().string()) }) diff --git a/src/servient.rs b/src/servient.rs index 6b0bde1..dc219ec 100644 --- a/src/servient.rs +++ b/src/servient.rs @@ -55,6 +55,41 @@ impl Servient { /// /// By default it sets the CORS headers to allow any origin, you may disable the behaviour /// by calling [ServientSettings::http_disable_permissive_cors]. + /// + /// # Examples + /// + /// This should fail: + /// ```compile_fail + /// # use wot_serve::{Servient, servient::{BuildServient,HttpRouter}}; + /// # use wot_td::thing::FormOperation; + /// let servient = Servient::builder("test") + /// .finish_extend() + /// .form(|f| { + /// f.href("/ref") + /// .http_get(|| async { "Hello, World!" }) + /// .op(FormOperation::ReadAllProperties) + /// .op(FormOperation::WriteAllProperties) + /// .into() + /// }) + /// .build_servient() + /// .unwrap(); + /// ``` + /// + /// This should work instead. + /// ``` + /// # use wot_serve::{Servient, servient::{BuildServient,HttpRouter}}; + /// # use wot_td::thing::FormOperation; + /// let servient = Servient::builder("test") + /// .finish_extend() + /// .form(|f| { + /// f.href("/ref") + /// .http_get(|| async { "Hello, World!" }) + /// .op(FormOperation::ReadAllProperties) + /// .into() + /// }) + /// .build_servient() + /// .unwrap(); + /// ``` pub fn builder(title: impl Into) -> ThingBuilder, ToExtend> { ThingBuilder::, ToExtend>::new(title) } @@ -94,11 +129,13 @@ mod test { f.href("/ref") .http_get(|| async { "Hello, World!" }) .op(FormOperation::ReadAllProperties) + .into() }) .form(|f| { f.href("/ref2") .http_get(|| async { "Hello, World! 2" }) .op(FormOperation::ReadAllProperties) + .into() }) .build_servient() .unwrap(); @@ -117,11 +154,13 @@ mod test { f.href("/hello") .http_get(|| async { "Reading Hello, World!" }) .op(FormOperation::ReadProperty) + .into() }) .form(|f| { f.href("/hello") .http_put(|| async { "Writing Hello, World!" }) .op(FormOperation::WriteProperty) + .into() }) }) .build_servient() @@ -138,18 +177,21 @@ mod test { b.input(|i| i.finish_extend().number()).form(|f| { f.href("/say_hello") .http_post(|| async { "Saying Hello, World!" }) + .into() }) }) .action("update", |b| { b.form(|f| { f.href("/update_hello") .http_patch(|| async { "Updating Hello, World!" }) + .into() }) }) .action("delete", |b| { b.form(|f| { f.href("/delete_hello") .http_delete(|| async { "Goodbye, World!" }) + .into() }) }) .build_servient() diff --git a/src/servient/builder.rs b/src/servient/builder.rs index e03d689..9145e4c 100644 --- a/src/servient/builder.rs +++ b/src/servient/builder.rs @@ -12,9 +12,9 @@ use datta::{Operator, UriTemplate}; use serde::{Deserialize, Serialize}; use uuid::Uuid; use wot_td::{ - builder::{FormBuilder, ThingBuilder, CAN_ADD_ANY_OPS, CAN_ADD_ONE_OP}, - extend::ExtendableThing, - protocol::http, + builder::{AdditionalExpectedResponseBuilder, FormBuilder, ThingBuilder}, + extend::{Extend, ExtendableThing}, + protocol::http, thing::FormOperation, }; #[doc(hidden)] @@ -272,12 +272,95 @@ pub trait HttpRouter { T: 'static; } -impl HttpRouter for FormBuilder +pub struct ServientFormBuilder( + FormBuilder, +); + +impl ServientFormBuilder { + /// Create a new builder with the specified Href + /// + /// See [FormBuilder::href]. + #[inline] + pub fn href(self, value: impl Into) -> ServientFormBuilder { + ServientFormBuilder(self.0.href(value)) + } +} + +impl ServientFormBuilder { + /// Set the security definitions that must be satisfied to access the resource + /// + /// See [FormBuilder::security]. + #[inline] + pub fn security(self, value: impl Into) -> Self { + Self(self.0.security(value)) + } + + /// Set the authorization scope identifiers + /// + /// See [FormBuilder::scope] + #[inline] + pub fn scope(self, value: impl Into) -> Self { + Self(self.0.scope(value)) + } + + /// Adds an additional response to the form builder. + /// + /// See [FormBuilder::additional_response] + #[inline] + pub fn additional_response(self, f: F) -> Self + where + F: FnOnce(&mut AdditionalExpectedResponseBuilder) -> &mut AdditionalExpectedResponseBuilder, + { + Self(self.0.additional_response(f)) + } + + /// Extends the form, passing a closure that returns `T`. + /// + /// See [FormBuilder::ext_with] + #[inline] + pub fn ext_with(self, f: F) -> ServientFormBuilder + where + OtherForm: Extend, + F: FnOnce() -> T, + { + ServientFormBuilder(self.0.ext_with(f)) + } + + /// Extends the form with an additional element. + /// + /// See [FormBuilder::ext]. + #[inline] + pub fn ext(self, t: T) -> ServientFormBuilder + where + OtherForm: Extend, + { + ServientFormBuilder(self.0.ext(t)) + } +} + +impl ServientFormBuilder { + /// Set the form intended operation + /// + /// See [FormBuilder::op]. + pub fn op(self, new_op: FormOperation) -> ServientFormBuilder { + ServientFormBuilder(self.0.op(new_op)) + } + +} + +impl From> for FormBuilder { + #[inline] + fn from(value: ServientFormBuilder) -> Self { + value.0 + } +} + +impl HttpRouter for FormBuilder where Other: ExtendableThing + Holder, OtherForm: Holder, { - type Target = FormBuilder; + type Target = ServientFormBuilder; /// Route GET requests to the given handler. fn http_get(mut self, handler: H) -> Self::Target @@ -289,7 +372,7 @@ where let f = self.other.field_mut(); f.method_router = method_router.get(handler); f.htv.method_name = Some(http::Method::Get); - self.into() + ServientFormBuilder(self) } /// Route PUT requests to the given handler. fn http_put(mut self, handler: H) -> Self::Target @@ -301,7 +384,7 @@ where let f = self.other.field_mut(); f.method_router = method_router.put(handler); f.htv.method_name = Some(http::Method::Put); - self.into() + ServientFormBuilder(self) } /// Route POST requests to the given handler. fn http_post(mut self, handler: H) -> Self::Target @@ -313,7 +396,7 @@ where let f = self.other.field_mut(); f.method_router = method_router.post(handler); f.htv.method_name = Some(http::Method::Post); - self.into() + ServientFormBuilder(self) } /// Route PATCH requests to the given handler. fn http_patch(mut self, handler: H) -> Self::Target @@ -325,7 +408,7 @@ where let f: &mut Form = self.other.field_mut(); f.method_router = method_router.patch(handler); f.htv.method_name = Some(http::Method::Patch); - self.into() + ServientFormBuilder(self) } /// Route DELETE requests to the given handler. fn http_delete(mut self, handler: H) -> Self::Target @@ -337,7 +420,7 @@ where let f: &mut Form = self.other.field_mut(); f.method_router = method_router.delete(handler); f.htv.method_name = Some(http::Method::Delete); - self.into() + ServientFormBuilder(self) } } From 5f95c1b4070efa9bad56068f8282f1a88a5fc740 Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Thu, 4 May 2023 10:41:00 +0200 Subject: [PATCH 5/9] fix: Leverage 0.3.1 Into --- examples/thing.rs | 4 ---- src/servient.rs | 8 -------- 2 files changed, 12 deletions(-) diff --git a/examples/thing.rs b/examples/thing.rs index 0f50e6d..d1f8a5f 100644 --- a/examples/thing.rs +++ b/examples/thing.rs @@ -37,7 +37,6 @@ async fn main() { b.ext(()) .http_get(|| async { "Hello World!" }) .href("/hello") - .into() }) .string() }) @@ -48,7 +47,6 @@ async fn main() { b.ext(()) .http_post(|| async { "I'm saying hello" }) .href("/say_hello") - .into() }) .input(|b| b.ext(()).finish_extend().null()) .form(|b| { @@ -56,14 +54,12 @@ async fn main() { .href("/say_hello/{action_id}") .http_get(|| async { "Checking ..." }) .op(wot_td::thing::FormOperation::QueryAction) - .into() }) .form(|b| { b.ext(()) .href("/say_hello/{action_id}") .http_delete(|| async { "Canceling ..." }) .op(wot_td::thing::FormOperation::CancelAction) - .into() }) .uri_variable("action_id", |b| b.ext(()).finish_extend().string()) }) diff --git a/src/servient.rs b/src/servient.rs index dc219ec..d0813f2 100644 --- a/src/servient.rs +++ b/src/servient.rs @@ -85,7 +85,6 @@ impl Servient { /// f.href("/ref") /// .http_get(|| async { "Hello, World!" }) /// .op(FormOperation::ReadAllProperties) - /// .into() /// }) /// .build_servient() /// .unwrap(); @@ -129,13 +128,11 @@ mod test { f.href("/ref") .http_get(|| async { "Hello, World!" }) .op(FormOperation::ReadAllProperties) - .into() }) .form(|f| { f.href("/ref2") .http_get(|| async { "Hello, World! 2" }) .op(FormOperation::ReadAllProperties) - .into() }) .build_servient() .unwrap(); @@ -154,13 +151,11 @@ mod test { f.href("/hello") .http_get(|| async { "Reading Hello, World!" }) .op(FormOperation::ReadProperty) - .into() }) .form(|f| { f.href("/hello") .http_put(|| async { "Writing Hello, World!" }) .op(FormOperation::WriteProperty) - .into() }) }) .build_servient() @@ -177,21 +172,18 @@ mod test { b.input(|i| i.finish_extend().number()).form(|f| { f.href("/say_hello") .http_post(|| async { "Saying Hello, World!" }) - .into() }) }) .action("update", |b| { b.form(|f| { f.href("/update_hello") .http_patch(|| async { "Updating Hello, World!" }) - .into() }) }) .action("delete", |b| { b.form(|f| { f.href("/delete_hello") .http_delete(|| async { "Goodbye, World!" }) - .into() }) }) .build_servient() From 6193c1ac664ab2dc19ea24f1112ce8c213320518 Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Thu, 4 May 2023 11:30:54 +0200 Subject: [PATCH 6/9] fix: rustfmt --- src/servient/builder.rs | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/servient/builder.rs b/src/servient/builder.rs index 9145e4c..da7c8a2 100644 --- a/src/servient/builder.rs +++ b/src/servient/builder.rs @@ -14,7 +14,8 @@ use uuid::Uuid; use wot_td::{ builder::{AdditionalExpectedResponseBuilder, FormBuilder, ThingBuilder}, extend::{Extend, ExtendableThing}, - protocol::http, thing::FormOperation, + protocol::http, + thing::FormOperation, }; #[doc(hidden)] @@ -276,17 +277,24 @@ pub struct ServientFormBuilder, ); -impl ServientFormBuilder { +impl + ServientFormBuilder +{ /// Create a new builder with the specified Href /// /// See [FormBuilder::href]. #[inline] - pub fn href(self, value: impl Into) -> ServientFormBuilder { + pub fn href( + self, + value: impl Into, + ) -> ServientFormBuilder { ServientFormBuilder(self.0.href(value)) } } -impl ServientFormBuilder { +impl + ServientFormBuilder +{ /// Set the security definitions that must be satisfied to access the resource /// /// See [FormBuilder::security]. @@ -343,12 +351,14 @@ impl ServientFormBuilder ServientFormBuilder { - ServientFormBuilder(self.0.op(new_op)) + ServientFormBuilder(self.0.op(new_op)) } - } -impl From> for FormBuilder { +impl + From> + for FormBuilder +{ #[inline] fn from(value: ServientFormBuilder) -> Self { value.0 From e409fd7a29176235aa62af83a4e7fcb322ba10ee Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Fri, 5 May 2023 10:07:53 +0200 Subject: [PATCH 7/9] fix: Add more documentation --- examples/thing.rs | 1 - src/servient.rs | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/examples/thing.rs b/examples/thing.rs index d1f8a5f..e5ce3e5 100644 --- a/examples/thing.rs +++ b/examples/thing.rs @@ -68,7 +68,6 @@ async fn main() { eprintln!("Listening to 127.0.0.1:8080"); dbg!(&servient.router); - dbg!(&servient.thing); println!("Running the servient for 10 seconds."); let _ = tokio::time::timeout(Duration::from_secs(10), async { diff --git a/src/servient.rs b/src/servient.rs index d0813f2..abce83a 100644 --- a/src/servient.rs +++ b/src/servient.rs @@ -75,6 +75,22 @@ impl Servient { /// .unwrap(); /// ``` /// + /// This should fail as well: + /// ```compile_fail + /// # use wot_serve::{Servient, servient::{BuildServient,HttpRouter}}; + /// # use wot_td::thing::FormOperation; + /// let servient = Servient::builder("test") + /// .finish_extend() + /// .form(|f| { + /// f.href("/ref") + /// .http_get(|| async { "Hello, World!" }) + /// .http_put(|| async { "Hello, World!" }) + /// .into() + /// }) + /// .build_servient() + /// .unwrap(); + /// ``` + /// /// This should work instead. /// ``` /// # use wot_serve::{Servient, servient::{BuildServient,HttpRouter}}; From 76726b2c695487f00ed4a9fafd1f72849f611134 Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Tue, 23 May 2023 15:26:19 +0200 Subject: [PATCH 8/9] test: Increase the coverage --- src/servient.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/servient.rs b/src/servient.rs index abce83a..a268c15 100644 --- a/src/servient.rs +++ b/src/servient.rs @@ -136,18 +136,37 @@ mod test { use super::*; + #[derive(serde::Serialize)] + struct E {} + + impl ExtendableThing for E { + type Form = (); + type DataSchema = (); + type ArraySchema = (); + type ObjectSchema = (); + type EventAffordance = (); + type ActionAffordance = (); + type ExpectedResponse = (); + type PropertyAffordance = (); + type InteractionAffordance = (); + } + #[test] fn build_servient() { let servient = Servient::builder("test") + .ext(E {}) .finish_extend() .form(|f| { - f.href("/ref") + f.ext(()) + .href("/ref") .http_get(|| async { "Hello, World!" }) .op(FormOperation::ReadAllProperties) }) .form(|f| { f.href("/ref2") .http_get(|| async { "Hello, World! 2" }) + .ext(()) + .security("basic") .op(FormOperation::ReadAllProperties) }) .build_servient() From be50d202f324531d465b1dafbdc354831117823a Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Thu, 7 Sep 2023 14:08:36 +0200 Subject: [PATCH 9/9] fix: Make sure the test enables the basic security if it uses it --- src/servient.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/servient.rs b/src/servient.rs index a268c15..1385f00 100644 --- a/src/servient.rs +++ b/src/servient.rs @@ -156,6 +156,7 @@ mod test { let servient = Servient::builder("test") .ext(E {}) .finish_extend() + .security(|b| b.basic()) .form(|f| { f.ext(()) .href("/ref")