Skip to content
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

Adding Xray Source Control Service #2141

Closed
wants to merge 50 commits into from
Closed
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
24d903d
Promoted version to 2.43.0
omerzi Jul 12, 2023
e9cb8b6
Merge branch 'dev' into v2
eyalbe4 Jul 12, 2023
12e17bc
Resove conflicts
eyalbe4 Jul 12, 2023
52da62e
Merge remote-tracking branch 'origin/dev' into v2
omerzi Jul 19, 2023
445071d
Merge remote-tracking branch 'origin/dev' into v2
omerzi Jul 23, 2023
2f56ca8
Merge branch 'dev' into v2
eyalbe4 Jul 24, 2023
1bfa0c1
Merge branch 'dev' into v2
eyalbe4 Jul 31, 2023
b958e74
Merge branch 'dev' into v2
eyalbe4 Aug 3, 2023
f89c9d4
Refactor to interface
EyalDelarea Aug 15, 2023
91e9bff
Split scan service
EyalDelarea Aug 15, 2023
b1ef9b6
Working XSC call
EyalDelarea Aug 16, 2023
65cca65
Merge branch 'dev' of https://github.com/jfrog/jfrog-cli into xsc
EyalDelarea Aug 17, 2023
718c0c2
update go.mod
EyalDelarea Aug 17, 2023
feaf222
Handle XSC/XRAY url provided from flags and config.
EyalDelarea Aug 17, 2023
52cec1e
update go.mod
EyalDelarea Aug 17, 2023
ffbaad3
Refactor
EyalDelarea Aug 17, 2023
a14747e
update deps
EyalDelarea Aug 20, 2023
43410a0
fix gosec
EyalDelarea Aug 21, 2023
c32e160
Update deps
EyalDelarea Aug 21, 2023
a935feb
update deps
EyalDelarea Aug 21, 2023
afa7a25
update dependencies
EyalDelarea Aug 22, 2023
47c759e
Pull dev
EyalDelarea Aug 22, 2023
66009e0
update deps
EyalDelarea Aug 23, 2023
e4ca999
Merge remote-tracking branch 'upstream/dev' into xsc
EyalDelarea Aug 24, 2023
cb85c8f
Add XSC tests
EyalDelarea Aug 24, 2023
0322ea3
trigget test
EyalDelarea Aug 24, 2023
084c270
fix test
EyalDelarea Aug 24, 2023
becb901
turn off and on xray test
EyalDelarea Aug 24, 2023
71d50b8
trigget test
EyalDelarea Aug 24, 2023
2a82b3a
Change test
EyalDelarea Aug 24, 2023
2876765
pull dev
EyalDelarea Aug 28, 2023
b5b80ae
pull dev
EyalDelarea Aug 29, 2023
8d06953
fix merge
EyalDelarea Aug 29, 2023
698e026
update deps
EyalDelarea Aug 29, 2023
0ec3b49
update deps
EyalDelarea Aug 29, 2023
321efb1
Update deps
EyalDelarea Aug 30, 2023
fdfc3a9
pull dev
EyalDelarea Aug 31, 2023
34e89bb
update deps
EyalDelarea Aug 31, 2023
5915ee0
merge dev
EyalDelarea Sep 3, 2023
2bdbdb8
Update deps
EyalDelarea Sep 3, 2023
63276fc
pull dev
EyalDelarea Sep 4, 2023
4bba9e1
Update deps
EyalDelarea Sep 4, 2023
7e559ff
pull dev
EyalDelarea Sep 5, 2023
a064ee4
update deps
EyalDelarea Sep 6, 2023
8a6b7ad
update deps
EyalDelarea Sep 6, 2023
f4825ba
update deps
EyalDelarea Sep 7, 2023
ab18d79
update deps
EyalDelarea Sep 8, 2023
2dad973
update deps
EyalDelarea Sep 8, 2023
f92fb12
CR
EyalDelarea Sep 10, 2023
cd5eb94
change to new xsc
EyalDelarea Sep 10, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/xrayTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
strategy:
fail-fast: false
matrix:
suite: [ xray,xsc ]
EyalDelarea marked this conversation as resolved.
Show resolved Hide resolved
os: [ ubuntu, windows, macos ]
runs-on: ${{ matrix.os }}-latest
env:
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ The available test types are:
| `-test.distribution` | Distribution tests |
| `-test.transfer` | Transfer tests |
| `-test.xray` | Xray tests |
| `-test.xsc` | Xsc tests |

