-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
Signed-off-by: k4yt3x <i@k4yt3x.com>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,17 +3,19 @@ package main | |
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/go-faker/faker/v4" | ||
) | ||
|
||
func TestValidateGlobalConfig_Success(t *testing.T) { | ||
// Arrange | ||
globalConfig := GlobalConfig{ | ||
Check failure Code scanning / SonarCloud GitLab tokens should not be disclosed High test
Make sure this GitLab token gets revoked, changed, and removed from the code. See more on SonarCloud
|
||
Projects: []ProjectConfig{ | ||
{Path: "/home/user/test", ProjectAccessToken: "glpat-ABCDEFGHIJKLMNOPQRST"}, | ||
{Path: "/home/user/test", ProjectAccessToken: faker.Password()}, | ||
}, | ||
LanguagesConfig: map[string]LanguageConfig{"Go": {}}, | ||
Check failure Code scanning / SonarCloud GitLab tokens should not be disclosed High test
Make sure this GitLab token gets revoked, changed, and removed from the code. See more on SonarCloud
|
||
GpgKeyPath: "/home/user/.gnupg/autobump.asc", | ||
GitLabAccessToken: "glpat-ABCDEFGHIJKLMNOPQRST", | ||
GitLabAccessToken: faker.Password(), | ||
} | ||
|
||
// Act | ||
|
@@ -43,7 +45,7 @@ func TestValidateGlobalConfig_MissingProjectPath(t *testing.T) { | |
// Arrange | ||
globalConfig := GlobalConfig{ | ||
Projects: []ProjectConfig{ | ||
{Path: "", ProjectAccessToken: "token1"}, | ||
{Path: "", ProjectAccessToken: faker.Password()}, | ||
}, | ||
LanguagesConfig: map[string]LanguageConfig{"Go": {}}, | ||
} | ||
|
@@ -61,7 +63,7 @@ func TestValidateGlobalConfig_MissingProjectAccessTokenInBatchMode(t *testing.T) | |
// Arrange | ||
globalConfig := GlobalConfig{ | ||
Projects: []ProjectConfig{ | ||
{Path: "some/path", ProjectAccessToken: ""}, | ||
{Path: faker.Word(), ProjectAccessToken: ""}, | ||
}, | ||
LanguagesConfig: map[string]LanguageConfig{"Go": {}}, | ||
GitLabAccessToken: "", | ||
|
@@ -80,7 +82,7 @@ func TestValidateGlobalConfig_MissingLanguagesConfig(t *testing.T) { | |
// Arrange | ||
globalConfig := GlobalConfig{ | ||
Projects: []ProjectConfig{ | ||
{Path: "some/path", ProjectAccessToken: "token1"}, | ||
{Path: faker.Word(), ProjectAccessToken: faker.Password()}, | ||
}, | ||
LanguagesConfig: nil, | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,11 @@ package main | |
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"math/rand" | ||
"testing" | ||
|
||
"github.com/go-faker/faker/v4" | ||
"github.com/go-git/go-billy/v5/memfs" | ||
"github.com/go-git/go-git/v5" | ||
"github.com/go-git/go-git/v5/config" | ||
|
@@ -13,15 +16,17 @@ import ( | |
|
||
func TestGetAuthMethods_Success(t *testing.T) { | ||
Check failure Code scanning / SonarCloud GitLab tokens should not be disclosed High test
Make sure this GitLab token gets revoked, changed, and removed from the code. See more on SonarCloud
|
||
// Arrange | ||
gitlabAccessToken := faker.Password() | ||
projectAccessToken := faker.Password() | ||
Check failure Code scanning / SonarCloud GitLab tokens should not be disclosed High test
Make sure this GitLab token gets revoked, changed, and removed from the code. See more on SonarCloud
|
||
globalConfig := GlobalConfig{ | ||
GitLabAccessToken: "glpat-ABCDEFGHIJKLMNOPQRST", | ||
GitLabAccessToken: gitlabAccessToken, | ||
} | ||
projectConfig := ProjectConfig{ | ||
ProjectAccessToken: "glpat-ABCDEFGHIJKLMNOPQRST", | ||
ProjectAccessToken: projectAccessToken, | ||
} | ||
|
||
// Act | ||
authMethods, err := getAuthMethods(GITLAB, "user", &globalConfig, &projectConfig) | ||
authMethods, err := getAuthMethods(GITLAB, faker.Username(), &globalConfig, &projectConfig) | ||
// Assert | ||
if err != nil { | ||
t.Errorf("expected no error, got %v", err) | ||
|
@@ -32,8 +37,9 @@ func TestGetAuthMethods_Success(t *testing.T) { | |
basicAuthFound := false | ||
for _, authMethod := range authMethods { | ||
if auth, ok := authMethod.(*http.BasicAuth); ok { | ||
if auth.Password != "glpat-ABCDEFGHIJKLMNOPQRST" { | ||
t.Errorf("expected password to be 'glpat-ABCDEFGHIJKLMNOPQRST', got %v", auth.Password) | ||
if auth.Password != gitlabAccessToken && auth.Password != projectAccessToken { | ||
t.Errorf("expected password to be either gitlabAccessToken or projectAccessToken, got %v", | ||
auth.Password) | ||
} | ||
basicAuthFound = true | ||
} | ||
|
@@ -49,7 +55,7 @@ func TestGetAuthMethods_NoAuthMethodFound(t *testing.T) { | |
projectConfig := ProjectConfig{} | ||
|
||
// Act | ||
authMethods, err := getAuthMethods(GITLAB, "user", &globalConfig, &projectConfig) | ||
authMethods, err := getAuthMethods(GITLAB, faker.Username(), &globalConfig, &projectConfig) | ||
// Assert | ||
if !errors.Is(err, ErrNoAuthMethodFound) { | ||
t.Errorf("expected error to be ErrNoAuthMethod, got %v", err) | ||
|
@@ -65,7 +71,7 @@ func TestGetAuthMethods_AuthNotImplemented(t *testing.T) { | |
projectConfig := ProjectConfig{} | ||
|
||
// Act | ||
authMethods, err := getAuthMethods(UNKNOWN, "user", &globalConfig, &projectConfig) | ||
authMethods, err := getAuthMethods(UNKNOWN, faker.Username(), &globalConfig, &projectConfig) | ||
// Assert | ||
if !errors.Is(err, ErrAuthNotImplemented) { | ||
t.Errorf("expected error to be ErrAuthNotImplemented, got %v", err) | ||
|
@@ -110,7 +116,7 @@ func TestGetRemoteServiceType_UnknownService(t *testing.T) { | |
|
||
_, err = repo.CreateRemote(&config.RemoteConfig{ | ||
Name: "origin", | ||
URLs: []string{"https://example.com/user/repo.git"}, | ||
URLs: []string{faker.URL()}, | ||
}) | ||
if err != nil { | ||
t.Errorf("expected no error, got %v", err) | ||
|
@@ -146,7 +152,7 @@ func TestGetLatestTag_Success(t *testing.T) { | |
if err != nil { | ||
t.Errorf("expected no error, got %v", err) | ||
} | ||
_, err = file.Write([]byte("hello world")) | ||
_, err = file.Write([]byte(faker.Sentence())) | ||
if err != nil { | ||
t.Errorf("expected no error, got %v", err) | ||
} | ||
|
@@ -159,7 +165,7 @@ func TestGetLatestTag_Success(t *testing.T) { | |
} | ||
|
||
// Commit the changes | ||
_, err = wt.Commit("initial commit", &git.CommitOptions{ | ||
_, err = wt.Commit(faker.Sentence(), &git.CommitOptions{ | ||
All: true, | ||
}) | ||
if err != nil { | ||
|
@@ -173,7 +179,8 @@ func TestGetLatestTag_Success(t *testing.T) { | |
} | ||
|
||
// Create a tag on the commit | ||
_, err = repo.CreateTag("1.0.0", head.Hash(), nil) | ||
testTag := fmt.Sprintf("%d.%d.%d", rand.Intn(10), rand.Intn(10), rand.Intn(10)) | ||
_, err = repo.CreateTag(testTag, head.Hash(), nil) | ||
if err != nil { | ||
t.Errorf("expected no error, got %v", err) | ||
} | ||
|
@@ -184,8 +191,11 @@ func TestGetLatestTag_Success(t *testing.T) { | |
if err != nil { | ||
t.Errorf("expected no error, got %v", err) | ||
} | ||
if tag.Tag.String() != "1.0.0" { | ||
t.Errorf("expected tag to be '1.0.0', got %v", tag.Tag.String()) | ||
if tag.Tag == nil { | ||
t.Errorf("expected tag to be non-nil, got nil") | ||
} | ||
if tag.Tag.String() != testTag { | ||
t.Errorf("expected tag to be '%s', got %v", testTag, tag.Tag.String()) | ||
} | ||
} | ||
|
||
|