-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: remove redundant ssh transformation [IDE-257] (#57)
- Loading branch information
1 parent
f8e7eba
commit 48f53df
Showing
3 changed files
with
3 additions
and
80 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -18,10 +18,8 @@ package util | |
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
"strings" | ||
|
||
"github.com/go-git/go-git/v5" | ||
"net/url" | ||
) | ||
|
||
func GetRepositoryUrl(path string) (string, error) { | ||
|
@@ -45,8 +43,6 @@ func GetRepositoryUrl(path string) (string, error) { | |
repoUrl := remote.Config().URLs[0] | ||
repoUrl, err = SanitiseCredentials(repoUrl) | ||
|
||
// we need to return an actual URL, not the SSH | ||
repoUrl = strings.Replace(repoUrl, "[email protected]:", "https://github.com/", 1) | ||
return repoUrl, err | ||
} | ||
|
||
|
This file contains 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 |
---|---|---|
|
@@ -71,34 +71,6 @@ func Test_GetRepositoryUrl_repo_without_credentials(t *testing.T) { | |
assert.Equal(t, expectedRepoUrl, actualUrl) | ||
} | ||
|
||
func Test_GetRepositoryUrl_repo_with_ssh(t *testing.T) { | ||
// check out a repo and prepare its config to contain credentials in the URL | ||
expectedRepoUrl := "https://github.com/snyk-fixtures/shallow-goof-locked.git" | ||
|
||
repoDir, err := testutil.SetupCustomTestRepo(t, expectedRepoUrl, "master", "", "shallow-goof-locked") | ||
require.NoError(t, err) | ||
|
||
repo, err := git.PlainOpenWithOptions(repoDir, &git.PlainOpenOptions{ | ||
DetectDotGit: true, | ||
}) | ||
require.NoError(t, err) | ||
|
||
config, err := repo.Config() | ||
assert.NoError(t, err) | ||
|
||
for i := range config.Remotes["origin"].URLs { | ||
config.Remotes["origin"].URLs[i] = "[email protected]:snyk-fixtures/shallow-goof-locked.git" | ||
} | ||
|
||
err = repo.SetConfig(config) | ||
assert.NoError(t, err) | ||
|
||
// run method under test | ||
actualUrl, err := util.GetRepositoryUrl(repoDir) | ||
assert.NoError(t, err) | ||
assert.Equal(t, expectedRepoUrl, actualUrl) | ||
} | ||
|
||
func Test_GetRepositoryUrl_no_repo(t *testing.T) { | ||
repoDir := t.TempDir() | ||
actualUrl, err := util.GetRepositoryUrl(repoDir) | ||
|
This file contains 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 |
---|---|---|
|
@@ -38,7 +38,7 @@ import ( | |
"github.com/snyk/code-client-go/scan" | ||
) | ||
|
||
func TestSmoke_Scan_HTTPS(t *testing.T) { | ||
func TestSmoke_Scan_IDE(t *testing.T) { | ||
var cloneTargetDir, err = testutil.SetupCustomTestRepo(t, "https://github.com/snyk-labs/nodejs-goof", "0336589", "", "") | ||
assert.NoError(t, err) | ||
|
||
|
@@ -88,7 +88,7 @@ func TestSmoke_Scan_HTTPS(t *testing.T) { | |
require.NotNil(t, response.Sarif.Runs[0].Results[0].Locations[0].PhysicalLocation.ArtifactLocation.URI) | ||
} | ||
|
||
func Test_SmokeScan_HTTPS_CLI(t *testing.T) { | ||
func Test_SmokeScan_CLI(t *testing.T) { | ||
var cloneTargetDir, err = testutil.SetupCustomTestRepo(t, "https://github.com/snyk-labs/nodejs-goof", "0336589", "", "") | ||
assert.NoError(t, err) | ||
|
||
|
@@ -142,51 +142,6 @@ func Test_SmokeScan_HTTPS_CLI(t *testing.T) { | |
require.NotNil(t, response.Sarif.Runs[0].Results[0].Locations[0].PhysicalLocation.ArtifactLocation.URI) | ||
} | ||
|
||
func TestSmoke_Scan_SSH(t *testing.T) { | ||
var cloneTargetDir, err = testutil.SetupCustomTestRepo(t, "[email protected]:snyk-labs/nodejs-goof", "0336589", "", "") | ||
assert.NoError(t, err) | ||
|
||
target, err := scan.NewRepositoryTarget(cloneTargetDir) | ||
assert.NoError(t, err) | ||
|
||
files := sliceToChannel([]string{filepath.Join(cloneTargetDir, "app.js"), filepath.Join(cloneTargetDir, "utils.js")}) | ||
|
||
logger := zerolog.New(os.Stdout) | ||
instrumentor := testutil.NewTestInstrumentor() | ||
errorReporter := testutil.NewTestErrorReporter() | ||
config := testutil.NewTestConfig() | ||
httpClient := codeClientHTTP.NewHTTPClient( | ||
func() *http.Client { | ||
client := http.Client{ | ||
Timeout: time.Duration(180) * time.Second, | ||
Transport: testutil.TestAuthRoundTripper{http.DefaultTransport}, | ||
} | ||
return &client | ||
}, | ||
codeClientHTTP.WithRetryCount(3), | ||
codeClientHTTP.WithLogger(&logger), | ||
) | ||
trackerFactory := scan.NewNoopTrackerFactory() | ||
|
||
codeScanner := codeClient.NewCodeScanner( | ||
config, | ||
httpClient, | ||
codeClient.WithTrackerFactory(trackerFactory), | ||
codeClient.WithInstrumentor(instrumentor), | ||
codeClient.WithErrorReporter(errorReporter), | ||
codeClient.WithLogger(&logger), | ||
) | ||
|
||
// let's have a requestID that does not change | ||
span := instrumentor.StartSpan(context.Background(), "UploadAndAnalyze") | ||
defer span.Finish() | ||
|
||
response, bundleHash, scanErr := codeScanner.UploadAndAnalyze(span.Context(), uuid.New().String(), target, files, map[string]bool{}) | ||
require.NoError(t, scanErr) | ||
require.NotEmpty(t, bundleHash) | ||
require.NotNil(t, response) | ||
} | ||
|
||
func TestSmoke_Scan_SubFolder(t *testing.T) { | ||
currDir, err := os.Getwd() | ||
require.NoError(t, err) | ||
|