When running the tests, builds and repositories with timestamps will be created, for example: `cli-rt1-1592990748` and `cli-rt2-1592990748`. The content of these repositories will be deleted once the tests are completed.

Expand Down
6 changes: 3 additions & 3 deletions general/cisetup/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
"github.com/jfrog/jfrog-client-go/artifactory/services"
"github.com/jfrog/jfrog-client-go/config"
"github.com/jfrog/jfrog-client-go/xray"
services2 "github.com/jfrog/jfrog-client-go/xray/services"
)

const (
Expand All @@ -24,7 +24,7 @@ var buildCmdByTech = map[coreutils.Technology]string{
coreutils.Npm: npmDefaultBuildCmd,
}

func CreateXrayServiceManager(serviceDetails *utilsconfig.ServerDetails) (*xray.XrayServicesManager, error) {
func CreateXrayServiceManager(serviceDetails *utilsconfig.ServerDetails) (services2.SecurityServiceManager, error) {
xrayDetails, err := serviceDetails.CreateXrayAuthConfig()
if err != nil {
return nil, err
Expand All @@ -35,7 +35,7 @@ func CreateXrayServiceManager(serviceDetails *utilsconfig.ServerDetails) (*xray.
if err != nil {
return nil, err
}
return xray.New(serviceConfig)
return services2.New(serviceConfig)
}

func GetAllRepos(serviceDetails *utilsconfig.ServerDetails, repoType, packageType string) (*[]services.RepositoryDetails, error) {
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ require (

// replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20230828134416-f0db33dd9344

replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20230907095444-fd00f19be95d
replace github.com/jfrog/jfrog-cli-core/v2 => github.com/eyaldelarea/jfrog-cli-core/v2 v2.0.0-20230908125357-1a8083ec27d6

// replace github.com/jfrog/gofrog => github.com/jfrog/gofrog v1.2.6-0.20230418122323-2bf299dd6d27

replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.28.1-0.20230906115540-2c3c91d271d6
replace github.com/jfrog/jfrog-client-go => github.com/eyaldelarea/jfrog-client-go v1.28.4-0.20230908125028-d74eec0e77cf

replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20230905120411-62d1bdd4eb38
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po=
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/eyaldelarea/jfrog-cli-core/v2 v2.0.0-20230908125357-1a8083ec27d6 h1:oX4BNcFKH6cuMhVV+/0fZJMQPZaMLkL5PYr1yBqzj80=
github.com/eyaldelarea/jfrog-cli-core/v2 v2.0.0-20230908125357-1a8083ec27d6/go.mod h1:SYqc9qeU7PcYBX+FjN3McE1N9rZQkEewOs7K+JRK7dQ=
github.com/eyaldelarea/jfrog-client-go v1.28.4-0.20230908125028-d74eec0e77cf h1:uh8eJRKBAY8MtCt5pPC8Wer6KZMnaid0f+pYIh6anA8=
github.com/eyaldelarea/jfrog-client-go v1.28.4-0.20230908125028-d74eec0e77cf/go.mod h1:soD5VL3X+G+0KKUNSlb0CSdF9nwHsQZCr0xqOGedAHM=
github.com/forPelevin/gomoji v1.1.8 h1:JElzDdt0TyiUlecy6PfITDL6eGvIaxqYH1V52zrd0qQ=
github.com/forPelevin/gomoji v1.1.8/go.mod h1:8+Z3KNGkdslmeGZBC3tCrwMrcPy5GRzAD+gL9NAwMXg=
github.com/frankban/quicktest v1.11.3/go.mod h1:wRf/ReqHper53s+kmmSZizM8NamnL3IM0I9ntUbOk+k=
Expand Down Expand Up @@ -239,10 +243,6 @@ github.com/jfrog/build-info-go v1.8.9-0.20230905120411-62d1bdd4eb38 h1:XyAcwWP2a
github.com/jfrog/build-info-go v1.8.9-0.20230905120411-62d1bdd4eb38/go.mod h1:QEskae5fQpjeY2PBzsjWtUQVskYSNDF2sSmw/Gx44dQ=
github.com/jfrog/gofrog v1.3.0 h1:o4zgsBZE4QyDbz2M7D4K6fXPTBJht+8lE87mS9bw7Gk=
github.com/jfrog/gofrog v1.3.0/go.mod h1:IFMc+V/yf7rA5WZ74CSbXe+Lgf0iApEQLxRZVzKRUR0=
github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20230907095444-fd00f19be95d h1:7Qlsj5PkqSfayuNaM07L8W+H0bBqEGd+iPusoJOU6w8=
github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20230907095444-fd00f19be95d/go.mod h1:PCRqGSz6tKQNtiITSk9WZGflJjno/Vg4DvXPLkH6xO8=
github.com/jfrog/jfrog-client-go v1.28.1-0.20230906115540-2c3c91d271d6 h1:9mNCAUu/uHx80s4rMc9PeI1lllrZ1MOPUesIMglFoTY=
github.com/jfrog/jfrog-client-go v1.28.1-0.20230906115540-2c3c91d271d6/go.mod h1:soD5VL3X+G+0KKUNSlb0CSdF9nwHsQZCr0xqOGedAHM=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
github.com/jszwec/csvutil v1.8.0 h1:G7vS2LGdpZZDH1HmHeNbxOaJ/ZnJlpwGFvOkTkJzzNk=
Expand Down
2 changes: 1 addition & 1 deletion inttestutils/buildinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package inttestutils

import (
"fmt"
"github.com/jfrog/jfrog-client-go/utils"
"net/http"
"path"
"testing"
Expand All @@ -12,7 +13,6 @@ import (
coreutils "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"

"github.com/jfrog/jfrog-client-go/http/httpclient"
"github.com/jfrog/jfrog-client-go/utils"
"github.com/jfrog/jfrog-client-go/utils/io/httputils"
"github.com/jfrog/jfrog-client-go/utils/log"
"github.com/stretchr/testify/assert"
Expand Down
2 changes: 1 addition & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func setupIntegrationTests() {
if *tests.TestPlugins {
InitPluginsTests()
}
if *tests.TestXray {
if *tests.TestXray || *tests.TestXsc {
InitXrayTests()
}
if *tests.TestAccess {
Expand Down
2 changes: 1 addition & 1 deletion scan/cli.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package scan

import (
"github.com/jfrog/jfrog-cli-core/v2/xray/commands/audit"
"github.com/jfrog/jfrog-cli-core/v2/xray/commands/curation"
xrutils "github.com/jfrog/jfrog-cli-core/v2/xray/utils"
curationdocs "github.com/jfrog/jfrog-cli/docs/scan/curation"
Expand All @@ -15,7 +16,6 @@ import (
corecommondocs "github.com/jfrog/jfrog-cli-core/v2/docs/common"
coreconfig "github.com/jfrog/jfrog-cli-core/v2/utils/config"
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
"github.com/jfrog/jfrog-cli-core/v2/xray/commands/audit"
"github.com/jfrog/jfrog-cli-core/v2/xray/commands/scan"
"github.com/jfrog/jfrog-cli/docs/common"
auditdocs "github.com/jfrog/jfrog-cli/docs/scan/audit"
Expand Down
3 changes: 3 additions & 0 deletions utils/cliutils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"github.com/jfrog/gofrog/version"
"github.com/jfrog/jfrog-cli/utils/tests"
"io"
"net/http"
"os"
Expand Down Expand Up @@ -364,6 +365,7 @@ func ShouldOfferConfig() (bool, error) {
func CreateServerDetailsFromFlags(c *cli.Context) (details *coreConfig.ServerDetails, err error) {
details = new(coreConfig.ServerDetails)
details.Url = clientutils.AddTrailingSlashIfNeeded(c.String(url))
details.XscUrl = clientutils.ReplaceXraySuffixWithXsc(details.Url)
details.ArtifactoryUrl = clientutils.AddTrailingSlashIfNeeded(c.String(configRtUrl))
details.DistributionUrl = clientutils.AddTrailingSlashIfNeeded(c.String(configDistUrl))
details.XrayUrl = clientutils.AddTrailingSlashIfNeeded(c.String(configXrUrl))
Expand Down Expand Up @@ -506,6 +508,7 @@ func CreateServerDetailsWithConfigOffer(c *cli.Context, excludeRefreshableTokens
// Take insecureTls value from options since it is not saved in config.
confDetails.InsecureTls = details.InsecureTls
confDetails.Url = clientutils.AddTrailingSlashIfNeeded(confDetails.Url)
confDetails.XscUrl = clientutils.AddTrailingSlashIfNeeded(confDetails.Url + tests.XscEndpoint)
confDetails.DistributionUrl = clientutils.AddTrailingSlashIfNeeded(confDetails.DistributionUrl)

// Create initial access token if needed.
Expand Down
1 change: 1 addition & 0 deletions utils/tests/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ const (
DockerRemoteRepositoryConfig = "docker_remote_repository_config.json"
DockerVirtualRepositoryConfig = "docker_virtual_repository_config.json"
XrayEndpoint = "xray/"
XscEndpoint = "xsc/"
DevRepoRepositoryConfig = "dev_repo_repository_config.json"
ProdRepoRepositoryConfig = "prod_repo_repository_config.json"
UploadDevSpecA = "upload_dev_spec_a.json"
Expand Down
6 changes: 5 additions & 1 deletion utils/tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"errors"
"flag"
"fmt"
"github.com/jfrog/jfrog-client-go/utils/tests"
"io"
"math/rand"
"os"
Expand Down Expand Up @@ -36,7 +37,6 @@ import (
"github.com/jfrog/jfrog-client-go/utils/errorutils"
"github.com/jfrog/jfrog-client-go/utils/io/fileutils"
"github.com/jfrog/jfrog-client-go/utils/log"
"github.com/jfrog/jfrog-client-go/utils/tests"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -68,6 +68,7 @@ var (
TestPoetry *bool
TestPlugins *bool
TestXray *bool
TestXsc *bool
TestAccess *bool
TestTransfer *bool
TestLifecycle *bool
Expand Down Expand Up @@ -104,6 +105,7 @@ func init() {
TestPoetry = flag.Bool("test.poetry", false, "Test Poetry")
TestPlugins = flag.Bool("test.plugins", false, "Test Plugins")
TestXray = flag.Bool("test.xray", false, "Test Xray")
TestXsc = flag.Bool("test.xsc", false, "Test Xsc")
TestAccess = flag.Bool("test.access", false, "Test Access")
TestTransfer = flag.Bool("test.transfer", false, "Test files transfer")
TestLifecycle = flag.Bool("test.lifecycle", false, "Test lifecycle")
Expand Down Expand Up @@ -403,6 +405,7 @@ func GetNonVirtualRepositories() map[*string]string {
TestPoetry: {&PoetryRemoteRepo},
TestPlugins: {&RtRepo1},
TestXray: {},
TestXsc: {},
TestAccess: {&RtRepo1},
TestTransfer: {&RtRepo1, &RtRepo2, &MvnRepo1, &MvnRemoteRepo, &DockerRemoteRepo},
TestLifecycle: {&RtDevRepo, &RtProdRepo},
Expand All @@ -428,6 +431,7 @@ func GetVirtualRepositories() map[*string]string {
TestPoetry: {&PoetryVirtualRepo},
TestPlugins: {},
TestXray: {},
TestXsc: {},
TestAccess: {},
}
return getNeededRepositories(virtualReposMap)
Expand Down
16 changes: 10 additions & 6 deletions xray_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (
"flag"
"fmt"
biutils "github.com/jfrog/build-info-go/utils"
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
"github.com/jfrog/jfrog-cli-core/v2/xray/scangraph"
"github.com/jfrog/jfrog-client-go/xray/services"
"net/http"
"net/http/httptest"
"os"
Expand All @@ -27,7 +29,6 @@ import (
coreCmd "github.com/jfrog/jfrog-cli-core/v2/common/commands"
commontests "github.com/jfrog/jfrog-cli-core/v2/common/tests"
"github.com/jfrog/jfrog-cli-core/v2/utils/config"
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
coretests "github.com/jfrog/jfrog-cli-core/v2/utils/tests"
coreCuration "github.com/jfrog/jfrog-cli-core/v2/xray/commands/curation"
"github.com/jfrog/jfrog-cli-core/v2/xray/commands/scan"
Expand All @@ -40,7 +41,6 @@ import (
clientUtils "github.com/jfrog/jfrog-client-go/utils"
"github.com/jfrog/jfrog-client-go/utils/io/fileutils"
clientTestUtils "github.com/jfrog/jfrog-client-go/utils/tests"
"github.com/jfrog/jfrog-client-go/xray/services"
xrayUtils "github.com/jfrog/jfrog-client-go/xray/services/utils"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand All @@ -60,7 +60,7 @@ func InitXrayTests() {

func authenticateXray() string {
*tests.JfrogUrl = clientUtils.AddTrailingSlashIfNeeded(*tests.JfrogUrl)
xrayDetails = &config.ServerDetails{XrayUrl: *tests.JfrogUrl + tests.XrayEndpoint}
xrayDetails = &config.ServerDetails{Url: *tests.JfrogUrl, XrayUrl: *tests.JfrogUrl + tests.XrayEndpoint, XscUrl: *tests.JfrogUrl + tests.XscEndpoint}
cred := fmt.Sprintf("--url=%s", xrayDetails.XrayUrl)
if *tests.JfrogAccessToken != "" {
xrayDetails.AccessToken = *tests.JfrogAccessToken
Expand All @@ -76,6 +76,7 @@ func authenticateXray() string {
coreutils.ExitOnErr(errors.New("Failed while attempting to authenticate with Xray: " + err.Error()))
}
xrayDetails.XrayUrl = xrayAuth.GetUrl()
xrayDetails.XscUrl = xrayAuth.GetXscUrl()
return cred
}

Expand Down Expand Up @@ -138,16 +139,19 @@ func TestXrayBinaryScanWithBypassArchiveLimits(t *testing.T) {

// Tests npm audit by providing simple npm project and asserts any error.
func TestXrayAuditNpmJson(t *testing.T) {
output := testXrayAuditNpm(t, string(utils.Json))
output := testXrayAuditNpm(t, string(utils.Json), false)
verifyJsonScanResults(t, output, 0, 1, 1)
}

func TestXrayAuditNpmSimpleJson(t *testing.T) {
output := testXrayAuditNpm(t, string(utils.SimpleJson))
output := testXrayAuditNpm(t, string(utils.SimpleJson), false)
verifySimpleJsonScanResults(t, output, 1, 1)
}

func testXrayAuditNpm(t *testing.T, format string) string {
func testXrayAuditNpm(t *testing.T, format string, isXsc bool) string {
if !isXsc {
initXrayTest(t, scangraph.GraphScanMinXrayVersion)
}
initXrayTest(t, scangraph.GraphScanMinXrayVersion)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

tempDirPath, createTempDirCallback := coretests.CreateTempDirWithCallbackAndAssert(t)
defer createTempDirCallback()
Expand Down
25 changes: 25 additions & 0 deletions xsc_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package main

import (
"github.com/jfrog/jfrog-cli-core/v2/xray/scangraph"
"github.com/jfrog/jfrog-cli/utils/tests"
clientutils "github.com/jfrog/jfrog-client-go/utils"
"testing"
)

func initXscTest(t *testing.T, minVersion string) {
if !*tests.TestXsc {
t.Skip("Skipping Xsc test. To run xsc test add the '-test.xsc=true' option.")
}
validateXscVersion(t, minVersion)
}
func validateXscVersion(t *testing.T, minVersion string) {
err := clientutils.ValidateMinimumVersion(clientutils.Xray, xrayDetails.XscVersion, minVersion)
if err != nil {
t.Skip(err)
}
}
func TestXSCAudit(t *testing.T) {
EyalDelarea marked this conversation as resolved.
Show resolved Hide resolved
initXscTest(t, scangraph.XscMinVersion)
testXrayAuditNpm(t, "json", true)
EyalDelarea marked this conversation as resolved.
Show resolved Hide resolved
}
Loading