public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pbs-devel] [PATCH v2 proxmox-backup] Fix #2926: parse_iface_attributes: always break on non-{attribitue, comment} token
@ 2020-08-13 13:04 Fabian Ebner
  2020-08-14  4:59 ` Dietmar Maurer
  0 siblings, 1 reply; 2+ messages in thread
From: Fabian Ebner @ 2020-08-13 13:04 UTC (permalink / raw)
  To: pbs-devel

There is no requirement to have at least
a blank line, attribute or comment in between two
interface definitions, e.g.
iface lo inet loopback
iface lo inet6 loopback

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---
 src/config/network.rs        | 97 ++++++++++++++++++++++++++++++++++++
 src/config/network/parser.rs |  4 +-
 2 files changed, 98 insertions(+), 3 deletions(-)

diff --git a/src/config/network.rs b/src/config/network.rs
index c217141f..02d0713c 100644
--- a/src/config/network.rs
+++ b/src/config/network.rs
@@ -600,4 +600,101 @@ mod test {
 
         Ok(())
     }
+
+    #[test]
+    fn test_network_config_create_no_blank_1() -> Result<(), Error> {
+        let input = "auto lo\n\
+                     iface lo inet loopback\n\
+                     iface lo inet6 loopback\n\
+                     auto ens18\n\
+                     iface ens18 inet static\n\
+                     \taddress 192.168.20.144/20\n\
+                     \tgateway 192.168.16.1\n\
+                     # comment\n\
+                     iface ens20 inet static\n\
+                     \taddress 192.168.20.145/20\n\
+                     iface ens21 inet manual\n\
+                     iface ens22 inet manual\n";
+
+        let mut parser = NetworkParser::new(&input.as_bytes()[..]);
+
+        let config = parser.parse_interfaces(None)?;
+
+        let output = String::try_from(config)?;
+
+        let expected = "auto lo\n\
+                        iface lo inet loopback\n\
+                        \n\
+                        iface lo inet6 loopback\n\
+                        \n\
+                        auto ens18\n\
+                        iface ens18 inet static\n\
+                        \taddress 192.168.20.144/20\n\
+                        \tgateway 192.168.16.1\n\
+                        #comment\n\
+                        \n\
+                        iface ens20 inet static\n\
+                        \taddress 192.168.20.145/20\n\
+                        \n\
+                        iface ens21 inet manual\n\
+                        \n\
+                        iface ens22 inet manual\n\
+                        \n";
+        assert_eq!(output, expected);
+
+        Ok(())
+    }
+
+    #[test]
+    fn test_network_config_create_no_blank_2() -> Result<(), Error> {
+        // Adapted from bug 2926
+        let input = "### Hetzner Online GmbH installimage\n\
+                     \n\
+                     source /etc/network/interfaces.d/*\n\
+                     \n\
+                     auto lo\n\
+                     iface lo inet loopback\n\
+                     iface lo inet6 loopback\n\
+                     \n\
+                     auto enp4s0\n\
+                     iface enp4s0 inet static\n\
+                     \taddress 10.10.10.10/24\n\
+                     \tgateway 10.10.10.1\n\
+                     \t# route 10.10.20.10/24 via 10.10.20.1\n\
+                     \tup route add -net 10.10.20.10 netmask 255.255.255.0 gw 10.10.20.1 dev enp4s0\n\
+                     \n\
+                     iface enp4s0 inet6 static\n\
+                     \taddress fe80::5496:35ff:fe99:5a6a/64\n\
+                     \tgateway fe80::1\n";
+
+        let mut parser = NetworkParser::new(&input.as_bytes()[..]);
+
+        let config = parser.parse_interfaces(None)?;
+
+        let output = String::try_from(config)?;
+
+        let expected = "### Hetzner Online GmbH installimage\n\
+                        \n\
+                        source /etc/network/interfaces.d/*\n\
+                        \n\
+                        auto lo\n\
+                        iface lo inet loopback\n\
+                        \n\
+                        iface lo inet6 loopback\n\
+                        \n\
+                        auto enp4s0\n\
+                        iface enp4s0 inet static\n\
+                        \taddress 10.10.10.10/24\n\
+                        \tgateway 10.10.10.1\n\
+                        \t# route 10.10.20.10/24 via 10.10.20.1\n\
+                        \tup route add -net 10.10.20.10 netmask 255.255.255.0 gw 10.10.20.1 dev enp4s0\n\
+                        \n\
+                        iface enp4s0 inet6 static\n\
+                        \taddress fe80::5496:35ff:fe99:5a6a/64\n\
+                        \tgateway fe80::1\n\
+                        \n";
+        assert_eq!(output, expected);
+
+        Ok(())
+    }
 }
diff --git a/src/config/network/parser.rs b/src/config/network/parser.rs
index 071bbcc7..a97d0f79 100644
--- a/src/config/network/parser.rs
+++ b/src/config/network/parser.rs
@@ -210,9 +210,7 @@ impl <R: BufRead> NetworkParser<R> {
                     self.eat(Token::Newline)?;
                     continue;
                 }
-                Token::Newline => break,
-                Token::EOF => break,
-                unexpected => bail!("unexpected token {:?} (expected iface attribute)", unexpected),
+                _ => break,
             }
 
             match self.peek()? {
-- 
2.20.1





^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [pbs-devel] [PATCH v2 proxmox-backup] Fix #2926: parse_iface_attributes: always break on non-{attribitue, comment} token
  2020-08-13 13:04 [pbs-devel] [PATCH v2 proxmox-backup] Fix #2926: parse_iface_attributes: always break on non-{attribitue, comment} token Fabian Ebner
@ 2020-08-14  4:59 ` Dietmar Maurer
  0 siblings, 0 replies; 2+ messages in thread
