-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(remote): improve input validation and security in remote operations
- Change file permissions from `0o700` to `0o600` in `WriteKey` function - Import `regexp` package in `remote.go` - Add `sanitizeInput` and `isValidInput` functions for input validation - Use sanitized inputs in `RemotePushNamedBranch` function - Add unit tests for `sanitizeInput` function in new `remote_test.go` file Signed-off-by: appleboy <[email protected]>
- Loading branch information
Showing
3 changed files
with
69 additions
and
3 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
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
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package repo | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestSanitizeInput(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
input string | ||
want string | ||
}{ | ||
{ | ||
name: "valid input with alphanumeric characters", | ||
input: "feature-branch", | ||
want: "feature-branch", | ||
}, | ||
{ | ||
name: "valid input with dots and slashes", | ||
input: "release/1.0.0", | ||
want: "release/1.0.0", | ||
}, | ||
{ | ||
name: "invalid input with spaces", | ||
input: "invalid branch", | ||
want: "", | ||
}, | ||
{ | ||
name: "invalid input with special characters", | ||
input: "invalid@branch!", | ||
want: "", | ||
}, | ||
{ | ||
name: "empty input", | ||
input: "", | ||
want: "", | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := sanitizeInput(tt.input); got != tt.want { | ||
t.Errorf("sanitizeInput() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |