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

Hotfix: Change http status code for client 2.4.2 #145

Merged
merged 1 commit into from
Aug 9, 2018

Conversation

micbar
Copy link
Contributor

@micbar micbar commented Aug 8, 2018

Hotfix for #144


Problem

The 2.4.2 desktop client goes into an infinite loop when he gets a "invalid_grant" while refreshing his access code with response code 400. This puts very high loads on the webserver.

Hotfix

If he would get the same response with http status code 200, he would stop his infinite loop and open the webUI to re authorize.

Changes

I changed the http status code to 200 after checking for the 2.4.2 client in the request header.

All other clients get the 400 status code, as the Oauth Specs demand it. https://tools.ietf.org/html/rfc6749#section-5.2

@CLAassistant
Copy link

CLAassistant commented Aug 8, 2018

CLA assistant check
All committers have signed the CLA.

@micbar micbar self-assigned this Aug 8, 2018
@pmaier1 pmaier1 mentioned this pull request Aug 8, 2018
21 tasks
$statusCode = Http::STATUS_OK;
}
else {
$statusCode = Http::STATUS_BAD_REQUEST;
Copy link
Contributor

Choose a reason for hiding this comment

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

How about moving this before the if condition?

$statusCode = Http::STATUS_BAD_REQUEST;
if (preg_match('/\bmirall\b.+2\.4\.2/i', $this->request->getHeader('User-Agent'))) {
	$statusCode = Http::STATUS_OK;
}

This eases the flow of reading - and you could add a comment on top outlining that this is a fix

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

can you tell my, how to set a http user agent header in the unit test case?

Copy link
Member

Choose a reason for hiding this comment

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

currently the request mock is created here:

$this->getMockBuilder('OCP\IRequest')->getMock(),

make it a class field and you can work on it in the individual tests

@micbar
Copy link
Contributor Author

micbar commented Aug 8, 2018

@patrickjahns @phil-davis @individual-it can anyone tell me why acceptance tests are failing?

@codecov
Copy link

codecov bot commented Aug 8, 2018

Codecov Report

Merging #145 into master will increase coverage by 0.07%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff             @@
##             master    #145      +/-   ##
===========================================
+ Coverage     82.12%   82.2%   +0.07%     
- Complexity      199     200       +1     
===========================================
  Files            21      21              
  Lines           705     708       +3     
===========================================
+ Hits            579     582       +3     
  Misses          126     126
Impacted Files Coverage Δ Complexity Δ
lib/Controller/OAuthApiController.php 100% <100%> (ø) 19 <0> (+1) ⬆️

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 89c17f0...b0cbaaa. Read the comment docs.

@micbar
Copy link
Contributor Author

micbar commented Aug 9, 2018

Output from travis/ci


File tests/.travis/custom.ini added to /home/travis/.phpenv/versions/nightly/etc/conf.d.
Using database oc_autotest
<?php
$AUTOCONFIG = array (
  'installed' => false,
  'dbtype' => 'oci',
  'dbtableprefix' => 'oc_',
  'adminlogin' => 'admin',
  'adminpass' => 'admin',
  'directory' => '/home/travis/build/owncloud/core/data-autotest',
  'dbuser' => 'autotest',
  'dbname' => 'XE',
  'dbhost' =>'',
  'dbpass' => 'owncloud',
  'loglevel' => 0,
);
Setup environment for sqlite testing ...
INDEX
This version of ownCloud is not compatible with PHP 7.3<br/>You are currently running PHP 7.4.0-dev.END INDEX
owncloud configuration:
<?php
$CONFIG = [
	'apps_paths' => [
		[
			'path'		=> OC::$SERVERROOT . '/apps',
			'url'		=> '/apps',
			'writable'	=> true,
		],
	],
	'default_language' => 'en',
];
if (\is_dir(OC::$SERVERROOT.'/apps2')) {
	$CONFIG['apps_paths'][] = [
		'path' => OC::$SERVERROOT . '/apps2',
		'url' => '/apps2',
		'writable' => false,
	];
}
if (\getenv("TC") === "selenium") {
	$CONFIG['skeletondirectory'] = OC::$SERVERROOT . '/tests/ui/skeleton';
}
data directory:
total 0
owncloud.log:
before_install.8
0.00s$ cd ../core
0.06s$ ./occ app:enable $APP_NAME
This version of ownCloud is not compatible with PHP 7.3
You are currently running PHP 7.4.0-dev.
The command "./occ app:enable $APP_NAME" failed and exited with 1 during .
Your build has been stopped.

@phil-davis
Copy link
Contributor

I restarted the first Travis job 974.1 for PHP 5.6 - that had hung for some reason and got the "no output for 10 minutes" message.

@phil-davis
Copy link
Contributor

Where did you see stuff about PHP 7.3 and PHP 7.4 ???

@micbar
Copy link
Contributor Author

micbar commented Aug 9, 2018

I saw that at the travis build log.

@phil-davis
Copy link
Contributor

Something went crazy in Travis! PHP 7.3beta1 came out last week, and so I guess PHP 7.4.0-dev does exist. But goodness knows what happened for Travis to use those.

Anyway, CI passes.

@DeepDiver1975
Copy link
Member

Will review soon.

$_SERVER['PHP_AUTH_PW'] = null;

$result = $this->controller->generateToken('refresh_token', null, null, $this->refreshToken->getToken());
$this->assertTrue($result instanceof JSONResponse);
Copy link
Member

Choose a reason for hiding this comment

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

assertInstanceOf

$this->assertNotEmpty($json->message_url);
$this->assertEquals($this->authorizationSuccessfulMessageUrl, $json->message_url);
$this->assertEquals(200, $result->getStatus());
$this->assertEquals(1, count($this->accessTokenMapper->findAll()));
Copy link
Member

Choose a reason for hiding this comment

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

assertCount


$result = $this->controller->generateToken('refresh_token', null, null, $this->refreshToken->getToken());
$this->assertTrue($result instanceof JSONResponse);
$json = json_decode($result->render());
Copy link
Member

Choose a reason for hiding this comment

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

just use getData - this gives you the array

This pull request was closed.
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.

5 participants