Skip to content

Commit

Permalink
Add duplicate removal for Common Names
Browse files Browse the repository at this point in the history
  • Loading branch information
hslatman committed May 5, 2022
1 parent 4470bf6 commit cf9eb76
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
2 changes: 2 additions & 0 deletions policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ func (p *Policy) Deduplicate() {
allow.Ips = removeDuplicates(allow.Ips)
allow.Emails = removeDuplicates(allow.Emails)
allow.Uris = removeDuplicates(allow.Uris)
allow.CommonNames = removeDuplicates(allow.CommonNames)
}
if deny := p.GetX509().GetDeny(); deny != nil {
deny.Dns = removeDuplicates(deny.Dns)
deny.Ips = removeDuplicates(deny.Ips)
deny.Emails = removeDuplicates(deny.Emails)
deny.Uris = removeDuplicates(deny.Uris)
deny.CommonNames = removeDuplicates(deny.CommonNames)
}
}
if ssh := p.GetSsh(); ssh != nil {
Expand Down
36 changes: 20 additions & 16 deletions policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,32 +54,36 @@ func TestPolicy_Deduplicate(t *testing.T) {
policy: &Policy{
X509: &X509Policy{
Allow: &X509Names{
Dns: []string{"*.local", "*.example.com", "*.local"},
Ips: []string{"192.168.0.0/24", "10.10.10.0/24", "192.168.0.0/24"},
Emails: []string{"@example.com", "@local", "@example.com"},
Uris: []string{"*.local", "*.example.com", "*.local"},
Dns: []string{"*.local", "*.example.com", "*.local"},
Ips: []string{"192.168.0.0/24", "10.10.10.0/24", "192.168.0.0/24"},
Emails: []string{"@example.com", "@local", "@example.com"},
Uris: []string{"*.local", "*.example.com", "*.local"},
CommonNames: []string{"bla", "host", "bla"},
},
Deny: &X509Names{
Dns: []string{"*.local", "*.example.com", "*.local"},
Ips: []string{"192.168.0.0/24", "10.10.10.0/24", "192.168.0.0/24"},
Emails: []string{"@example.com", "@local", "@example.com"},
Uris: []string{"*.local", "*.example.com", "*.local"},
Dns: []string{"*.local", "*.example.com", "*.local"},
Ips: []string{"192.168.0.0/24", "10.10.10.0/24", "192.168.0.0/24"},
Emails: []string{"@example.com", "@local", "@example.com"},
Uris: []string{"*.local", "*.example.com", "*.local"},
CommonNames: []string{"bla", "host", "bla"},
},
},
},
expected: &Policy{
X509: &X509Policy{
Allow: &X509Names{
Dns: []string{"*.local", "*.example.com"},
Ips: []string{"192.168.0.0/24", "10.10.10.0/24"},
Emails: []string{"@example.com", "@local"},
Uris: []string{"*.local", "*.example.com"},
Dns: []string{"*.local", "*.example.com"},
Ips: []string{"192.168.0.0/24", "10.10.10.0/24"},
Emails: []string{"@example.com", "@local"},
Uris: []string{"*.local", "*.example.com"},
CommonNames: []string{"bla", "host"},
},
Deny: &X509Names{
Dns: []string{"*.local", "*.example.com"},
Ips: []string{"192.168.0.0/24", "10.10.10.0/24"},
Emails: []string{"@example.com", "@local"},
Uris: []string{"*.local", "*.example.com"},
Dns: []string{"*.local", "*.example.com"},
Ips: []string{"192.168.0.0/24", "10.10.10.0/24"},
Emails: []string{"@example.com", "@local"},
Uris: []string{"*.local", "*.example.com"},
CommonNames: []string{"bla", "host"},
},
},
},
Expand Down

0 comments on commit cf9eb76

Please sign in to comment.