Пример #1
0
    def accept_ssl_certificate(self, path, on_failure=None):
        """If the repository uses SSL, this method is used to determine whether
        the SSL certificate can be automatically accepted.

        If the cert cannot be accepted, the ``on_failure`` callback
        is executed.

        ``on_failure`` signature::

            void on_failure(e:Exception, path:str, cert:dict)
        """
        self._accept_cert = {}
        self._accept_on_failure = on_failure

        auth = ra.Auth([
            ra.get_simple_provider(),
            ra.get_username_provider(),
            ra.get_ssl_server_trust_prompt_provider(self._accept_trust_prompt),
        ])
        cfg = get_config(self.config_dir)
        client = SVNClient(cfg, auth)
        try:
            info = client.info(path)
            logging.debug('SVN: Got repository information for %s: %s' %
                          (path, info))
        except SubversionException as e:
            if on_failure:
                on_failure(e, path, self._accept_cert)
Пример #2
0
def create_auth_baton(url):
    """Create an authentication baton for the specified URL.

    :param url: URL to create auth baton for.
    """
    try:
        import urllib.parse as urlparse
    except ImportError:  # python < 3
        import urlparse
    parsed_url = urlparse.urlsplit(url)

    auth_config = SubversionAuthenticationConfig(parsed_url.scheme,
                                                 parsed_url.hostname,
                                                 parsed_url.port,
                                                 parsed_url.path)

    # Specify Subversion providers first, because they use file data
    # rather than prompting the user.
    providers = []
    providers += get_stock_svn_providers()
    providers += auth_config.get_svn_auth_providers()
    providers += [get_ssl_client_cert_pw_provider(1)]

    auth_baton = ra.Auth(providers)
    if parsed_url.username is not None:
        auth_baton.set_parameter(subvertpy.AUTH_PARAM_DEFAULT_USERNAME,
                                 parsed_url.username)
    if parsed_url.password is not None:
        auth_baton.set_parameter(subvertpy.AUTH_PARAM_DEFAULT_PASSWORD,
                                 parsed_url.password)
    return auth_baton
Пример #3
0
    def __init__(self, config_dir, repopath, username=None, password=None):
        super(Client, self).__init__(config_dir, repopath, username, password)
        self.repopath = B(self.repopath)
        self.config_dir = B(config_dir)

        self._ssl_trust_prompt_cb = None

        auth_providers = [
            ra.get_simple_provider(),
            ra.get_username_provider(),
        ]

        if repopath.startswith('https:'):
            auth_providers += [
                ra.get_ssl_client_cert_file_provider(),
                ra.get_ssl_client_cert_pw_file_provider(),
                ra.get_ssl_server_trust_file_provider(),
                ra.get_ssl_server_trust_prompt_provider(self.ssl_trust_prompt),
            ]

        self.auth = ra.Auth(auth_providers)

        if username:
            self.auth.set_parameter(B('svn:auth:username'), B(username))

        if password:
            self.auth.set_parameter(B('svn:auth:password'), B(password))

        cfg = get_config(self.config_dir)
        self.client = SVNClient(cfg, auth=self.auth)
Пример #4
0
    def test_diff(self):
        r = ra.RemoteAccess(self.repos_url,
                            auth=ra.Auth([ra.get_username_provider()]))
        dc = self.get_commit_editor(self.repos_url)
        f = dc.add_file("foo")
        f.modify("foo1")
        dc.close()

        dc = self.get_commit_editor(self.repos_url)
        f = dc.open_file("foo")
        f.modify("foo2")
        dc.close()

        if client.api_version() < (1, 5):
            self.assertRaises(NotImplementedError, self.client.diff, 1, 2,
                              self.repos_url, self.repos_url)
            return  # Skip test

        (outf, errf) = self.client.diff(1, 2, self.repos_url, self.repos_url)
        self.addCleanup(outf.close)
        self.addCleanup(errf.close)
        self.assertEqual(
            """Index: foo
===================================================================
--- foo\t(revision 1)
+++ foo\t(revision 2)
@@ -1 +1 @@
-foo1
\\ No newline at end of file
+foo2
\\ No newline at end of file
""", outf.read())
        self.assertEqual("", errf.read())
