]> andersk Git - jira-zephyrbot.git/commitdiff
jirabot2 that can log in.
authorAnders Kaseorg <andersk@mit.edu>
Thu, 12 Feb 2009 06:56:18 +0000 (01:56 -0500)
committerAnders Kaseorg <andersk@mit.edu>
Thu, 12 Feb 2009 06:56:18 +0000 (01:56 -0500)
jirabot2.py

index 9e66d8e558bc58b4c6de478ed8bb1891eeda7ed2..1187bde6fac036adbeb323071ce64a85e1262b7d 100644 (file)
@@ -1,30 +1,16 @@
-import httplib
 import mechanize
 
-def make_cert_handler(key_file=None, cert_file=None):
-    if cert_file is None:
-        cert_file = key_file
-
-    class HTTPSCertConnection(httplib.HTTPSConnection):
-        def __init__(self, host):
-            httplib.HTTPSConnection.__init__(self, host,
-                                             key_file=key_file,
-                                             cert_file=cert_file)
-
-    class HTTPSCertHandler(mechanize.HTTPSHandler):
-        def https_open(self, req):
-            return self.do_open(HTTPSCertConnection, req)
-
-    return HTTPSCertHandler
-
-cj = mechanize.CookieJar()
-
-cert_handler = make_cert_handler("cert.pem")
-opener = mechanize.build_opener(mechanize.HTTPRedirectHandler, cert_handler, mechanize.HTTPCookieProcessor(cj))
-mechanize.install_opener(opener)
-
 b = mechanize.Browser()
 b.set_handle_robots(False)
+b.add_client_certificate("https://idp.mit.edu:9443", "cert.pem", "cert.pem")
 b.addheaders = [("Accept-Language", "en-us,en;q=0.5"),]
-b.open("https://jira.mit.edu/jira/secure/Dashboard.jsp://jira.mit.edu/jira/secure/Dashboard.jspa")
+b.open("https://jira.mit.edu/jira/secure/Dashboard.jspa")
 b.follow_link(text="MIT Touchstone")
+b.select_form("wayfForm1")
+b.submit()
+b.select_form(predicate=lambda f: any(c.name == 'login_certificate'
+                                      for c in f.controls))
+b.submit()
+b.select_form(nr=0)
+b.submit()
+print b.response().read()
This page took 0.070757 seconds and 5 git commands to generate.