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

AF-1690 Copy content-type/length on mock-aware fall-through #317

Merged

Conversation

evanweible-wf
Copy link
Contributor

Problem

When MockTransports are installed, requests are wrapped in a "mock-aware" class when constructed. When fallThrough: true, these requests will switch to real requests if there isn't an applicable handler/expectation. This is achieved by constructing a new request instance with the real transport platform on demand and copying all of the request properties over from the mock-aware wrapper to the real request.

We weren't copying the contentType and contentLength properties. If a consumer had explicitly set one of these properties (rare, but does happen), they would not be copied over in this scenario.

Solution

Be sure to also copy contentType (only if it was explicitly set) and contentLength when switching from a mock-aware request to a real request.

Testing

  • CI passes (test added)

Code Review

@Workiva/app-frameworks
@travissanderson-wf

@evanweible-wf evanweible-wf requested a review from a team as a code owner July 19, 2018 00:10
@aviary2-wf
Copy link

Security Insights

No security relevant content was detected by automated scans.

Action Items

  • Review PR for security impact; comment "security review required" if needed or unsure
  • Verify aviary.yaml coverage of security relevant code

Questions or Comments? Reach out on HipChat: InfoSec Forum.

@@ -462,7 +465,7 @@ abstract class CommonRequest extends Object
/// a real request instance (created from a TransportPlatform instance).
///
/// This is handled by the mock request mixin.
Future<BaseResponse> switchToRealRequest({bool streamResponse}) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed this signature so that I could test switchToRealRequest directly.

if (this is! MultipartRequest) {
realRequest.encoding = encoding;
}

return streamResponse
? realRequest.streamSend(method)
: realRequest.send(method);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This part is just moved to CommonRequest class above.

Copy link
Member

@maxwellpeterson-wf maxwellpeterson-wf left a comment

Choose a reason for hiding this comment

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

Nice

@travissanderson-wf
Copy link

QA +1 this resolves the use case for which I reported the bug! thanks

@sebastianmalysa-wf
Copy link

@Workiva/release-management-pp

@rmconsole4-wk rmconsole4-wk merged commit 168fe75 into master Jul 19, 2018
@rmconsole4-wk rmconsole4-wk deleted the copy_content_type_and_length_on_mock_aware_fall_through branch July 19, 2018 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants