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

106 add synthesis tests #108

Merged
merged 5 commits into from
Dec 31, 2024
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
130 changes: 130 additions & 0 deletions pkg/collector/data/examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,3 +335,133 @@ var ExampleDumbeldore = Example{
},
},
}

// ExampleTwoDeniesSimple
// Simple example with two denies
// Slytherin can talk to all but Dumbledore
// Gryffindor can talk to all but Dumbledore
var ExampleTwoDeniesSimple = Example{
vms: []string{"Slytherin", "Hufflepuff", "Gryffindor", "Dumbledore1", "Dumbledore2"},
groups: map[string][]string{
"Slytherin": {"Slytherin"},
"Hufflepuff": {"Hufflepuff"},
"Gryffindor": {"Gryffindor"},
"Dumbledore": {"Dumbledore1", "Dumbledore2"},
"Dumbledore1": {"Dumbledore1"},
"Dumbledore2": {"Dumbledore2"},
},
policies: []category{
{
name: "Two-Denys-Simple-Test",
categoryType: "Application",
rules: []rule{
{
name: "no-conn-to-dumb1",
id: 1,
source: "ANY",
dest: "Dumbledore1",
services: []string{"ANY"},
action: drop,
},
{
name: "no-conn-to-dumb2",
id: 2,
source: "ANY",
dest: "Dumbledore2",
services: []string{"ANY"},
action: drop,
},
{
name: "Slytherin-to-all",
id: 3,
source: "Slytherin",
dest: "ANY",
services: []string{"ANY"},
action: allow,
},
{
name: "Gryffindor-to-all",
id: 4,
source: "Gryffindor",
dest: "ANY",
services: []string{"ANY"},
action: allow,
},
},
},
{
name: "Default-L3-Section",
categoryType: "Application",
rules: []rule{
defaultDenyRule(denyRuleIDApp),
},
},
},
}

// ExampleDenyPassSimple one pass and two denies, span over two categories
// all can talk to all but Slytherin and Hufflepuff (or to Gryffindor and Dumbledore)
var ExampleDenyPassSimple = Example{
vms: []string{"Slytherin", "Hufflepuff", "Gryffindor", "Dumbledore1", "Dumbledore2"},
groups: map[string][]string{
"Slytherin": {"Slytherin"},
"Hufflepuff": {"Hufflepuff"},
"Gryffindor": {"Gryffindor"},
"Dumbledore": {"Dumbledore1", "Dumbledore2"},
"Dumbledore1": {"Dumbledore1"},
"Dumbledore2": {"Dumbledore2"},
},
policies: []category{
{
name: "Env-pass-and-deny",
categoryType: "Environment",
rules: []rule{
{
name: "pass-all-to-dumb",
id: 10218,
source: "ANY",
dest: "Dumbledore",
services: []string{"ANY"},
action: jumpToApp,
},
{
name: "deny-all-to-Hufflepuff",
id: 10219,
source: "ANY",
dest: "Hufflepuff",
services: []string{"ANY"},
action: drop,
},
{
name: "deny-all-to-Slytherin",
id: 10220,
source: "ANY",
dest: "Slytherin",
services: []string{"ANY"},
action: drop,
},
},
},
{
name: "App-Allow-All",
categoryType: "Application",
rules: []rule{
{
name: "allow-all-to-all",
id: newRuleID,
source: "ANY",
dest: "ANY",
services: []string{"ANY"},
action: allow,
},
},
},
{
name: "Default-L3-Section",
categoryType: "Application",
rules: []rule{
defaultDenyRule(denyRuleIDApp),
},
},
},
}
8 changes: 8 additions & 0 deletions pkg/synthesis/synthesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ var allTests = []synthesisTest{
name: "ExampleDumbeldore",
exData: data.ExampleDumbeldore,
},
{
name: "ExampleTwoDeniesSimple",
exData: data.ExampleTwoDeniesSimple,
},
{
name: "ExampleDenyPassSimple",
exData: data.ExampleDenyPassSimple,
},
}

func (synTest *synthesisTest) runPreprocessing(t *testing.T, mode testMode) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Allow Only Rules
~~~~~~~~~~~~~~~~~
inbound rules
All Connections from (*) to (*)
outbound rules
All Connections from (*) to (*)
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
category: Environment
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
symbolic inbound rules:
0. action: jump_to_application paths: All Connections from (*) to (group = Dumbledore)
1. action: deny paths: All Connections from (*) to (group = Hufflepuff)
2. action: deny paths: All Connections from (*) to (group = Slytherin)
symbolic outbound rules:
0. action: jump_to_application paths: All Connections from (*) to (group = Dumbledore)
1. action: deny paths: All Connections from (*) to (group = Hufflepuff)
2. action: deny paths: All Connections from (*) to (group = Slytherin)
category: Application
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
symbolic inbound rules:
0. action: allow paths: All Connections from (*) to (*)
1. action: deny paths: All Connections from (*) to (*)
symbolic outbound rules:
0. action: allow paths: All Connections from (*) to (*)
1. action: deny paths: All Connections from (*) to (*)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Allow Only Rules
~~~~~~~~~~~~~~~~~
inbound rules
All Connections from (group = Slytherin) to (group != Dumbledore1 and group != Dumbledore2)
All Connections from (group = Gryffindor) to (group != Dumbledore1 and group != Dumbledore2)
outbound rules
All Connections from (group = Slytherin) to (group != Dumbledore1 and group != Dumbledore2)
All Connections from (group = Gryffindor) to (group != Dumbledore1 and group != Dumbledore2)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
category: Application
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
symbolic inbound rules:
0. action: deny paths: All Connections from (*) to (group = Dumbledore1)
1. action: deny paths: All Connections from (*) to (group = Dumbledore2)
2. action: allow paths: All Connections from (group = Slytherin) to (*)
3. action: allow paths: All Connections from (group = Gryffindor) to (*)
4. action: deny paths: All Connections from (*) to (*)
symbolic outbound rules:
0. action: deny paths: All Connections from (*) to (group = Dumbledore1)
1. action: deny paths: All Connections from (*) to (group = Dumbledore2)
2. action: allow paths: All Connections from (group = Slytherin) to (*)
3. action: allow paths: All Connections from (group = Gryffindor) to (*)
4. action: deny paths: All Connections from (*) to (*)
Loading