#!/usr/bin/python
#
-# Copyright (C) 2014 Simo Sorce <simo@redhat.com>
-#
-# see file 'COPYING' for use and warranty information
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
+# Copyright (C) 2014 Ipsilon project Contributors, for license see COPYING
from lxml import html
import requests
def first_value(self, rule):
result = self.tree.xpath(rule)
- if type(result) is list:
+ if isinstance(result, list):
if len(result) > 0:
result = result[0]
else:
def all_values(self, rule):
result = self.tree.xpath(rule)
- if type(result) is list:
+ if isinstance(result, list):
return result
return [result]
session = self.get_session(url)
allow_redirects = False
if krb:
- # In at least the test instance we don't get back a negotiate
- # blob to do mutual authentication against.
+ # python-requests-kerberos isn't too bright about doing mutual
+ # authentication and it tries to do it on any non-401 response
+ # which doesn't work in our case since we follow redirects.
kerberos_auth = HTTPKerberosAuth(mutual_authentication=OPTIONAL)
kwargs['auth'] = kerberos_auth
allow_redirects = True
return values
def handle_login_form(self, idp, page):
- if type(page) != PageTree:
+ if not isinstance(page, PageTree):
raise TypeError("Expected PageTree object")
srv = self.servers[idp]
{'headers': headers, 'data': payload}]
def handle_return_form(self, page):
- if type(page) != PageTree:
+ if not isinstance(page, PageTree):
raise TypeError("Expected PageTree object")
try:
{'headers': headers, 'data': payload}]
def handle_openid_form(self, page):
- if type(page) != PageTree:
+ if not isinstance(page, PageTree):
raise TypeError("Expected PageTree object")
if not page.first_value('//title/text()') == \
{'headers': headers, 'data': payload}]
def handle_openid_consent_form(self, page):
- if type(page) != PageTree:
+ if not isinstance(page, PageTree):
raise TypeError("Expected PageTree object")
try:
args = {}
while True:
- # pylint: disable=star-args
r = self.access(action, url, krb=krb, **args)
if r.status_code == 303 or r.status_code == 302:
if not follow_redirect:
raise ValueError("Unhandled status (%d) on url %s" % (
r.status_code, url))
- def auth_to_idp(self, idp, krb=False):
+ def auth_to_idp(self, idp, krb=False, rule=None, expected=None):
srv = self.servers[idp]
target_url = '%s/%s/' % (srv['baseuri'], idp)
page = self.fetch_page(idp, url, krb=krb)
- page.expected_value('//div[@id="welcome"]/p/text()',
- 'Welcome %s!' % srv['user'])
+ if rule is None:
+ rule = '//div[@id="welcome"]/p/text()'
+ if expected is None:
+ expected = 'Welcome %s!' % srv['user']
+
+ page.expected_value(rule, expected)
def logout_from_idp(self, idp):