Skip to content

Commit

Permalink
i/p/requestrules: add test cases for partially- and fully-expired con…
Browse files Browse the repository at this point in the history
…flicing merged rules

Signed-off-by: Oliver Calder <[email protected]>
  • Loading branch information
olivercalder committed Dec 18, 2024
1 parent 116ba56 commit 76cf4f3
Showing 1 changed file with 97 additions and 0 deletions.
97 changes: 97 additions & 0 deletions interfaces/prompting/requestrules/requestrules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,103 @@ func (s *requestrulesSuite) TestAddRuleMerges(c *C) {
},
},
},
{
// First rule is fully expired but would otherwise conflict with
// the second rule.
input: []prompting.PermissionMap{
{
"read": &prompting.PermissionEntry{
Outcome: prompting.OutcomeDeny,
Lifespan: prompting.LifespanTimespan,
Duration: "1ns", // Will expire and not conflict
},
"write": &prompting.PermissionEntry{
Outcome: prompting.OutcomeAllow,
Lifespan: prompting.LifespanTimespan,
Duration: "1ns", // Will expire and not conflict
},
},
{
"read": &prompting.PermissionEntry{
Outcome: prompting.OutcomeAllow,
Lifespan: prompting.LifespanTimespan,
Duration: "10s",
},
"write": &prompting.PermissionEntry{
Outcome: prompting.OutcomeDeny,
Lifespan: prompting.LifespanForever,
},
},
},
output: []prompting.PermissionMap{
{
"read": &prompting.PermissionEntry{
Outcome: prompting.OutcomeAllow,
Lifespan: prompting.LifespanTimespan,
Duration: "10s",
},
"write": &prompting.PermissionEntry{
Outcome: prompting.OutcomeDeny,
Lifespan: prompting.LifespanForever,
},
},
},
},
{
// First rule is partially expired but would otherwise conflict
// with the second rule.
input: []prompting.PermissionMap{
{
"read": &prompting.PermissionEntry{
Outcome: prompting.OutcomeDeny,
Lifespan: prompting.LifespanTimespan,
Duration: "1ns", // Will expire and not conflict
},
"write": &prompting.PermissionEntry{
Outcome: prompting.OutcomeDeny,
Lifespan: prompting.LifespanTimespan,
Duration: "10s",
},
"execute": &prompting.PermissionEntry{
Outcome: prompting.OutcomeAllow,
Lifespan: prompting.LifespanForever,
},
},
{
"read": &prompting.PermissionEntry{
Outcome: prompting.OutcomeAllow,
Lifespan: prompting.LifespanTimespan,
Duration: "10s",
},
"write": &prompting.PermissionEntry{
Outcome: prompting.OutcomeDeny,
Lifespan: prompting.LifespanForever,
},
"execute": &prompting.PermissionEntry{
Outcome: prompting.OutcomeAllow,
Lifespan: prompting.LifespanTimespan,
Duration: "10s",
},
},
},
output: []prompting.PermissionMap{
{
"read": &prompting.PermissionEntry{
Outcome: prompting.OutcomeAllow,
Lifespan: prompting.LifespanTimespan,
Duration: "10s",
},
"write": &prompting.PermissionEntry{
Outcome: prompting.OutcomeDeny,
Lifespan: prompting.LifespanForever,
},
"execute": &prompting.PermissionEntry{
Outcome: prompting.OutcomeAllow,
Lifespan: prompting.LifespanForever,
},
},
},
},
} {
// Set root so rule creation does not interfere between test cases
dirs.SetRootDir(c.MkDir())
Expand Down

0 comments on commit 76cf4f3

Please sign in to comment.