Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CI github action for testing on push and PR #205

Merged
merged 1 commit into from
Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: CI
on:
- push
- pull_request

jobs:
test:
runs-on: 'windows-2019'
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
- run: go test -gcflags=all=-d=checkptr -v ./...
40 changes: 26 additions & 14 deletions pkg/security/grantvmgroupaccess_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ import (
exec "golang.org/x/sys/execabs"
)

const (
vmAccountName = `NT VIRTUAL MACHINE\\Virtual Machines`
vmAccountSID = "S-1-5-83-0"
)

// TestGrantVmGroupAccess verifies for the three case of a file, a directory,
// and a file in a directory that the appropriate ACEs are set, including
// inheritance in the second two examples. These are the expected ACES. Is
Expand Down Expand Up @@ -59,9 +64,9 @@ func TestGrantVmGroupAccess(t *testing.T) {
t.Fatal(err)
}

verifyicacls(t,
verifyVMAccountDACLs(t,
f.Name(),
[]string{`NT VIRTUAL MACHINE\\Virtual Machines:(R)`},
[]string{`(R)`},
)

// Two items here:
Expand All @@ -74,35 +79,42 @@ func TestGrantVmGroupAccess(t *testing.T) {
//
// In properties for the directory, advanced security settings, this will
// show as a single line "Allow/Virtual Machines/Read/Inherited from none/This folder, subfolder and files
verifyicacls(t,
verifyVMAccountDACLs(t,
d,
[]string{`NT VIRTUAL MACHINE\\Virtual Machines:(R)`, `NT VIRTUAL MACHINE\\Virtual Machines:(OI)(CI)(IO)(GR)`},
[]string{`(R)`, `(OI)(CI)(IO)(GR)`},
)

verifyicacls(t,
verifyVMAccountDACLs(t,
find.Name(),
[]string{`NT VIRTUAL MACHINE\\Virtual Machines:(I)(R)`},
[]string{`(I)(R)`},
)

}

func verifyicacls(t *testing.T, name string, aces []string) {
func verifyVMAccountDACLs(t *testing.T, name string, permissions []string) {
cmd := exec.Command("icacls", name)
outb, err := cmd.CombinedOutput()
if err != nil {
t.Fatal(err)
}
out := string(outb)

for _, ace := range aces {
for _, p := range permissions {
// Avoid '(' and ')' being part of match groups
ace = strings.Replace(ace, "(", "\\(", -1)
ace = strings.Replace(ace, ")", "\\)", -1)
p = strings.Replace(p, "(", "\\(", -1)
p = strings.Replace(p, ")", "\\)", -1)

nameToCheck := vmAccountName + ":" + p
sidToCheck := vmAccountSID + ":" + p

rxName := regexp.MustCompile(nameToCheck)
rxSID := regexp.MustCompile(sidToCheck)

matchesName := rxName.FindAllStringIndex(out, -1)
matchesSID := rxSID.FindAllStringIndex(out, -1)

rx := regexp.MustCompile(ace)
matches := rx.FindAllStringIndex(out, -1)
if len(matches) != 1 {
t.Fatalf("expected one match for %s got %d\n%s", ace, len(matches), out)
if len(matchesName) != 1 && len(matchesSID) != 1 {
t.Fatalf("expected one match for %s or %s\n%s", nameToCheck, sidToCheck, out)
}
}
}