Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to allow specifying restler_multipart_formdata directly in the grammar #341

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

marina-p
Copy link
Contributor

@marina-p marina-p commented Sep 8, 2021

Using the following in the dictionary and grammar, with this change, restler_multipart_formdata can be used to send a file as the body of the corresponding
POST request:

    # Remove this next Content-Type line
    #primitives.restler_static_string("Content-Type: application/json\r\n"),
    primitives.restler_refreshable_authentication_token("authentication_token_tag"),
    primitives.restler_static_string("\r\n"), # Make sure this is here
    primitives.restler_multipart_formdata("file1"),
    primitives.restler_static_string("\r\n"),

Dictionary:

  "restler_multipart_formdata": {
    "file1": [
      {
        "content-disposition": "name=\"file1\"; filename=\"test0.txt\"",
        "datastream": "c:\\temp\\restler\\test0.txt"
      },
      {
          "content-disposition": "name=\"file2\"; filename=\"test1.txt\"",
          "datastream": "c:\\temp\\restler\\test1.txt"
      }
    ]
  }

Using the following in the dictionary and grammar, with this check-in, files are sent as the body of the corresponding
POST request.

    # Remove this next Content-Type line
    #primitives.restler_static_string("Content-Type: application/json\r\n"),
    primitives.restler_refreshable_authentication_token("authentication_token_tag"),
    primitives.restler_static_string("\r\n"), # Make sure this is here
    primitives.restler_multipart_formdata("file1"),
    primitives.restler_static_string("\r\n"),

Dictionary:
  "restler_multipart_formdata": {
    "file1": [
      {
        "content-disposition": "name=\"file1\"; filename=\"test0.txt\"",
        "datastream": "c:\\temp\\restler\\test0.txt"
      },
      {
          "content-disposition": "name=\"file2\"; filename=\"test1.txt\"",
          "datastream": "c:\\temp\\restler\\test1.txt"
      }
    ]
  },
@marina-p marina-p requested a review from PatGod September 8, 2021 21:20
@marina-p marina-p linked an issue Sep 8, 2021 that may be closed by this pull request
Copy link
Contributor

@PatGod PatGod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

restler_mutipart_formdata does not seem to be documented anywhere in any of the .md file.

Could you please add this, or is this just some scaffolding and this doc will come in a future PR?

@ijard-akshay
Copy link

We did give a try using your branch with .zip file as multipart file as payload. But it is failing at 2 levels:

  1. In your code branch for Restler-> Engine -> primitives.py:
    It is missing basepath implementation. It is throwing below error:
    Cannot import grammar: module 'engine.primitives' has no attribute 'restler_basepath'

  2. Dictinary.json is throwing error similar to earlier found issue:

Cannot deserialize mutations dictionary: An exception occurred during deserialization: Newtonsoft.Json.JsonSerializationException: Could not find member 'restler_multipart_formdata' on object of type 'MutationsDictionary'. Path 'restler_multipart_formdata',

@Oleggg2000
Copy link

Oleggg2000 commented Aug 10, 2023

I have the save 2nd issue as @ijard-akshay
StdErr.txt of Compile folder:

Unhandled exception. System.ArgumentException: Could not read dictionary: ERROR: Cannot deserialize mutations dictionary. An exception occurred during deserialization: Newtonsoft.Json.JsonSerializationException: Could not find member 'restler_multipart_formdata' on object of type 'MutationsDictionary'. Path 'restler_multipart_formdata', line 33, position 33.
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ResolvePropertyAndCreatorValues(JsonObjectContract contract, JsonProperty containerProperty, JsonReader reader, Type objectType)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObjectUsingCreatorWithParameters(JsonReader reader, JsonObjectContract contract, JsonProperty containerProperty, ObjectConstructor`1 creator, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateNewObject(JsonReader reader, JsonObjectContract objectContract, JsonProperty containerMember, JsonProperty containerProperty, String id, Boolean& createdFromNonDefaultCreator)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
at Restler.Dictionary.getDictionary$cont@225(String dictionaryFilePath, Unit unitVar) in D:\PKIS_Tests\restler-fuzzer\src\compiler\Restler.Compiler\Dictionary.fs:line 225
at Restler.Workflow.generateGrammarFromSwagger(String grammarOutputDirectoryPath, Config config) in D:\PKIS_Tests\restler-fuzzer\src\compiler\Restler.Compiler\Workflow.fs:line 98
at Restler.Workflow.generateRestlerGrammar(Config config) in D:\PKIS_Tests\restler-fuzzer\src\compiler\Restler.Compiler\Workflow.fs:line 250
at Program.main(String[] argv) in D:\PKIS_Tests\restler-fuzzer\src\compiler\Restler.CompilerExe\Program.fs:line 43

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Schema to send a file as request body for an API fuzzing
4 participants