Пример #1
0
    def test_encode_form_data_as_2tuple_parameter(self):
        data = [("param1", "value1"), ("param2", "value2"), ("param2", "value3")]

        r = FormRenderer()
        body, content_type = r.encode_params(data)
        self.assertEqual(content_type, "application/x-www-form-urlencoded")
        self.assertEqual(body, "param1=value1&param2=value2&param2=value3")
Пример #2
0
    def test_encode_form_data_as_2tuple_parameter(self):
        data = [("param1", "value1"), ("param2", "value2"),
                ("param2", "value3")]

        r = FormRenderer()
        body, content_type = r.encode_params(data)
        self.assertEqual(content_type, "application/x-www-form-urlencoded")
        self.assertEqual(body, "param1=value1&param2=value2&param2=value3")
Пример #3
0
    def test_encode_form_data_none_csharp(self):
        data = {"param1": "value 1", "param2": None}

        r = FormRenderer(output_str='csharp')
        body, content_type = r.encode_params(data)
        self.assertEqual(content_type, "application/x-www-form-urlencoded")
        self.assertIn("param2=Null", body)
        self.assertIn("param1=value+1", body)
Пример #4
0
    def test_encode_form_data_boolean_true(self):
        data = {"param1": "value 1", "param2": True}

        r = FormRenderer()
        body, content_type = r.encode_params(data)
        self.assertEqual(content_type, "application/x-www-form-urlencoded")
        self.assertIn("param2=true", body)
        self.assertIn("param1=value+1", body)
Пример #5
0
    def test_encode_form_data_none_csharp(self):
        data = {"param1": "value 1", "param2": None}

        r = FormRenderer(output_str="csharp")
        body, content_type = r.encode_params(data)
        self.assertEqual(content_type, "application/x-www-form-urlencoded")
        self.assertIn("param2=Null", body)
        self.assertIn("param1=value+1", body)
Пример #6
0
    def test_encode_form_data_boolean_false(self):
        data = {"param1": "value 1", "param2": False}

        r = FormRenderer()
        body, content_type = r.encode_params(data)
        self.assertEqual(content_type, "application/x-www-form-urlencoded")
        self.assertIn("param2=false", body)
        self.assertIn("param1=value+1", body)
Пример #7
0
    def test_encode_form_data_array_pipes(self):
        data = {"param1": "value 1", "param2": ["value2", "value3"]}

        r = FormRenderer(collection_format="pipes")
        body, content_type = r.encode_params(data)
        self.assertEqual(content_type, "application/x-www-form-urlencoded")
        self.assertIn("param2[]=value2|value3", body)
        self.assertIn("param1=value+1", body)
Пример #8
0
    def test_encode_form_data_array_pipes(self):
        data = {"param1": "value 1", "param2": ["value2", "value3"]}

        r = FormRenderer(collection_format='pipes')
        body, content_type = r.encode_params(data)
        self.assertEqual(content_type, "application/x-www-form-urlencoded")
        self.assertIn("param2[]=value2|value3", body)
        self.assertIn("param1=value+1", body)
Пример #9
0
    def test_encode_form_data_array_encoded(self):
        data = {"param1": "value 1", "param2": ["value2", "value3"]}

        r = FormRenderer(collection_format='encoded')
        body, content_type = r.encode_params(data)
        self.assertEqual(content_type, "application/x-www-form-urlencoded")
        self.assertIn("param2=%5B%27value2%27%2C+%27value3%27%5D", body)
        self.assertIn("param1=value+1", body)
Пример #10
0
    def test_encode_form_data_files(self):
        files = {"file_upload": "tests/resources/file.pdf", "file_upload2": "tests/resources/file.png"}
        data = {"param1": "value1", "param2": "value2"}

        r = FormRenderer()
        body, content_type = r.encode_params(data, files=files)
        self.assertEqual(content_type, "application/x-www-form-urlencoded")
        self.assertIn("param2=value2", body)
        self.assertIn("param1=value1", body)
        self.assertNotIn("file_upload", body)
Пример #11
0
    def test_encode_form_data_files(self):
        files = {
            "file_upload": "tests/resources/file.pdf",
            "file_upload2": "tests/resources/file.png"
        }
        data = {"param1": "value1", "param2": "value2"}

        r = FormRenderer()
        body, content_type = r.encode_params(data, files=files)
        self.assertEqual(content_type, "application/x-www-form-urlencoded")
        self.assertIn("param2=value2", body)
        self.assertIn("param1=value1", body)
        self.assertNotIn("file_upload", body)
