Max has uploaded this change for review. ( https://gerrit.osmocom.org/12226


Change subject: Add tests for IMSI ACLs
......................................................................

Add tests for IMSI ACLs

Change-Id: Ia782f12b49bed6428bc9b9f513237e4e6aefdec9
---
M tests/sgsn/sgsn_test.c
M tests/sgsn/sgsn_test.ok
2 files changed, 115 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-sgsn refs/changes/26/12226/1

diff --git a/tests/sgsn/sgsn_test.c b/tests/sgsn/sgsn_test.c
index 4c0dc00..21bff5c 100644
--- a/tests/sgsn/sgsn_test.c
+++ b/tests/sgsn/sgsn_test.c
@@ -1337,6 +1337,108 @@
        cleanup_test();
 }

+static bool add_check_acl(const char *imsi, struct sgsn_config *cfg)
+{
+       struct imsi_acl_entry *e;
+       size_t old = sgsn_acl_count(cfg), new;
+       int rc;
+
+       printf("[%zu] Adding ACL %s [%zu]... ", old, imsi, strlen(imsi));
+
+       rc = sgsn_acl_add(imsi, cfg);
+       new = sgsn_acl_count(cfg);
+
+       if (rc < 0) {
+               printf("failed to add acl %s, total entries %zu\n", imsi, new);
+               return false;
+       }
+
+       if (new - old != 1) {
+               printf("failed to add acl %s: incorrect number of total entries 
%zu\n", imsi, new);
+               return false;
+       }
+
+       e = sgsn_acl_lookup(imsi, cfg);
+       if (e)
+               printf("added as %s [%zu], total entries %zu\n", e->imsi, 
strlen(e->imsi), new);
+       else {
+               printf("failed to obtain added %s entry, total entries %zu\n", 
imsi, new);
+               return false;
+       }
+
+       return true;
+}
+
+static bool del_check_acl(const char *imsi, struct sgsn_config *cfg)
+{
+       size_t old = sgsn_acl_count(cfg), new;
+       int rc;
+
+       printf("[%zu] Removing ACL %s... ", old, imsi);
+
+       rc = sgsn_acl_del(imsi, cfg);
+       new = sgsn_acl_count(cfg);
+
+       if (rc < 0) {
+               printf("failed to remove acl %s, total entries %zu\n", imsi, 
sgsn_acl_count(cfg));
+               if (new != old)
+                       printf("\tincorrect number of total entries %zu\n", 
new);
+               return false;
+       }
+
+       if (old - new != 1) {
+               printf("failed to remove acl %s: incorrect number of total 
entries %zu\n", imsi, new);
+               return false;
+       }
+
+       printf("OK, total entries %zu\n", new);
+
+       return true;
+}
+
+static void test_imsi_acl(struct sgsn_config *cfg)
+{
+       printf("Testing IMSI ACLs\n");
+
+       /* add short IMSI */
+       if (!add_check_acl("1010000000016", cfg))
+               return;
+
+       /* add complete IMSI */
+       if (!add_check_acl("001010000000011", cfg))
+               return;
+       if (!add_check_acl("001010000000012", cfg))
+               return;
+       if (!add_check_acl("001010000000013", cfg))
+               return;
+
+       /* delete non-existent - should fail: */
+       if (del_check_acl("666010000000012", cfg))
+               return;
+
+       /* delete existent short */
+       if (!del_check_acl("1010000000016", cfg))
+               return;
+
+       /* delete existent complete */
+       if (!del_check_acl("001010000000012", cfg))
+               return;
+       if (!del_check_acl("001010000000011", cfg))
+               return;
+       if (!del_check_acl("001010000000013", cfg))
+               return;
+
+       /* double-delete - should fail: */
+       if (del_check_acl("001010000000013", cfg))
+               return;
+
+       /* add long IMSI - should fail: */
+       if (add_check_acl("00101002222222222222222200000011", cfg))
+               return;
+
+       cleanup_test();
+}
+
 static void test_apn_matching(void)
 {
        struct apn_ctx *actx, *actxs[9];
@@ -1660,6 +1762,7 @@
        test_gmm_cancel();
        test_apn_matching();
        test_ggsn_selection();
+       test_imsi_acl(&sgsn->cfg);
        printf("Done\n");

        talloc_report_full(osmo_sgsn_ctx, stderr);
diff --git a/tests/sgsn/sgsn_test.ok b/tests/sgsn/sgsn_test.ok
index e7e7cf6..3d63a63 100644
--- a/tests/sgsn/sgsn_test.ok
+++ b/tests/sgsn/sgsn_test.ok
@@ -24,4 +24,16 @@
 Testing cancellation
 Testing APN matching
 Testing GGSN selection
+Testing IMSI ACLs
+[0] Adding ACL 1010000000016 [13]... added as 1010000000016 [13], total 
entries 1
+[1] Adding ACL 001010000000011 [15]... added as 001010000000011 [15], total 
entries 2
+[2] Adding ACL 001010000000012 [15]... added as 001010000000012 [15], total 
entries 3
+[3] Adding ACL 001010000000013 [15]... added as 001010000000013 [15], total 
entries 4
+[4] Removing ACL 666010000000012... failed to remove acl 666010000000012, 
total entries 4
+[4] Removing ACL 1010000000016... OK, total entries 3
+[3] Removing ACL 001010000000012... OK, total entries 2
+[2] Removing ACL 001010000000011... OK, total entries 1
+[1] Removing ACL 001010000000013... OK, total entries 0
+[0] Removing ACL 001010000000013... failed to remove acl 001010000000013, 
total entries 0
+[0] Adding ACL 00101002222222222222222200000011 [32]... failed to obtain added 
00101002222222222222222200000011 entry, total entries 1
 Done

--
To view, visit https://gerrit.osmocom.org/12226
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-sgsn
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia782f12b49bed6428bc9b9f513237e4e6aefdec9
Gerrit-Change-Number: 12226
Gerrit-PatchSet: 1
Gerrit-Owner: Max <[email protected]>

Reply via email to