From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 4EA2461CDF for ; Fri, 18 Dec 2020 12:38:04 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 4BFF72F839 for ; Fri, 18 Dec 2020 12:37:34 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 9B5C22F7FD for ; Fri, 18 Dec 2020 12:37:32 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id EFD854539C for ; Fri, 18 Dec 2020 12:26:29 +0100 (CET) From: Wolfgang Bumiller To: pbs-devel@lists.proxmox.com Date: Fri, 18 Dec 2020 12:26:08 +0100 Message-Id: <20201218112608.6845-21-w.bumiller@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201218112608.6845-1-w.bumiller@proxmox.com> References: <20201218112608.6845-1-w.bumiller@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.018 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [verify-api.rs] Subject: [pbs-devel] [PATCH backup 2/2] tests: verify-api: check AllOf schemas X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Dec 2020 11:38:04 -0000 Signed-off-by: Wolfgang Bumiller --- tests/verify-api.rs | 46 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/tests/verify-api.rs b/tests/verify-api.rs index 944d24cb..7b7371f6 100644 --- a/tests/verify-api.rs +++ b/tests/verify-api.rs @@ -1,3 +1,5 @@ +use std::collections::HashSet; + use anyhow::{bail, format_err, Error}; use proxmox_backup::api2; @@ -31,11 +33,41 @@ fn verify_object_schema(schema: &ObjectSchema) -> Result<(), Error> { Ok(()) } +// verify entries in an AllOf schema are actually object schemas and that they don't contain +// duplicate keys +fn verify_all_of_schema(schema: &AllOfSchema) -> Result<(), Error> { + for entry in schema.list { + match entry { + Schema::Object(obj) => verify_object_schema(obj)?, + _ => bail!("AllOf schema with a non-object schema entry!"), + } + } + + let mut keys = HashSet::<&'static str>::new(); + let mut dupes = String::new(); + for property in schema.properties() { + if keys.insert(property.0) { + if dupes.is_empty() { + dupes.push_str(", "); + } + dupes.push_str(property.0); + } + } + if !dupes.is_empty() { + bail!("Duplicate keys found in AllOf schema: {}", dupes); + } + + Ok(()) +} + fn verify_schema(schema: &Schema) -> Result<(), Error> { match schema { Schema::Object(obj_schema) => { verify_object_schema(obj_schema)?; } + Schema::AllOf(all_of_schema) => { + verify_all_of_schema(all_of_schema)?; + } Schema::Array(arr_schema) => { verify_schema(arr_schema.items)?; } @@ -68,10 +100,18 @@ fn verify_api_method( info: &ApiMethod ) -> Result<(), Error> { - verify_object_schema(info.parameters) - .map_err(|err| format_err!("{} {} parameters: {}", method, path, err))?; + match &info.parameters { + ParameterSchema::Object(obj) => { + verify_object_schema(obj) + .map_err(|err| format_err!("{} {} parameters: {}", method, path, err))?; + } + ParameterSchema::AllOf(all_of) => { + verify_all_of_schema(all_of) + .map_err(|err| format_err!("{} {} parameters: {}", method, path, err))?; + } + } - verify_schema(info.returns) + verify_schema(info.returns.schema) .map_err(|err| format_err!("{} {} returns: {}", method, path, err))?; verify_access_permissions(info.access.permission) -- 2.20.1