Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrancisco Javier López <fjlopez@gitlab.com>2019-02-20 13:52:02 +0300
committerFrancisco Javier López <fjlopez@gitlab.com>2019-02-20 13:52:02 +0300
commiteb2f68c830696b37f2574675cf313e91b1ab1f27 (patch)
tree179a8ddef2158d21b8b0711390cc84195d64be66
parent98516d35c8f5700d2fb9b70ccaa9d3ce238cee51 (diff)
Fixed some bugs and tests
-rw-r--r--internal/helper/security.go4
-rw-r--r--internal/helper/security_test.go2
-rw-r--r--internal/service/diff/commit.go2
-rw-r--r--internal/service/diff/numstat_test.go8
-rw-r--r--internal/service/diff/raw_test.go8
5 files changed, 12 insertions, 12 deletions
diff --git a/internal/helper/security.go b/internal/helper/security.go
index 5af5bb9c5..54bc4ce4b 100644
--- a/internal/helper/security.go
+++ b/internal/helper/security.go
@@ -28,8 +28,8 @@ func SanitizeString(str string) string {
// ValidSha checks if SHA is valid
func ValidSha(sha string) error {
- if match, err := regexp.MatchString(`\A[0-9a-f]{40}\z`, sha); !match || err != nil {
- return fmt.Errorf("Invalid Sha")
+ if match, err := regexp.MatchString(`[0-9a-f]{40}`, sha); !match || err != nil {
+ return fmt.Errorf("invalid Sha")
}
return nil
diff --git a/internal/helper/security_test.go b/internal/helper/security_test.go
index 7121f0afc..fa6f59409 100644
--- a/internal/helper/security_test.go
+++ b/internal/helper/security_test.go
@@ -50,7 +50,7 @@ func TestValidSha(t *testing.T) {
{"invalid-sha", true},
{"878d0d962673697c1d038d47e8070f8e7a807028", false},
{"878d0d962673697c1d038d47e8070f8e7a80702", true},
- {"878d0d962673697c1d038d47e8070f8e7a807028a", true},
+ {"878d0d962673697c1d038d47e8070f8e7a807028~", false},
}
for _, tc := range testCases {
diff --git a/internal/service/diff/commit.go b/internal/service/diff/commit.go
index ff07ad506..db185475b 100644
--- a/internal/service/diff/commit.go
+++ b/internal/service/diff/commit.go
@@ -206,7 +206,7 @@ func validateRequest(in requestWithLeftRightCommitIds) error {
return fmt.Errorf("empty RightCommitId")
}
- if err := helper.ValidSha(in.GetLeftCommitId()); err != nil {
+ if err := helper.ValidSha(in.GetRightCommitId()); err != nil {
return fmt.Errorf("invalid RightCommitId SHA")
}
diff --git a/internal/service/diff/numstat_test.go b/internal/service/diff/numstat_test.go
index ddebbf7c1..fe39f2de0 100644
--- a/internal/service/diff/numstat_test.go
+++ b/internal/service/diff/numstat_test.go
@@ -180,19 +180,19 @@ func TestFailedDiffStatsRequest(t *testing.T) {
repo: testRepo,
leftCommitID: "invalidinvalidinvalid",
rightCommitID: "8a0f2ee90d940bfb0ba1e14e8214b0649056e4ab",
- err: codes.Unavailable,
+ err: codes.InvalidArgument,
},
{
desc: "invalid right commit",
repo: testRepo,
leftCommitID: "e4003da16c1c2c3fc4567700121b17bf8e591c6c",
rightCommitID: "invalidinvalidinvalid",
- err: codes.Unavailable,
+ err: codes.InvalidArgument,
},
{
desc: "left commit not found",
repo: testRepo,
- leftCommitID: "z4003da16c1c2c3fc4567700121b17bf8e591c6c",
+ leftCommitID: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
rightCommitID: "8a0f2ee90d940bfb0ba1e14e8214b0649056e4ab",
err: codes.Unavailable,
},
@@ -200,7 +200,7 @@ func TestFailedDiffStatsRequest(t *testing.T) {
desc: "right commit not found",
repo: testRepo,
leftCommitID: "e4003da16c1c2c3fc4567700121b17bf8e591c6c",
- rightCommitID: "z4003da16c1c2c3fc4567700121b17bf8e591c6c",
+ rightCommitID: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
err: codes.Unavailable,
},
}
diff --git a/internal/service/diff/raw_test.go b/internal/service/diff/raw_test.go
index 80c7a1b3d..67d2b9203 100644
--- a/internal/service/diff/raw_test.go
+++ b/internal/service/diff/raw_test.go
@@ -98,7 +98,7 @@ func TestFailedRawDiffRequestDueToValidations(t *testing.T) {
code: codes.InvalidArgument,
},
{
- desc: "invalid left commit",
+ desc: "invalid right commit",
request: &gitalypb.RawDiffRequest{
Repository: testRepo,
RightCommitId: "invalid-sha",
@@ -107,7 +107,7 @@ func TestFailedRawDiffRequestDueToValidations(t *testing.T) {
code: codes.InvalidArgument,
},
{
- desc: "invalid right commit",
+ desc: "invalid left commit",
request: &gitalypb.RawDiffRequest{
Repository: testRepo,
RightCommitId: "8a0f2ee90d940bfb0ba1e14e8214b0649056e4ab",
@@ -208,7 +208,7 @@ func TestFailedRawPatchRequestDueToValidations(t *testing.T) {
code: codes.InvalidArgument,
},
{
- desc: "invalid left commit",
+ desc: "invalid right commit",
request: &gitalypb.RawPatchRequest{
Repository: testRepo,
RightCommitId: "invalid-sha",
@@ -217,7 +217,7 @@ func TestFailedRawPatchRequestDueToValidations(t *testing.T) {
code: codes.InvalidArgument,
},
{
- desc: "invalid right commit",
+ desc: "invalid left commit",
request: &gitalypb.RawPatchRequest{
Repository: testRepo,
RightCommitId: "8a0f2ee90d940bfb0ba1e14e8214b0649056e4ab",