diff --git a/ocis/tests/acceptance/features/apiOcisSpecific/apiAuthOcs-ocsDELETEAuth.feature b/ocis/tests/acceptance/features/apiOcisSpecific/apiAuthOcs-ocsDELETEAuth.feature index 431b184be..d02220583 100644 --- a/ocis/tests/acceptance/features/apiOcisSpecific/apiAuthOcs-ocsDELETEAuth.feature +++ b/ocis/tests/acceptance/features/apiOcisSpecific/apiAuthOcs-ocsDELETEAuth.feature @@ -3,6 +3,7 @@ Feature: auth + # these endpoints are handled by the reva ocs implementation Scenario: send DELETE requests to OCS endpoints as admin with wrong password When the administrator requests these endpoints with "DELETE" using password "invalid" about user "Alice" | endpoint | @@ -20,39 +21,15 @@ Feature: auth Then the HTTP status code of responses on all endpoints should be "401" And the OCS status code of responses on all endpoints should be "notset" + # these endpoints are handled by the ocis ocs implementation Scenario: send DELETE requests to OCS endpoints as admin with wrong password When the administrator requests these endpoints with "DELETE" using password "invalid" about user "Alice" | endpoint | | /ocs/v1.php/cloud/users/%username% | - | /ocs/v1.php/cloud/users/%username%/subadmins | - Then the HTTP status code of responses on all endpoints should be "200" - And the OCS status code of responses on all endpoints should be "997" - - Scenario: send DELETE requests to OCS endpoints as admin with wrong password - When the administrator requests these endpoints with "DELETE" using password "invalid" about user "Alice" - | endpoint | - | /ocs/v2.php/cloud/users/%username% | - Then the HTTP status code of responses on all endpoints should be "401" - And the OCS status code of responses on all endpoints should be "997" - - Scenario: send DELETE requests to OCS endpoints as admin with wrong password - When the administrator requests these endpoints with "DELETE" using password "invalid" about user "Alice" - | endpoint | - | /ocs/v1.php/cloud/users/%username%/groups | - Then the HTTP status code of responses on all endpoints should be "200" - And the OCS status code of responses on all endpoints should be "997" - - Scenario: send DELETE requests to OCS endpoints as admin with wrong password - When the administrator requests these endpoints with "DELETE" using password "invalid" about user "Alice" - | endpoint | - | /ocs/v2.php/cloud/users/%username%/groups | - Then the HTTP status code of responses on all endpoints should be "401" - And the OCS status code of responses on all endpoints should be "997" - - Scenario: send DELETE requests to OCS endpoints as admin with wrong password - When the administrator requests these endpoints with "DELETE" using password "invalid" about user "Alice" - | endpoint | | /ocs/v2.php/cloud/users/%username% | + | /ocs/v1.php/cloud/users/%username%/subadmins | | /ocs/v2.php/cloud/users/%username%/subadmins | + | /ocs/v1.php/cloud/users/%username%/groups | + | /ocs/v2.php/cloud/users/%username%/groups | Then the HTTP status code of responses on all endpoints should be "401" And the OCS status code of responses on all endpoints should be "997" diff --git a/ocis/tests/acceptance/features/apiOcisSpecific/apiAuthOcs-ocsGETAuth.feature b/ocis/tests/acceptance/features/apiOcisSpecific/apiAuthOcs-ocsGETAuth.feature index 3bb8bbf4b..eb9a67b17 100644 --- a/ocis/tests/acceptance/features/apiOcisSpecific/apiAuthOcs-ocsGETAuth.feature +++ b/ocis/tests/acceptance/features/apiOcisSpecific/apiAuthOcs-ocsGETAuth.feature @@ -27,7 +27,7 @@ Feature: auth | /ocs/v1.php/privatedata/getattribute | | /ocs/v2.php/privatedata/getattribute | Then the HTTP status code of responses on all endpoints should be "401" - And the OCS status code of responses on all endpoints should be "997" + And the OCS status code of responses on all endpoints should be "notset" @issue-ocis-ocs-26 # after fixing all issues delete this Scenario and use the one from oC10 core @@ -35,10 +35,6 @@ Feature: auth When a user requests these endpoints with "GET" and no authentication | endpoint | | /ocs/v1.php/cloud/users | - Then the HTTP status code of responses on all endpoints should be "200" - And the OCS status code of responses on all endpoints should be "997" - When a user requests these endpoints with "GET" and no authentication - | endpoint | | /ocs/v2.php/cloud/users | Then the HTTP status code of responses on all endpoints should be "401" And the OCS status code of responses on all endpoints should be "997" @@ -84,10 +80,6 @@ Feature: auth When the user "Alice" requests these endpoints with "GET" with basic auth | endpoint | | /ocs/v1.php/cloud/users | - Then the HTTP status code of responses on all endpoints should be "200" - And the OCS status code of responses on all endpoints should be "997" - When the user "Alice" requests these endpoints with "GET" with basic auth - | endpoint | | /ocs/v2.php/cloud/users | Then the HTTP status code of responses on all endpoints should be "200" And the OCS status code of responses on all endpoints should be "997" @@ -121,7 +113,7 @@ Feature: auth | /ocs/v1.php/privatedata/getattribute | | /ocs/v2.php/privatedata/getattribute | Then the HTTP status code of responses on all endpoints should be "401" - And the OCS status code of responses on all endpoints should be "997" + And the OCS status code of responses on all endpoints should be "notset" @issue-ocis-reva-29 @issue-ocis-reva-30 @@ -133,10 +125,6 @@ Feature: auth When user "Alice" requests these endpoints with "GET" using password "invalid" | endpoint | | /ocs/v1.php/cloud/users | - Then the HTTP status code of responses on all endpoints should be "200" - And the OCS status code of responses on all endpoints should be "997" - When user "Alice" requests these endpoints with "GET" using password "invalid" - | endpoint | | /ocs/v2.php/cloud/users | Then the HTTP status code of responses on all endpoints should be "401" And the OCS status code of responses on all endpoints should be "997" @@ -169,7 +157,7 @@ Feature: auth | /ocs/v1.php/privatedata/getattribute | | /ocs/v2.php/privatedata/getattribute | Then the HTTP status code of responses on all endpoints should be "401" - And the OCS status code of responses on all endpoints should be "997" + And the OCS status code of responses on all endpoints should be "notset" @skipOnOcV10 @issue-ocis-reva-29 @@ -183,10 +171,6 @@ Feature: auth When user "brian" requests these endpoints with "GET" using password "invalid" | endpoint | | /ocs/v1.php/cloud/users | - Then the HTTP status code of responses on all endpoints should be "200" - And the OCS status code of responses on all endpoints should be "100" - When user "brian" requests these endpoints with "GET" using password "invalid" - | endpoint | | /ocs/v2.php/cloud/users | - Then the HTTP status code of responses on all endpoints should be "200" - And the OCS status code of responses on all endpoints should be "200" + Then the HTTP status code of responses on all endpoints should be "401" + And the OCS status code of responses on all endpoints should be "997" diff --git a/ocis/tests/acceptance/features/apiOcisSpecific/apiAuthOcs-ocsPOSTAuth.feature b/ocis/tests/acceptance/features/apiOcisSpecific/apiAuthOcs-ocsPOSTAuth.feature index 1580ae86c..0a5e9a9a2 100644 --- a/ocis/tests/acceptance/features/apiOcisSpecific/apiAuthOcs-ocsPOSTAuth.feature +++ b/ocis/tests/acceptance/features/apiOcisSpecific/apiAuthOcs-ocsPOSTAuth.feature @@ -33,10 +33,6 @@ Feature: auth When user "Alice" requests these endpoints with "POST" including body "doesnotmatter" using password "invalid" about user "Alice" | endpoint | | /ocs/v1.php/cloud/users | - Then the HTTP status code of responses on all endpoints should be "200" - And the OCS status code of responses on all endpoints should be "997" - When user "Alice" requests these endpoints with "POST" including body "doesnotmatter" using password "invalid" about user "Alice" - | endpoint | | /ocs/v2.php/cloud/users | Then the HTTP status code of responses on all endpoints should be "401" And the OCS status code of responses on all endpoints should be "997" @@ -47,10 +43,6 @@ Feature: auth When user "Alice" requests these endpoints with "POST" including body "doesnotmatter" using password "invalid" about user "Alice" | endpoint | | /ocs/v1.php/cloud/users/%username%/groups | - Then the HTTP status code of responses on all endpoints should be "200" - And the OCS status code of responses on all endpoints should be "997" - When user "Alice" requests these endpoints with "POST" including body "doesnotmatter" using password "invalid" about user "Alice" - | endpoint | | /ocs/v2.php/cloud/users/%username%/groups | Then the HTTP status code of responses on all endpoints should be "401" And the OCS status code of responses on all endpoints should be "997" @@ -61,10 +53,6 @@ Feature: auth When user "Alice" requests these endpoints with "POST" including body "doesnotmatter" using password "invalid" about user "Alice" | endpoint | | /ocs/v1.php/cloud/users/%username%/subadmins | - Then the HTTP status code of responses on all endpoints should be "200" - And the OCS status code of responses on all endpoints should be "997" - When user "Alice" requests these endpoints with "POST" including body "doesnotmatter" using password "invalid" about user "Alice" - | endpoint | | /ocs/v2.php/cloud/users/%username%/subadmins | Then the HTTP status code of responses on all endpoints should be "401" And the OCS status code of responses on all endpoints should be "997" diff --git a/ocis/tests/acceptance/features/apiOcisSpecific/apiAuthOcs-ocsPUTAuth.feature b/ocis/tests/acceptance/features/apiOcisSpecific/apiAuthOcs-ocsPUTAuth.feature index a747e0271..0b2505bff 100644 --- a/ocis/tests/acceptance/features/apiOcisSpecific/apiAuthOcs-ocsPUTAuth.feature +++ b/ocis/tests/acceptance/features/apiOcisSpecific/apiAuthOcs-ocsPUTAuth.feature @@ -19,10 +19,6 @@ Feature: auth When the administrator requests these endpoints with "PUT" with body "doesnotmatter" using password "invalid" about user "Alice" | endpoint | | /ocs/v1.php/cloud/users/%username% | - Then the HTTP status code of responses on all endpoints should be "200" - And the OCS status code of responses on all endpoints should be "997" - When the administrator requests these endpoints with "PUT" with body "doesnotmatter" using password "invalid" about user "Alice" - | endpoint | | /ocs/v2.php/cloud/users/%username% | Then the HTTP status code of responses on all endpoints should be "401" And the OCS status code of responses on all endpoints should be "997" @@ -34,12 +30,8 @@ Feature: auth When the administrator requests these endpoints with "PUT" with body "doesnotmatter" using password "invalid" about user "Alice" | endpoint | | /ocs/v1.php/cloud/users/%username%/disable | - | /ocs/v1.php/cloud/users/%username%/enable | - Then the HTTP status code of responses on all endpoints should be "200" - And the OCS status code of responses on all endpoints should be "997" - When the administrator requests these endpoints with "PUT" with body "doesnotmatter" using password "invalid" about user "Alice" - | endpoint | | /ocs/v2.php/cloud/users/%username%/disable | + | /ocs/v1.php/cloud/users/%username%/enable | | /ocs/v2.php/cloud/users/%username%/enable | Then the HTTP status code of responses on all endpoints should be "401" And the OCS status code of responses on all endpoints should be "997" diff --git a/ocs/pkg/service/v0/response/version.go b/ocs/pkg/service/v0/response/version.go index bb55dce4c..312132b05 100644 --- a/ocs/pkg/service/v0/response/version.go +++ b/ocs/pkg/service/v0/response/version.go @@ -32,6 +32,9 @@ func APIVersion(ctx context.Context) string { // OcsV1StatusCodes returns the http status codes for the OCS API v1. func OcsV1StatusCodes(meta data.Meta) int { + if meta.StatusCode == data.MetaUnauthorized.StatusCode { + return http.StatusUnauthorized + } return http.StatusOK } diff --git a/ocs/pkg/service/v0/service.go b/ocs/pkg/service/v0/service.go index 9880be20a..3b955795a 100644 --- a/ocs/pkg/service/v0/service.go +++ b/ocs/pkg/service/v0/service.go @@ -88,6 +88,8 @@ func NewService(opts ...Option) Service { r.With(requireSelfOrAdmin).Get("/", svc.GetSelf) r.Get("/signing-key", svc.GetSigningKey) }) + + // for /users endpoints see https://github.com/owncloud/core/blob/master/apps/provisioning_api/appinfo/routes.php#L44-L56 r.Route("/users", func(r chi.Router) { r.With(requireAdmin).Get("/", svc.ListUsers) r.With(requireAdmin).Post("/", svc.AddUser) @@ -95,6 +97,8 @@ func NewService(opts ...Option) Service { r.With(requireSelfOrAdmin).Get("/", svc.GetUser) r.With(requireSelfOrAdmin).Put("/", svc.EditUser) r.With(requireAdmin).Delete("/", svc.DeleteUser) + r.With(requireAdmin).Put("/enable", svc.NotImplementedStub) + r.With(requireAdmin).Put("/disable", svc.NotImplementedStub) }) r.Route("/{userid}/groups", func(r chi.Router) { @@ -102,12 +106,21 @@ func NewService(opts ...Option) Service { r.With(requireAdmin).Post("/", svc.AddToGroup) r.With(requireAdmin).Delete("/", svc.RemoveFromGroup) }) + + r.Route("/{userid}/subadmins", func(r chi.Router) { + r.With(requireAdmin).Post("/", svc.NotImplementedStub) + r.With(requireSelfOrAdmin).Get("/", svc.NotImplementedStub) + r.With(requireAdmin).Delete("/", svc.NotImplementedStub) + }) }) + + // for /groups endpoints see https://github.com/owncloud/core/blob/master/apps/provisioning_api/appinfo/routes.php#L65-L69 r.Route("/groups", func(r chi.Router) { r.With(requireAdmin).Get("/", svc.ListGroups) r.With(requireAdmin).Post("/", svc.AddGroup) - r.With(requireAdmin).Delete("/{groupid}", svc.DeleteGroup) r.With(requireSelfOrAdmin).Get("/{groupid}", svc.GetGroupMembers) + r.With(requireAdmin).Delete("/{groupid}", svc.DeleteGroup) + r.With(requireAdmin).Get("/{groupid}/subadmins", svc.NotImplementedStub) }) }) r.Route("/config", func(r chi.Router) { @@ -145,3 +158,8 @@ func (o Ocs) getAccountService() accounts.AccountsService { func (o Ocs) getGroupsService() accounts.GroupsService { return accounts.NewGroupsService("com.owncloud.api.accounts", defaultClient) } + +// NotImplementedStub returns a not implemented error +func (o Ocs) NotImplementedStub(w http.ResponseWriter, r *http.Request) { + render.Render(w, r, response.ErrRender(data.MetaUnknownError.StatusCode, "Not implemented")) +}