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

enhancement: make security test timeout configurable via env variable #512

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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 api/analysis/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func StartAnalysis(RID string, repository types.Repository) {
// step 2: run enry as huskyCI initial step
enryScan := securitytest.SecTestScanInfo{}
enryScan.SecurityTestName = "enry"
enryScan.TimeOut = repository.TimeOut
allScansResults := securitytest.RunAllInfo{}

defer func() {
Expand Down
2 changes: 2 additions & 0 deletions api/securitytest/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func (results *RunAllInfo) runGenericScans(enryScan SecTestScanInfo) error {
go func(genericTest *types.SecurityTest) {
defer wg.Done()
newGenericScan := SecTestScanInfo{}
newGenericScan.TimeOut = enryScan.TimeOut
if err := newGenericScan.New(enryScan.RID, enryScan.URL, enryScan.Branch, genericTest.Name); err != nil {
select {
case <-syncChan:
Expand Down Expand Up @@ -166,6 +167,7 @@ func (results *RunAllInfo) runLanguageScans(enryScan SecTestScanInfo) error {
go func(languageTest *types.SecurityTest) {
defer wg.Done()
newLanguageScan := SecTestScanInfo{}
newLanguageScan.TimeOut = enryScan.TimeOut
if err := newLanguageScan.New(enryScan.RID, enryScan.URL, enryScan.Branch, languageTest.Name); err != nil {
select {
case <-syncChan:
Expand Down
8 changes: 7 additions & 1 deletion api/securitytest/securitytest.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type SecTestScanInfo struct {
Branch string
SecurityTestName string
ErrorFound error
TimeOut int
ReqNotFound bool
WarningFound bool
PackageNotFound bool
Expand Down Expand Up @@ -71,7 +72,12 @@ func (scanInfo *SecTestScanInfo) setSecurityTestContainer(securityTestName strin

// Start starts a new huskyCI scan!
func (scanInfo *SecTestScanInfo) Start() error {
if err := scanInfo.dockerRun(scanInfo.Container.SecurityTest.TimeOutInSeconds); err != nil {
// Override default timeout if a custom timeout is passed
timeOut := scanInfo.TimeOut
if timeOut == 0 {
timeOut = scanInfo.Container.SecurityTest.TimeOutInSeconds
}
if err := scanInfo.dockerRun(timeOut); err != nil {
scanInfo.ErrorFound = err
scanInfo.prepareContainerAfterScan()
return err
Expand Down
1 change: 1 addition & 0 deletions api/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
type Repository struct {
URL string `bson:"repositoryURL" json:"repositoryURL"`
Branch string `json:"repositoryBranch"`
TimeOut int `json:"timeOutInSeconds"`
CreatedAt time.Time `bson:"createdAt" json:"createdAt"`
}

Expand Down
1 change: 1 addition & 0 deletions client/analysis/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func StartAnalysis() (string, error) {
requestPayload := types.JSONPayload{
RepositoryURL: config.RepositoryURL,
RepositoryBranch: config.RepositoryBranch,
TimeOutInSeconds: config.TimeOutInSeconds,
}

marshalPayload, err := json.Marshal(requestPayload)
Expand Down
5 changes: 5 additions & 0 deletions client/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package config
import (
"errors"
"os"
"strconv"
)

// RepositoryURL stores the repository URL of the project to be analyzed.
Expand All @@ -24,13 +25,17 @@ var HuskyToken string
// HuskyUseTLS stores if huskyCI is to use an HTTPS connection.
var HuskyUseTLS bool

// Timeout in Seconds for huskyCI tests
var TimeOutInSeconds int

// SetConfigs sets all configuration needed to start the client.
func SetConfigs() {
RepositoryURL = os.Getenv(`HUSKYCI_CLIENT_REPO_URL`)
RepositoryBranch = os.Getenv(`HUSKYCI_CLIENT_REPO_BRANCH`)
HuskyAPI = os.Getenv(`HUSKYCI_CLIENT_API_ADDR`)
HuskyToken = os.Getenv(`HUSKYCI_CLIENT_TOKEN`)
HuskyUseTLS = getUseTLS()
TimeOutInSeconds, _ = strconv.Atoi(os.Getenv(`HUSKYCI_CLIENT_TESTS_TIMEOUT`))
}

// CheckEnvVars checks if all environment vars are set.
Expand Down
1 change: 1 addition & 0 deletions client/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var IsJSONoutput bool
type JSONPayload struct {
RepositoryURL string `json:"repositoryURL"`
RepositoryBranch string `json:"repositoryBranch"`
TimeOutInSeconds int `json:"timeOutInSeconds"`
}

// Target is the struct that represents HuskyCI API target
Expand Down