|
| 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