Пример #12
0
 def test_11paths_authentication_class_with_dynamic_time(self):
     auth = X11PathsAuthentication(app_id="123456", secret="654321")
     context = HttpRequestContext(method="POST",
                                  url_path="/path/",
                                  body_params={"param": "value"},
                                  renderer=FormRenderer())
     res_context = auth.apply_authentication(context=context)
     self.assertNotEqual("11PATHS 123456 8Ok3S1xUFLtjRxRkWVoZAKXZc1A=",
                         res_context.headers["Authorization"])
Пример #13
0
 def test_11paths_authentication_with_body(self):
     context = HttpRequestContext(method="POST",
                                  url_path="/path/",
                                  body_params={"param": "value"},
                                  renderer=FormRenderer())
     header_value = x_11paths_authorization(app_id="123456",
                                            secret="654321",
                                            context=context,
                                            utc="2016-01-01 00:00:00")
     self.assertEqual("11PATHS 123456 8Ok3S1xUFLtjRxRkWVoZAKXZc1A=",
                      header_value)
Пример #14
0
def set_form_parameters(context):
    """
    Parameters:

        +-------------+--------------+
        | param_name  | param_value  |
        +=============+==============+
        | param1      | value1       |
        +-------------+--------------+
        | param2      | value2       |
        +-------------+--------------+
    """
    safe_add_http_request_context_to_behave_context(context)
    context.http_request_context.body_params = get_parameters(context)
    context.http_request_context.renderer = FormRenderer()
Пример #15
0
class Latch(HttpSdk):

    DEFAULT_HOST = "https://latch.elevenpaths.com"
    DEFAULT_RENDERER = FormRenderer()

    API_VERSION = "0.6"
    API_CHECK_STATUS_URL__VERSION = "/api/%s/status"
    API_PAIR_URL__VERSION = "/api/%s/pair"
    API_PAIR_WITH_ID_URL__VERSION = "/api/%s/pairWithId"
    API_UNPAIR_URL__VERSION = "/api/%s/unpair"

    def __init__(self, app_id, secret_key):
        super(Latch, self).__init__()
        self.app_id = app_id
        self.secret_key = secret_key
        self.authentication_instances += (X11PathsAuthentication(
            self.app_id, self.secret_key), )

    def pair_with_id(self, account_id):
        return self._http_request(
            "GET", self.API_PAIR_WITH_ID_URL__VERSION % self.API_VERSION +
            "/" + account_id)

    def pair(self, token, my_time=None):
        auth_instances = (X11PathsAuthentication(self.app_id,
                                                 self.secret_key,
                                                 utc=my_time), )
        return self._http_request(
            "GET",
            self.API_PAIR_URL__VERSION % self.API_VERSION + "/" + token,
            authentication_instances=auth_instances)

    def status(self, account_id):
        return self._http_request(
            "GET", self.API_CHECK_STATUS_URL__VERSION % self.API_VERSION +
            "/" + account_id)

    def operation_status(self, account_id, operation_id):
        return self._http_request(
            "GET", self.API_CHECK_STATUS_URL__VERSION % self.API_VERSION +
            "/" + account_id + "/op/" + operation_id)

    def unpair(self, account_id):
        return self._http_request(
            "GET",
            self.API_UNPAIR_URL__VERSION % self.API_VERSION + "/" + account_id)
Пример #16
0
 def test_11paths_authentication_form_multi(self):
     auth = X11PathsAuthentication(
         app_id="QRKJw6qX4fykZ3G3yqkQ",
         secret="eHkAXTebECWBs4TtNbNMBYC99AzMrmaydUWcUFEM",
         utc="2016-12-12 11:18:45")
     context = HttpRequestContext(
         method="POST",
         url_path=
         "/api/0.1/vulnerabilities/15fc104c-dc55-41d4-8d4e-4d76eda7a029/consequences",
         body_params={
             "consequence.scopes[]": "1",
             "consequence.impact[]": "1",
             "consequence.description[es]": "test",
             "consequence.description[en]": "test"
         },
         renderer=FormRenderer())
     res_context = auth.apply_authentication(context=context)
     self.assertEqual(
         "11PATHS QRKJw6qX4fykZ3G3yqkQ CMf3royzdD4l/P0RVKyr2uOXZ4Y=",
         res_context.headers[AUTHORIZATION_HEADER_NAME])
Пример #17
0
 def test_encode_form_data_no_data(self):
     r = FormRenderer()
     body, content_type = r.encode_params()
     self.assertEqual(content_type, "application/x-www-form-urlencoded")
     self.assertEqual(body, "")
Пример #18
0
 def test_encode_form_data_no_data(self):
     r = FormRenderer()
     body, content_type = r.encode_params()
     self.assertEqual(content_type, "application/x-www-form-urlencoded")
     self.assertEqual(body, "")