|  | 
| 2 | 2 | # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/. | 
| 3 | 3 | 
 | 
| 4 | 4 | """This module tests the repo finder.""" | 
|  | 5 | +import os | 
|  | 6 | +from pathlib import Path | 
| 5 | 7 | 
 | 
| 6 | 8 | import pytest | 
| 7 |  | -from defusedxml.ElementTree import fromstring | 
| 8 | 9 | from packageurl import PackageURL | 
| 9 | 10 | 
 | 
|  | 11 | +from macaron.config.defaults import load_defaults | 
| 10 | 12 | from macaron.config.target_config import Configuration | 
| 11 |  | -from macaron.repo_finder import repo_validator | 
| 12 | 13 | from macaron.repo_finder.repo_finder_java import JavaRepoFinder | 
| 13 | 14 | from macaron.slsa_analyzer.analyzer import Analyzer | 
| 14 | 15 | 
 | 
| @@ -74,34 +75,49 @@ def test_resolve_analysis_target( | 
| 74 | 75 |     assert Analyzer.to_analysis_target(config, available_domains) == expect | 
| 75 | 76 | 
 | 
| 76 | 77 | 
 | 
| 77 |  | -def test_pom_extraction_ordering() -> None: | 
|  | 78 | +@pytest.mark.parametrize( | 
|  | 79 | +    ("user_config_input", "expected"), | 
|  | 80 | +    [ | 
|  | 81 | +        ( | 
|  | 82 | +            """ | 
|  | 83 | +                [repofinder.java] | 
|  | 84 | +                repo_pom_paths = | 
|  | 85 | +                    scm.connection | 
|  | 86 | +                    scm.url | 
|  | 87 | +                """, | 
|  | 88 | +            ["scm:git:git@github.com:oracle-samples/macaron.git", "https://github.com/oracle/macaron"], | 
|  | 89 | +        ), | 
|  | 90 | +        ( | 
|  | 91 | +            """ | 
|  | 92 | +                [repofinder.java] | 
|  | 93 | +                repo_pom_paths = | 
|  | 94 | +                    scm.url | 
|  | 95 | +                    scm.connection | 
|  | 96 | +                """, | 
|  | 97 | +            ["https://github.com/oracle/macaron", "scm:git:git@github.com:oracle-samples/macaron.git"], | 
|  | 98 | +        ), | 
|  | 99 | +    ], | 
|  | 100 | +) | 
|  | 101 | +def test_pom_extraction_ordering(tmp_path: Path, user_config_input: str, expected: list[str]) -> None: | 
| 78 | 102 |     """Test the ordering of elements extracted from the POM is correct and maintained.""" | 
| 79 | 103 |     pom_text = """ | 
| 80 | 104 |     <project> | 
| 81 | 105 |         <url>https://example.org</url> | 
| 82 | 106 |         <scm> | 
| 83 | 107 |             <connection>scm:git:git@github.com:oracle-samples/macaron.git</connection> | 
| 84 |  | -            <developerConnection>scm:git:git@github.com:oracle/macaron.git</developerConnection> | 
| 85 | 108 |             <url>https://github.com/oracle/macaron</url> | 
| 86 | 109 |         </scm> | 
| 87 | 110 |         <properties> | 
| 88 | 111 |             <url>1.9.15</url> | 
| 89 | 112 |         </properties> | 
| 90 | 113 |     </project> | 
| 91 | 114 |     """ | 
| 92 |  | -    pom = fromstring(pom_text) | 
|  | 115 | +    user_config_path = os.path.join(tmp_path, "config.ini") | 
|  | 116 | +    with open(user_config_path, "w", encoding="utf-8") as user_config_file: | 
|  | 117 | +        user_config_file.write(user_config_input) | 
|  | 118 | +    load_defaults(user_config_path) | 
|  | 119 | + | 
| 93 | 120 |     repo_finder = JavaRepoFinder() | 
| 94 | 121 | 
 | 
| 95 | 122 |     # Retrieve SCM from POM. | 
| 96 |  | -    connection_urls = repo_finder._find_scm(pom, ["scm.connection", "scm.url"])  # pylint: disable=W0212 | 
| 97 |  | -    assert connection_urls | 
| 98 |  | -    connection_url = repo_validator.find_valid_repository_url(connection_urls) | 
| 99 |  | -    assert connection_url | 
| 100 |  | - | 
| 101 |  | -    urls = repo_finder._find_scm(pom, ["scm.url", "scm.connection"])  # pylint: disable=W0212 | 
| 102 |  | -    assert urls | 
| 103 |  | -    url = repo_validator.find_valid_repository_url(urls) | 
| 104 |  | -    assert url | 
| 105 |  | - | 
| 106 |  | -    # Ensure found URLs differ. | 
| 107 |  | -    assert connection_url != url | 
|  | 123 | +    assert expected == repo_finder._read_pom(pom_text)  # pylint: disable=W0212 | 
0 commit comments