From e4cdf8bea7d137cce41a9fd0124e8d09b8534ee0 Mon Sep 17 00:00:00 2001 From: jkoberg Date: Thu, 31 Mar 2022 13:30:06 +0200 Subject: [PATCH] unit-tests Signed-off-by: jkoberg --- .../http/services/owncloud/ocdav/token.go | 23 ++++++++++++++++--- .../owncloud/ocs/conversions/permissions.go | 2 +- .../ocs/conversions/permissions_test.go | 1 - 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/internal/http/services/owncloud/ocdav/token.go b/internal/http/services/owncloud/ocdav/token.go index 9e71e94623..50817ec958 100644 --- a/internal/http/services/owncloud/ocdav/token.go +++ b/internal/http/services/owncloud/ocdav/token.go @@ -1,3 +1,21 @@ +// Copyright 2018-2022 CERN +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// In applying this license, CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + package ocdav import ( @@ -89,7 +107,7 @@ func (s *svc) handleGetToken(w http.ResponseWriter, r *http.Request, tkn string, } if protected { - if t.PasswordProtected == true { + if t.PasswordProtected { log.Error().Msg("password protected private links are not supported") w.WriteHeader(http.StatusBadRequest) return @@ -111,9 +129,8 @@ func (s *svc) handleGetToken(w http.ResponseWriter, r *http.Request, tkn string, return } - w.Write(b) + _, _ = w.Write(b) w.WriteHeader(http.StatusOK) - return } func buildTokenInfo(owner *user.User, tkn string, token string, passProtected bool, c gateway.GatewayAPIClient) (TokenInfo, error) { diff --git a/internal/http/services/owncloud/ocs/conversions/permissions.go b/internal/http/services/owncloud/ocs/conversions/permissions.go index a580c8ce10..b3cc3a2eb4 100644 --- a/internal/http/services/owncloud/ocs/conversions/permissions.go +++ b/internal/http/services/owncloud/ocs/conversions/permissions.go @@ -51,7 +51,7 @@ var ( // The value must be in the valid range. func NewPermissions(val int) (Permissions, error) { if val == int(PermissionInvalid) { - return PermissionInvalid, nil //fmt.Errorf("permissions %d out of range %d - %d", val, PermissionRead, PermissionAll) + return PermissionInvalid, nil } else if val < int(PermissionInvalid) || int(PermissionAll) < val { return PermissionInvalid, ErrPermissionNotInRange } diff --git a/internal/http/services/owncloud/ocs/conversions/permissions_test.go b/internal/http/services/owncloud/ocs/conversions/permissions_test.go index ec09a32b7b..8b20338b05 100644 --- a/internal/http/services/owncloud/ocs/conversions/permissions_test.go +++ b/internal/http/services/owncloud/ocs/conversions/permissions_test.go @@ -33,7 +33,6 @@ func TestNewPermissions(t *testing.T) { func TestNewPermissionsWithInvalidValueShouldFail(t *testing.T) { vals := []int{ - int(PermissionInvalid), -1, int(PermissionAll) + 1, }