Skip to content

Commit

Permalink
(WIP) fix?
Browse files Browse the repository at this point in the history
Signed-off-by: Aditya Sirish <aditya@saky.in>
  • Loading branch information
adityasaky committed May 25, 2024
1 parent c5053bd commit 78fbe85
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 12 deletions.
6 changes: 3 additions & 3 deletions internal/gitinterface/commit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package gitinterface
import (
"bytes"
"context"
"os"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -36,8 +35,9 @@ var (
)

func TestRepositoryCommit(t *testing.T) {
os.Mkdir("gittuf-test", 0o775)
repo := CreateTestGitRepository(t, "gittuf-test")
// os.Mkdir("gittuf-test", 0o775)
tempDir := t.TempDir()
repo := CreateTestGitRepository(t, tempDir)

refName := "refs/heads/main"
treeBuilder := NewReplacementTreeBuilder(repo)
Expand Down
44 changes: 35 additions & 9 deletions internal/gitinterface/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
package gitinterface

import (
"fmt"
"os"
"os/exec"
"path"
"path/filepath"
"runtime"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -40,15 +43,15 @@ var (
func CreateTestGitRepository(t *testing.T, dir string) *Repository {
t.Helper()

var keysDir string
if dir == "gittuf-test" {
dir = dir + "/repo"
os.Mkdir(dir, 0o755)
keysDir = dir + "/keys"
os.Mkdir(keysDir, 0o755)
} else {
keysDir = t.TempDir()
}
// var keysDir string
// if dir == "gittuf-test" {
// dir = dir + "/repo"
// os.Mkdir(dir, 0o755)
// keysDir = dir + "/keys"
// os.Mkdir(keysDir, 0o755)
// } else {
keysDir := t.TempDir()
// }

setupSigningKeys(t, keysDir)

Expand Down Expand Up @@ -94,4 +97,27 @@ func setupSigningKeys(t *testing.T, dir string) {
if err := os.WriteFile(publicKeyPath, sshPublicKey, 0o600); err != nil {
t.Fatal(err)
}

// Inspired by Minikube
if runtime.GOOS == "windows" {
powershellPath, err := exec.LookPath("powershell")
if err != nil {
t.Fatal(err)
}

currentUserSidCmd := exec.Command(powershellPath, "-NoProfile", "-NonInteractive", "([System.Security.Principal.WindowsIdentity]::GetCurrent()).User.Value")
currentUserSidB, err := currentUserSidCmd.Output()
if err != nil {
t.Fatal(err)
}
currentUserSid := strings.TrimSpace(string(currentUserSidB))

for _, keyPath := range []string{privateKeyPath, publicKeyPath} {
icaclsArgs := fmt.Sprintf(`"%s" /grant:r *%s:F /inheritancelevel:r`, keyPath, currentUserSid)
icaclsCmd := exec.Command(powershellPath, "-NoProfile", "-NonInteractive", "icacls.exe", icaclsArgs)
if err := icaclsCmd.Run(); err != nil {
t.Fatal(err)
}
}
}
}

0 comments on commit 78fbe85

Please sign in to comment.