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

fix azure public and ssh scans #8

Merged
merged 1 commit into from
Jan 12, 2023
Merged
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 apis/azureapi/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
const (
DEFAULT_HOST string = "azure.com"
DEV_HOST string = "dev.azure.com"
SSH_DEV_HOST string = "ssh.dev.azure.com"
)

type IAzureAPI interface {
Expand Down
2 changes: 1 addition & 1 deletion azureparser/v1/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (az *AzureURL) GetRepoName() string { return az.repo }
func (az *AzureURL) GetPath() string { return az.path }
func (az *AzureURL) GetToken() string { return az.token }
func (az *AzureURL) GetHttpCloneURL() string {
return fmt.Sprintf("https://%s@%s/%s/%s/_git/%s", az.GetOwnerName(), az.GetHostName(), az.GetOwnerName(), az.GetProjectName(), az.GetRepoName())
return fmt.Sprintf("https://%s/%s/%s/_git/%s", az.GetHostName(), az.GetOwnerName(), az.GetProjectName(), az.GetRepoName())
}

func (az *AzureURL) SetOwnerName(o string) { az.owner = o }
Expand Down
40 changes: 39 additions & 1 deletion azureparser/v1/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ var (
urlD = "https://dev.azure.com/dwertent/ks-testing-public/_git/ks-testing-public?path=/scripts&version=GTv1.0.1&_a=contents"
urlE = "https://dev.azure.com/dwertent/ks-testing-public/_git/ks-testing-public?path=%2F&version=GBdev"
urlF = "https://dwertent@dev.azure.com/dwertent/ks-testing-public/_git/ks-testing-public"
// scp-like syntax supported by git for ssh
// see: https://mirrors.edge.kernel.org/pub/software/scm/git/docs/git-clone.html#URLS
// regular form
urlG = "git@ssh.dev.azure.com:v3/dwertent/ks-testing-public/ks-testing-public"
)

func TestNewAzureParserWithURL(t *testing.T) {
Expand Down Expand Up @@ -62,9 +66,43 @@ func TestNewAzureParserWithURL(t *testing.T) {
assert.Equal(t, "", az.GetBranchName())
assert.Equal(t, "/scripts", az.GetPath())
}
{
az, err := NewAzureParserWithURL(urlE)
assert.NoError(t, err)
assert.Equal(t, "dev.azure.com", az.GetHostName())
assert.Equal(t, "azure", az.GetProvider())
assert.Equal(t, "dwertent", az.GetOwnerName())
assert.Equal(t, "ks-testing-public", az.GetRepoName())
assert.Equal(t, urlA, az.GetURL().String())
assert.Equal(t, "", az.GetTag())
assert.Equal(t, "dev", az.GetBranchName())
assert.Equal(t, "/", az.GetPath())
}
{
az, err := NewAzureParserWithURL(urlF)
assert.NoError(t, err)
assert.Equal(t, "dev.azure.com", az.GetHostName())
assert.Equal(t, "azure", az.GetProvider())
assert.Equal(t, "dwertent", az.GetOwnerName())
assert.Equal(t, "ks-testing-public", az.GetRepoName())
assert.Equal(t, urlA, az.GetURL().String())
assert.Equal(t, "", az.GetBranchName())
assert.Equal(t, "", az.GetPath())
}
{
az, err := NewAzureParserWithURL(urlG)
assert.NoError(t, err)
assert.NoError(t, err)
assert.Equal(t, "dev.azure.com", az.GetHostName())
assert.Equal(t, "azure", az.GetProvider())
assert.Equal(t, "dwertent", az.GetOwnerName())
assert.Equal(t, "ks-testing-public", az.GetRepoName())
assert.Equal(t, urlA, az.GetURL().String())
assert.Equal(t, "", az.GetBranchName())
assert.Equal(t, "", az.GetPath())
}
}


func TestSetDefaultBranch(t *testing.T) {
{
az, err := NewAzureParserWithURL(urlA)
Expand Down
2 changes: 1 addition & 1 deletion init.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func NewGitAPI(fullURL string) (IGitAPI, error) {
return githubparserv1.NewGitHubParserWithURL(fullURL)
case gitlabapi.DEFAULT_HOST:
return gitlabparserv1.NewGitLabParserWithURL(fullURL)
case azureapi.DEFAULT_HOST, azureapi.DEV_HOST:
case azureapi.DEFAULT_HOST, azureapi.DEV_HOST, azureapi.SSH_DEV_HOST:
return azureparserv1.NewAzureParserWithURL(fullURL)
case bitbucketapi.DEFAULT_HOST:
return bitbucketparserv1.NewBitBucketParserWithURL(fullURL)
Expand Down