Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(multi-tenancy): upsert groot for namespace after drop data #9159

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions edgraph/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,9 @@ func (s *Server) Alter(ctx context.Context, op *api.Operation) (*api.Payload, er

// just reinsert the GraphQL schema, no need to alter dgraph schema as this was drop_data
_, err = UpdateGQLSchema(ctx, graphQLSchema, "")
// recreate the admin account after a drop data operation
InitializeAcl(nil)

// Since all data has been dropped, we need to recreate the admin account in the respective namespace.
upsertGuardianAndGroot(nil, namespace)
return empty, err
}

Expand Down
123 changes: 123 additions & 0 deletions systest/multi-tenancy/login_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
//go:build integration
// +build integration

/*
* Copyright 2024 Dgraph Labs, Inc. and Contributors
*
* 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.
*/

package main

import (
"context"
"testing"

"github.com/stretchr/testify/require"

"github.com/dgraph-io/dgo/v240/protos/api"
"github.com/dgraph-io/dgraph/v24/dgraphapi"
"github.com/dgraph-io/dgraph/v24/x"
)

func addData(t *testing.T, gc *dgraphapi.GrpcClient) {
require.NoError(t, gc.SetupSchema(`name: string .`))

rdfs := `
_:a <name> "alice" .
_:b <name> "bob" .
_:c <name> "sagar" .
_:d <name> "ajay" .`
_, err := gc.Mutate(&api.Mutation{SetNquads: []byte(rdfs), CommitNow: true})
require.NoError(t, err)
}

func (msuite *MultitenancyTestSuite) TestLoggingIntoTheNSAfterDropDataFromTheNS() {
t := msuite.T()
gc, cleanup, err := msuite.dc.Client()
require.NoError(t, err)
defer cleanup()

hc, err := msuite.dc.HTTPClient()
require.NoError(t, err)

require.NoError(t, gc.LoginIntoNamespace(context.Background(),
dgraphapi.DefaultUser, dgraphapi.DefaultPassword, x.GalaxyNamespace))
require.NoError(t, gc.DropAll())

require.NoError(t, hc.LoginIntoNamespace(dgraphapi.DefaultUser, dgraphapi.DefaultPassword, x.GalaxyNamespace))
for i := 1; i < 5; i++ {
ns, err := hc.AddNamespace()
require.NoError(t, err)
require.NoError(t, gc.LoginIntoNamespace(context.Background(), dgraphapi.DefaultUser, dgraphapi.DefaultPassword, ns))

addData(t, gc)

// Drop data from the namespace
require.NoError(t, gc.Alter(context.Background(), &api.Operation{DropOp: api.Operation_DATA}))

// Login into the namespace
require.NoError(t, gc.LoginIntoNamespace(context.Background(),
dgraphapi.DefaultUser, dgraphapi.DefaultPassword, ns))
}
}

func (msuite *MultitenancyTestSuite) TestLoggingIntoAllNamespacesAfterDropDataOperationFromDefaultNs() {
t := msuite.T()
gc, cleanup, err := msuite.dc.Client()
require.NoError(t, err)
defer cleanup()

hc, err := msuite.dc.HTTPClient()
require.NoError(t, err)

require.NoError(t, gc.LoginIntoNamespace(context.Background(),
dgraphapi.DefaultUser, dgraphapi.DefaultPassword, x.GalaxyNamespace))

require.NoError(t, gc.DropAll())
require.NoError(t, hc.LoginIntoNamespace(dgraphapi.DefaultUser, dgraphapi.DefaultPassword, x.GalaxyNamespace))

nss := []uint64{}
for i := 1; i <= 2; i++ {
ns, err := hc.AddNamespace()
require.NoError(t, err)
nss = append(nss, ns)
require.NoError(t, gc.LoginIntoNamespace(context.Background(),
dgraphapi.DefaultUser, dgraphapi.DefaultPassword, ns))

addData(t, gc)
}

// Drop data from default namespace
require.NoError(t, gc.LoginIntoNamespace(context.Background(),
dgraphapi.DefaultUser, dgraphapi.DefaultPassword, x.GalaxyNamespace))

require.NoError(t, gc.Alter(context.Background(), &api.Operation{DropOp: api.Operation_DATA}))

// verify here that login into the namespace should not fail
require.NoError(t, gc.LoginIntoNamespace(context.Background(),
dgraphapi.DefaultUser, dgraphapi.DefaultPassword, x.GalaxyNamespace))

for _, ns := range nss {
require.NoError(t, gc.LoginIntoNamespace(context.Background(),
dgraphapi.DefaultUser, dgraphapi.DefaultPassword, ns))
query := `{
q(func: has(name)) {
count(uid)
}
}`
resp, err := gc.Query(query)
require.NoError(t, err)
require.Contains(t, string(resp.Json), `"count":4`)
}
}
Loading