From: Dietmar Maurer @ 2020-08-14  4:59 UTC (permalink / raw)
  To: Proxmox Backup Server development discussion, Fabian Ebner

applied, with following changes:

--- a/src/config/network.rs
+++ b/src/config/network.rs
@@ -602,7 +602,7 @@ mod test {
     }
 
     #[test]
-    fn test_network_config_create_no_blank_1() -> Result<(), Error> {
+    fn test_network_config_parser_no_blank_1() -> Result<(), Error> {
         let input = "auto lo\n\
                      iface lo inet loopback\n\
                      iface lo inet6 loopback\n\
@@ -646,7 +646,7 @@ mod test {
     }
 
     #[test]
-    fn test_network_config_create_no_blank_2() -> Result<(), Error> {
+    fn test_network_config_parser_no_blank_2() -> Result<(), Error> {
         // Adapted from bug 2926
         let input = "### Hetzner Online GmbH installimage\n\


> On 08/13/2020 3:04 PM Fabian Ebner <f.ebner@proxmox.com> wrote:
> 
>  
> There is no requirement to have at least
> a blank line, attribute or comment in between two
> interface definitions, e.g.
> iface lo inet loopback
> iface lo inet6 loopback
> 
> Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
> ---
>  src/config/network.rs        | 97 ++++++++++++++++++++++++++++++++++++
>  src/config/network/parser.rs |  4 +-
>  2 files changed, 98 insertions(+), 3 deletions(-)
> 
> diff --git a/src/config/network.rs b/src/config/network.rs
> index c217141f..02d0713c 100644
> --- a/src/config/network.rs
> +++ b/src/config/network.rs
> @@ -600,4 +600,101 @@ mod test {
>  
>          Ok(())
>      }
> +
> +    #[test]
> +    fn test_network_config_create_no_blank_1() -> Result<(), Error> {
> +        let input = "auto lo\n\
> +                     iface lo inet loopback\n\
> +                     iface lo inet6 loopback\n\
> +                     auto ens18\n\
> +                     iface ens18 inet static\n\
> +                     \taddress 192.168.20.144/20\n\
> +                     \tgateway 192.168.16.1\n\
> +                     # comment\n\
> +                     iface ens20 inet static\n\
> +                     \taddress 192.168.20.145/20\n\
> +                     iface ens21 inet manual\n\
> +                     iface ens22 inet manual\n";
> +
> +        let mut parser = NetworkParser::new(&input.as_bytes()[..]);
> +
> +        let config = parser.parse_interfaces(None)?;
> +
> +        let output = String::try_from(config)?;
> +
> +        let expected = "auto lo\n\
> +                        iface lo inet loopback\n\
> +                        \n\
> +                        iface lo inet6 loopback\n\
> +                        \n\
> +                        auto ens18\n\
> +                        iface ens18 inet static\n\
> +                        \taddress 192.168.20.144/20\n\
> +                        \tgateway 192.168.16.1\n\
> +                        #comment\n\
> +                        \n\
> +                        iface ens20 inet static\n\
> +                        \taddress 192.168.20.145/20\n\
> +                        \n\
> +                        iface ens21 inet manual\n\
> +                        \n\
> +                        iface ens22 inet manual\n\
> +                        \n";
> +        assert_eq!(output, expected);
> +
> +        Ok(())
> +    }
> +
> +    #[test]
> +    fn test_network_config_create_no_blank_2() -> Result<(), Error> {
> +        // Adapted from bug 2926
> +        let input = "### Hetzner Online GmbH installimage\n\
> +                     \n\
> +                     source /etc/network/interfaces.d/*\n\
> +                     \n\
> +                     auto lo\n\
> +                     iface lo inet loopback\n\
> +                     iface lo inet6 loopback\n\
> +                     \n\
> +                     auto enp4s0\n\
> +                     iface enp4s0 inet static\n\
> +                     \taddress 10.10.10.10/24\n\
> +                     \tgateway 10.10.10.1\n\
> +                     \t# route 10.10.20.10/24 via 10.10.20.1\n\
> +                     \tup route add -net 10.10.20.10 netmask 255.255.255.0 gw 10.10.20.1 dev enp4s0\n\
> +                     \n\
> +                     iface enp4s0 inet6 static\n\
> +                     \taddress fe80::5496:35ff:fe99:5a6a/64\n\
> +                     \tgateway fe80::1\n";
> +
> +        let mut parser = NetworkParser::new(&input.as_bytes()[..]);
> +
> +        let config = parser.parse_interfaces(None)?;
> +
> +        let output = String::try_from(config)?;
> +
> +        let expected = "### Hetzner Online GmbH installimage\n\
> +                        \n\
> +                        source /etc/network/interfaces.d/*\n\
> +                        \n\
> +                        auto lo\n\
> +                        iface lo inet loopback\n\
> +                        \n\
> +                        iface lo inet6 loopback\n\
> +                        \n\
> +                        auto enp4s0\n\
> +                        iface enp4s0 inet static\n\
> +                        \taddress 10.10.10.10/24\n\
> +                        \tgateway 10.10.10.1\n\
> +                        \t# route 10.10.20.10/24 via 10.10.20.1\n\
> +                        \tup route add -net 10.10.20.10 netmask 255.255.255.0 gw 10.10.20.1 dev enp4s0\n\
> +                        \n\
> +                        iface enp4s0 inet6 static\n\
> +                        \taddress fe80::5496:35ff:fe99:5a6a/64\n\
> +                        \tgateway fe80::1\n\
> +                        \n";
> +        assert_eq!(output, expected);
> +
> +        Ok(())
> +    }
>  }
> diff --git a/src/config/network/parser.rs b/src/config/network/parser.rs
> index 071bbcc7..a97d0f79 100644
> --- a/src/config/network/parser.rs
> +++ b/src/config/network/parser.rs
> @@ -210,9 +210,7 @@ impl <R: BufRead> NetworkParser<R> {
>                      self.eat(Token::Newline)?;
>                      continue;
>                  }
> -                Token::Newline => break,
> -                Token::EOF => break,
> -                unexpected => bail!("unexpected token {:?} (expected iface attribute)", unexpected),
> +                _ => break,
>              }
>  
>              match self.peek()? {
> -- 
> 2.20.1
> 
> 
> 
> _______________________________________________
> pbs-devel mailing list
> pbs-devel@lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-08-14  5:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-13 13:04 [pbs-devel] [PATCH v2 proxmox-backup] Fix #2926: parse_iface_attributes: always break on non-{attribitue, comment} token Fabian Ebner
2020-08-14  4:59 ` Dietmar Maurer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal