mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-14 11:03:09 +02:00
eff38f6c9d
* Make sure the UA scan is known to the scan object. Fixes downloading reports later on. * Move polling into pkg/whitesource, add test for e2e scan * Remove conditions from stash config resource * Don't use version stored in CPE. This will prevent the versioningModel from being applied.
98 lines
3.1 KiB
Go
98 lines
3.1 KiB
Go
package whitesource
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/SAP/jenkins-library/pkg/mock"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"testing"
|
|
)
|
|
|
|
func TestExecuteScanUA(t *testing.T) {
|
|
t.Parallel()
|
|
t.Run("happy path UA", func(t *testing.T) {
|
|
// init
|
|
config := ScanOptions{
|
|
ScanType: "unified-agent",
|
|
OrgToken: "org-token",
|
|
UserToken: "user-token",
|
|
ProductName: "mock-product",
|
|
ProjectName: "mock-project",
|
|
AgentDownloadURL: "https://download.ua.org/agent.jar",
|
|
AgentFileName: "unified-agent.jar",
|
|
ConfigFilePath: "ua.cfg",
|
|
M2Path: ".pipeline/m2",
|
|
}
|
|
utilsMock := NewScanUtilsMock()
|
|
utilsMock.AddFile("wss-generated-file.config", []byte("key=value"))
|
|
scan := newTestScan(&config)
|
|
// test
|
|
err := scan.ExecuteUAScan(&config, utilsMock)
|
|
// assert
|
|
require.NoError(t, err)
|
|
content, err := utilsMock.FileRead("ua.cfg")
|
|
require.NoError(t, err)
|
|
contentAsString := string(content)
|
|
assert.Contains(t, contentAsString, "key=value\n")
|
|
assert.Contains(t, contentAsString, "gradle.aggregateModules=true\n")
|
|
assert.Contains(t, contentAsString, "maven.aggregateModules=true\n")
|
|
assert.Contains(t, contentAsString, "maven.m2RepositoryPath=.pipeline/m2\n")
|
|
assert.Contains(t, contentAsString, "excludes=")
|
|
|
|
require.Len(t, utilsMock.Calls, 4)
|
|
fmt.Printf("calls: %v\n", utilsMock.Calls)
|
|
expectedCall := mock.ExecCall{
|
|
Exec: "java",
|
|
Params: []string{
|
|
"-jar",
|
|
config.AgentFileName,
|
|
"-d", ".",
|
|
"-c", config.ConfigFilePath,
|
|
"-apiKey", config.OrgToken,
|
|
"-userKey", config.UserToken,
|
|
"-project", config.ProjectName,
|
|
"-product", config.ProductName,
|
|
"-productVersion", scan.ProductVersion,
|
|
},
|
|
}
|
|
assert.Equal(t, expectedCall, utilsMock.Calls[3])
|
|
})
|
|
t.Run("UA is downloaded", func(t *testing.T) {
|
|
// init
|
|
config := ScanOptions{
|
|
ScanType: "unified-agent",
|
|
ProjectName: "mock-project",
|
|
AgentDownloadURL: "https://download.ua.org/agent.jar",
|
|
AgentFileName: "unified-agent.jar",
|
|
}
|
|
utilsMock := NewScanUtilsMock()
|
|
utilsMock.AddFile("wss-generated-file.config", []byte("dummy"))
|
|
scan := newTestScan(&config)
|
|
// test
|
|
err := scan.ExecuteUAScan(&config, utilsMock)
|
|
// assert
|
|
require.NoError(t, err)
|
|
require.Len(t, utilsMock.DownloadedFiles, 1)
|
|
assert.Equal(t, "https://download.ua.org/agent.jar", utilsMock.DownloadedFiles[0].SourceURL)
|
|
assert.Equal(t, "unified-agent.jar", utilsMock.DownloadedFiles[0].FilePath)
|
|
})
|
|
t.Run("UA is NOT downloaded", func(t *testing.T) {
|
|
// init
|
|
config := ScanOptions{
|
|
ScanType: "unified-agent",
|
|
ProjectName: "mock-project",
|
|
AgentDownloadURL: "https://download.ua.org/agent.jar",
|
|
AgentFileName: "unified-agent.jar",
|
|
}
|
|
utilsMock := NewScanUtilsMock()
|
|
utilsMock.AddFile("wss-generated-file.config", []byte("dummy"))
|
|
utilsMock.AddFile("unified-agent.jar", []byte("dummy"))
|
|
scan := newTestScan(&config)
|
|
// test
|
|
err := scan.ExecuteUAScan(&config, utilsMock)
|
|
// assert
|
|
require.NoError(t, err)
|
|
assert.Len(t, utilsMock.DownloadedFiles, 0)
|
|
})
|
|
}
|