예제 #1
0
def test_wssec_signature_authentication(test_wsdl):
    class WssecMockClass(BaseAuthMockSoapClass):
        def _api_test(self, request, url, method, params, headers):
            root = etree.XML(request.body)
            auth_header = root.getchildren()[0].getchildren()[0]
            soap_request = root.getchildren()[1].getchildren()[0]
            assert auth_header.tag == "{http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd}Security"
            token = auth_header.getchildren()[0]
            assert token.tag == '{http://www.w3.org/2000/09/xmldsig#}Signature'
            info, value, keyinfo = token.getchildren()
            assert info.text == '\n'
            assert '==' in value.text
            assert keyinfo.text == '\n'
            assert soap_request.tag == "{urn:examples:helloservice}sayHello"
            kwargs = {}
            for arg in soap_request.getchildren():
                kwargs[arg.tag] = arg.text
            assert kwargs == {"firstName": "xavier"}
            return self._response(request, "test_soap_response")

    wssec_cred = workday.auth.WsSecurityCertificateAuthentication("tests/fixtures/privatekey.key", "tests/fixtures/certificate.crt")
    client = workday.WorkdayClient(wsdls=test_wsdl, authentication=wssec_cred)
    client._session.adapters = {}
    adapter = ClassAdapter(WssecMockClass)
    client._session.mount("https://workday.com/", adapter)

    #  I provided bad certs in the tests.. this should send but fail
    with pytest.raises(zeep.exceptions.SignatureVerificationFailed):
        assert hasattr(client, "test")
        assert hasattr(client.test, "sayHello")
        assert isinstance(
            client.test.sayHello("xavier"), workday.soap.WorkdayResponse
        )
예제 #2
0
def test_bad_wsdl_types(wsdl, test_authentication):
    """
    Workday client should only accept a valid dictionary for the value
    of `wsdls`
    """
    with pytest.raises(TypeError):
        workday.WorkdayClient(wsdls=wsdl, authentication=test_authentication)
예제 #3
0
def test_wssec_credential_authentication(test_wsdl):
    class WssecMockClass(BaseAuthMockSoapClass):
        def _api_test(self, request, url, method, params, headers):
            root = etree.XML(request.body)
            auth_header = root.getchildren()[0].getchildren()[0]
            soap_request = root.getchildren()[1].getchildren()[0]
            assert auth_header.tag == "{http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd}Security"
            token = auth_header.getchildren()[0]
            assert token.tag == '{http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd}UsernameToken'
            assert token.getchildren()[0].text == 'user1'
            assert token.getchildren()[1].text == 'password2'
            assert soap_request.tag == "{urn:examples:helloservice}sayHello"
            kwargs = {}
            for arg in soap_request.getchildren():
                kwargs[arg.tag] = arg.text
            assert kwargs == {"firstName": "xavier"}
            return self._response(request, "test_soap_response")

    wssec_cred = workday.auth.WsSecurityCredentialAuthentication("user1", "password2")
    client = workday.WorkdayClient(wsdls=test_wsdl, authentication=wssec_cred)
    client._session.adapters = {}
    adapter = ClassAdapter(WssecMockClass)
    client._session.mount("https://workday.com/", adapter)
    assert hasattr(client, "test")
    assert hasattr(client.test, "sayHello")
    assert isinstance(
        client.test.sayHello("xavier"), workday.soap.WorkdayResponse
    )
예제 #4
0
def test_client_auth(test_wsdl):
    """
    WorkdayClient should check that authentication argument is one of
    :class:`workday.auth.BaseAuthentication`
    """
    with pytest.raises(ValueError):
        workday.WorkdayClient(wsdls=test_wsdl, authentication=("username", "password"))
예제 #5
0
def test_proxy_configuration(test_wsdl, test_authentication):
    """
    Test that the client has a https proxy if specified
    """
    _PROXY_URL = "https://proxy.com:8888"
    client = workday.WorkdayClient(
        wsdls=test_wsdl, authentication=test_authentication, proxy_url=_PROXY_URL
    )
    assert client._session.proxies == {"https": _PROXY_URL}
예제 #6
0
def test_disable_ssl_auth(test_wsdl, test_authentication):
    """
    Test that the client has SSL verification disabled if specified
    """
    client = workday.WorkdayClient(
        wsdls=test_wsdl,
        authentication=test_authentication,
        disable_ssl_verification=True,
    )
    assert client._session.verify == False
예제 #7
0
def test_ssl_verification(test_wsdl, test_authentication):
    """
    Test that the client has SSL verification enabled by default
    """
    client = workday.WorkdayClient(
        wsdls=test_wsdl,
        authentication=test_authentication,
        disable_ssl_verification=None,
    )
    assert client._session.verify == True
예제 #8
0
def main():
    with open('.tenant.yml', 'r') as tenant_cfg:
        config = yaml.safe_load(tenant_cfg)

    client = workday.WorkdayClient(
        wsdls=config['wsdls'],
        authentication=WsSecurityCertificateCredentialAuthentication(
            config['user'],
            config['password'],
            private_certificate_path="privatekey.key",
            public_certificate_path="certificate.crt"),
        disable_ssl_verification=True,
    )

    print(client.talent.Get_Certification_Issuers().data)
예제 #9
0
    def _retrieve_data(self, data_source: WorkdayDataSource) -> pd.DataFrame:
        """ Only supports Anonymous or Credentials authentification """

        if self.username:
            auth = WsSecurityCredentialAuthentication('@'.join((self.username, self.tenant)), self.password)
        else:
            auth = AnonymousAuthentication()

        apis = {
            data_source.service: data_source.service_WSDL_URL
        }

        client = workday.WorkdayClient(
            wsdls=apis,
            authentication=auth
        )
        print(client)


        data = getattr(getattr(client, data_source.service) , data_source.operation)(    
            Request_References = data_source.request_references_param,
            Request_Criteria = data_source.request_criteria_param,
            Response_Filter = data_source.response_filter_param,
            Response_Group = data_source.response_group_param,
        )
        
        num_page = data.total_pages

        data_json = json.loads(json.dumps(zeep.helpers.serialize_object(data.data), default=json_serial))

        df = pd.DataFrame(use_jq_to_parse(data_json, data_source.filter))

        if num_page > 1:
            for i in range(num_page-1):
                data_next = json.loads(json.dumps(zeep.helpers.serialize_object(data.next().data), default=json_serial))
                df = df.append(pd.DataFrame(use_jq_to_parse(data_next, data_source.filter)), ignore_index=True)

        return df