def test_get_unknown_authentication_method(self, m):
     sde_client = SDEClient("http://localhost/sde", "Unknown", None, None,
                            None, None)
     m.register_uri('GET',
                    SDEClient.GET_TASK_URI % (sde_client.url, '1', '1-T2'),
                    json=json.loads(GET_TASK_RESPONSE))
     sde_client.get_task('1', 'FAILED')
 def test_get_task_token_auth(self, m):
     sde_client = SDEClient("http://localhost/sde", "PAT", None, None, None,
                            "1234abcd")
     m.register_uri('GET',
                    SDEClient.GET_TASK_URI % (sde_client.url, '1', '1-T2'),
                    json=json.loads(GET_TASK_RESPONSE))
     eq_(json.loads(GET_TASK_RESPONSE), sde_client.get_task('1', '1-T2'))
 def test_get_task_basic_auth(self, m):
     sde_client = SDEClient("http://localhost/sde", "Basic", None, "admin",
                            "admin", None)
     m.register_uri('GET',
                    SDEClient.GET_TASK_URI % (sde_client.url, '1', '1-T2'),
                    json=json.loads(GET_TASK_RESPONSE))
     eq_(json.loads(GET_TASK_RESPONSE), sde_client.get_task('1', '1-T2'))
 def test_get_unknown_task(self, m):
     sde_client = SDEClient("http://localhost/sde", "Basic", None, "admin",
                            "admin", None)
     m.register_uri('GET',
                    SDEClient.GET_TASK_URI %
                    (sde_client.url, '1', 'FAILED'),
                    status_Code=403)
     sde_client.get_task('1', 'FAILED')
 def test_get_project_by_id(self, m):
     sde_client = SDEClient("http://localhost/sde", "Basic", None, "admin",
                            "admin", None)
     m.register_uri('GET',
                    SDEClient.GET_PROJECT_BY_ID % (sde_client.url, '1'),
                    json=json.loads(GET_PROJECT_BY_ID_RESPONSE))
     eq_(json.loads(GET_PROJECT_BY_ID_RESPONSE),
         sde_client.get_project_by_id('1'))
 def test_check_vulnerabilities_ok(self, m):
     sde_client = SDEClient("http://localhost/sde", "Basic", None, "admin",
                            "admin", None)
     m.register_uri('GET',
                    SDEClient.GET_PROJECT_BY_ID % (sde_client.url, '1'),
                    json=json.loads(GET_PROJECT_BY_ID_RESPONSE))
     result = sde_client.check_risk_policy_compliant("1")
     eq_(result['name'], "Project Test")
     eq_(result['risk_policy_compliant'], True)
 def test_get_unknown_authentication_method(self, m):
     sde_client = SDEClient("http://localhost/sde", "Unknown", None, None,
                            None, None)
     m.register_uri('GET',
                    SDEClient.GET_PROJECTS %
                    (sde_client.url, '1280', 'FAILED'),
                    json=json.loads(GET_PROJECT_RESPONSE))
     m.register_uri('GET',
                    SDEClient.GET_APPLICATIONS %
                    (sde_client.url, 'Application Test'),
                    json=json.loads(GET_APPLICATION_RESPONSE))
     sde_client.get_project('Application Test', 'FAILED')
 def test_get_unknown_project(self, m):
     sde_client = SDEClient("http://localhost/sde", "Basic", None, "admin",
                            "admin", None)
     m.register_uri('GET',
                    SDEClient.GET_PROJECTS %
                    (sde_client.url, '1280', 'FAILED'),
                    status_Code=403)
     m.register_uri('GET',
                    SDEClient.GET_APPLICATIONS %
                    (sde_client.url, 'Application Test'),
                    json=json.loads(GET_APPLICATION_RESPONSE))
     sde_client.get_project('Application Test', 'FAILED')
 def test_get_project_token_auth(self, m):
     sde_client = SDEClient("http://localhost/sde", "PAT", None, None, None,
                            "1234abcd")
     m.register_uri('GET',
                    SDEClient.GET_PROJECTS %
                    (sde_client.url, '1', 'Project Test'),
                    json=json.loads(GET_PROJECT_RESPONSE))
     m.register_uri('GET',
                    SDEClient.GET_APPLICATIONS %
                    (sde_client.url, 'Application Test'),
                    json=json.loads(GET_APPLICATION_RESPONSE))
     eq_(
         json.loads(GET_PROJECT_RESPONSE)['results'][0],
         sde_client.get_project('Application Test', 'Project Test'))
 def test_check_vulnerabilities_failed(self, m):
     sde_client = SDEClient("http://localhost/sde", "Basic", None, "admin",
                            "admin", None)
     m.register_uri('GET',
                    SDEClient.GET_TASKS_URI % (sde_client.url, '1'),
                    json=json.loads(GET_TASKS_RESPONSE))
     m.register_uri('GET',
                    SDEClient.GET_PROJECTS %
                    (sde_client.url, '1', 'Project Test'),
                    json=json.loads(GET_PROJECT_RESPONSE))
     m.register_uri('GET',
                    SDEClient.GET_APPLICATIONS %
                    (sde_client.url, 'Application Test'),
                    json=json.loads(GET_APPLICATION_RESPONSE))
     result = sde_client.check_vulnerabilities('Application Test',
                                               'Project Test', 50, 0, 0)
     eq_(result['highResult'], 100)
     eq_(result['mediumResult'], 0)
     eq_(result['lowResult'], 0)
     eq_(result['success'], False)
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#

