Skip to content

Fix: Robust base64 and string fallback for body decoding (#73) - #84

Open
furkancingoz wants to merge 1 commit into
Trendyol:mainfrom
furkancingoz:fix/body-decoding-fallback
Open

Fix: Robust base64 and string fallback for body decoding (#73)#84
furkancingoz wants to merge 1 commit into
Trendyol:mainfrom
furkancingoz:fix/body-decoding-fallback

Conversation

@furkancingoz

Copy link
Copy Markdown

Closes #73

When the client passes a raw JSON string instead of a base64 encoded string (or a base64 string with missing padding), JSONDecoder currently crashes with Encountered Data is not valid Base64. This caused Mockingstar to fail at mocking requests that had Arabic characters in the body, as the payload wasn't valid strict base64.

This PR adds a custom init(from decoder: Decoder) to MockServerRequestModel which gracefully falls back:

  1. Tries standard Base64 decoding.
  2. Tries padded Base64 decoding (in case padding is missing).
  3. Falls back to UTF-8 raw string bytes.

Also includes unit tests to ensure no regressions.

…chars

Fixed an issue (Trendyol#73) where  would crash with a  error when  was not valid base64 (e.g. when raw JSON strings containing Arabic characters were sent instead of a base64 encoded string, or when the base64 string had missing padding).
Implemented a custom  in  to handle standard Base64, padded Base64, and raw string fallbacks gracefully.
@yusufozgul

Copy link
Copy Markdown
Collaborator

hello, root problem is not inside mocking star. So no need this pr

more info: #73 (comment)

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.

Mockingstar can't encode request body with Base64 if request body contains Arabic characters

2 participants