Пример #5
0
def create_auth_baton(url):
    """Create an authentication baton for the specified URL.

    :param url: URL to create auth baton for.
    """
    import urlparse
    (scheme, netloc, path, _, _) = urlparse.urlsplit(url)
    (creds, host) = urllib.splituser(netloc)
    (host, port) = urllib.splitport(host)

    auth_config = SubversionAuthenticationConfig(scheme, host, port, path)

    # Specify Subversion providers first, because they use file data
    # rather than prompting the user.
    providers = []
    providers += get_stock_svn_providers()
    providers += auth_config.get_svn_auth_providers()
    providers += [get_ssl_client_cert_pw_provider(1)]

    auth_baton = ra.Auth(providers)
    if creds is not None:
        (user, password) = urllib.splitpasswd(creds)
        if user is not None:
            auth_baton.set_parameter(subvertpy.AUTH_PARAM_DEFAULT_USERNAME, user)
        if password is not None:
            auth_baton.set_parameter(subvertpy.AUTH_PARAM_DEFAULT_PASSWORD, password)
    return auth_baton
Пример #6
0
 def test_username(self):
     auth = ra.Auth([
         ra.get_username_prompt_provider(
             lambda realm, may_save: ("somebody", False), 0)
     ])
     creds = auth.credentials("svn.username", "MyRealm")
     self.assertEqual(("somebody", 0), next(creds))
     self.assertRaises(StopIteration, next, creds)
Пример #7
0
 def test_client_cert(self):
     auth = ra.Auth([
         ra.get_ssl_client_cert_prompt_provider(
             lambda realm, may_save: ("filename", False), 0)
     ])
     creds = auth.credentials("svn.ssl.client-cert", "MyRealm")
     self.assertEqual(("filename", False), creds.next())
     self.assertRaises(StopIteration, creds.next)
Пример #8
0
 def test_client_cert_pw(self):
     auth = ra.Auth([
         ra.get_ssl_client_cert_pw_prompt_provider(
             lambda realm, may_save: ("supergeheim", False), 0)
     ])
     creds = auth.credentials("svn.ssl.client-passphrase", "MyRealm")
     self.assertEqual(("supergeheim", False), next(creds))
     self.assertRaises(StopIteration, next, creds)
Пример #9
0
 def test_server_untrust(self):
     auth = ra.Auth([
         ra.get_ssl_server_trust_prompt_provider(
             lambda realm, failures, certinfo, may_save: None)
     ])
     auth.set_parameter("svn:auth:ssl:failures", 23)
     creds = auth.credentials("svn.ssl.server", "MyRealm")
     self.assertRaises(StopIteration, next, creds)
Пример #10
0
 def test_simple(self):
     auth = ra.Auth([
         ra.get_simple_prompt_provider(
             lambda realm, uname, may_save: ("foo", "geheim", False), 0)
     ])
     creds = auth.credentials("svn.simple", "MyRealm")
     self.assertEqual(("foo", "geheim", 0), next(creds))
     self.assertRaises(StopIteration, next, creds)
Пример #11
0
 def test_commit_start(self):
     self.build_tree({"dc/foo": None})
     self.client = client.Client(auth=ra.Auth([ra.get_username_provider()]),
                                 log_msg_func=lambda c: "Bmessage")
     self.client.add("dc/foo")
     self.client.commit(["dc"])
     r = ra.RemoteAccess(self.repos_url)
     revprops = r.rev_proplist(1)
     self.assertEqual("Bmessage", revprops["svn:log"])
Пример #12
0
    def accept_ssl_certificate(self, path, on_failure=None):
        """If the repository uses SSL, this method is used to determine whether
        the SSL certificate can be automatically accepted.

        If the cert cannot be accepted, the ``on_failure`` callback
        is executed.

        ``on_failure`` signature::

            void on_failure(e:Exception, path:str, cert:dict)
        """
        cert = {}

        def _accept_trust_prompt(realm, failures, certinfo, may_save):
            cert.update({
                'realm': realm,
                'failures': failures,
                'hostname': certinfo[0],
                'finger_print': certinfo[1],
                'valid_from': certinfo[2],
                'valid_until': certinfo[3],
                'issuer_dname': certinfo[4],
            })

            if on_failure:
                return 0, False
            else:
                del cert['failures']
                return failures, True

        auth = ra.Auth([
            ra.get_simple_provider(),
            ra.get_username_provider(),
            ra.get_ssl_client_cert_file_provider(),
            ra.get_ssl_client_cert_pw_file_provider(),
            ra.get_ssl_server_trust_file_provider(),
            ra.get_ssl_server_trust_prompt_provider(_accept_trust_prompt),
        ])

        if self.username:
            auth.set_parameter(AUTH_PARAM_DEFAULT_USERNAME, self.username)

        if self.password:
            auth.set_parameter(AUTH_PARAM_DEFAULT_PASSWORD, self.password)

        cfg = get_config(self.config_dir)
        client = SVNClient(cfg, auth)

        try:
            info = client.info(path)
            logging.debug('SVN: Got repository information for %s: %s' %
                          (path, info))
        except SubversionException as e:
            if on_failure:
                on_failure(e, path, cert)

        return cert
