forked from sonic-net/sonic-utilities
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refix: Validate acl.json after parsing, add unit test (sonic-net#322)
* Refix: Validate acl.json after parsing, add unit test * Include test input files in package
- Loading branch information
1 parent
ac43b20
commit 2ce2b78
Showing
9 changed files
with
357 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[pytest] | ||
filterwarnings = | ||
ignore::DeprecationWarning |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
{ | ||
"acl": { | ||
"acl-sets": { | ||
"acl-set": { | ||
"sonic-ssh-only": { | ||
"acl-entries": { | ||
"acl-entry": { | ||
"1": { | ||
"config": { | ||
"sequence-id": 1 | ||
}, | ||
"actions": { | ||
"config": { | ||
"forwarding-action": "ACCEPT" | ||
} | ||
}, | ||
"ip": { | ||
"config": { | ||
"protocol": "IP_TCP", | ||
"source-ip-address": "192.168.0.0/18" | ||
} | ||
}, | ||
"transport": { | ||
"config": { | ||
"destination-port": "22" | ||
} | ||
} | ||
}, | ||
"2": { | ||
"config": { | ||
"sequence-id": 2 | ||
}, | ||
"actions": { | ||
"config": { | ||
"forwarding-action": "ACCEPT" | ||
} | ||
}, | ||
"ip": { | ||
"config": { | ||
"protocol": "IP_TCP", | ||
"source-ip-address": "192.168.192.0/18" | ||
} | ||
}, | ||
"transport": { | ||
"config": { | ||
"destination-port": "22" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"config": { | ||
"name": "sonic-ssh-only" | ||
} | ||
}, | ||
"Sonic-SNMP_ACL": { | ||
"acl-entries": { | ||
"acl-entry": { | ||
"1": { | ||
"config": { | ||
"sequence-id": 1 | ||
}, | ||
"actions": { | ||
"config": { | ||
"forwarding-action": "ACCEPT" | ||
} | ||
}, | ||
"ip": { | ||
"config": { | ||
"protocol": "IP_UDP", | ||
"source-ip-address": "192.168.0.0/18" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"config": { | ||
"name": "Sonic-SNMP_ACL" | ||
} | ||
}, | ||
"sonic-everflow": { | ||
"acl-entries": { | ||
"acl-entry": { | ||
"1": { | ||
"config": { | ||
"sequence-id": 1 | ||
}, | ||
"actions": { | ||
"config": { | ||
"forwarding-action": "ACCEPT" | ||
} | ||
}, | ||
"ip": { | ||
"config": { | ||
"protocol": "IP_TCP", | ||
"source-ip-address": "127.0.0.1/32", | ||
"destination-ip-address": "127.0.0.1/32" | ||
} | ||
}, | ||
"transport": { | ||
"config": { | ||
"source-port": "0", | ||
"destination-port": "0" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"config": { | ||
"name": "sonic-everflow" | ||
} | ||
}, | ||
"everflowV6": { | ||
"acl-entries": { | ||
"acl-entry": { | ||
"1": { | ||
"config": { | ||
"sequence-id": 1 | ||
}, | ||
"actions": { | ||
"config": { | ||
"forwarding-action": "ACCEPT" | ||
} | ||
}, | ||
"ip": { | ||
"config": { | ||
"protocol": "IP_TCP", | ||
"source-ip-address": "::1/128", | ||
"destination-ip-address": "::1/128" | ||
} | ||
}, | ||
"transport": { | ||
"config": { | ||
"source-port": "0", | ||
"destination-port": "0" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"config": { | ||
"name": "everflowV6" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
{ | ||
"acl": { | ||
"acl-sets": { | ||
"acl-set": { | ||
"sonic-ssh-only": { | ||
"acl-entries": { | ||
"acl-entry": { | ||
"1": { | ||
"config": { | ||
"sequence-id": 1 | ||
}, | ||
"actions": { | ||
"config": { | ||
"forwarding-action": "ACCEPT" | ||
} | ||
}, | ||
"ip": { | ||
"config": { | ||
"protocol": "IP_TCP", | ||
"source-ip-address": "192.168.0.0/18" | ||
} | ||
}, | ||
"transport": { | ||
"config": { | ||
"destination-port": "22" | ||
} | ||
} | ||
}, | ||
"2": { | ||
"config": { | ||
"sequence-id": 2 | ||
}, | ||
"actions": { | ||
"config": { | ||
"forwarding-action": "ACCEPT" | ||
} | ||
}, | ||
"ip": { | ||
"config": { | ||
"protocol": "IP_TCP", | ||
"source-ip-address": "192.168.192.0/18" | ||
} | ||
}, | ||
"transport": { | ||
"config": { | ||
"destination-port": "22" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"config": { | ||
"name": "sonic-ssh-only" | ||
} | ||
}, | ||
"Sonic-SNMP_ACL": { | ||
"acl-entries": { | ||
"acl-entry": { | ||
"1": { | ||
"config": { | ||
"sequence-id": 1 | ||
}, | ||
"actions": { | ||
"config": { | ||
"forwarding-action": "ACCEPT" | ||
} | ||
}, | ||
"ip": { | ||
"config": { | ||
"protocol": "IP_UDP", | ||
"source-ip-address": "192.168.0.0/18" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"config": { | ||
"name": "Sonic-SNMP_ACL" | ||
} | ||
}, | ||
"sonic-everflow": { | ||
"acl-entries": { | ||
"acl-entry": { | ||
"1": { | ||
"config": { | ||
"sequence-id": 1 | ||
}, | ||
"actions": { | ||
"config": { | ||
"forwarding-action": "ACCEPT" | ||
} | ||
}, | ||
"ip": { | ||
"config": { | ||
"protocol": "IP_TCP", | ||
"source-ip-address": "127.0.0.1/32", | ||
"destination-ip-address": "127.0.0.1/32" | ||
} | ||
}, | ||
"transport": { | ||
"config": { | ||
"source-port": "0", | ||
"destination-port": "0" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"config": { | ||
"name": "sonic-everflow" | ||
} | ||
}, | ||
"everflowV6": { | ||
"acl-entries": { | ||
"acl-entry": { | ||
"1": { | ||
"config": { | ||
"sequence-id": 1 | ||
}, | ||
"actions": { | ||
"config": { | ||
"forwarding-action": "ACCEPT" | ||
} | ||
}, | ||
"ip": { | ||
"config": { | ||
"protocol": "IP_TCP", | ||
"source-ip-address": "::1/128", | ||
"destination-ip-address": "::1/128" | ||
} | ||
}, | ||
"transport": { | ||
"config": { | ||
"source-port": "0", | ||
"destination-port": "0" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"config": { | ||
"name": "everflowV6" | ||
} | ||
}, | ||
"TimeStampHeader": "Configuration last updated on: [9/13/2018 11:00:16 AM]" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"acl": { | ||
"acl-sets": { | ||
"acl-set": {} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import sys | ||
import os | ||
import pytest | ||
from unittest import TestCase | ||
|
||
test_path = os.path.dirname(os.path.abspath(__file__)) | ||
modules_path = os.path.dirname(test_path) | ||
sys.path.insert(0, modules_path) | ||
|
||
from acl_loader import * | ||
from acl_loader.main import * | ||
|
||
class TestAclLoader(TestCase): | ||
def setUp(self): | ||
pass | ||
|
||
def test_acl_empty(self): | ||
yang_acl = AclLoader.parse_acl_json(os.path.join(test_path, 'acl_input/empty_acl.json')) | ||
assert len(yang_acl.acl.acl_sets.acl_set) == 0 | ||
|
||
def test_valid(self): | ||
yang_acl = AclLoader.parse_acl_json(os.path.join(test_path, 'acl_input/acl1.json')) | ||
assert len(yang_acl.acl.acl_sets.acl_set) == 4 | ||
|
||
def test_invalid(self): | ||
with pytest.raises(AclLoaderException): | ||
yang_acl = AclLoader.parse_acl_json(os.path.join(test_path, 'acl_input/acl2.json')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[pytest] | ||
filterwarnings = | ||
ignore::DeprecationWarning |