Visitar URL original
[For 10.4][API] user-sync OCS API by micbar · Pull Request #36428 · owncloud/core · GitHub
Skip to content

[For 10.4][API] user-sync OCS API - #36428

Merged
micbar merged 4 commits into
masterfrom
feature/user-sync-2
Dec 20, 2019
Merged

micbar merged 4 commits into
masterfrom
feature/user-sync-2

Conversation

@micbar

@micbar micbar commented Nov 13, 2019

Copy link
Copy Markdown
Contributor

Description

External user provisioning system need an http api to trigger user-sync for a specific user.

Authorization

The http API can only be executed by a user with admin priviledges. Suggestion is to create a technical user who is in the admin group

Route

 curl -X POST http://localhost:8080/ocs/v2.php/cloud/user-sync/admin -v -u admin

Response

  • 200 - if sync was executed
  • 404 - given userId is unknown
  • 409 - mutliple users have been found for the given user id - not unique user criteria

Related Issue

How Has This Been Tested?

  • user curl command as above with an admin user

Screenshots (if appropriate):

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:

Open tasks:

@micbar micbar self-assigned this Nov 13, 2019
@micbar micbar added this to the QA milestone Nov 13, 2019
@micbar micbar added the QA:team label Nov 13, 2019
@micbar

micbar commented Nov 13, 2019

Copy link
Copy Markdown
Contributor Author

@phil-davis Now you can add the acceptance tests to this branch.

This is a breaking change for the next minor version.
We will do the full QA here before merging.

@micbar
micbar changed the base branch from feature/user-sync to master November 13, 2019 19:19
@micbar micbar assigned phil-davis and unassigned micbar Nov 13, 2019
@micbar micbar changed the title [API] user-sync OCS API [New Minor Version][API] user-sync OCS API Nov 13, 2019
@dpakach

dpakach commented Nov 14, 2019

Copy link
Copy Markdown
Contributor

@micbar @DeepDiver1975 , I have added acceptance tests for checking the cases when there are not any external user backends. Some status codes seem out of place. Please have a look

@phil-davis phil-davis assigned dpakach and unassigned phil-davis Nov 14, 2019
@dpakach dpakach removed their assignment Nov 20, 2019
@micbar micbar mentioned this pull request Nov 21, 2019
2 of 12 tasks
@micbar micbar changed the title [New Minor Version][API] user-sync OCS API [For 10.4][API] user-sync OCS API Nov 25, 2019
@phil-davis

Copy link
Copy Markdown
Contributor

@micbar @DeepDiver1975 , I have added acceptance tests for checking the cases when there are not any external user backends. Some status codes seem out of place. Please have a look

@micbar @DeepDiver1975 please have a look at the added acceptance test scenarios and see if any of the failure codes need to be adjusted/made more consistent.

@phil-davis

Copy link
Copy Markdown
Contributor

@dpakach I don't think we ever sorted out how to add a "happy path" acceptance test for this in the user_ldap tests. Can link post here about how far you got (or link to a comment somewhere)?

We really need to have a "happy path" test passing somewhere.

@dpakach

dpakach commented Dec 2, 2019

Copy link
Copy Markdown
Contributor

@dpakach I don't think we ever sorted out how to add a "happy path" acceptance test for this in the user_ldap tests. Can link post here about how far you got (or link to a comment somewhere)?

We really need to have a "happy path" test passing somewhere.

@phil-davis I tried doing that but could not make work. Either there is some problem in my configuration or some bug. I had created the issue #36312.
I think those tests should be added in user_ldap.

@DeepDiver1975

Copy link
Copy Markdown
Contributor

@micbar @DeepDiver1975 please have a look at the added acceptance test scenarios and see if any of the failure codes need to be adjusted/made more consistent.

I'm not that deep into the acceptance tests these days - I see you as the lead dev on these topic @phil-davis .

Regarding the tests not working properly I cannot add more then I did on #36312
We have this API live in production for weeks now and it works - with an ldap backend.

@phil-davis

phil-davis commented Dec 2, 2019 •

Copy link
Copy Markdown
Contributor

Regarding the tests not working properly I cannot add more then I did

NP - I will look with @dpakach and our guys

@phil-davis phil-davis self-assigned this Dec 3, 2019
@codecov

codecov Bot commented Dec 3, 2019 •

Copy link
Copy Markdown

Codecov Report

Merging #36428 into master will decrease coverage by <.01%.
The diff coverage is 70.96%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #36428      +/-   ##
============================================
- Coverage     64.68%   64.67%   -0.01%     
- Complexity    19071    19106      +35     
============================================
  Files          1268     1269       +1     
  Lines         74516    74723     +207     
  Branches       1311     1320       +9     
============================================
+ Hits          48201    48329     +128     
- Misses        25929    26006      +77     
- Partials        386      388       +2
Flag Coverage Δ Complexity Δ
#javascript 54.12% <ø> (+0.1%) 0 <ø> (ø) ⬇️
#phpunit 65.84% <70.96%> (-0.02%) 19106 <9> (+35)
Impacted Files Coverage Δ Complexity Δ
core/routes.php 48.71% <ø> (ø) 0 <0> (ø) ⬇️
core/Application.php 23.57% <10%> (-1.21%) 1 <0> (ø)
lib/private/User/SyncService.php 83.72% <100%> (+0.09%) 61 <4> (+1) ⬆️
core/Controller/UserSyncController.php 100% <100%> (ø) 5 <5> (?)
...amework/Middleware/Security/SecurityMiddleware.php 95.16% <100%> (+1.82%) 24 <0> (+1) ⬆️
core/Command/User/SyncBackend.php 78.89% <100%> (ø) 38 <0> (ø) ⬇️
core/Command/App/Enable.php 87.87% <0%> (-12.13%) 8% <0%> (+3%)
core/js/sharedialogshareelistview.js 73.23% <0%> (-7.91%) 0% <0%> (ø)
lib/private/Share20/ProviderFactory.php 85.36% <0%> (-6.74%) 17% <0%> (+1%)
apps/files_sharing/lib/Capabilities.php 93.15% <0%> (-5.19%) 12% <0%> (+2%)
... and 15 more

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 d74d406...dcacc2a. Read the comment docs.

@DeepDiver1975

Copy link
Copy Markdown
Contributor

Feel free to fix right away, Phil

@phil-davis

Copy link
Copy Markdown
Contributor

Note: I rebased just now so that we have this on top of the latest master.

@phil-davis

Copy link
Copy Markdown
Contributor

Feel free to fix right away, Phil

@micbar I have lots to do, and I do not see easily how to fix/catch this 500 status code.

NotAdminException is thrown - I guess in SecurityMiddleware.php and that should be caught somewhere and turned into a nicer HTTP status like 403.

Strangely, I do not see other examples of places where it is currently being caught.

Some developer will know what to do in 5 minutes (maybe)?

@micbar

micbar commented Dec 6, 2019

Copy link
Copy Markdown
Contributor Author

Thanks @sharidas . Let us see what CI says.

@micbar

micbar commented Dec 6, 2019 •

Copy link
Copy Markdown
Contributor Author

@phil-davis @skshetry The response Code is now 403 Forbidden.

@phil-davis

Copy link
Copy Markdown
Contributor

@phil-davis @skshetry The response Code is now 403 Forbidden.

I suspect that this will be a more general fix that might catch other places where we test sending an API request to an admin-only endpoint, but with only authentication of an ordinary user. Probably the status codes will now be better. There might be some test expectations to adjust (improve) when we see the CI result.

@sharidas
sharidas force-pushed the feature/user-sync-2 branch 4 times, most recently from 8589764 to 3696eca Compare December 9, 2019 07:26
@phil-davis

Copy link
Copy Markdown
Contributor

I rebased just now to make sure this is up-to-date and passing.

@phil-davis
phil-davis dismissed DeepDiver1975’s stale review December 19, 2019 12:54

comments were addressed

@phil-davis phil-davis left a comment

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.

Tests are OK here, as far as they go.
We will need to work out a way to do a manual test of this with LDAP set-up, because I never managed to get the user_ldap CI setup to successfully do a user sync through this API.
Someone else needs to approve the actual code.

@VicDeo VicDeo left a comment

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.

Looks good, just some minor changes

Comment thread lib/private/User/SyncService.php Resolved
Comment thread core/Controller/UserSyncController.php Resolved
Comment thread core/Controller/UserSyncController.php Resolved
Comment thread core/Controller/UserSyncController.php Resolved
Comment thread core/Controller/UserSyncController.php Outdated
*/
public function syncUser($userId): Result {
foreach ($this->userManager->getBackends() as $backEnd) {
$users = $backEnd->getUsers($userId, 2);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If I remember correctly, we had already problems if there are users with the similar name. What if we have "Scott", "Scotty", "Scott_A"... and we want to sync "Scott"? Even if we have only one "Scott" in the system, I think the method will return an error.

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.

You mean it will throw an exception? Or return an empty value?

Comment thread core/Controller/UserSyncController.php Resolved
Comment thread core/Controller/UserSyncController.php Resolved
if ($exception instanceof NotLoggedInException) {
return $controller->buildResponse(new Result(null, API::RESPOND_UNAUTHORISED, 'Unauthorised'));
} elseif ($exception instanceof NotAdminException) {
return $controller->buildResponse(new Result(null, $exception->getCode(), $exception->getMessage()));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The exception doesn't explicitly says that the error code should be an HTTP code, and it doesn't guarantee it. We should at least include a comment saying that we expect an HTTP code as the error code of the exception.

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.

The docblock of the parent method mentions that the return value is a http Response object. Isn't that sufficient?

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.

NotAdminException has a code Http::STATUS_FORBIDDEN so it looks ok from my side...
https://github.com/owncloud/core/blob/master/lib/private/AppFramework/Middleware/Security/Exceptions/NotAdminException.php#L37

@micbar
micbar merged commit afb447b into master Dec 20, 2019
@delete-merged-branch
delete-merged-branch Bot deleted the feature/user-sync-2 branch December 20, 2019 11:57
@phil-davis

Copy link
Copy Markdown
Contributor

Note: acceptance test added in owncloud/user_ldap#562

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.

7 participants