- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1.1k
          SBOM - Add the pref and qualifiers to the purl
          #18993
        
          New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Open
      
      
            ErniGH
  wants to merge
  3
  commits into
  conan-io:develop2
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
ErniGH:erni/pref-and-qualifiers-in-purl
  
      
      
   
  
    
  
  
  
 
  
      
    base: develop2
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from 2 commits
      Commits
    
    
            Show all changes
          
          
            3 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      
    File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import textwrap | ||
| import json | ||
| from symbol import pass_stmt | ||
|         
                  ErniGH marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
|  | ||
| import pytest | ||
|  | ||
|  | @@ -291,7 +292,8 @@ def test_sbom_generation_custom_name(self, cyclone_version, name, result): | |
| assert os.path.exists(os.path.join(tc.current_folder, "sbom", "sbom.cdx.json")) | ||
| assert f'"name": "{result}"' in tc.load(os.path.join(tc.current_folder, "sbom", "sbom.cdx.json")) | ||
|  | ||
| def test_cyclonedx_check_content(self, cyclone_version): | ||
| @pytest.mark.parametrize("qualifiers", [None, ["os", "arch"]]) | ||
| def test_cyclonedx_check_content(self, cyclone_version, qualifiers): | ||
| _sbom_hook_post_package = textwrap.dedent(""" | ||
| import json | ||
| import os | ||
|  | @@ -300,7 +302,7 @@ def test_cyclonedx_check_content(self, cyclone_version): | |
| from conan.tools.sbom import {cyclone_version} | ||
|  | ||
| def post_package(conanfile): | ||
| sbom_cyclonedx= {cyclone_version}(conanfile) | ||
| sbom_cyclonedx= {cyclone_version}(conanfile, qualifiers={qualifiers}) | ||
| metadata_folder = conanfile.package_metadata_folder | ||
| file_name = "sbom.cdx.json" | ||
| with open(os.path.join(metadata_folder, file_name), 'w') as f: | ||
|  | @@ -309,14 +311,15 @@ def post_package(conanfile): | |
| """) | ||
| tc = TestClient() | ||
| hook_path = os.path.join(tc.paths.hooks_path, "hook_sbom.py") | ||
| save(hook_path, _sbom_hook_post_package.format(cyclone_version=cyclone_version)) | ||
| save(hook_path, _sbom_hook_post_package.format(cyclone_version=cyclone_version, qualifiers=qualifiers)) | ||
| conanfile_bar = textwrap.dedent(""" | ||
| from conan import ConanFile | ||
| class HelloConan(ConanFile): | ||
| name = 'bar' | ||
| version = '1.0' | ||
| author = 'conan-dev' | ||
| package_type = 'application' | ||
| settings = 'os', 'arch', 'compiler', 'build_type' | ||
| """) | ||
|  | ||
| conanfile_foo = textwrap.dedent(""" | ||
|  | @@ -326,6 +329,7 @@ class HelloConan(ConanFile): | |
| version = '1.0' | ||
| author = 'conan-dev' | ||
| package_type = 'application' | ||
| settings = 'os', 'arch', 'compiler', 'build_type' | ||
|  | ||
| def requirements(self): | ||
| self.requires("bar/1.0") | ||
|  | @@ -334,6 +338,7 @@ def requirements(self): | |
| tc.run("create .") | ||
| tc.save({"conanfile.py": conanfile_foo}) | ||
| tc.run("create .") | ||
| foo_rrev = tc.exported_recipe_revision() | ||
|  | ||
| create_layout = tc.created_layout() | ||
| cyclone_path = os.path.join(create_layout.metadata(), "sbom.cdx.json") | ||
|  | @@ -353,6 +358,10 @@ def requirements(self): | |
| assert not content_json["components"][0].get("author") | ||
| assert content_json["components"][0]["authors"][0]["name"] == 'conan-dev' | ||
| assert content_json["components"][0]["type"] == 'application' | ||
| if qualifiers: | ||
| assert all(q in content_json["components"][0]["purl"] for q in qualifiers) | ||
| else: | ||
| assert f"pkg:conan/[email protected]?rref={foo_rrev}&pref=" in content_json["components"][0]["purl"] | ||
|  | ||
| @pytest.mark.parametrize("user, channel, user_dep, channel_dep", [("user", None, "user_dep", None), ("user", "channel", "user_dep", "channel_dep")]) | ||
| def test_sbom_user_path(self, hook_setup_post_package_tl, user, channel, user_dep, channel_dep): | ||
|  | ||
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have discussed that this should be rrev, but we have decided to do that in a different PR