/scratch.rkt

http://github.com/tnelson/Margrave · Racket · 144 lines · 32 code · 34 blank · 78 comment · 0 complexity · 7f311b75d27064f5ddfe466484c05def MD5 · raw file

  1. ; Copyright © 2009-2010 Brown University and Worcester Polytechnic Institute.
  2. ;
  3. ; This file is part of Margrave.
  4. ; Margrave is free software: you can redistribute it and/or modify
  5. ; it under the terms of the GNU Lesser General Public License as published by
  6. ; the Free Software Foundation, either version 3 of the License, or
  7. ; (at your option) any later version.
  8. ;
  9. ; Margrave is distributed in the hope that it will be useful,
  10. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ; GNU Lesser General Public License for more details.
  13. ;
  14. ; You should have received a copy of the GNU Lesser General Public License
  15. ; along with Margrave. If not, see <http://www.gnu.org/licenses/>.
  16. #lang racket
  17. ; TEMPORARY! Will be a nice module path soon.
  18. (require ;(file "./read.rkt")
  19. "margrave.rkt"
  20. "margrave-xml.rkt"
  21. "margrave-policy-vocab.rkt"
  22. xml)
  23. ; Welcome to Margrave! This file contains examples that are separated by (pause-for-user) so that you can
  24. ; execute it and read it in tandem.
  25. (start-margrave-engine (current-directory) '() '("-log"))
  26. ;(load-policy (build-path (current-directory) "tests" "extconference.p"))
  27. (load-policy (build-path (current-directory) "tests" "conference1.p"))
  28. ;(load-policy (build-path (current-directory) "tests" "conference2.p"))
  29. ;(load-policy (build-path (current-directory) "tests" "phone1.p"))
  30. (load-policy (build-path (current-directory) "tests" "fwex1.p"))
  31. ;(load-policy (build-path (current-directory) "tests" "fwex1a.p"))
  32. ;(load-policy (build-path (current-directory) "tests" "fwex2.p"))
  33. ;(load-policy (build-path (current-directory) "tests" "fwex3.p"))
  34. ;(load-policy (build-path (current-directory) "tests" "happyrouterless.p"))
  35. ;(load-policy (build-path (current-directory) "tests" "happyroutermore.p"))
  36. ;(load-policy (build-path (current-directory) "tests" "iout.p"))
  37. (load-policy (build-path (current-directory) "tests" "subset.p"))
  38. ;(mtext "info")
  39. ;(mtext "info fwex1")
  40. ;(mtext "info examplefw1")
  41. ;(m (xml-make-rename-command "conferencepolicy1" "conf1"))
  42. ;(m (xml-make-rename-command "conferencepolicy2" "conf2"))
  43. ;(m (xml-make-rename-command "fwex1" "firewall1"))
  44. ;(m (xml-make-rename-command "fwex1a" "firewall1a"))
  45. ;(m (xml-make-rename-command "fwex2" "firewall2"))
  46. ;(m (xml-make-rename-command "happyrouterless" "HRless"))
  47. ;(m (xml-make-rename-command "happyroutermore" "HRmore"))
  48. (display-response (mtext "rename conferencepolicy1 conf1"))
  49. ;(mtext "rename conferencepolicy2 conf2")
  50. ;(mtext "rename fwex1 firewall1")
  51. ;(mtext "rename fwex1a firewall1a")
  52. ;(mtext "rename fwex2 firewall2")
  53. ;(mtext "rename happyrouterless HRless")
  54. ;(mtext "rename happyroutermore HRmore")
  55. ;(mtext "info")
  56. ;(mtext "info conf1")
  57. ; Mypol doesn't exist: expect an error on UNDER clause.
  58. ;(define test-string "EXPLORE xsort(x) AND xsort(y) UNDER mypol INCLUDE mypol:rule1(x, y), mypol:rule2(x, y), mypol:rule1_applies(x, y), mypol:rule2_applies(x, y) TUPLING")
  59. ;(define test-stream (open-input-string test-string))
  60. ;(define test-xml (evalxml test-string))
  61. ;(m test-xml)
  62. (define theid (mtext "EXPLORE conf1:permit(s, a, r) INCLUDE conf1:permit"))
  63. ;(printf "Id: ~a~n" (xml-explore-result->id theid))
  64. (display-response (mtext "GET ONE"))
  65. (display-response (mtext "EXPLORE conf1:permit(s, a, r) INCLUDE conf1:permit(s, a, r), conf1:deny(s, a, r) DEBUG 3 TUPLING"))
  66. ; You don't need to pass an EXPLORE id if you're referencing the last explore:
  67. (display-response (mtext "GET ONE"))
  68. (display-response (mtext "SHOW REALIZED conf1:permit(s, a, r), conf1:deny(s, a, r), assigned(s, r)"))
  69. (display-response (mtext "SHOW UNREALIZED conf1:permit(s, a, r), conf1:deny(s, a, r), assigned(s, r)"))
  70. (display-response (mtext "SHOW REALIZED conf1:permit(s, a, r), conf1:deny(s, a, r), assigned(s, r) FOR CASES assigned(s, r), conf1:deny(s, a, r)"))
  71. ;(mtext "EXPLORE firewall1:accept(ipsrc, ipdest, portsrc, portdest, pro) INCLUDE firewall1:accept(ipsrc, ipdest, portsrc, portdest, pro) TUPLING")
  72. ;(mtext "GET ONE 0")
  73. ;(mtext "EXPLORE firewall1:accept(ipsrc, ipdest, portsrc, portdest, pro) INCLUDE firewall1:accept")
  74. ;(mtext "GET ONE 0")
  75. ;(mtext "create vocabulary myvoc")
  76. ;(mtext "add to myvoc sort xsort")
  77. ;(mtext "add to myvoc subsort xsort s1")
  78. ;(mtext "add to myvoc subsort xsort s2")
  79. ;(mtext "add to myvoc decision permit")
  80. ;(mtext "add to myvoc decision deny")
  81. ;(mtext "add to myvoc requestvar x xsort")
  82. ;(mtext "add to myvoc requestvar y xsort")
  83. ;(mtext "create policy leaf mypol myvoc")
  84. ;(mtext "add rule to mypol rule1 permit (s1 x) (s2 y)")
  85. ;(mtext "add rule to mypol rule2 deny (s2 x) (s1 y)")
  86. ;(mtext "prepare mypol")
  87. ;(mtext "explore xsort(x) and xsort(y) UNDER mypol INCLUDE mypol:rule1(x, y), mypol:rule2(x, y), mypol:rule1_applies(x, y), mypol:rule2_applies(x, y) tupling")
  88. ;(mtext "show REALIZED 0 mypol:rule1(x, y), mypol:rule2(x, y) for cases mypol:rule1_applies(x, y), mypol:rule2_applies(x, y)")
  89. ;(mtext "info myvoc")
  90. (display-response (mtext "GET QUALIFIED RULES IN conf1"))
  91. (display-response (mtext "EXPLORE subject(x) and subject(y) and subject(z) and x=y and y=z UNDER conf1 TUPLING"))
  92. ;(display-response (mtext "EXPLORE subject(x) and notasort(y) and subject(z) and x=y and y=z UNDER conf1 TUPLING"))
  93. ;(display-response (mtext "EXPLORE subject(x) and notasort(y) and subject(z) and x=y and y=z TUPLING"))
  94. (display-response (mtext "GET ONE"))
  95. (printf "~a~n" (mtext "SHOW ONE"))
  96. (printf "~a~n" (mtext "SHOW ONE 0"))
  97. (printf "~a~n" (mtext "GET ALL"))
  98. (printf "~n~n~a~n" (mtext "SHOW ALL"))
  99. (display-response (mtext "EXPLORE NOT subject (x) AND x=y and NOT y=z UNDER conf1"))
  100. ; Should display x, y, and z anyway.
  101. (printf "~a~n" (mtext "SHOW ONE"))
  102. ; No sort inference can be done here. Only know 2 variables x and y.
  103. ; Ceiling should be 2, both assertions should be UNIV.
  104. (display-response (mtext "EXPLORE x = y UNDER subspolicy DEBUG 3 TUPLING"))
  105. ;(display-response (mtext "EXPLORE x = y AND NOT potato(x) AND NOT tool(x) UNDER subspolicy"))
  106. (printf "~a~n" (mtext "SHOW ALL"))
  107. ;(stop-margrave-engine)
  108. (display-response (mtext "EXPLORE conf1:Deny(s, a, r) AND
  109. reviewer(s) AND paper(r) AND readpaper(a)"))
  110. (printf "~a~n" (mtext "SHOW ALL"))