Пример #13
0
    def __init__(self, config_dir, repopath, username=None, password=None):
        """Initialize the client.

        Args:
            config_dir (unicode):
                The Subversion configuration directory.

            repopath (unicode):
                The path to the Subversion repository.

            username (unicode, optional):
                The username used to authenticate with the repository.

            password (unicode, optional):
                The password used to authenticate with the repository.
        """
        super(Client, self).__init__(config_dir, repopath, username, password)

        self.repopath = self.repopath
        self.config_dir = config_dir

        self._ssl_trust_prompt_cb = None

        auth_providers = [
            ra.get_simple_provider(),
            ra.get_username_provider(),
        ]

        if repopath.startswith('https:'):
            auth_providers += [
                ra.get_ssl_client_cert_file_provider(),
                ra.get_ssl_client_cert_pw_file_provider(),
                ra.get_ssl_server_trust_file_provider(),
                ra.get_ssl_server_trust_prompt_provider(self.ssl_trust_prompt),
            ]

        self.auth = ra.Auth(auth_providers)
        self.username = None
        self.password = None

        if username:
            self.username = username
            self.auth.set_parameter(AUTH_PARAM_DEFAULT_USERNAME,
                                    self.username)

        if password:
            self.password = password
            self.auth.set_parameter(AUTH_PARAM_DEFAULT_PASSWORD,
                                    self.password)

        cfg = get_config(self.config_dir)
        self.client = SVNClient(cfg, auth=self.auth)
Пример #14
0
    def test_retry(self):
        self.i = 0

        def inc_foo(realm, may_save):
            self.i += 1
            return ("somebody%d" % self.i, False)

        auth = ra.Auth([ra.get_username_prompt_provider(inc_foo, 2)])
        creds = auth.credentials("svn.username", "MyRealm")
        self.assertEqual(("somebody1", 0), next(creds))
        self.assertEqual(("somebody2", 0), next(creds))
        self.assertEqual(("somebody3", 0), next(creds))
        self.assertRaises(StopIteration, next, creds)
Пример #15
0
    def init_ra_and_client(self):
        """
        Initializes the RA and client layers.

        With the SWIG bindings, getting unified diffs runs the remote server
        sometimes runs out of open files. It is not known whether the Subvertpy
        is affected by this.
        """
        def getclientstring():
            return 'hgsubversion'

        # TODO: handle certificate authentication, Mercurial style
        def getpass(realm, username, may_save):
            return self.username or username, self.password or '', False

        def getuser(realm, may_save):
            return self.username or '', False

        providers = ra.get_platform_specific_client_providers()
        providers += [
            ra.get_simple_provider(),
            ra.get_username_provider(),
            ra.get_ssl_client_cert_file_provider(),
            ra.get_ssl_client_cert_pw_file_provider(),
            ra.get_ssl_server_trust_file_provider(),
            ra.get_username_prompt_provider(getuser, 0),
            ra.get_simple_prompt_provider(getpass, 0),
        ]

        auth = ra.Auth(providers)
        if self.username:
            auth.set_parameter(subvertpy.AUTH_PARAM_DEFAULT_USERNAME,
                               self.username)
        if self.password:
            auth.set_parameter(subvertpy.AUTH_PARAM_DEFAULT_PASSWORD,
                               self.password)

        self.remote = ra.RemoteAccess(url=self.svn_url,
                                      client_string_func=getclientstring,
                                      auth=auth)

        self.client = client.Client()
        self.client.auth = auth
