示例#1
0
 def test_end2end(self):
     """Test pypi-scan analysis from start to finish."""
     package_names = get_all_packages()
     top_packages = get_top_packages()
     squat_candidates = create_suspicious_package_dict(
         package_names, top_packages)
     store_squatting_candidates(squat_candidates)
示例#2
0
    def test_get_top_packages(self):
        """Test get_top_packages function."""
        # Check default setting
        top_packages = get_top_packages()
        self.assertEqual(len(top_packages), 50)
        self.assertEqual(top_packages["requests"], 4)

        # Check user supplied number of top packages
        top_packages = get_top_packages(100)
        self.assertEqual(len(top_packages), 100)
        self.assertEqual(top_packages["requests"], 4)

        # Check if stored package option works
        stored_packages = get_top_packages(50, stored=True)
        self.assertEqual(len(stored_packages), 50)
        self.assertEqual(stored_packages["requests"], 4)
示例#3
0
def top_mods(max_distance, top_n, min_len, stored_json):
    """Check top packages for typosquatters.

    Prints top packages and any potential typosquatters

    Args:
        max_distance (int): maximum edit distance to check for typosquatting
        top_n (int): the number of top packages to retrieve
        min_len (int): a minimum length of characters
        stored_json (bool): a flag to denote whether to used stored top packages json

    """
    # Get list of potential typosquatters
    package_names = get_all_packages()
    top_packages = get_top_packages(top_n=top_n, stored=stored_json)
    filtered_package_list = filter_by_package_name_len(top_packages, min_len=min_len)
    squat_candidates = create_suspicious_package_dict(
        package_names, filtered_package_list, max_distance
    )
    post_whitelist_candidates = whitelist(squat_candidates)
    store_squatting_candidates(post_whitelist_candidates)

    print_suspicious_packages(post_whitelist_candidates)