Skip to content

Commit

Permalink
Add rules to the output
Browse files Browse the repository at this point in the history
  • Loading branch information
grahamgilbert committed May 28, 2024
1 parent ba24b0d commit 76b2c2d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tables/authdb/authdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type AuthDBRight struct {
Mechanisms []string `json:"mechanisms,omitempty" plist:"mechanisms,omitempty"`
Modified float64 `json:"modified" plist:"modified"`
RequireAppleSigned bool `json:"require-apple-signed,omitempty" plist:"require-apple-signed,omitempty"`
Rule []string `json:"rule,omitempty" plist:"rule,omitempty"`
SessionOwner bool `json:"session-owner" plist:"session-owner"`
Shared bool `json:"shared" plist:"shared"`
Timeout int `json:"timeout" plist:"timeout"`
Expand All @@ -42,6 +43,7 @@ func AuthDBColumns() []table.ColumnDefinition {
table.TextColumn("mechanisms"),
table.TextColumn("modified"),
table.TextColumn("require_apple_signed"),
table.TextColumn("rule"),
table.TextColumn("session_owner"),
table.TextColumn("shared"),
table.TextColumn("timeout"),
Expand Down Expand Up @@ -117,6 +119,7 @@ func buildOutput(rights []AuthDBRight) []map[string]string {
"mechanisms": strings.Join(right.Mechanisms, ","),
"modified": fmt.Sprintf("%f", right.Modified),
"require_apple_signed": utils.BoolToString(right.RequireAppleSigned),
"rule": strings.Join(right.Rule, ","),
"session_owner": utils.BoolToString(right.SessionOwner),
"shared": utils.BoolToString(right.Shared),
"timeout": strconv.Itoa(right.Timeout),
Expand Down
39 changes: 39 additions & 0 deletions tables/authdb/authdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,3 +292,42 @@ func TestBuildOutput(t *testing.T) {

assert.Equal(t, expectedOutput, actualOutput, "Expected output to match")
}

func TestGetRuleWithRules(t *testing.T) {
runner := utils.MockCmdRunner{
Output: `<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>class</key>
<string>rule</string>
<key>created</key>
<real>730353220.36463201</real>
<key>modified</key>
<real>738604357.04363894</real>
<key>rule</key>
<array>
<string>allow</string>
</array>
<key>version</key>
<integer>0</integer>
</dict>
</plist>`,
Err: nil,
}

expected := AuthDBRight{
Name: "system.preferences.datetime",
Class: "rule",
Created: 730353220.36463201,
Modified: 738604357.04363894,
Rule: []string{"allow"},
Version: 0,
}

r := utils.Runner{}
r.Runner = runner
out, err := getRule(r, "system.preferences.datetime")
assert.NoError(t, err)
assert.Equal(t, expected, out)
}

0 comments on commit 76b2c2d

Please sign in to comment.