summaryrefslogtreecommitdiffstats
path: root/tests
AgeCommit message (Collapse)AuthorFilesLines
2017-10-28automatically create db tables on osmo-hlr invocationNeels Hofmeyr2-1/+1
If a database file is missing, osmo-hlr creates it, as is the default sqlite3 API behavior -- before this patch, that db file is created, but lacks useful tables. Actually also create initial tables in it, as osmo-nitb did. In effect, the 'vty-test' target in tests/Makefile.am no longer needs to create a database manually. (The 'ctrl-test' still does, because it also wants to add subscriber data on top of the bare tables.) Note: it could be desirable to bail if the desired database file does not exist. That is however a different semantic from this patch; this is not changing the fact that a db file is created, this just creates a usable one. Note: I am about to add osmo-hlr-db-tool to do database migration from osmo-nitb. For that, it is desirable to bootstrap a usable database, which is the core reason for this patch. Don't plainly duplicate hlr.sql to .c, but create db_bootstrap.h as a BUILT_SOURCE from reading in sql/hlr.sql and mangling via sed to a list of SQL statement strings. On each db_open(), run this bootstrap sequence. In sql/hlr.sql, these tweaks are necessary: * Add 'IF NOT EXISTS' to 'CREATE TABLE', so that the bootstrap sequence can be run on an already bootstrapped db. * Drop the final comment at the bottom, which ended up being an empty SQL statement and causing sqlite3 API errors, seemed to have no purpose anyway. Note: by composing the statement strings as multiline and including the SQL comments, sqlite3 actually retains the comments contained in table definitions and prints them back during 'sqlite3 hlr.db .dump'. Change-Id: If77dbbfe1af3e66aaec91cb6295b687f37678636
2017-10-28db_test: fix *FLAGSNeels Hofmeyr1-7/+1
The -I includes should be in CFLAGS, not CPPFLAGS. I noticed problems with it when trying to add an -I$(builddir) in an upcoming patch that adds a BUILT_SOURCE, If77dbbfe1af3e66aaec91cb6295b687f37678636. Change-Id: Ie57a04b7efc7a1e16cf0e3625d8ad2f0ef0089b0
2017-10-28tests/Makefile: use test db var instead of repeating the pathNeels Hofmeyr1-2/+2
Change-Id: I9859b522b5ffa7f2c9ed33ab849199d4b4e6696c
2017-10-27test_subscriber.ctrl: test against octal/hex interpretation of idNeels Hofmeyr2-0/+20
Add a large enough subscriber id and add a test that ensures a leading zero is not interpreted as octal, and that a leading 0x is invalid and not interpreted as hexadecimal. Change-Id: Ib468b7cb595cf52331ebb41e6de0e8f57f69e173
2017-10-27ctrl: completely replace all CTRL commandsNeels Hofmeyr4-35/+714
The previous commands are not conforming to how the CTRL interface is intended to work: SET enable-ps <IMSI> SET disable-ps <IMSI> SET status-ps <IMSI> 'status-ps' is a write-only command even though it returns the status. 'enable-ps' / 'disable-ps' indicate the value instead of a variable name of an entity. The entity <IMSI> takes the place of the variable value. See also https://lists.osmocom.org/pipermail/openbsc/2017-September/011236.html Instead, replace with SET subscriber.by-imsi-123456.ps-enabled {0,1} GET subscriber.by-imsi-123456.ps-enabled and also provide further CTRL functions while at it: {SET,GET} subscriber.by-{imsi,msisdn,id}-123456.{cs,ps}-enabled {0,1} GET subscriber.by-{imsi,msisdn,id}-123456.{info,info-aud,info-all} Provide CTRL tests in the form of transcripts. Adjust tests/test_subscriber.sql to feature nonzero SQN, to see some values for SQN in the CTRL transcript tests. (This does not affect the VTY tests, because that creates its own subscribers, and there's no VTY command to set the SQN.) This is the first time an application uses CTRL_NODE ids that are defined outside of libosmocore, see 'Depends' below. Implementation choice: the first idea was to have a '.' between the 'by-xxx' and the value, like: subscriber.by-xxx.123456.function but the difficulty with subscribers is that they are not in RAM, and I can't just point node_data at a struct instance that is always there (like, say, a global bts[0] struct in osmo-bsc). Instead, I want to store the selector and later decide whether to read from the DB or whatever. With a '.' separating things, the only way in a ctrl function to obtain both 'by-xxx' and '123456' for picking a subscriber record would be to parse the entire variable path string elements, including 'subscriber' and 'function', which would then also clumsily fix at which node level we hook these commands; there could have been separate CTRL_NODE_SUBSCR_BY_{IMSI,MSISDN,ID} parent nodes, but we cannot introspect the current parent node dynamically within a ctrl function handler (plus I'm not sure whether it's possible and a good idea to have the same command under multiple parent nodes). Rather than that, I store the 'by-foo-123' token in the node_data pointer to have both bits of information pointed at by a single pointer; I use the incoming command parsing to get this token pre-separated from surrounding node names, and no need to re-allocate it, since the vector of tokens lives until after command execution is complete. Each leaf command obtains this token from cmd->node (aka node_data), and feeds this token to a common static function to parse selector and value from it and to retrieve a subscriber record as needed. (BTW, I have mentioned on the mailing list that this way might be necessary to avoid numeric-only CTRL node names, but we don't need to, and that is not at all related to this choice of structure.) Depends: libosmocore I1bd62ae0d4eefde7e1517db15a2155640a1bab58 libosmocore Ic9dba0e4a1eb5a7dc3cee2f181b9024ed4fc7005 Change-Id: I98ee6a06b3aa6a67adb868e0b63b0e04eb42eb50
2017-10-17add hlr_subsrc_nam to put GSUP client notification in proper APINeels Hofmeyr1-0/+6
This code should not live in a CTRL interface function but be proper hlr_* API. Change-Id: I4c9b8f9ad51d49517474e8b51afc3cc2e1c9299a
2017-10-17replace ctrl_test_runner.py with transcript test_subscriber.ctrlNeels Hofmeyr3-243/+46
Use the new osmo_verify_transcript_ctrl.py from osmo-python-tests to completely replace current ctrl_test_runner.py with a CTRL interaction transcript. Add missing EXTRA_DIST entry of test_subscriber.sql. Depends: osmo-python-tests Id47331009910e651372b9c9c76e12f2e8964cc2c Change-Id: Iff93abe370b8f3ecf42082d1d0eaa1fbeca5b122
2017-10-17add test_nodes.vtyNeels Hofmeyr2-0/+118
Automatically picked up by the vty-test target, by file name extension. Change-Id: I8dba373cee1be954504f79c3305b0111071757e7
2017-10-17implement subscriber vty interface, testsNeels Hofmeyr2-2/+367
Implement VTY commands for subscriber manipulation: - create / delete subscriber - modify MSISDN - add/edit/remove 2G and 3G authentication data - show by IMSI, MSISDN or DB ID. (enable/disable CS/PS and purge/unpurge to follow later.) Implement VTY unit tests for the new commands using new osmo_verify_transcript_vty.py from osmo-python-tests. Depends: libosmocore I1e94f5b0717b947d2a7a7d36bacdf04a75cb3522 osmo-python-tests Id47331009910e651372b9c9c76e12f2e8964cc2c Change-Id: I42b3b70a0439a8f2e4964d7cc31e593c1f0d7537
2017-10-15fix db_subscr_get_by_*(): clear output data; test in db_test.cNeels Hofmeyr1-3/+16
db_subscr_get_by_*() failed to clear the out-param struct, meaning that data could remain in a struct even though it is not present in the database. Always zero out the struct before writing to it. Adjust the db_test to catch this error by writing "-invalid-data-" to each struct before running db get functions. Change-Id: I038bd437452c87841d709fcdd5ac30ab1356b2db
2017-10-11fix db_update_sqn(): reset stmt in all error casesNeels Hofmeyr2-0/+291
Use the common db_bind_int64() so that the stmt bindings are cleared for any errors and to get error logging for free. On error with sqlite3_step(), log the SQL error message, and make sure the stmt is cleared of bindings and reset. After sqlite3_step(), verify that exactly one row was modifed, log and return errors otherwise. After this patch, the DB interaction closely matches the other (refactored) DB functions. Change-Id: I0d870d405e2e0a830360d9ad19f0a3f9e09d8cf2
2017-10-11refactor db_get_auth_data return valNeels Hofmeyr2-59/+59
Adopt the error handling of the other db functions: return -ENOENT on unknown subscriber and -EIO on SQL failure. Return 0 for no error, instead of the number of rows modified. Adjust the single caller: db_get_auc() (and db_test.c). Change-Id: I006f471962bdad95d00a3a4c41a28ebbc9740884
2017-10-11add db_subscr_update_aud_by_id(), complete db_subscr_delete_by_id()Neels Hofmeyr2-0/+760
Add ability to add and remove auc_2g and auc_3g table rows with db_subscr_update_aud_by_id(). In db_subscr_delete_by_id(), make sure that when deleting a subscriber, also all auth data associated with that user ID is removed as well. A newly created subscriber must not obtain the same auth tokens just by getting the same id. Depends: libosmocore Idf75946eb0a84e145adad13fc7c78bb7a267aa0a Change-Id: Icb11b5e059fb920447a9aa414db1819a0c020529
2017-10-11refactor db_subscr_purgeNeels Hofmeyr2-0/+175
Use named parameters in the SQL statements. Use db_bind_* functions to drop some code dup. Adopt error handling (rc and logging) to match the other db functions: return -ENOENT for unknown subscriber, -EIO for SQL failures. Change-Id: Iad49d29b90a708c6cf55bfb3bcc02d9e29001a15
2017-10-11refactor db_subscr_lu()Neels Hofmeyr2-0/+174
Use named parameters in the SQL statement. Use db_bind_* functions to drop some code dup. Use explicit subscriber id arg instead of subscriber struct. Match return values and error logging to other db functions. Change-Id: I35665e84ddbe54a6f218b24033df969ad2e669a0
2017-10-11refactor db_subscr_ps() to db_subscr_nam()Neels Hofmeyr2-0/+183
Allow to set nam_ps and nam_cs from this same function, by adding the is_ps arg. Combine both NAM_PS stmts to DB_STMT_UPD_NAM_PS_BY_IMSI, add another such stmt for CS. Use named parameters instead of parameter indexes. Improve error return values as well as error logging to clearly indicate whether the operation could not find the requested IMSI, or other errors occured. Adjust the single caller. This prepares for upcoming VTY and possibly CTRL commands, and the error handling introduced here has been or will be adopted by other functions in previous or subsequent patches. Change-Id: I6e70e15228f5bb10bee6758ae5dc9687d65839bd
2017-10-11add db_subscr_get_by_msisdn() and db_subscr_get_by_id()Neels Hofmeyr2-24/+85
Factor out the selected SQL columns as SEL_COLUMNS macro, so that each of the new DB_STMTs will select identical columns: the old DB_STMT_SEL_BY_IMSI as well as the new DB_STMT_SEL_BY_MSISDN and DB_STMT_SEL_BY_ID. Add the new functions db_subscr_get_by_msisdn() and db_subscr_get_by_id() and factor out common parts with db_subscr_get_by_imsi() to static db_sel(). Change-Id: I6d0ddd1b7e3f6b180b4b1b2663c5725d2a4a9428
2017-10-11less noise: simplify db_remove_reset()Neels Hofmeyr1-5/+0
db_remove_reset() needs to be called after each stmt run, whether it succeeded or not. In case sqlite3_clear_bindings() would fail to unbind a stmt, we would anyway be beyond recovery. There seem to be no plausible situations where such failure would occur, unless there have been no bindings in the first place. In case there was an SQL stmt failure, sqlite3_reset() will re-barf the same error message, we will always have logged it earlier already in the proper context. We are never evaluating the return value, nor would we know how to recover from non-success. The conclusions: - db_remove_reset() does not need to log any errors. - db_remove_reset() does not need to return success. Change-Id: I21678463e59f607f5f5c5732963e274392f0fffd
2017-10-11add initial db_test: creating and deleting subscribersNeels Hofmeyr6-0/+661
Change-Id: I2a0d277f55162bf5ceb0fc7d50390f2994daed71
2017-10-11ctrl_test_runner.py: use proper constant as test db pathNeels Hofmeyr1-1/+1
Change-Id: I9533a9ff8c0f8d24c678583a9197143a187908f3
2017-09-28add CTRL tests for enable-/disable-/status-psNeels Hofmeyr2-0/+55
Change-Id: I014437db9c0f15d818e04810f6cb14bf475ee002
2017-09-28add basic CTRL interface testsNeels Hofmeyr2-0/+209
Prepare for adding tests of enable-/disable-/status-ps CTRL commands. Change-Id: Ie195169c574716b514da7e04a3ce9727ef70a55e
2017-07-13Another attempt at fixing .debMax1-1/+1
The previous efforts have failed: python3 does not supply /usr/bin/python symlink. Let's use python-minimal dependency. Change-Id: If9e3f31622efae132b25683c54ce09c83ce43415
2017-07-12deb: use python in shebangMax1-2/+2
This should fix the .deb build on OBS. Change-Id: I095e5c273e30a6e124833bf58b231c6367ab48d6
2017-07-11Attempt to fix .deb packageMax2-5/+3
After recent switch to legacy python2 .deb fails on OBS. Let's put known-to-work python3 dependency back but keep the script itself on python without version specifier as it seems to work fine with both versions. This, in turn, causes tests to fail on FreeBSD so disable them for now. Change-Id: I4a87252d411d840fca7362736a8c7877efa6ff52 Related: SYS#3322
2017-06-07tests/auc: Don't require python3Daniel Willmann1-1/+1
Our jenkins buildslave does not have python3 installed so call python2 instead. Change-Id: Ifb59b79021b2c935b326496ed339f12e13c96b8e Ticket: SYS#3322
2017-03-16debug log: output ind slot, previous sqn, and sqn db updateNeels Hofmeyr2-0/+26
Change-Id: Ib86442ea45f6c1948b3d260f59d35bdca38fbd32
2017-03-16UMTS AKA: implement SQN increment according to SEQ and INDNeels Hofmeyr6-0/+287
Add ind_bitlen column to auc_3g to record each USIM's IND size according to 3GPP TS 33.102 -- default is 5 bits, as suggested by the spec. Introduce auc_3g_ind to each connecting GSUP client to use as IND index for generating auth tuples sent to this client. With osmo_gsup_server_add_conn(), implement a scheme where clients receive fixed auc_3g_ind indexes based on the order in which they connect; each new connection takes the lowest unused auc_3g_ind, so in case one of the clients restarts, it will most likely receive the same auc_3g_ind, and if one client disconnects, no other clients' auc_3g_ind are affected. Add gsup_server_test.c to test the auc_3g_ind index distribution scheme. Depends: libosmocore I4eac5be0c0b2cede04464c4c3a0873102d952453 for llist_first Related: OS#1969 Change-Id: If4501ed4ff8e923fa6fe8b80c44c5ad647a8ed60
2017-03-16fix debug log: adjust to new SQN increment schemeNeels Hofmeyr2-30/+30
We can no longer accurately print the SQN from AUTS resync, since the SQN is incremented after AUTS. Instead, always print the SQN from the generated tuple, i.e. exactly the one left in auth data *after* the tuple was generated. This change was forgotten in recent adjustments to the new SQN incrementing scheme from libosmocore, in change-id I4ec5a578537acb1d9e1ebfe00a72417fc3ca5894 for libosmocore change-id Iadf43f21e0605e9e85f7e8026c40985f7ceff1a3. It should have been obvious that something was missing in the previous patch from the auc_test output: the SQN in the output changed while the AUTN remained the same. That slipped by without being noticed :/ Change-Id: I0e1e828da931a3d22c75306c55bdb7f44df6512f
2017-03-15auc tests: fix after SQN scheme changes from libosmocoreNeels Hofmeyr4-107/+106
In change-id Iadf43f21e0605e9e85f7e8026c40985f7ceff1a3, libosmocore changes from incrementing SQN after tuple generation to incrementing SQN before tuple generation. Thus we now need to pass desired_sqn - 1 to get the same tuples. Adjust all regression tests, showing that the tuples as well as the SQNs used to generate the tuples remain unchanged, and only the SQN before and after generating reflect different values. Related: OS#1968 OS#1969 Change-Id: I4ec5a578537acb1d9e1ebfe00a72417fc3ca5894
2017-03-15auc tests: adjust cosmetically to prepare for SQN changesNeels Hofmeyr5-93/+118
The current auc tests test a lot with SQN == 0. An upcoming change in the SQN algorithms from libosmocore [1] will require us to pass desired_sqn - 1, because the tuple generation will increment the SQN before calculating. Later on [2] we will also want to employ ind_bits and ind in the test. In order to have some room in the number range, cosmetically adjust the current SQN tested for from 0 to 32, changing the generated AUTN. The upcoming adjustment to the new situation will then be able to show that only the SQN values before and after vector generation change while the auth tuples as well as the SQNs used for generation remain the same (without having to trick around with wrapping SQN past its maximum value). Note that the TS 55.205 test sets include neither SQN nor AUTN. While AUTN changes with changing SQN, all the other values are invariant of the SQN used. So we can simply choose a different SQN and ignore the difference in the AUTN. [1] change-id Iadf43f21e0605e9e85f7e8026c40985f7ceff1a3 "store last sqn" [2] change-id Ibc97e1736a797ffcbf8c1f7d41c5c4518f4e41bf "fix SQN increment" Related: OS#1969 Change-Id: I45d1866cde1b3e777460df76100af2fe4767c678
2017-02-22cosmetic: rename auc_3g_test.c to auc_test.cNeels Hofmeyr5-9/+9
The test includes 2G-only tests so the name is misleading. Splitting up makes no sense. Change-Id: I1a5a40413bf6636ead9370fb827aa0338c049e7f
2017-02-22cosmetic: auc_3g_test: improve test debugging toolsNeels Hofmeyr1-5/+66
In the test failure mismatch printf, better indicate the place of first mismatch. Helpful if some byte within a hexdump differs, the case when debugging AUTS. Copy some optarg code from openbsc's msc_vlr tests to provide verbose mode that prints log statements' source file and line. Change-Id: I1b23da055b5edacba09310411caf43c4cd1c29bc
2017-02-22auc_compute_vectors(): fix AUTS resync for multiple vectorsNeels Hofmeyr2-55/+5
Fix bug where AUTS was fed to each vector generation and thus each vector was generated with the same SQN. In auc_3g_test, adjust the bug indicating test expectations to now expect the proper results. Depends: libosmocore change-id If943731a78089f0aac3d55245de80596d01314a4 Change-Id: I425a1d92c85896227341f565f5361c0d830ce866
2017-02-22cosmetic: refactor auc_compute_vectors(), add debug logNeels Hofmeyr4-363/+438
Make the generation logic easier to understand (hopefully). Massively extend debug logging, which serves to illustrate the current AUTS failure shown by auc_3g_test. Since DAUC now logs the vectors, there is no need to print the vectors in VEC_IS() in auc_3g_test and auc_ts_55_205_test_sets anymore. Adjust testlog expectations accordingly. Change-Id: Ifb36d010a4ac64c765517e15b9074424ec19cc60
2017-02-22auc_3g_test: add AUTS test with N vectors, to show bugNeels Hofmeyr2-0/+198
Add test that shows how passing AUTS to auc_compute_vectors performs an AUTS sync on each vector and hence produces the same SQN each time. This will generate one working vector as resync result, and then N-1 more with the wrong SQN as far as the USIM is concerned. This causes a resync to be necessary on every authentication. Depends: libosmocore change-id If943731a78089f0aac3d55245de80596d01314a4 Change-Id: I246c9edfb009b593f834bb5b0577b65bfde7083c
2017-02-22auc_3g_test: allow to inc fake rand bytes upon rand requestNeels Hofmeyr1-10/+16
Preparing for upcoming unit test, in a separate commit for cosmetic reasons (setting the flag to false across the code). Change-Id: I6b9899cd898eecc95b244432f416041b194a7187
2017-02-22auc_gen_vectors(): ensure sane arguments, testNeels Hofmeyr2-0/+242
In auc_gen_vectors(), add various checks that the auth data arguments passed make sense, and add unit test to verify that they work. (Caught a segfault due to NULL dereference with this.) Change-Id: I775652b6a91d382707ce32176a3fe4ef547cbca7
2017-02-22auc_3g_test: add AUTS resync testNeels Hofmeyr2-0/+87
Used this to catch a bug where the AUTS process failed to copy RAND to the auth vector (libosmocore). Depends: libosmocore change-id If943731a78089f0aac3d55245de80596d01314a4 Change-Id: I06dd8671aa515139bdc3f08883f08276662cf25f
2017-02-01auth: verify test sets from 3GPP TS 55.205Neels Hofmeyr10-14/+1605
Put to-text conversion of the 3GPP TS 55.205 PDF's section defining the test vectors in tests/auc/gen_ts_55_205_test_sets/ts55_205_test_sets.txt and add python script to generate auc_ts_55_205_test_sets.c from that at build time. The generated auc_ts_55_205_test_sets.c runs through all 19 test sets, verifying that our gsm_milenage() matches the reference data. Change-Id: Idff9d757ab956179aa41ada2a223fd9f439aafbd
2017-02-01tests: auc_3g_test: implement vector generation testNeels Hofmeyr2-1/+366
Change-Id: I291bccd62661ff5790dc43d91dc63a9e4b0e0ff2
2017-02-01Add test suite skeleton with empty test (auc_3g_test)Neels Hofmeyr6-0/+159
Change-Id: I6359b0809ce8578850fd65887a568714fb35dbd8