Skip to content

Commit 28f8c7a

Browse files
hemantskcaphrim007
authored andcommitted
Protocol Inspection - Profile, Compliance, Signature (#1359)
* Protocol Inspection - Profile, Signature, Compliance * Protocol Inspection * Protocol Inspection * securiy__init__.py flake changes * Revert "securiy__init__.py flake changes" This reverts commit 01d31e7. * securiy__init__.py flake changes * version support
1 parent 653ed0c commit 28f8c7a

4 files changed

Lines changed: 426 additions & 1 deletion

File tree

f5/bigip/tm/security/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@
3131
from f5.bigip.tm.security.analytics import Analytics
3232
from f5.bigip.tm.security.dos import Dos
3333
from f5.bigip.tm.security.firewall import Firewall
34+
from f5.bigip.tm.security.protocol_inspection import Protocol_Inspection
3435

3536

3637
class Security(OrganizingCollection):
3738
"""BIG-IP® Security organizing collection."""
3839

3940
def __init__(self, tm):
4041
super(Security, self).__init__(tm)
41-
self._meta_data['allowed_lazy_attributes'] = [Dos, Firewall, Analytics]
42+
self._meta_data['allowed_lazy_attributes'] = [Dos, Firewall, Analytics, Protocol_Inspection]
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# coding=utf-8
2+
#
3+
# Copyright 2017 F5 Networks Inc.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
"""BIG-IP® Advanced Firewall Manager™ (AFM®) module.
19+
20+
REST URI
21+
``http://localhost/mgmt/tm/security/protocol-inspection``
22+
23+
GUI Path
24+
``Security --> Protocol Security --> Inspection_Profiles
25+
Security --> Protocol Security --> Inspection_List
26+
``
27+
28+
REST Kind
29+
``tm:security:protocol-inspection*``
30+
"""
31+
32+
from f5.bigip.resource import Collection
33+
from f5.bigip.resource import OrganizingCollection
34+
from f5.bigip.resource import Resource
35+
from f5.sdk_exception import UnsupportedMethod
36+
37+
38+
class Protocol_Inspection(OrganizingCollection):
39+
"""BIG-IP® Protocol Inspection Organizing collection"""
40+
def __init__(self, security):
41+
super(Protocol_Inspection, self).__init__(security)
42+
self._meta_data['allowed_lazy_attributes'] = [
43+
Profiles,
44+
Compliances,
45+
Signatures,
46+
]
47+
48+
49+
class Profiles(Collection):
50+
""""BIG-IP® Protocol Inspection Profile collection"""
51+
def __init__(self, protocol_inspection):
52+
super(Profiles, self).__init__(protocol_inspection)
53+
self._meta_data['allowed_lazy_attributes'] = [Profile]
54+
self._meta_data['attribute_registry'] = \
55+
{'tm:security:protocol-inspection:profile:profilestate':
56+
Profile}
57+
58+
59+
class Profile(Resource):
60+
"""BIG-IP® Protocol Inspection Profile resource"""
61+
def __init__(self, profiles):
62+
super(Profile, self).__init__(profiles)
63+
self._meta_data['required_json_kind'] = \
64+
'tm:security:protocol-inspection:profile:profilestate'
65+
self._meta_data['required_creation_parameters'].update(('partition',))
66+
67+
68+
class Compliances(Collection):
69+
def __init__(self, protocol_inspection):
70+
super(Compliances, self).__init__(protocol_inspection)
71+
self._meta_data['allowed_lazy_attributes'] = [Compliance]
72+
self._meta_data['attribute_registry'] = \
73+
{'tm:security:protocol-inspection:compliance:compliancestate':
74+
Compliance}
75+
76+
77+
class Compliance(Resource):
78+
"""BIG-IP® Protocol Inspection Compliance resource"""
79+
def __init__(self, compliances):
80+
super(Compliance, self).__init__(compliances)
81+
self._meta_data['required_json_kind'] = \
82+
'tm:security:protocol-inspection:compliance:compliancestate'
83+
self._meta_data['required_load_parameters'] = set()
84+
85+
def create(self, **kwargs):
86+
raise UnsupportedMethod(
87+
"%s does not support the create method" % self.__class__.__name__
88+
)
89+
90+
def delete(self, **kwargs):
91+
raise UnsupportedMethod(
92+
"%s does not support the delete method" % self.__class__.__name__
93+
)
94+
95+
def modify(self, **kwargs):
96+
raise UnsupportedMethod(
97+
"%s does not support the delete method" % self.__class__.__name__
98+
)
99+
100+
101+
class Signatures(Collection):
102+
"""BIG-IP® Protocol Inspection Signature collection"""
103+
def __init__(self, protocol_inspection):
104+
super(Signatures, self).__init__(protocol_inspection)
105+
self._meta_data['allowed_lazy_attributes'] = [Signature]
106+
self._meta_data['attribute_registry'] = \
107+
{'tm:security:protocol-inspection:signature:signaturestate':
108+
Signature}
109+
110+
111+
class Signature(Resource):
112+
"""BIG-IP® Protocol Inspection Signature resource"""
113+
def __init__(self, signatures):
114+
super(Signature, self).__init__(signatures)
115+
self._meta_data['required_json_kind'] = \
116+
'tm:security:protocol-inspection:signature:signaturestate'
117+
self._meta_data['required_creation_parameters'].update((
118+
'partition', 'sig', 'description'))
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
# Copyright 2017 F5 Networks Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
16+
import pytest
17+
from requests.exceptions import HTTPError
18+
19+
from distutils.version import LooseVersion
20+
from f5.bigip.tm.security.protocol_inspection import Compliance
21+
from f5.bigip.tm.security.protocol_inspection import Profile
22+
from f5.bigip.tm.security.protocol_inspection import Signature
23+
24+
DESC = 'TEST DESCRIPTION'
25+
26+
27+
@pytest.fixture(scope='function')
28+
def profile(mgmt_root):
29+
r1 = mgmt_root.tm.security.protocol_inspection.profiles.profile.create(
30+
name='fake_prof', partition='Common')
31+
yield r1
32+
r1.delete()
33+
34+
35+
@pytest.fixture(scope='function')
36+
def signature(mgmt_root):
37+
param_set = {'name': 'fake_signature', 'description': DESC,
38+
'sig': 'content:\"hello\";', 'partition': 'Common'}
39+
r1 = mgmt_root.tm.security.protocol_inspection.\
40+
signatures.signature.create(**param_set)
41+
yield r1
42+
r1.delete()
43+
44+
45+
@pytest.mark.skipif(
46+
LooseVersion(pytest.config.getoption('--release')) < LooseVersion('13.1.0'),
47+
reason='This collection is fully implemented on 13.1.0 or greater.'
48+
)
49+
class TestProfile(object):
50+
"""Profile functional tests"""
51+
52+
def test_create_req_args(self, profile):
53+
URI = 'https://localhost/mgmt/tm/security/' \
54+
'protocol-inspection/profile/~Common~fake_prof'
55+
assert profile.name == 'fake_prof'
56+
assert profile.partition == 'Common'
57+
assert profile.selfLink.startswith(URI)
58+
assert not hasattr(profile, 'description')
59+
60+
def test_create_opt_args(self, mgmt_root):
61+
prof = mgmt_root.tm.security.\
62+
protocol_inspection.profiles.profile.create(
63+
name='fake_prof', partition='Common',
64+
defaultsFrom='/Common/protocol_inspection_http',
65+
description=DESC)
66+
URI = 'https://localhost/mgmt/tm/security/' \
67+
'protocol-inspection/profile/~Common~fake_prof'
68+
assert prof.name == 'fake_prof'
69+
assert prof.partition == 'Common'
70+
assert prof.selfLink.startswith(URI)
71+
assert hasattr(prof, 'description')
72+
assert hasattr(prof, 'defaultsFrom')
73+
assert prof.description == DESC
74+
prof.delete()
75+
76+
def test_refresh(self, mgmt_root, profile):
77+
profc = mgmt_root.tm.security.protocol_inspection.profiles
78+
prof = profc.profile.load(name='fake_prof', partition='Common')
79+
assert profile.name == prof.name
80+
assert profile.kind == prof.kind
81+
assert profile.selfLink == prof.selfLink
82+
assert not hasattr(profile, 'description')
83+
assert not hasattr(prof, 'description')
84+
prof.modify(description=DESC)
85+
assert hasattr(prof, 'description')
86+
assert prof.description == DESC
87+
profile.refresh()
88+
assert profile.selfLink == prof.selfLink
89+
assert hasattr(profile, 'description')
90+
assert profile.description == prof.description
91+
92+
def test_delete(self, mgmt_root):
93+
rc = mgmt_root.tm.security.protocol_inspection.profiles
94+
r1 = rc.profile.create(name='fake_prof', partition='Common')
95+
r1.delete()
96+
with pytest.raises(HTTPError) as err:
97+
rc.profile.load(name='fake_prof', partition='Common')
98+
assert err.value.response.status_code == 404
99+
100+
def test_load_no_object(self, mgmt_root):
101+
rc = mgmt_root.tm.security.protocol_inspection.profiles
102+
with pytest.raises(HTTPError) as err:
103+
rc.profile.load(name='fake_prof', partition='Common')
104+
assert err.value.response.status_code == 404
105+
106+
def test_profile_collection(self, mgmt_root, profile):
107+
r1 = profile
108+
URI = 'https://localhost/mgmt/tm/security/' \
109+
'protocol-inspection/profile/~Common~fake_prof'
110+
assert r1.name == 'fake_prof'
111+
assert r1.partition == 'Common'
112+
assert r1.selfLink.startswith(URI)
113+
rc = mgmt_root.tm.security.protocol_inspection.\
114+
profiles.get_collection()
115+
assert isinstance(rc, list)
116+
assert len(rc)
117+
assert isinstance(rc[0], Profile)
118+
119+
120+
@pytest.mark.skipif(
121+
LooseVersion(pytest.config.getoption('--release')) < LooseVersion('13.1.0'),
122+
reason='This collection is fully implemented on 13.1.0 or greater.'
123+
)
124+
class TestSignature(object):
125+
"""Signature functional tests"""
126+
127+
def test_create_req_args(self, signature):
128+
r1 = signature
129+
URI = 'https://localhost/mgmt/tm/security/' \
130+
'protocol-inspection/signature/~Common~fake_signature'
131+
assert r1.name == 'fake_signature'
132+
assert r1.partition == 'Common'
133+
assert r1.description == DESC
134+
assert r1.selfLink.startswith(URI)
135+
136+
def test_create_opt_args(self, mgmt_root):
137+
prof = mgmt_root.tm.security.protocol_inspection.signatures.\
138+
signature.create(name='fake_signature',
139+
partition='Common', sig='content:"abc";',
140+
service='http', description=DESC)
141+
URI = 'https://localhost/mgmt/tm/security/' \
142+
'protocol-inspection/signature/~Common~fake_signature'
143+
assert prof.name == 'fake_signature'
144+
assert prof.partition == 'Common'
145+
assert prof.selfLink.startswith(URI)
146+
assert hasattr(prof, 'description')
147+
assert hasattr(prof, 'service')
148+
assert prof.description == DESC
149+
prof.delete()
150+
151+
def test_refresh(self, mgmt_root, signature):
152+
sigc = mgmt_root.tm.security.protocol_inspection.signatures
153+
sig = sigc.signature.load(name='fake_signature', partition='Common')
154+
assert signature.name == sig.name
155+
assert signature.kind == sig.kind
156+
assert signature.selfLink == sig.selfLink
157+
assert not hasattr(signature, 'documentation')
158+
assert not hasattr(sig, 'documentation')
159+
sig.modify(documentation='custom doc')
160+
assert hasattr(sig, 'documentation')
161+
assert sig.documentation == 'custom doc'
162+
signature.refresh()
163+
assert signature.selfLink == sig.selfLink
164+
assert hasattr(signature, 'documentation')
165+
assert signature.documentation == sig.documentation
166+
167+
def test_delete(self, mgmt_root):
168+
sigc = mgmt_root.tm.security.protocol_inspection.signatures
169+
sig = sigc.signature.create(name='fake_signature',
170+
partition='Common', sig='content:"abc";',
171+
description=DESC)
172+
sig.delete()
173+
with pytest.raises(HTTPError) as err:
174+
sigc.signature.load(name='fake_signature', partition='Common')
175+
assert err.value.response.status_code == 404
176+
177+
def test_load_no_object(self, mgmt_root):
178+
sigc = mgmt_root.tm.security.protocol_inspection.signatures
179+
with pytest.raises(HTTPError) as err:
180+
sigc.signature.load(name='fake_signature', partition='Common')
181+
assert err.value.response.status_code == 404
182+
183+
def test_signature_collection(self, mgmt_root, signature):
184+
s1 = signature
185+
URI = 'https://localhost/mgmt/tm/security/' \
186+
'protocol-inspection/signature/~Common~fake_signature'
187+
assert s1.name == 'fake_signature'
188+
assert s1.partition == 'Common'
189+
assert s1.selfLink.startswith(URI)
190+
sigc = mgmt_root.tm.security.protocol_inspection.\
191+
signatures.get_collection()
192+
assert isinstance(sigc, list)
193+
assert len(sigc)
194+
assert isinstance(sigc[0], Signature)
195+
196+
197+
@pytest.mark.skipif(
198+
LooseVersion(pytest.config.getoption('--release')) < LooseVersion('13.1.0'),
199+
reason='This collection is fully implemented on 13.1.0 or greater.'
200+
)
201+
class TestCompliance(object):
202+
"""Compliance functional tests"""
203+
204+
def test_compliance_collection(self, mgmt_root):
205+
compc = mgmt_root.tm.security.protocol_inspection.\
206+
compliances.get_collection()
207+
assert isinstance(compc, list)
208+
assert len(compc)
209+
assert isinstance(compc[0], Compliance)

0 commit comments

Comments
 (0)