More windows tests

This commit is contained in:
Viktor Liu
2025-07-03 13:56:32 +02:00
parent f1bb4d2ac3
commit aa30b7afe8
4 changed files with 17 additions and 13 deletions

View File

@@ -75,6 +75,10 @@ func TestSSHClient_DialWithKey(t *testing.T) {
}
func TestSSHClient_CommandExecution(t *testing.T) {
if runtime.GOOS == "windows" && isCI() {
t.Skip("Skipping Windows command execution tests in CI due to S4U authentication issues")
}
server, _, client := setupTestSSHServerAndClient(t)
defer func() {
err := server.Stop()
@@ -174,8 +178,8 @@ func TestSSHClient_ContextCancellation(t *testing.T) {
// Check for actual timeout-related errors rather than string matching
assert.True(t,
errors.Is(err, context.DeadlineExceeded) ||
errors.Is(err, context.Canceled) ||
strings.Contains(err.Error(), "timeout"),
errors.Is(err, context.Canceled) ||
strings.Contains(err.Error(), "timeout"),
"Expected timeout-related error, got: %v", err)
}
})

View File

@@ -401,6 +401,10 @@ func TestSSHServerFeatureCompatibility(t *testing.T) {
t.Skip("Skipping SSH feature compatibility tests in short mode")
}
if runtime.GOOS == "windows" && isCI() {
t.Skip("Skipping Windows SSH compatibility tests in CI due to S4U authentication issues")
}
if !isSSHClientAvailable() {
t.Skip("SSH client not available on this system")
}

View File

@@ -574,11 +574,15 @@ func TestUsernameValidation(t *testing.T) {
{"username_with_newline", "user\nname", true, "invalid characters"},
{"reserved_dot", ".", true, "cannot be '.' or '..'"},
{"reserved_dotdot", "..", true, "cannot be '.' or '..'"},
{"username_with_at_symbol", "user@domain", true, "invalid characters"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Skip hyphen test on Windows - Windows allows usernames starting with hyphens
if tt.name == "username_starting_with_hyphen" && runtime.GOOS == "windows" {
t.Skip("Windows allows usernames starting with hyphens")
}
err := validateUsername(tt.username)
if tt.wantErr {
assert.Error(t, err, "Should reject invalid username")

View File

@@ -35,7 +35,6 @@ func validateUsername(username string) error {
return err
}
warnAboutProblematicCharacters(usernameToValidate)
return nil
}
@@ -57,11 +56,11 @@ func validateUsernameLength(username string) error {
// validateUsernameCharacters checks for invalid characters in Windows usernames
func validateUsernameCharacters(username string) error {
invalidChars := []rune{'"', '/', '\\', '[', ']', ':', ';', '|', '=', ',', '+', '*', '?', '<', '>'}
invalidChars := []rune{'"', '/', '\\', '[', ']', ':', ';', '|', '=', ',', '+', '*', '?', '<', '>', ' ', '`', '&', '\n'}
for _, char := range username {
for _, invalid := range invalidChars {
if char == invalid {
return fmt.Errorf("username contains invalid character '%c'", char)
return fmt.Errorf("username contains invalid characters")
}
}
if char < 32 || char == 127 {
@@ -84,13 +83,6 @@ func validateUsernameFormat(username string) error {
return nil
}
// warnAboutProblematicCharacters warns about characters that may cause issues
func warnAboutProblematicCharacters(username string) {
if strings.Contains(username, "@") {
log.Warnf("username '%s' contains '@' character which may cause login issues", username)
}
}
// createExecutorCommand creates a command using Windows executor for privilege dropping
func (s *Server) createExecutorCommand(session ssh.Session, localUser *user.User, hasPty bool) (*exec.Cmd, error) {
log.Debugf("creating Windows executor command for user %s (Pty: %v)", localUser.Username, hasPty)