• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

input-output-hk / catalyst-libs / 17261071422

27 Aug 2025 08:09AM UTC coverage: 66.962% (+0.01%) from 66.948%
17261071422

Pull #497

github

web-flow
Merge 94dfdf398 into 74fefc0f1
Pull Request #497: refactor(rust/signed-doc): Move `validate_id_and_ver` as separate rules `IdRule` and `VerRule`

88 of 111 new or added lines in 4 files covered. (79.28%)

3 existing lines in 1 file now uncovered.

12623 of 18851 relevant lines covered (66.96%)

2799.35 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.18
/rust/signed_doc/src/validator/rules/mod.rs
1
//! A list of validation rules for all metadata fields
2
//! <https://input-output-hk.github.io/catalyst-libs/architecture/08_concepts/signed_doc/meta/>
3

4
use futures::FutureExt;
5

6
use crate::{providers::CatalystSignedDocumentProvider, CatalystSignedDocument};
7

8
mod content_encoding;
9
mod content_type;
10
mod doc_ref;
11
mod id;
12
mod parameters;
13
mod reply;
14
mod section;
15
mod signature_kid;
16
mod template;
17
mod ver;
18

19
pub(crate) use content_encoding::ContentEncodingRule;
20
pub(crate) use content_type::ContentTypeRule;
21
pub(crate) use doc_ref::RefRule;
22
pub(crate) use id::IdRule;
23
pub(crate) use parameters::ParametersRule;
24
pub(crate) use reply::ReplyRule;
25
pub(crate) use section::SectionRule;
26
pub(crate) use signature_kid::SignatureKidRule;
27
pub(crate) use template::{ContentRule, ContentSchema};
28
pub(crate) use ver::VerRule;
29

30
/// Struct represented a full collection of rules for all fields
31
pub(crate) struct Rules {
32
    /// 'id' field validation rule
33
    pub(crate) id: Option<IdRule>,
34
    /// 'ver' field validation rule
35
    pub(crate) ver: Option<VerRule>,
36
    /// 'content-type' field validation rule
37
    pub(crate) content_type: ContentTypeRule,
38
    /// 'content-encoding' field validation rule
39
    pub(crate) content_encoding: ContentEncodingRule,
40
    /// 'ref' field validation rule
41
    pub(crate) doc_ref: RefRule,
42
    /// document's content validation rule
43
    pub(crate) content: ContentRule,
44
    /// 'reply' field validation rule
45
    pub(crate) reply: ReplyRule,
46
    /// 'section' field validation rule
47
    pub(crate) section: SectionRule,
48
    /// 'parameters' field validation rule
49
    pub(crate) parameters: ParametersRule,
50
    /// `kid` field validation rule
51
    pub(crate) kid: SignatureKidRule,
52
}
53

54
impl Rules {
55
    /// All field validation rules check
56
    pub(crate) async fn check<Provider>(
14✔
57
        &self,
14✔
58
        doc: &CatalystSignedDocument,
14✔
59
        provider: &Provider,
14✔
60
    ) -> anyhow::Result<bool>
14✔
61
    where
14✔
62
        Provider: CatalystSignedDocumentProvider,
14✔
63
    {
14✔
64
        let rules = [
14✔
65
            self.id
14✔
66
                .as_ref()
14✔
67
                .map_or_else(|| pass().boxed(), |rule| rule.check(doc, provider).boxed()),
14✔
68
            self.ver
14✔
69
                .as_ref()
14✔
70
                .map_or_else(|| pass().boxed(), |rule| rule.check(doc).boxed()),
14✔
71
            self.content_type.check(doc).boxed(),
14✔
72
            self.content_encoding.check(doc).boxed(),
14✔
73
            self.content.check(doc, provider).boxed(),
14✔
74
            self.doc_ref.check(doc, provider).boxed(),
14✔
75
            self.reply.check(doc, provider).boxed(),
14✔
76
            self.section.check(doc).boxed(),
14✔
77
            self.parameters.check(doc, provider).boxed(),
14✔
78
            self.kid.check(doc).boxed(),
14✔
79
        ];
80

81
        let res = futures::future::join_all(rules)
14✔
82
            .await
14✔
83
            .into_iter()
14✔
84
            .collect::<anyhow::Result<Vec<_>>>()?
14✔
85
            .iter()
14✔
86
            .all(|res| *res);
14✔
87
        Ok(res)
14✔
88
    }
14✔
89
}
90

91
/// An async no-op function to pass a rule validation.
92
#[allow(clippy::unused_async)]
NEW
UNCOV
93
pub async fn pass() -> anyhow::Result<bool> {
×
NEW
UNCOV
94
    Ok(true)
×
NEW
UNCOV
95
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc