Skip to content

Refactor OC_Request into TrustedDomainHelper and IRequest - #14056

Merged
LukasReschke merged 4 commits into
masterfrom
refactor/13976
Feb 17, 2015
Merged

LukasReschke merged 4 commits into
masterfrom
refactor/13976

Conversation

@LukasReschke

Copy link
Copy Markdown
Contributor

This changeset removes the static class OC_Request and moves the functions either into IRequest which is accessible via \OC::$server::->getRequest() or into a separated TrustedDomainHelper class for some helper methods which should not be publicly exposed.

This changes only internal methods and nothing on the public API. Some public functions in util.php have been deprecated though in favour of the new non-static functions.

Unfortunately some part of this code uses things like __DIR__ and thus is not completely unit-testable. Where tests where possible they ahve been added though.

Fixes #13976 which was requested in #13973 (comment)

(let's hope the tests pass on Jenkins as well – can't run the full test suite locally but for the changes parts they worked just fine – will take a look once CI passed)

@DeepDiver1975 As requested by you.
@th3fallen @nickvergessen @MorrisJobke @PVince81 Huge PR. Would be cool if you have some time to review this and test carefully.

Fixes itself.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is a behavioural change already announced for 8.0 but let's finally introduce this with 8.1 – won't break sane setups, in other cases a simple error will be shown to the admin.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Did it default to "localhost" before ? Or is it something else ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Previously you could disable the trusted domain check by just not adding any domain to the config. Though on every update ownCloud will add the used domain anyways.

I saw this abused a lot of time in the forum by users for some other purposes that it was never meant to. To prevent admins from doing this mistake this will though not be possible anylonger.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Okay, makes sense

@LukasReschke

Copy link
Copy Markdown
Contributor Author

No worries: Most changes are in test files and others are pretty simple changes like "replacing the old call with the new one".

Comment thread lib/private/connector/sabre/file.php Outdated

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm not really sure if we want to have hasModificationTime on the IRequest. It only seems to be used for SabreDAV – opinions?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

a simple key based access should be fine as well

@LukasReschke
LukasReschke force-pushed the refactor/13976 branch 2 times, most recently from 93a3c23 to 1ea7c54 Compare February 11, 2015 17:04
@LukasReschke

Copy link
Copy Markdown
Contributor Author

Did I already mention that I love our encryption "unit tests"? – Honestly stuff like https://github.com/owncloud/core/blob/dfbc405a45f42acd1202d5f0649619388adbfb83/apps/files_encryption/tests/webdav.php#L101-101 makes it IMPOSSIBLE to do ANY adjustments ANYWHERE without breaking some stuff…………

Again and again: SETTING UP A WHOLE WEBDAV SERVER IN A UNIT TEST IS NOT A UNIT TEST…

@LukasReschke
LukasReschke force-pushed the refactor/13976 branch 2 times, most recently from 51b696e to 45294d6 Compare February 11, 2015 19:52
@LukasReschke

Copy link
Copy Markdown
Contributor Author

This is ready to review now… Be aware that this includes some horrible hacks in the server container because our unit tests are setting $_SERVER headers when the container has already been initialized. Obviously this failed hard with the new approach…

Thus now the request class gets initialized all the time new it is requested :-/
(has no performance impact though)

Comment thread lib/base.php

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we make a method getServerVar() ? Would make it mockable.
(or maybe something for later)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@PVince81

Copy link
Copy Markdown
Contributor

To test:

  • web UI
  • public link (with "overridehost" set)
  • upgrade from stable7 to this branch with trusted domains set
  • run cron.php from CLI
  • reverse proxy env

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If we had "getServerVar()" this might be mockable 😄

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Well it is mockable? ;-)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

$request = new Request(['server' => ['foo' = >'bar']],…)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Fair enough.

@ghost

ghost commented Feb 16, 2015

Copy link
Copy Markdown

Refer to this link for build results (access rights to CI server needed):
https://ci.owncloud.org//job/pull-request-analyser-ng-simple/9549/
Test PASSed.

@PVince81

Copy link
Copy Markdown
Contributor

Tested, works 👍

Comment thread lib/base.php

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can't we inject the config object which is created above?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Nope. Above thing is not associated in any way with an IConfig sigh

@nickvergessen

Copy link
Copy Markdown
Contributor

👍 apart from the 👔 s above

This changeset removes the static class `OC_Request` and moves the functions either into `IRequest` which is accessible via `\OC::$server::->getRequest()` or into a separated `TrustedDomainHelper` class for some helper methods which should not be publicly exposed.

This changes only internal methods and nothing on the public API. Some public functions in `util.php` have been deprecated though in favour of the new non-static functions.

Unfortunately some part of this code uses things like `__DIR__` and thus is not completely unit-testable. Where tests where possible they ahve been added though.

Fixes #13976 which was requested in #13973 (comment)
@LukasReschke

Copy link
Copy Markdown
Contributor Author

@nickvergessen Incorporated your changes.

@LukasReschke

Copy link
Copy Markdown
Contributor Author

/me is throwing a 💣 against Jenkins

@scrutinizer-notifier

Copy link
Copy Markdown

The inspection completed: 38 new issues, 43 updated code elements

@ghost

ghost commented Feb 16, 2015

Copy link
Copy Markdown

Refer to this link for build results (access rights to CI server needed):
https://ci.owncloud.org//job/pull-request-analyser-ng-simple/9586/
Test PASSed.

LukasReschke added a commit that referenced this pull request Feb 17, 2015
Refactor OC_Request into TrustedDomainHelper and IRequest
@LukasReschke
LukasReschke merged commit 76c511d into master Feb 17, 2015
@LukasReschke
LukasReschke deleted the refactor/13976 branch February 17, 2015 12:17
@lock lock Bot locked as resolved and limited conversation to collaborators Aug 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Kill OC_Request

5 participants