Pau Espin Pedrol has submitted this change and it was merged. ( https://gerrit.osmocom.org/11009 )
Change subject: encryption: Reuse code using test lib features ...................................................................... encryption: Reuse code using test lib features Change-Id: I9b6944516c524a0c11a47aec6839f8ee9d571661 --- A suites/encryption/lib/testlib.py M suites/encryption/register_a5_0_authopt.py M suites/encryption/register_a5_0_authreq.py M suites/encryption/register_a5_1_authreq.py 4 files changed, 66 insertions(+), 125 deletions(-) Approvals: Harald Welte: Looks good to me, approved Jenkins Builder: Verified diff --git a/suites/encryption/lib/testlib.py b/suites/encryption/lib/testlib.py new file mode 100644 index 0000000..3948941 --- /dev/null +++ b/suites/encryption/lib/testlib.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python3 +from osmo_gsm_tester.testenv import * + +def encryption_test_setup_run(enable_auth, algo): + hlr = suite.hlr() + bts = suite.bts() + mgw_msc = suite.mgw() + mgw_bsc = suite.mgw() + stp = suite.stp() + msc = suite.msc(hlr, mgw_msc, stp) + bsc = suite.bsc(msc, mgw_bsc, stp) + ms = suite.modem() + + print('start network...') + msc.set_authentication(enable_auth) + msc.set_encryption(algo) + bsc.set_encryption(algo) + hlr.start() + stp.start() + msc.start() + mgw_msc.start() + mgw_bsc.start() + bsc.bts_add(bts) + bsc.start() + bts.start() + wait(bsc.bts_is_connected, bts) + + ms.log_info() + good_ki = ms.ki() + bad_ki = ("%1X" % (int(good_ki[0], 16) ^ 0x01)) + good_ki[1:] + + print('KI changed: ' + good_ki + " => " + bad_ki) + ms.set_ki(bad_ki) + hlr.subscriber_add(ms) + if enable_auth: + print('Attempt connection with wrong KI...') + ms.connect(msc.mcc_mnc()) + + sleep(40) # TODO: read pcap or CTRL interface and look for Rejected? (gsm_a.dtap.msg_mm_type == 0x04) + print('Asserting modem did not register') + # FIXME: this can fail because ofono qmi signals registered before being accepted by network. See OS#2458 + # assert not ms.is_connected(msc.mcc_mnc()) + assert not msc.subscriber_attached(ms) + + hlr.subscriber_delete(ms) + print('KI changed: ' + bad_ki + " => " + good_ki) + ms.set_ki(good_ki) + hlr.subscriber_add(ms, ms.msisdn) + print('Attempt connection with correct KI...') + else: + print('Attempt connection with wrong KI, should work as it is not used...') + ms.connect(msc.mcc_mnc()) + wait(ms.is_connected, msc.mcc_mnc()) + wait(msc.subscriber_attached, ms) diff --git a/suites/encryption/register_a5_0_authopt.py b/suites/encryption/register_a5_0_authopt.py index acbbb1f..1b7f471 100755 --- a/suites/encryption/register_a5_0_authopt.py +++ b/suites/encryption/register_a5_0_authopt.py @@ -1,37 +1,8 @@ #!/usr/bin/env python3 from osmo_gsm_tester.testenv import * -hlr = suite.hlr() -bts = suite.bts() -mgw_msc = suite.mgw() -mgw_bsc = suite.mgw() -stp = suite.stp() -msc = suite.msc(hlr, mgw_msc, stp) -bsc = suite.bsc(msc, mgw_bsc, stp) -ms = suite.modem() +import testlib +suite.test_import_modules_register_for_cleanup(testlib) +from testlib import encryption_test_setup_run -print('start network...') -msc.set_authentication(False) -msc.set_encryption('a5_0') -bsc.set_encryption('a5_0') -hlr.start() -stp.start() -msc.start() -mgw_msc.start() -mgw_bsc.start() -bsc.bts_add(bts) -bsc.start() -bts.start() -wait(bsc.bts_is_connected, bts) - -ms.log_info() -good_ki = ms.ki() -bad_ki = ("%1X" % (int(good_ki[0], 16) ^ 0x01)) + good_ki[1:] - -print('KI changed: ' + good_ki + " => " + bad_ki) -ms.set_ki(bad_ki) -hlr.subscriber_add(ms) -print('Attempt connection with wrong KI, should work as it is not used...') -ms.connect(msc.mcc_mnc()) -wait(ms.is_connected, msc.mcc_mnc()) -wait(msc.subscriber_attached, ms) +encryption_test_setup_run(False, 'a5_0') diff --git a/suites/encryption/register_a5_0_authreq.py b/suites/encryption/register_a5_0_authreq.py index 789ace5..feca525 100755 --- a/suites/encryption/register_a5_0_authreq.py +++ b/suites/encryption/register_a5_0_authreq.py @@ -1,50 +1,8 @@ #!/usr/bin/env python3 from osmo_gsm_tester.testenv import * -hlr = suite.hlr() -bts = suite.bts() -mgw_msc = suite.mgw() -mgw_bsc = suite.mgw() -stp = suite.stp() -msc = suite.msc(hlr, mgw_msc, stp) -bsc = suite.bsc(msc, mgw_bsc, stp) -ms = suite.modem() +import testlib +suite.test_import_modules_register_for_cleanup(testlib) +from testlib import encryption_test_setup_run -print('start network...') -msc.set_authentication(True) -msc.set_encryption('a5_0') -bsc.set_encryption('a5_0') -hlr.start() -stp.start() -msc.start() -mgw_msc.start() -mgw_bsc.start() -bsc.bts_add(bts) -bsc.start() -bts.start() -wait(bsc.bts_is_connected, bts) - -ms.log_info() -good_ki = ms.ki() -bad_ki = ("%1X" % (int(good_ki[0], 16) ^ 0x01)) + good_ki[1:] - -print('KI changed: ' + good_ki + " => " + bad_ki) -ms.set_ki(bad_ki) -hlr.subscriber_add(ms) -print('Attempt connection with wrong KI...') -ms.connect(msc.mcc_mnc()) - -sleep(40) # TODO: read pcap or CTRL interface and look for Rejected? (gsm_a.dtap.msg_mm_type == 0x04) -print('Asserting modem did not register') -# FIXME: this can fail because ofono qmi signals registered before being accepted by network. See OS#2458 -# assert not ms.is_connected(msc.mcc_mnc()) -assert not msc.subscriber_attached(ms) - -hlr.subscriber_delete(ms) -print('KI changed: ' + bad_ki + " => " + good_ki) -ms.set_ki(good_ki) -hlr.subscriber_add(ms, ms.msisdn) -print('Attempt connection with correct KI...') -ms.connect(msc.mcc_mnc()) -wait(ms.is_connected, msc.mcc_mnc()) -wait(msc.subscriber_attached, ms) +encryption_test_setup_run(True, 'a5_0') diff --git a/suites/encryption/register_a5_1_authreq.py b/suites/encryption/register_a5_1_authreq.py index e7aa76c..077819b 100755 --- a/suites/encryption/register_a5_1_authreq.py +++ b/suites/encryption/register_a5_1_authreq.py @@ -1,50 +1,8 @@ #!/usr/bin/env python3 from osmo_gsm_tester.testenv import * -hlr = suite.hlr() -bts = suite.bts() -mgw_msc = suite.mgw() -mgw_bsc = suite.mgw() -stp = suite.stp() -msc = suite.msc(hlr, mgw_msc, stp) -bsc = suite.bsc(msc, mgw_bsc, stp) -ms = suite.modem() +import testlib +suite.test_import_modules_register_for_cleanup(testlib) +from testlib import encryption_test_setup_run -print('start network...') -msc.set_authentication(True) -msc.set_encryption('a5_1') -bsc.set_encryption('a5_1') -hlr.start() -stp.start() -msc.start() -mgw_msc.start() -mgw_bsc.start() -bsc.bts_add(bts) -bsc.start() -bts.start() -wait(bsc.bts_is_connected, bts) - -ms.log_info() -good_ki = ms.ki() -bad_ki = ("%1X" % (int(good_ki[0], 16) ^ 0x01)) + good_ki[1:] - -print('KI changed: ' + good_ki + " => " + bad_ki) -ms.set_ki(bad_ki) -hlr.subscriber_add(ms) -print('Attempt connection with wrong KI...') -ms.connect(msc.mcc_mnc()) - -sleep(40) # TODO: read pcap or CTRL interface and look for Rejected? (gsm_a.dtap.msg_mm_type == 0x04) -print('Asserting modem did not register') -# FIXME: this can fail because ofono qmi signals registered before being accepted by network. See OS#2458 -# assert not ms.is_connected(msc.mcc_mnc()) -assert not msc.subscriber_attached(ms) - -hlr.subscriber_delete(ms) -print('KI changed: ' + bad_ki + " => " + good_ki) -ms.set_ki(good_ki) -hlr.subscriber_add(ms, ms.msisdn) -print('Attempt connection with correct KI...') -ms.connect(msc.mcc_mnc()) -wait(ms.is_connected, msc.mcc_mnc()) -wait(msc.subscriber_attached, ms) +encryption_test_setup_run(True, 'a5_1') -- To view, visit https://gerrit.osmocom.org/11009 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-gsm-tester Gerrit-Branch: master Gerrit-MessageType: merged Gerrit-Change-Id: I9b6944516c524a0c11a47aec6839f8ee9d571661 Gerrit-Change-Number: 11009 Gerrit-PatchSet: 2 Gerrit-Owner: Pau Espin Pedrol <pes...@sysmocom.de> Gerrit-Reviewer: Harald Welte <lafo...@gnumonks.org> Gerrit-Reviewer: Jenkins Builder (1000002) Gerrit-Reviewer: Pau Espin Pedrol <pes...@sysmocom.de>