@@ -11,6 +11,7 @@ import (
1111 "strings"
1212 "testing"
1313
14+ pythoncmd "github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/python"
1415 "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
1516
1617 biutils "github.com/jfrog/build-info-go/utils"
@@ -595,6 +596,69 @@ func validateBuildTimestampProperty(properties map[string][]string, moduleType b
595596 return nil
596597}
597598
599+ func TestCreateAqlQueryForSearchBySHA256 (t * testing.T ) {
600+ tests := []struct {
601+ name string
602+ repo string
603+ sha256s []string
604+ expected string
605+ }{
606+ {
607+ name : "single SHA256" ,
608+ repo : "pypi-local" ,
609+ sha256s : []string {"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" },
610+ expected : `{"repo": "pypi-local","$or": [{"sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"}]}` ,
611+ },
612+ {
613+ name : "multiple SHA256s" ,
614+ repo : "pypi-local" ,
615+ sha256s : []string {
616+ "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" ,
617+ "a1b2c3d4e5f6789012345678901234567890abcdef1234567890abcdef123456" ,
618+ "f6e5d4c3b2a1098765432109876543210987654321098765432109876543210987" ,
619+ },
620+ expected : `{"repo": "pypi-local","$or": [{"sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"},{"sha256": "a1b2c3d4e5f6789012345678901234567890abcdef1234567890abcdef123456"},{"sha256": "f6e5d4c3b2a1098765432109876543210987654321098765432109876543210987"}]}` ,
621+ },
622+ {
623+ name : "empty SHA256s" ,
624+ repo : "pypi-local" ,
625+ sha256s : []string {},
626+ expected : `{"repo": "pypi-local","$or": []}` ,
627+ },
628+ {
629+ name : "different repository" ,
630+ repo : "maven-local" ,
631+ sha256s : []string {"abc123def456" },
632+ expected : `{"repo": "maven-local","$or": [{"sha256": "abc123def456"}]}` ,
633+ },
634+ }
635+
636+ for _ , tt := range tests {
637+ t .Run (tt .name , func (t * testing.T ) {
638+ result := pythoncmd .CreateAqlQueryForSearchBySHA256 (tt .repo , tt .sha256s )
639+ assert .Equal (t , tt .expected , result )
640+
641+ // Verify it's valid JSON
642+ var jsonObj map [string ]interface {}
643+ err := json .Unmarshal ([]byte (result ), & jsonObj )
644+ assert .NoError (t , err , "Generated query should be valid JSON" )
645+ assert .Equal (t , tt .repo , jsonObj ["repo" ], "Repository should match" )
646+
647+ // Verify $or array exists and has correct structure
648+ orArray , ok := jsonObj ["$or" ].([]interface {})
649+ assert .True (t , ok , "$or should be an array" )
650+ assert .Equal (t , len (tt .sha256s ), len (orArray ), "Number of SHA256 conditions should match" )
651+
652+ // Verify each SHA256 condition
653+ for i , sha256 := range tt .sha256s {
654+ condition , ok := orArray [i ].(map [string ]interface {})
655+ assert .True (t , ok , "Each condition should be an object" )
656+ assert .Equal (t , sha256 , condition ["sha256" ], "SHA256 value should match" )
657+ }
658+ })
659+ }
660+ }
661+
598662func TestSetupPipCommand (t * testing.T ) {
599663 if ! * tests .TestPip {
600664 t .Skip ("Skipping Pip test. To run Pip test add the '-test.pip=true' option." )
0 commit comments