Add more tests for deletions
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 22 May 2014 21:44:37 +0000 (22:44 +0100)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Fri, 23 May 2014 13:18:07 +0000 (14:18 +0100)
src/tests/keywords/update-remove-index [new file with mode: 0644]
src/tests/keywords/update-remove-list
src/tests/keywords/update-remove-value

diff --git a/src/tests/keywords/update-remove-index b/src/tests/keywords/update-remove-index
new file mode 100644 (file)
index 0000000..58df9a5
--- /dev/null
@@ -0,0 +1,100 @@
+#
+# PRE: update update-remove-value
+#
+#  Remove all attributes in a list
+#
+update {
+       control:Cleartext-Password := 'hello'
+       reply:Filter-Id := 'filter'
+}
+
+update {
+       request:Tmp-String-0 := 'foobarbaz'
+       request:Tmp-Integer-0 := 123456789
+       request:Tmp-IP-Address-0 := 192.0.2.1
+       request:Tmp-IP-Address-0 += 192.0.2.2
+       request:Tmp-IP-Address-0 += 192.0.2.3
+       request:Tmp-IP-Address-0 += 192.0.2.2
+       request:Tmp-IP-Address-0 += 192.0.2.4
+}
+
+
+update request {
+       Tmp-IP-Address-0[3] -= 192.0.2.2
+}
+
+# Only the 1st, 2nd, 3rd and 5th Tmp-IP-Address attributes should still be in the list
+if (("%{Tmp-IP-Address-0[0]}" != '192.0.2.1') || \
+    ("%{Tmp-IP-Address-0[1]}" != '192.0.2.2') || \
+    ("%{Tmp-IP-Address-0[2]}" != '192.0.2.3') || \
+    ("%{Tmp-IP-Address-0[3]}" != '192.0.2.4') || \
+    ("%{Tmp-IP-Address-0[4]}" != '')) {
+       update reply {
+               Filter-Id += 'fail 1'
+       }
+}
+
+# There's still a 192.0.2.2 but it's not at index 3
+update request {
+       Tmp-IP-Address-0[3] -= 192.0.2.2
+}
+
+# Should be the same as the previous result
+if (("%{Tmp-IP-Address-0[0]}" != '192.0.2.1') || \
+    ("%{Tmp-IP-Address-0[1]}" != '192.0.2.2') || \
+    ("%{Tmp-IP-Address-0[2]}" != '192.0.2.3') || \
+    ("%{Tmp-IP-Address-0[3]}" != '192.0.2.4') || \
+    ("%{Tmp-IP-Address-0[4]}" != '')) {
+       update reply {
+               Filter-Id += 'fail 2'
+       }
+}
+
+# Remove whatever's at index 0
+update request {
+       Tmp-IP-Address-0[0] !* ANY
+}
+
+# IP address at index 0 should be removed
+if (("%{Tmp-IP-Address-0[0]}" != '192.0.2.2') || \
+    ("%{Tmp-IP-Address-0[1]}" != '192.0.2.3') || \
+    ("%{Tmp-IP-Address-0[2]}" != '192.0.2.4') || \
+    ("%{Tmp-IP-Address-0[3]}" != '')) {
+       update reply {
+               Filter-Id += 'fail 3'
+       }
+}
+
+# Remove whatever's at index 3 (should be nothing)
+update request {
+       Tmp-IP-Address-0[3] !* ANY
+}
+
+# Should be the same as the previous result
+if (("%{Tmp-IP-Address-0[0]}" != '192.0.2.2') || \
+    ("%{Tmp-IP-Address-0[1]}" != '192.0.2.3') || \
+    ("%{Tmp-IP-Address-0[2]}" != '192.0.2.4') || \
+    ("%{Tmp-IP-Address-0[3]}" != '')) {
+       update reply {
+               Filter-Id += 'fail 4'
+       }
+}
+
+# Remove all instances of Tmp-IP-Address
+update request {
+       Tmp-IP-Address-0 !* ANY
+}
+
+# No more IP address attributes!
+if ("%{Tmp-IP-Address-0[0]}" != '') {
+       update reply {
+               Filter-Id += 'fail 5'
+       }
+}
+
+# Non Tmp-IP-Address-0 address attributes should still be in the request list
+if ((Tmp-String-0 != 'foobarbaz') || (Tmp-Integer-0 != 123456789)) {
+       update reply {
+               Filter-Id += 'fail 6'
+       }
+}
index a5c2d5a..22ae577 100644 (file)
@@ -15,8 +15,8 @@ update request {
 }
 
 if ((Tmp-String-0 != 'foobarbaz') || (Tmp-Integer-0 != 123456789) || (Tmp-IP-Address-0 != 192.0.2.1)) {
-       update {
-               reply:Filter-Id := 'fail'
+       update reply {
+               Filter-Id += 'fail 0'
        }
 }
 
@@ -29,8 +29,8 @@ update {
 if ((Tmp-String-0 && (Tmp-String-0 == 'foobarbaz')) || \
     (Tmp-Integer-0 && (Tmp-Integer-0 == 123456789)) || \
     (Tmp-IP-Address-0 && (Tmp-IP-Address-0 == 192.0.2.1))) {
-       update {
-               reply:Filter-Id := 'fail'
+       update reply {
+               Filter-Id := 'fail 1'
        }
 }
 
index 75b48dd..3fd1f94 100644 (file)
@@ -13,38 +13,104 @@ update {
        request:Tmp-Integer-0 := 123456789
        request:Tmp-IP-Address-0 := 192.0.2.1
        request:Tmp-IP-Address-0 += 192.0.2.2
+       request:Tmp-IP-Address-0 += 192.0.2.3
+       request:Tmp-IP-Address-0 += 192.0.2.4
        control:Tmp-IP-Address-0 := 192.0.2.1
        control:Tmp-IP-Address-0 += 192.0.2.3
 }
 
-if (("%{Tmp-IP-Address-0[0]}" != 192.0.2.1) || ("%{Tmp-IP-Address-0[1]}" != 192.0.2.2)) {
-       update {
-               reply:Filter-Id := 'fail'
+if (("%{Tmp-IP-Address-0[0]}" != 192.0.2.1) || \
+    ("%{Tmp-IP-Address-0[1]}" != 192.0.2.2) || \
+    ("%{Tmp-IP-Address-0[2]}" != 192.0.2.3) || \
+    ("%{Tmp-IP-Address-0[3]}" != 192.0.2.4)) {
+       update reply {
+               Filter-Id += 'fail 0'
        }
 }
 
-# Remove all attributes in the control list
+# Remove Tmp-IP-Address-0 with a specific value
 update {
        request:Tmp-IP-Address-0 -= 192.0.2.1
 }
 
-# Non Tmp-IP-Address-0 address attributes should still be in the request list
-if ((Tmp-String-0 != 'foobarbaz') || (Tmp-Integer-0 != 123456789)) {
+# Only the 2nd, 3rd and 4th Tmp-IP-Address attributes should still be in the list
+if (("%{Tmp-IP-Address-0[0]}" != '192.0.2.2') || \
+    ("%{Tmp-IP-Address-0[1]}" != '192.0.2.3') || \
+    ("%{Tmp-IP-Address-0[2]}" != '192.0.2.4') || \
+    ("%{Tmp-IP-Address-0[3]}" != '')) {
        update reply {
-               reply:Filter-Id := 'fail'
+               Filter-Id += 'fail 1'
        }
 }
 
-# Only the 2nd Tmp-IP-Address attribute should still be in the list
-if (("%{Tmp-IP-Address-0[0]}" != '192.0.2.2') || ("%{Tmp-IP-Address-0[1]}" != '')) {
-       update {
-               reply:Filter-Id := 'fail'
+# Remove Tmp-IP-Address-0 with a specific value (somewhere in the middle)
+update {
+       request:Tmp-IP-Address-0 -= 192.0.2.3
+}
+
+# Only the 1st, and 3rd Tmp-IP-Address attributes should still be in the list
+if (("%{Tmp-IP-Address-0[0]}" != '192.0.2.2') || \
+    ("%{Tmp-IP-Address-0[1]}" != '192.0.2.4') || \
+    ("%{Tmp-IP-Address-0[2]}" != '')) {
+       update reply {
+               Filter-Id += 'fail 2'
+       }
+}
+
+# Remove Tmp-IP-Address-0 with a specific value (which doesn't exist)
+update {
+       request:Tmp-IP-Address-0 -= 192.0.2.3
+}
+
+# Only the 1st, and 3rd Tmp-IP-Address attributes should still be in the list
+if (("%{Tmp-IP-Address-0[0]}" != '192.0.2.2') || \
+    ("%{Tmp-IP-Address-0[1]}" != '192.0.2.4') || \
+    ("%{Tmp-IP-Address-0[2]}" != '')) {
+       update reply {
+               Filter-Id += 'fail 3'
+       }
+}
+
+# Remove Tmp-IP-Address-4 (which doesn't exist - more to check for SEGV/assert)
+update {
+       request:Tmp-IP-Address-4 -= 192.0.2.3
+}
+
+# Remove Tmp-IP-Address-0 with a specific value
+update {
+       request:Tmp-IP-Address-0 -= 192.0.2.4
+}
+
+# Only the 1st, and 3rd Tmp-IP-Address attributes should still be in the list
+if (("%{Tmp-IP-Address-0[0]}" != '192.0.2.2') || \
+    ("%{Tmp-IP-Address-0[1]}" != '')) {
+       update reply {
+               Filter-Id += 'fail 4'
+       }
+}
+
+# Remove Tmp-IP-Address-0 with a specific value
+update {
+       request:Tmp-IP-Address-0 -= 192.0.2.2
+}
+
+# Only the 1st, and 3rd Tmp-IP-Address attributes should still be in the list
+if ("%{Tmp-IP-Address-0[0]}" != '') {
+       update reply {
+               Filter-Id += 'fail 5'
+       }
+}
+
+# Non Tmp-IP-Address-0 address attributes should still be in the request list
+if ((Tmp-String-0 != 'foobarbaz') || (Tmp-Integer-0 != 123456789)) {
+       update reply {
+               Filter-Id += 'fail 6'
        }
 }
 
 # But there should still be some in the control list
 if (("%{control:Tmp-IP-Address-0[0]}" != 192.0.2.1) || ("%{control:Tmp-IP-Address-0[1]}" != 192.0.2.3)) {
        update {
-               reply:Filter-Id := 'fail'
+               Filter-Id += 'fail 7'
        }
 }