from sdelements.SDEClient import SDEClient

proxy = None
if sdServer['proxyHost'] or sdServer['proxySshHost']:
    proxy = {
        'http': '%s:%s' % (sdServer['proxyHost'], sdServer['proxyPort']),
        'https': '%s:%s' % (sdServer['proxySshHost'], sdServer['proxySshPort'])
    }
client = SDEClient(sdServer['url'], sdServer['authenticationMethod'], proxy,
                   sdServer['username'], sdServer['password'],
                   sdServer['token'], sdServer['enableSslVerification'])
result = client.check_vulnerabilities(application, project, high, medium, low)

highResult = result["highResult"]
mediumResult = result["mediumResult"]
lowResult = result["lowResult"]
if result["success"]:
    print "Test successful"
else:
    print "+ highResult: [%s]" % result["highResult"]
    print "+ mediumResult: [%s]" % result["mediumResult"]
    print "+ lowResult: [%s]\n" % result["lowResult"]
    raise Exception("Vulnerabilities found")
 def test_get_unknown_application(self, m):
     sde_client = SDEClient("http://localhost/sde", "Basic", None, "admin", "admin", None)
     m.register_uri('GET', SDEClient.GET_APPLICATIONS % (sde_client.url, 'FAILED'), status_Code=403)
     sde_client.get_application('FAILED')
 def test_get_application_basic_auth(self, m):
     sde_client = SDEClient("http://localhost/sde", "Basic", None, "admin", "admin", None)
     m.register_uri('GET', SDEClient.GET_APPLICATIONS % (sde_client.url, 'Application Test'), json=json.loads(GET_APPLICATION_RESPONSE))
     eq_(json.loads(GET_APPLICATION_RESPONSE)['results'][0], sde_client.get_application('Application Test'))
#
# Copyright 2019 XEBIALABS
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#

from sdelements.SDEClient import SDEClient

proxy = None
if sdServer['proxyHost'] or sdServer['proxySshHost']:
    proxy = {'http': '%s:%s' % (sdServer['proxyHost'], sdServer['proxyPort']),
             'https': '%s:%s' % (sdServer['proxySshHost'], sdServer['proxySshPort'])}
client = SDEClient(sdServer['url'], sdServer['authenticationMethod'], proxy, sdServer['username'], sdServer['password'], sdServer['token'], sdServer['enableSslVerification'])
result = client.check_risk_policy_compliant(projectId)

riskPolicyCompliant = result["risk_policy_compliant"]
projectName = result["name"]

if not riskPolicyCompliant:
    raise Exception("Project with id [%s] is not compliant" % projectId)