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

Allow reading params of PUT with empty body more than once #37394

Merged
merged 1 commit into from
May 15, 2020

Conversation

VicDeo
Copy link
Member

@VicDeo VicDeo commented May 15, 2020

Description

Allows read URL params of PUT request with an empty body more than once.
Missing or 0 Content-Length means that the request has an empty body and we should NOT throw LogicException while reading it.

How Has This Been Tested?

  1. Create an OCS route with urlParam like this:
[
	'root' => '/cloud',
	'name' => 'Users#enableUser',
	'url' => '/users/{userId}/enable',
	'verb' => 'PUT'
],
  1. Create a controller
use OCP\AppFramework\OCSController;

class UsersController extends OCSController {
/**
	 * @NoCSRFRequired
	 *
	 * @param string $userId
	 * @return Result
	 */
	public function enableUser($userId) {
		return $this->setEnabled($userId, true);
	}
  1. Use it
curl -X PUT http://admin:admin@localhost/OC/ocs/v1.php/cloud/users/fatima/enable

Expected

$userId is 'fatima' in the controller

Actual

$userId is null

The log file contains

{"reqId":"08vb9aIDIHfQVAQp5ZB1","level":3,"time":"2020-05-15T09:19:24+00:00","remoteAddr":"127.0.0.1","user":"admin","app":"PHP","method":"PUT","url":"\/OC\/ocs\/v1.php\/cloud\/users\/user1\/disable","message":"LogicException: \"put\" can only be accessed once if not application\/x-www-form-urlencoded or application\/json. at 
 \/lib\/private\/AppFramework\/Http\/Request.php#395"}

OCS routes always get format param from URL and adding one more URL param causes a logic exception

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Database schema changes (next release will require increase of minor version instead of patch)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Technical debt
  • Tests only (no source changes)

Checklist:

  • Code changes
  • Unit tests added
  • Acceptance tests added
  • Documentation ticket raised:
  • Changelog item, see TEMPLATE

@VicDeo VicDeo added this to the development milestone May 15, 2020
@VicDeo VicDeo self-assigned this May 15, 2020
@update-docs
Copy link

update-docs bot commented May 15, 2020

Thanks for opening this pull request! The maintainers of this repository would appreciate it if you would create a changelog item based on your changes.

@VicDeo VicDeo force-pushed the fix-double-getParam-for-PUT branch from c840db3 to f5b5f32 Compare May 15, 2020 10:18
@VicDeo VicDeo changed the title Allow reading params of PUT more than once Allow reading params of PUT with empty body more than once May 15, 2020
@VicDeo VicDeo requested a review from jvillafanez May 15, 2020 10:21
@VicDeo VicDeo force-pushed the fix-double-getParam-for-PUT branch from f5b5f32 to a534964 Compare May 15, 2020 10:53
@codecov
Copy link

codecov bot commented May 15, 2020

Codecov Report

Merging #37394 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master   #37394   +/-   ##
=========================================
  Coverage     64.57%   64.57%           
- Complexity    19220    19222    +2     
=========================================
  Files          1268     1268           
  Lines         75105    75107    +2     
  Branches       1331     1331           
=========================================
+ Hits          48496    48498    +2     
  Misses        26217    26217           
  Partials        392      392           
Flag Coverage Δ Complexity Δ
#javascript 54.14% <ø> (ø) 0.00 <ø> (ø)
#phpunit 65.73% <100.00%> (+<0.01%) 19222.00 <0.00> (+2.00)
Impacted Files Coverage Δ Complexity Δ
lib/private/AppFramework/Http/Request.php 91.75% <100.00%> (+0.05%) 143.00 <0.00> (+2.00)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1e5e612...a534964. Read the comment docs.

Copy link
Member

@jvillafanez jvillafanez left a comment

Choose a reason for hiding this comment

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

Code changes look fine, although I'm not sure about possible side effects.

@VicDeo VicDeo merged commit afa378c into master May 15, 2020
@delete-merged-branch delete-merged-branch bot deleted the fix-double-getParam-for-PUT branch May 15, 2020 13:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants