Skip to content

Commit

Permalink
Add FindAcceptedUsers method to OCM Invite API (cs3org#1527)
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 authored and root committed Apr 20, 2021
1 parent 1709814 commit 42b6af3
Show file tree
Hide file tree
Showing 10 changed files with 345 additions and 181 deletions.
3 changes: 3 additions & 0 deletions changelog/unreleased/ocm-find-accepted-users.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Enhancement: Add FindAcceptedUsers method to OCM Invite API

https://github.com/cs3org/reva/pull/1527
2 changes: 0 additions & 2 deletions cmd/reva/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ var (
moveCommand(),
mkdirCommand(),
ocmFindAcceptedUsersCommand(),
ocmInviteGenerateCommand(),
ocmInviteForwardCommand(),
ocmShareCreateCommand(),
ocmShareListCommand(),
ocmShareRemoveCommand(),
Expand Down
24 changes: 11 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ require (
github.com/Masterminds/goutils v1.1.0 // indirect
github.com/Masterminds/semver v1.5.0 // indirect
github.com/Masterminds/sprig v2.22.0+incompatible
github.com/ReneKroon/ttlcache/v2 v2.4.0
github.com/aws/aws-sdk-go v1.38.13
github.com/ReneKroon/ttlcache/v2 v2.3.0
github.com/aws/aws-sdk-go v1.37.24
github.com/c-bata/go-prompt v0.2.5
github.com/cheggaaa/pb v1.0.29
github.com/coreos/go-oidc v2.2.1+incompatible
github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e
github.com/cs3org/go-cs3apis v0.0.0-20210325133324-32b03d75a535
github.com/cs3org/go-cs3apis v0.0.0-20210310133342-f4a10134033c
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/eventials/go-tus v0.0.0-20200718001131-45c7ec8f5d59
github.com/ffurano/grpc-proto v0.0.0-20210312134900-65801a1ca184
github.com/go-ldap/ldap/v3 v3.3.0
github.com/go-ldap/ldap/v3 v3.2.4
github.com/go-openapi/errors v0.19.6 // indirect
github.com/go-openapi/strfmt v0.19.2 // indirect
github.com/go-sql-driver/mysql v1.6.0
github.com/golang/protobuf v1.5.2
github.com/go-sql-driver/mysql v1.5.0
github.com/golang/protobuf v1.4.3
github.com/gomodule/redigo v1.8.4
github.com/google/go-github v17.0.0+incompatible
github.com/google/go-querystring v1.0.0 // indirect
Expand All @@ -31,18 +31,16 @@ require (
github.com/imdario/mergo v0.3.8 // indirect
github.com/jedib0t/go-pretty v4.3.0+incompatible
github.com/mattn/go-sqlite3 v2.0.3+incompatible
github.com/minio/minio-go/v7 v7.0.10
github.com/mitchellh/copystructure v1.0.0 // indirect
github.com/mitchellh/mapstructure v1.4.1
github.com/onsi/ginkgo v1.16.1
github.com/onsi/ginkgo v1.15.1
github.com/onsi/gomega v1.11.0
github.com/ory/fosite v0.39.0
github.com/pkg/errors v0.9.1
github.com/pkg/xattr v0.4.3
github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35 // indirect
github.com/rs/cors v1.7.0
github.com/rs/zerolog v1.21.0
github.com/sciencemesh/meshdirectory-web v1.0.4
github.com/rs/zerolog v1.20.0
github.com/stretchr/testify v1.7.0
github.com/studio-b12/gowebdav v0.0.0-20200303150724-9380631c29a1
github.com/tus/tusd v1.1.1-0.20200416115059-9deabf9d80c2
Expand All @@ -52,11 +50,11 @@ require (
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
golang.org/x/sys v0.0.0-20210218155724-8ebf48af031b
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221
google.golang.org/grpc v1.37.0
google.golang.org/protobuf v1.26.0
google.golang.org/grpc v1.36.0
google.golang.org/protobuf v1.23.0
)

go 1.16
go 1.13

replace (
github.com/eventials/go-tus => github.com/andrewmostello/go-tus v0.0.0-20200314041820-904a9904af9a
Expand Down
104 changes: 60 additions & 44 deletions go.sum

Large diffs are not rendered by default.

220 changes: 220 additions & 0 deletions grpc-tests/userprovider_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
// Copyright 2018-2021 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 grpctests

import (
"context"
"errors"
"net"
"os"
"os/exec"
"testing"
"time"

userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
v1beta11 "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
"github.com/cs3org/reva/pkg/rgrpc/todo/pool"
"github.com/stretchr/testify/assert"
)

const grpcAddress = "localhost:19000"
const timeoutMs = 30000

func Test_service_GetUser(t *testing.T) {
providers := []struct {
name string
existingIdp string
}{
{
name: "json",
existingIdp: "localhost:20080",
},
{
name: "demo",
existingIdp: "http://localhost:9998",
},
}

for _, tt := range providers {
t.Run(tt.name, func(t *testing.T) {
// start revad with the specific provider
cmd := exec.Command("../cmd/revad/revad", "-c", "userproviders/"+tt.name+".toml")
err := cmd.Start()

if err != nil {
t.Fatalf("Could not start revad! ERROR: %v", err)
}

// wait till port is open
_ = waitForPort("open")

// even the port is open the service might not be available yet
time.Sleep(1 * time.Second)

GetUser(t, tt.existingIdp)

// kill revad
err = cmd.Process.Signal(os.Kill)
if err != nil {
t.Fatalf("Could not kill revad! ERROR: %v", err)
}
_ = waitForPort("close")
})
}
}

func GetUser(t *testing.T, existingIdp string) {
tests := []struct {
name string
userID *userpb.UserId
want *userpb.GetUserResponse
}{
{
name: "simple",
userID: &userpb.UserId{
Idp: existingIdp,
OpaqueId: "f7fbf8c8-139b-4376-b307-cf0a8c2d0d9c",
},
want: &userpb.GetUserResponse{
Status: &v1beta11.Status{
Code: 1,
},
User: &userpb.User{
Username: "marie",
Mail: "[email protected]",
DisplayName: "Marie Curie",
Groups: []string{
"radium-lovers",
"polonium-lovers",
"physics-lovers",
},
},
},
},
{
name: "not-existing opaqueId",
userID: &userpb.UserId{
Idp: existingIdp,
OpaqueId: "doesnote-xist-4376-b307-cf0a8c2d0d9c",
},
want: &userpb.GetUserResponse{
Status: &v1beta11.Status{
Code: 15,
},
},
},
{
name: "no opaqueId",
userID: &userpb.UserId{
Idp: existingIdp,
OpaqueId: "",
},
want: &userpb.GetUserResponse{
Status: &v1beta11.Status{
Code: 15,
},
},
},
{
name: "not-existing idp",
userID: &userpb.UserId{
Idp: "http://does-not-exist:12345",
OpaqueId: "f7fbf8c8-139b-4376-b307-cf0a8c2d0d9c",
},
want: &userpb.GetUserResponse{
Status: &v1beta11.Status{
Code: 15,
},
},
},
{
name: "no idp",
userID: &userpb.UserId{
OpaqueId: "f7fbf8c8-139b-4376-b307-cf0a8c2d0d9c",
},
want: &userpb.GetUserResponse{
Status: &v1beta11.Status{
Code: 1,
},
User: &userpb.User{
Username: "marie",
Mail: "[email protected]",
DisplayName: "Marie Curie",
Groups: []string{
"radium-lovers",
"polonium-lovers",
"physics-lovers",
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ctx := context.Background()

serviceClient, err := pool.GetUserProviderServiceClient(grpcAddress)
if err != nil {
t.Fatalf("cannot get UserProviderServiceClient! ERROR: %v", err)
}

userResp, err := serviceClient.GetUser(ctx, &userpb.GetUserRequest{
UserId: tt.userID,
})
if err != nil {
t.Fatalf("cannot get user! ERROR: %v", err)
}
assert.Equal(t, tt.want.Status.Code, userResp.Status.Code)
if tt.want.User == nil {
assert.Nil(t, userResp.User)
} else {
// make sure not to run into a nil pointer error
if userResp.User == nil {
t.Fatalf("no user in response %v", userResp)
}
assert.Equal(t, tt.want.User.Username, userResp.User.Username)
assert.Equal(t, tt.want.User.Mail, userResp.User.Mail)
assert.Equal(t, tt.want.User.DisplayName, userResp.User.DisplayName)
assert.Equal(t, tt.want.User.Groups, userResp.User.Groups)
}
})
}
}

func waitForPort(expectedStatus string) error {
if expectedStatus != "open" && expectedStatus != "close" {
return errors.New("status can only be 'open' or 'close'")
}
timoutCounter := 0
for timoutCounter <= timeoutMs {
conn, err := net.Dial("tcp", grpcAddress)
if err == nil {
_ = conn.Close()
if expectedStatus == "open" {
break
}
} else if expectedStatus == "close" {
break
}

time.Sleep(1 * time.Millisecond)
timoutCounter++
}
return nil
}
2 changes: 1 addition & 1 deletion internal/grpc/services/gateway/storageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1861,7 +1861,7 @@ func (s *svc) GetQuota(ctx context.Context, req *gateway.GetQuotaRequest) (*prov

res, err := c.GetQuota(ctx, &provider.GetQuotaRequest{
Opaque: req.GetOpaque(),
//Ref: req.GetRef(), // TODO send which storage space ... or root
// Ref: req.GetRef(), // TODO send which storage space ... or root
})
if err != nil {
return nil, errors.Wrap(err, "gateway: error calling GetQuota")
Expand Down
18 changes: 12 additions & 6 deletions internal/http/services/owncloud/ocdav/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ func (h *VersionsHandler) Handler(s *svc, rid *provider.ResourceId) http.Handler
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()

if rid == (*provider.ResourceId)(nil) {
http.Error(w, "404 Not Found", http.StatusNotFound)
return
}

// baseURI is encoded as part of the response payload in href field
baseURI := path.Join(ctx.Value(ctxKeyBaseURI).(string), wrapResourceID(rid))
ctx = context.WithValue(ctx, ctxKeyBaseURI, baseURI)
Expand Down Expand Up @@ -135,6 +130,17 @@ func (h *VersionsHandler) doListVersions(w http.ResponseWriter, r *http.Request,
// add version dir . entry, derived from file info
infos = append(infos, &provider.ResourceInfo{
Type: provider.ResourceType_RESOURCE_TYPE_CONTAINER,
Id: &provider.ResourceId{
StorageId: "virtual", // this is a virtual storage
OpaqueId: path.Join("meta", wrapResourceID(rid), "v"),
},
Etag: info.Etag,
MimeType: "httpd/unix-directory",
Mtime: info.Mtime,
Path: "v",
// PermissionSet
Size: 0,
Owner: info.Owner,
})

for i := range versions {
Expand All @@ -147,7 +153,7 @@ func (h *VersionsHandler) doListVersions(w http.ResponseWriter, r *http.Request,
OpaqueId: info.Id.OpaqueId + "@" + versions[i].GetKey(),
},
// Checksum
Etag: versions[i].Etag,
// Etag: v.ETag,
// MimeType
Mtime: &types.Timestamp{
Seconds: versions[i].Mtime,
Expand Down
2 changes: 1 addition & 1 deletion internal/http/services/owncloud/ocs/conversions/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (r *Role) OCSPermissions() Permissions {
// M = Mounted
func (r *Role) WebDAVPermissions(isDir, isShared, isMountpoint, isPublic bool) string {
var b strings.Builder
//b.Grow(7)
// b.Grow(7)
if !isPublic && isShared {
fmt.Fprintf(&b, "S")
}
Expand Down
Loading

0 comments on commit 42b6af3

Please sign in to comment.