fix: harden thothctl Windows safe I/O
This commit is contained in:
@@ -3,14 +3,14 @@ package main
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/aritmolab/thothii/tools/thothctl/internal/testsupport"
|
||||
)
|
||||
|
||||
func TestRunLogsRedactsAnUnlabelledDeclaredSecret(t *testing.T) {
|
||||
@@ -155,7 +155,7 @@ func TestRunFailsClosedForTraversalAndParentSymlinkSecretSources(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
linkDirectory := filepath.Join(fixture.root, "linked")
|
||||
symlinkOrSkip(t, realDirectory, linkDirectory)
|
||||
testsupport.SymlinkOrSkip(t, realDirectory, linkDirectory)
|
||||
return filepath.Join(linkDirectory, "secret")
|
||||
},
|
||||
"final symlink": func(t *testing.T, fixture cliFixture) string {
|
||||
@@ -164,7 +164,7 @@ func TestRunFailsClosedForTraversalAndParentSymlinkSecretSources(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
linkSecret := filepath.Join(fixture.root, "linked-secret")
|
||||
symlinkOrSkip(t, realSecret, linkSecret)
|
||||
testsupport.SymlinkOrSkip(t, realSecret, linkSecret)
|
||||
return linkSecret
|
||||
},
|
||||
} {
|
||||
@@ -458,13 +458,3 @@ func assertDockerNotInvoked(t *testing.T, fixture cliFixture) {
|
||||
t.Errorf("Docker was invoked: stat error = %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func symlinkOrSkip(t *testing.T, target, link string) {
|
||||
t.Helper()
|
||||
if err := os.Symlink(target, link); err != nil {
|
||||
if runtime.GOOS == "windows" && errors.Is(err, os.ErrPermission) {
|
||||
t.Skip("Windows symlink privilege is unavailable")
|
||||
}
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user