From c2c3defdde9f79da57a7bed45c956cd7086e5d2b Mon Sep 17 00:00:00 2001 From: Petr Vobornik Date: Fri, 12 Dec 2014 14:04:10 +0100 Subject: try to use forms based auth in tests - an EXAMPLE --- ipatests/test_webui/test_otptoken.py | 54 ++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/ipatests/test_webui/test_otptoken.py b/ipatests/test_webui/test_otptoken.py index 151cfb0b0..2afd8f9c4 100644 --- a/ipatests/test_webui/test_otptoken.py +++ b/ipatests/test_webui/test_otptoken.py @@ -24,6 +24,17 @@ OTP Token Tests from ipatests.test_webui.ui_driver import UI_driver from ipatests.test_webui.ui_driver import screenshot import ipatests.test_webui.data_user as user +from ipatests.util import get_api +from ipalib.rpc import jsonclient +from ipalib import api +from ipapython import ipautil +import json +from ipapython.ipautil import run +from ipapython import certdb +from ipalib import x509, certstore +from ipaplatform.paths import paths +from urllib2 import urlparse + ENTITY = 'otptoken' @@ -145,3 +156,46 @@ class test_otptoken(UI_driver): ) print self.config_uri self.rpc(user.ENTITY + '_del', [uid], { 'continue': True }) + + def _prepare_nss_dir(self, ipa_server): + """ + Create temporary NSS Database with IPA server CA cert + """ + + # create new NSSDatabase + tmp_db = certdb.NSSDatabase() + pwd_file = ipautil.write_tmp_file(ipautil.ipa_generate_password()) + tmp_db.create_db(pwd_file.name) + + # download and add cert + url = urlparse.urlunparse(('http', ipautil.format_netloc(ipa_server), + '/ipa/config/ca.crt', '', '', '')) + stdout, stderr, rc = run([paths.BIN_WGET, "-O", "-", url]) + certs = x509.load_certificate_list(stdout, tmp_db.secdir) + ca_certs = [cert.der_data for cert in certs] + for i, cert in enumerate(ca_certs): + tmp_db.add_cert(cert, 'CA certificate %d' % (i + 1), 'C,,') + + return tmp_db + + def test_rpc(self): + + ipa_server = self.config['ipa_server'] + tmp_cert_db = self._prepare_nss_dir(ipa_server) + + api.bootstrap( + context='webui_tests', + in_server=False, + debug=False, + verbose=1, + xmlrpc_uri="https://" + ipa_server + "/ipa/json", + ) + api.finalize() + api.Backend.rpcclient.connect( + nss_dir=tmp_cert_db.secdir, + user=u"admin", + password=u"Secret123" + ) + result = api.Command.user_show(u'admin') + print json.dumps(result) + assert False -- cgit