[augeas-devel] augeas: master - Added a Post Fix Access lens along with the unit tests

David Lutterkort lutter at fedoraproject.org
Mon Nov 16 19:05:27 UTC 2009


Gitweb:        http://git.fedorahosted.org/git/augeas.git?p=augeas.git;a=commitdiff;h=d7231fb8ec5de109c27e855f867ad0bd8074002b
Commit:        d7231fb8ec5de109c27e855f867ad0bd8074002b
Parent:        f4c87e3bf9518720227f097149beeba93dcfa9d1
Author:        Partha Aji <paji at redhat.com>
AuthorDate:    Fri Nov 13 16:04:08 2009 -0500
Committer:     David Lutterkort <lutter at redhat.com>
CommitterDate: Mon Nov 16 11:04:53 2009 -0800

Added a Post Fix Access lens along with the unit tests

---
 AUTHORS                              |    1 +
 lenses/postfix_access.aug            |   29 ++++++++++++++++++
 lenses/tests/test_postfix_access.aug |   53 ++++++++++++++++++++++++++++++++++
 3 files changed, 83 insertions(+), 0 deletions(-)

diff --git a/AUTHORS b/AUTHORS
index 7920733..bd8032e 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -4,6 +4,7 @@ Written by:
 
 Contributions by:
 
+  Partha Aji       <paji at redhat.com>
   Sylvain Baubeau  <bob at glumol.com>
   Anders F Björklund <afb at users.sourceforge.net>
   Matthew Booth    <mbooth at redhat.com>
diff --git a/lenses/postfix_access.aug b/lenses/postfix_access.aug
new file mode 100644
index 0000000..8b6a5de
--- /dev/null
+++ b/lenses/postfix_access.aug
@@ -0,0 +1,29 @@
+(* Parsing /etc/postfix/access *)
+
+module Postfix_Access =
+  autoload xfm
+
+  let sep_tab = Util.del_ws_tab
+  let sep_spc = Util.del_ws_spc
+
+  let eol = del /[ \t]*\n/ "\n"
+  let indent = del /[ \t]*/ ""
+
+  let comment = Util.comment
+  let empty   = Util.empty
+
+  let char = /[^# \n\t]/
+  let text =
+    let cont = /\n[ \t]+/ in
+    let any = /[^#\n]/ in
+    char | (char . (any | cont)* .char)
+
+  let word = char+
+  let record = [ seq "spec" .
+                  [ label "pattern" . store  word ] . sep_tab .
+                  [ label "action" . store word ] .
+                  [ label "parameters" . sep_spc . store text ]? . eol ]
+
+  let lns = ( empty | comment | record )*
+
+  let xfm = transform lns (incl "/etc/postfix/access")
diff --git a/lenses/tests/test_postfix_access.aug b/lenses/tests/test_postfix_access.aug
new file mode 100644
index 0000000..e8b5872
--- /dev/null
+++ b/lenses/tests/test_postfix_access.aug
@@ -0,0 +1,53 @@
+(* Tests for the Postfix Access module *)
+
+module Test_postfix_access =
+
+  let three_entries = "127.0.0.1  DISCARD You totally suck
+   Really
+#ok no more comments
+user@ REJECT
+"
+
+  test Postfix_access.record get "127.0.0.1 REJECT\n" =
+    { "1" { "pattern" = "127.0.0.1" }
+          { "action" = "REJECT" } }
+
+  test Postfix_access.lns get three_entries =
+    { "1" { "pattern" = "127.0.0.1" }
+          { "action" = "DISCARD" }
+          { "parameters" = "You totally suck\n   Really" } }
+    {"#comment" = "ok no more comments" }
+    { "2" { "pattern" = "user@" }
+          { "action" = "REJECT" } }
+
+  test Postfix_access.record put "127.0.0.1 OK\n" after
+      set "/1/action" "REJECT"
+  = "127.0.0.1 REJECT\n"
+
+  test Postfix_access.lns put three_entries after
+    set "/2/parameters" "Rejected you loser" ;
+    rm "/1/parameters"
+  = "127.0.0.1  DISCARD
+#ok no more comments
+user@ REJECT Rejected you loser
+"
+
+(* Deleting the 'action' node violates the schema; each postfix access *)
+(* entry must have one                                                 *)
+  test Postfix_access.lns put three_entries after
+      rm "/1/action"
+    = *
+
+  (* Make sure blank lines get through *)
+  test Postfix_access.lns get "127.0.0.1\tREJECT  \n \n\n
+user@*\tOK\tI 'll let you in \n\tseriously\n" =
+    { "1" { "pattern" = "127.0.0.1" }
+          { "action" = "REJECT" } }
+    {} {} {}
+    { "2" { "pattern" = "user@*" }
+          { "action" = "OK" }
+          { "parameters" = "I 'll let you in \n\tseriously" } }
+
+(* Local Variables: *)
+(* mode: caml *)
+(* End: *)




More information about the augeas-devel mailing list