Skip to content

Commit 48f53df

Browse files
refactor: remove redundant ssh transformation [IDE-257] (#57)
1 parent f8e7eba commit 48f53df

File tree

3 files changed

+3
-80
lines changed

3 files changed

+3
-80
lines changed

internal/util/repository.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ package util
1818

1919
import (
2020
"fmt"
21-
"net/url"
22-
"strings"
23-
2421
"github.com/go-git/go-git/v5"
22+
"net/url"
2523
)
2624

2725
func GetRepositoryUrl(path string) (string, error) {
@@ -45,8 +43,6 @@ func GetRepositoryUrl(path string) (string, error) {
4543
repoUrl := remote.Config().URLs[0]
4644
repoUrl, err = SanitiseCredentials(repoUrl)
4745

48-
// we need to return an actual URL, not the SSH
49-
repoUrl = strings.Replace(repoUrl, "[email protected]:", "https://github.com/", 1)
5046
return repoUrl, err
5147
}
5248

internal/util/repository_test.go

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -71,34 +71,6 @@ func Test_GetRepositoryUrl_repo_without_credentials(t *testing.T) {
7171
assert.Equal(t, expectedRepoUrl, actualUrl)
7272
}
7373

74-
func Test_GetRepositoryUrl_repo_with_ssh(t *testing.T) {
75-
// check out a repo and prepare its config to contain credentials in the URL
76-
expectedRepoUrl := "https://github.com/snyk-fixtures/shallow-goof-locked.git"
77-
78-
repoDir, err := testutil.SetupCustomTestRepo(t, expectedRepoUrl, "master", "", "shallow-goof-locked")
79-
require.NoError(t, err)
80-
81-
repo, err := git.PlainOpenWithOptions(repoDir, &git.PlainOpenOptions{
82-
DetectDotGit: true,
83-
})
84-
require.NoError(t, err)
85-
86-
config, err := repo.Config()
87-
assert.NoError(t, err)
88-
89-
for i := range config.Remotes["origin"].URLs {
90-
config.Remotes["origin"].URLs[i] = "[email protected]:snyk-fixtures/shallow-goof-locked.git"
91-
}
92-
93-
err = repo.SetConfig(config)
94-
assert.NoError(t, err)
95-
96-
// run method under test
97-
actualUrl, err := util.GetRepositoryUrl(repoDir)
98-
assert.NoError(t, err)
99-
assert.Equal(t, expectedRepoUrl, actualUrl)
100-
}
101-
10274
func Test_GetRepositoryUrl_no_repo(t *testing.T) {
10375
repoDir := t.TempDir()
10476
actualUrl, err := util.GetRepositoryUrl(repoDir)

scan_smoke_test.go

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import (
3838
"github.com/snyk/code-client-go/scan"
3939
)
4040

41-
func TestSmoke_Scan_HTTPS(t *testing.T) {
41+
func TestSmoke_Scan_IDE(t *testing.T) {
4242
var cloneTargetDir, err = testutil.SetupCustomTestRepo(t, "https://github.com/snyk-labs/nodejs-goof", "0336589", "", "")
4343
assert.NoError(t, err)
4444

@@ -88,7 +88,7 @@ func TestSmoke_Scan_HTTPS(t *testing.T) {
8888
require.NotNil(t, response.Sarif.Runs[0].Results[0].Locations[0].PhysicalLocation.ArtifactLocation.URI)
8989
}
9090

91-
func Test_SmokeScan_HTTPS_CLI(t *testing.T) {
91+
func Test_SmokeScan_CLI(t *testing.T) {
9292
var cloneTargetDir, err = testutil.SetupCustomTestRepo(t, "https://github.com/snyk-labs/nodejs-goof", "0336589", "", "")
9393
assert.NoError(t, err)
9494

@@ -142,51 +142,6 @@ func Test_SmokeScan_HTTPS_CLI(t *testing.T) {
142142
require.NotNil(t, response.Sarif.Runs[0].Results[0].Locations[0].PhysicalLocation.ArtifactLocation.URI)
143143
}
144144

145-
func TestSmoke_Scan_SSH(t *testing.T) {
146-
var cloneTargetDir, err = testutil.SetupCustomTestRepo(t, "[email protected]:snyk-labs/nodejs-goof", "0336589", "", "")
147-
assert.NoError(t, err)
148-
149-
target, err := scan.NewRepositoryTarget(cloneTargetDir)
150-
assert.NoError(t, err)
151-
152-
files := sliceToChannel([]string{filepath.Join(cloneTargetDir, "app.js"), filepath.Join(cloneTargetDir, "utils.js")})
153-
154-
logger := zerolog.New(os.Stdout)
155-
instrumentor := testutil.NewTestInstrumentor()
156-
errorReporter := testutil.NewTestErrorReporter()
157-
config := testutil.NewTestConfig()
158-
httpClient := codeClientHTTP.NewHTTPClient(
159-
func() *http.Client {
160-
client := http.Client{
161-
Timeout: time.Duration(180) * time.Second,
162-
Transport: testutil.TestAuthRoundTripper{http.DefaultTransport},
163-
}
164-
return &client
165-
},
166-
codeClientHTTP.WithRetryCount(3),
167-
codeClientHTTP.WithLogger(&logger),
168-
)
169-
trackerFactory := scan.NewNoopTrackerFactory()
170-
171-
codeScanner := codeClient.NewCodeScanner(
172-
config,
173-
httpClient,
174-
codeClient.WithTrackerFactory(trackerFactory),
175-
codeClient.WithInstrumentor(instrumentor),
176-
codeClient.WithErrorReporter(errorReporter),
177-
codeClient.WithLogger(&logger),
178-
)
179-
180-
// let's have a requestID that does not change
181-
span := instrumentor.StartSpan(context.Background(), "UploadAndAnalyze")
182-
defer span.Finish()
183-
184-
response, bundleHash, scanErr := codeScanner.UploadAndAnalyze(span.Context(), uuid.New().String(), target, files, map[string]bool{})
185-
require.NoError(t, scanErr)
186-
require.NotEmpty(t, bundleHash)
187-
require.NotNil(t, response)
188-
}
189-
190145
func TestSmoke_Scan_SubFolder(t *testing.T) {
191146
currDir, err := os.Getwd()
192147
require.NoError(t, err)

0 commit comments

Comments
 (0)