aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorOliver Smith <osmith@sysmocom.de>2019-01-09 12:03:51 +0100
committerHarald Welte <laforge@gnumonks.org>2019-01-24 15:29:08 +0000
commit81db389fd489f1b7962e72105a5a2cc5f3feb3fb (patch)
treee32a60a21953e23f8ac246435ec485fe7c722baf /tests
parent7943e269380fc00d6c8bbedca7d52360c36384f1 (diff)
Add IMEI column to subscriber table
Extend the database scheme, add imei to the hlr_subscriber struct and create db_subscr_update_imei_by_imsi() and db_subscr_get_by_imei(). The new functions are used in db_test, and in follow-up commits [1], [2]. Upgrade DB schema to version 2. SQLite can only insert new columns at the end of the table, so this happens when upgrading the database. In new databases, the column is placed after the IMEISV column (where it makes more sense in my opinion). This should not have any effect, as we never rely on the order of the columns in the tables. Follow-up commit [1] will make use of this column to save the IMEI as received from the MSC/VLR with the Check-IMEI Procedure. It was decided to use Check-IMEI instead of the recent Automatic Device Detection Procedure (which would send the IMEISV) in OS#3733, because with Check-IMEI we don't need to rely on very recent releases of the specification. [1] change-id I09274ecbed64224f7ae305e09ede773931da2a57 "Optionally store IMEI in subscriber table" [2] change-id I1af7b573ca2a1cb22497052665012d9c1acf3b30 "VTY: integrate IMEI" Depends: Id2d2a3a93b033bafc74c62e15297034bf4aafe61 (libosmocore) Related: OS#2541 Change-Id: If232c80bea35d5c6864b889ae92d477eeaa3f45d
Diffstat (limited to 'tests')
-rw-r--r--tests/db/db_test.c18
-rw-r--r--tests/db/db_test.err48
2 files changed, 66 insertions, 0 deletions
diff --git a/tests/db/db_test.c b/tests/db/db_test.c
index c4ed6ed..56905a9 100644
--- a/tests/db/db_test.c
+++ b/tests/db/db_test.c
@@ -148,6 +148,7 @@ void dump_subscr(struct hlr_subscriber *subscr)
Pd(id);
Ps(imsi);
Ps(msisdn);
+ Ps(imei);
Ps(vlr_number);
Ps(sgsn_number);
Ps(sgsn_address);
@@ -296,6 +297,23 @@ static void test_subscr_create_update_sel_delete()
ASSERT_RC(db_subscr_update_msisdn_by_imsi(dbc, "foobar", "99"), -ENOENT);
ASSERT_SEL(msisdn, "99", -ENOENT);
+ comment("Set valid / invalid IMEI");
+
+ ASSERT_RC(db_subscr_update_imei_by_imsi(dbc, imsi0, "12345678901234"), 0);
+ ASSERT_SEL(imei, "12345678901234", 0);
+
+ ASSERT_RC(db_subscr_update_imei_by_imsi(dbc, imsi0, "123456789012345"), -EINVAL); /* too long */
+ ASSERT_SEL(imei, "12345678901234", 0);
+ ASSERT_SEL(imei, "123456789012345", -ENOENT);
+
+ comment("Set the same IMEI again");
+ ASSERT_RC(db_subscr_update_imei_by_imsi(dbc, imsi0, "12345678901234"), 0);
+ ASSERT_SEL(imei, "12345678901234", 0);
+
+ comment("Remove IMEI");
+ ASSERT_RC(db_subscr_update_imei_by_imsi(dbc, imsi0, NULL), 0);
+ ASSERT_SEL(imei, "12345678901234", -ENOENT);
+
comment("Set / unset nam_cs and nam_ps");
/* nam_val, is_ps */
diff --git a/tests/db/db_test.err b/tests/db/db_test.err
index 1d34045..6ebdae2 100644
--- a/tests/db/db_test.err
+++ b/tests/db/db_test.err
@@ -227,6 +227,54 @@ db_subscr_get_by_msisdn(dbc, "99", &g_subscr) --> -ENOENT
DAUC Cannot read subscriber from db: MSISDN='99': No such subscriber
+--- Set valid / invalid IMEI
+
+db_subscr_update_imei_by_imsi(dbc, imsi0, "12345678901234") --> 0
+
+db_subscr_get_by_imei(dbc, "12345678901234", &g_subscr) --> 0
+struct hlr_subscriber {
+ .id = 1,
+ .imsi = '123456789000000',
+ .msisdn = '543210123456789',
+ .imei = '12345678901234',
+}
+
+db_subscr_update_imei_by_imsi(dbc, imsi0, "123456789012345") --> -EINVAL
+DAUC Cannot update subscriber IMSI='123456789000000': invalid IMEI: '123456789012345'
+
+db_subscr_get_by_imei(dbc, "12345678901234", &g_subscr) --> 0
+struct hlr_subscriber {
+ .id = 1,
+ .imsi = '123456789000000',
+ .msisdn = '543210123456789',
+ .imei = '12345678901234',
+}
+
+db_subscr_get_by_imei(dbc, "123456789012345", &g_subscr) --> -ENOENT
+DAUC Cannot read subscriber from db: IMEI=123456789012345: No such subscriber
+
+
+--- Set the same IMEI again
+
+db_subscr_update_imei_by_imsi(dbc, imsi0, "12345678901234") --> 0
+
+db_subscr_get_by_imei(dbc, "12345678901234", &g_subscr) --> 0
+struct hlr_subscriber {
+ .id = 1,
+ .imsi = '123456789000000',
+ .msisdn = '543210123456789',
+ .imei = '12345678901234',
+}
+
+
+--- Remove IMEI
+
+db_subscr_update_imei_by_imsi(dbc, imsi0, NULL) --> 0
+
+db_subscr_get_by_imei(dbc, "12345678901234", &g_subscr) --> -ENOENT
+DAUC Cannot read subscriber from db: IMEI=12345678901234: No such subscriber
+
+
--- Set / unset nam_cs and nam_ps
db_subscr_nam(dbc, imsi0, false, true) --> 0