Пример #16
0
    def __init__(self, config_dir, repopath, username=None, password=None):
        super(Client, self).__init__(config_dir, repopath, username, password)
        self.repopath = B(self.repopath)
        self.config_dir = B(config_dir)

        self._ssl_trust_prompt_cb = None

        auth_providers = [
            ra.get_simple_provider(),
            ra.get_username_provider(),
        ]

        if repopath.startswith('https:'):
            auth_providers += [
                ra.get_ssl_client_cert_file_provider(),
                ra.get_ssl_client_cert_pw_file_provider(),
                ra.get_ssl_server_trust_file_provider(),
                ra.get_ssl_server_trust_prompt_provider(self.ssl_trust_prompt),
            ]

        self.auth = ra.Auth(auth_providers)
        self.username = None
        self.password = None

        if username:
            self.username = username
            self.auth.set_parameter(AUTH_PARAM_DEFAULT_USERNAME,
                                    B(self.username))

        if password:
            self.password = password
            self.auth.set_parameter(AUTH_PARAM_DEFAULT_PASSWORD,
                                    B(self.password))

        cfg = get_config(self.config_dir)
        self.client = SVNClient(cfg, auth=self.auth)
Пример #17
0
    def setUp(self):

        super(TestClient, self).setUp()
        self.repos_url = self.make_client("d", "dc")
        self.client = client.Client(auth=ra.Auth([ra.get_username_provider()]))
Пример #18
0
def calculate_hot_spots(jiraKey,repoUrl,end_time = time.time(),cache_update_time = time.time()):
    providers = ra.get_platform_specific_client_providers()
    providers += [
            ra.get_simple_provider(),
            ra.get_username_provider(),
            ra.get_ssl_client_cert_file_provider(),
            ra.get_ssl_client_cert_pw_file_provider(),
            ra.get_ssl_server_trust_file_provider(),
            ra.get_username_prompt_provider(getuser, 0),
            ra.get_simple_prompt_provider(getpass, 0),
        ]
    
    auth=ra.Auth(providers)
    auth.set_parameter(subvertpy.AUTH_PARAM_DEFAULT_USERNAME, settings.username) 
    auth.set_parameter(subvertpy.AUTH_PARAM_DEFAULT_PASSWORD, settings.password)

    conn = ra.RemoteAccess(repoUrl,auth=auth)

    global bugCache
    global svnCache
    
    if jiraKey in bugCache:
        bugs = bugCache[jiraKey]
    else:
        bugs = []
    if jiraKey in svnCache:
        svn_entries = svnCache[jiraKey]
    else:
        svn_entries = []
    
    
    
    start_time = end_time
    scores = {}
    authors = {}
    modified_files = []
    
    if (len(bugs) == 0 and len(svn_entries) == 0) or time.time() > cache_update_time:
        #retrieve the SVN log entries
        for (changed_paths, rev, revprops, has_children) in conn.iter_log(paths=None,start=0, end=conn.get_latest_revnum(), discover_changed_paths=True):
            svn_entries.append((changed_paths, rev, revprops, has_children))
        #query jira for all the closed bugs
        bugs = get_bugs(jiraKey)
        #add to the cache dictionary
        bugCache[jiraKey] = bugs
        svnCache[jiraKey] = svn_entries
    
    for (changed_paths, rev, revprops, has_children) in svn_entries:
        commit_time = time.mktime(dateutil.parser.parse(revprops["svn:date"]).timetuple())
        if commit_time <= end_time:
            #this svn commit contains code that fixed a bug
            if fixed_bug(revprops["svn:log"].decode('utf8') ,bugs):
	            #only consider *.java and *.js files for now
                modified_files.extend([(commit_time,filename,revprops["svn:author"]) for filename in changed_paths.keys() if is_source_file(filename)])
            if commit_time < start_time:
                start_time = commit_time
    
    for modified_file in modified_files:
        filename = modified_file[1]
        author = modified_file[2]
        #as per Google's description, normalize t between 0 and 1
        t = (modified_file[0]-start_time)/(end_time-start_time)
        #google's magic sauce
        score = 1/(1+(math.e**(-12*t+12)))
        #map the score to the file
        if filename not in scores:
            scores[filename] = score
        else:
            scores[filename] = scores[filename] + score
        #map the author(s) to the file
        if filename not in authors:
           authors[filename] = [author]
        else:
           authors[filename].append(author)

    #convert the list of authors to a map containing the counts 
    for filename,authorsList in authors.items():
        authors[filename]=Counter(authorsList)
    
    
    sorted_scores = sorted(scores.iteritems(), key=operator.itemgetter(1))
    sorted_scores.reverse()
    
    #add the author count to the scores tuple
    scoresWithAuthors =[]
    for score in sorted_scores:
        scoresWithAuthors.append((score[0],score[1],authors[score[0]]))
    
    #return the top 10 hotspots
    return scoresWithAuthors[:10]
Пример #19
0
 def test_platform_auth_providers(self):
     ra.Auth(ra.get_platform_specific_client_providers())
Пример #20
0
 def test_set_default_password(self):
     a = ra.Auth([])
     a.set_parameter("svn:auth:password", "bar")
     self.assertEqual("bar", a.get_parameter("svn:auth:password"))
Пример #21
0
 def test_set_default_username(self):
     a = ra.Auth([])
     a.set_parameter("svn:auth:username", "foo")
     self.assertEqual("foo", a.get_parameter("svn:auth:username"))
Пример #22
0
    def init_ra_and_client(self):
        """
        Initializes the RA and client layers.

        With the SWIG bindings, getting unified diffs runs the remote server
        sometimes runs out of open files. It is not known whether the Subvertpy
        is affected by this.
        """
        def getclientstring():
            return 'hgsubversion'

        def simple(realm, username, may_save):
            return _prompt.simple(realm, username, may_save)

        def username(realm, may_save):
            return _prompt.username(realm, may_save)

        def ssl_client_cert(realm, may_save):
            return _prompt.ssl_client_cert(realm, may_save)

        def ssl_client_cert_pw(realm, may_save):
            return _prompt.ssl_client_cert_pw(realm, may_save)

        def ssl_server_trust(realm, failures, cert_info, may_save):
            creds = _prompt.ssl_server_trust(realm, failures, cert_info, may_save)
            if creds is None:
                # We need to reject the certificate, but subvertpy doesn't
                # handle None as a return value here, and requires
                # we instead return a tuple of (int, bool). Because of that,
                # we return (0, False) instead.
                creds = (0, False)
            return creds

        providers = ra.get_platform_specific_client_providers()
        providers += [
            ra.get_simple_provider(),
            ra.get_username_provider(),
            ra.get_ssl_client_cert_file_provider(),
            ra.get_ssl_client_cert_pw_file_provider(),
            ra.get_ssl_server_trust_file_provider(),
        ]
        if _prompt:
            providers += [
                ra.get_simple_prompt_provider(simple, 2),
                ra.get_username_prompt_provider(username, 2),
                ra.get_ssl_client_cert_prompt_provider(ssl_client_cert, 2),
                ra.get_ssl_client_cert_pw_prompt_provider(ssl_client_cert_pw, 2),
                ra.get_ssl_server_trust_prompt_provider(ssl_server_trust),
            ]

        auth = ra.Auth(providers)
        if self.username:
            auth.set_parameter(subvertpy.AUTH_PARAM_DEFAULT_USERNAME, self.username)
        if self.password:
            auth.set_parameter(subvertpy.AUTH_PARAM_DEFAULT_PASSWORD, self.password)

        try:
            self.remote = ra.RemoteAccess(url=self.svn_url,
                                          client_string_func=getclientstring,
                                          auth=auth)
        except SubversionException, e:
            # e.child contains a detailed error messages
            msglist = []
            svn_exc = e
            while svn_exc:
                if svn_exc.args[0]:
                    msglist.append(svn_exc.args[0])
                svn_exc = svn_exc.child
            msg = '\n'.join(msglist)
            raise common.SubversionConnectionException(msg)
Пример #23
0
 def __init__(self):
     super(SubversionCredentialStore, self).__init__()
     self.auth = ra.Auth([ra.get_simple_provider()])
Пример #24
0
 def test_not_registered(self):
     auth = ra.Auth([])
     self.assertRaises(SubversionException, auth.credentials, "svn.simple",
                       "MyRealm")
Пример #25
0
 def setUp(self):
     super(TestRemoteAccess, self).setUp()
     self.repos_url = self.make_repository("d")
     self.ra = ra.RemoteAccess(self.repos_url,
                               auth=ra.Auth([ra.get_username_provider()]))