|
| 1 | +//go:build integration |
| 2 | +// +build integration |
| 3 | + |
| 4 | +/* |
| 5 | + * Copyright 2024 Dgraph Labs, Inc. and Contributors |
| 6 | + * |
| 7 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | + * you may not use this file except in compliance with the License. |
| 9 | + * You may obtain a copy of the License at |
| 10 | + * |
| 11 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | + * |
| 13 | + * Unless required by applicable law or agreed to in writing, software |
| 14 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | + * See the License for the specific language governing permissions and |
| 17 | + * limitations under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package main |
| 21 | + |
| 22 | +import ( |
| 23 | + "context" |
| 24 | + "testing" |
| 25 | + |
| 26 | + "github.com/stretchr/testify/require" |
| 27 | + |
| 28 | + "github.com/dgraph-io/dgo/v240/protos/api" |
| 29 | + "github.com/dgraph-io/dgraph/v24/dgraphapi" |
| 30 | + "github.com/dgraph-io/dgraph/v24/x" |
| 31 | +) |
| 32 | + |
| 33 | +func addData(t *testing.T, gc *dgraphapi.GrpcClient) { |
| 34 | + require.NoError(t, gc.SetupSchema(`name: string .`)) |
| 35 | + |
| 36 | + rdfs := ` |
| 37 | + _:a <name> "alice" . |
| 38 | + _:b <name> "bob" . |
| 39 | + _:c <name> "sagar" . |
| 40 | + _:d <name> "ajay" .` |
| 41 | + _, err := gc.Mutate(&api.Mutation{SetNquads: []byte(rdfs), CommitNow: true}) |
| 42 | + require.NoError(t, err) |
| 43 | +} |
| 44 | + |
| 45 | +func (msuite *MultitenancyTestSuite) TestLoggingIntoTheNSAfterDropDataFromTheNS() { |
| 46 | + t := msuite.T() |
| 47 | + gc, cleanup, err := msuite.dc.Client() |
| 48 | + require.NoError(t, err) |
| 49 | + defer cleanup() |
| 50 | + |
| 51 | + hc, err := msuite.dc.HTTPClient() |
| 52 | + require.NoError(t, err) |
| 53 | + |
| 54 | + require.NoError(t, gc.LoginIntoNamespace(context.Background(), |
| 55 | + dgraphapi.DefaultUser, dgraphapi.DefaultPassword, x.GalaxyNamespace)) |
| 56 | + require.NoError(t, gc.DropAll()) |
| 57 | + for i := 1; i < 5; i++ { |
| 58 | + require.NoError(t, hc.LoginIntoNamespace(dgraphapi.DefaultUser, |
| 59 | + dgraphapi.DefaultPassword, x.GalaxyNamespace)) |
| 60 | + ns, err := hc.AddNamespace() |
| 61 | + require.NoError(t, err) |
| 62 | + require.NoError(t, hc.LoginIntoNamespace(dgraphapi.DefaultUser, dgraphapi.DefaultPassword, ns)) |
| 63 | + require.NoError(t, gc.LoginIntoNamespace(context.Background(), dgraphapi.DefaultUser, dgraphapi.DefaultPassword, ns)) |
| 64 | + |
| 65 | + addData(t, gc) |
| 66 | + |
| 67 | + // Drop data from the namespace |
| 68 | + require.NoError(t, gc.Alter(context.Background(), &api.Operation{DropOp: api.Operation_DATA})) |
| 69 | + |
| 70 | + // Login into the namespace |
| 71 | + require.NoError(t, gc.LoginIntoNamespace(context.Background(), |
| 72 | + dgraphapi.DefaultUser, dgraphapi.DefaultPassword, ns)) |
| 73 | + |
| 74 | + require.NoError(t, hc.LoginIntoNamespace(dgraphapi.DefaultUser, dgraphapi.DefaultPassword, ns)) |
| 75 | + } |
| 76 | +} |
| 77 | + |
| 78 | +func (msuite *MultitenancyTestSuite) TestLoggingIntoAllNamespacesAfterDropDataOperationFromDefaultNs() { |
| 79 | + t := msuite.T() |
| 80 | + gc, cleanup, err := msuite.dc.Client() |
| 81 | + require.NoError(t, err) |
| 82 | + defer cleanup() |
| 83 | + |
| 84 | + hc, err := msuite.dc.HTTPClient() |
| 85 | + require.NoError(t, err) |
| 86 | + |
| 87 | + require.NoError(t, gc.LoginIntoNamespace(context.Background(), |
| 88 | + dgraphapi.DefaultUser, dgraphapi.DefaultPassword, x.GalaxyNamespace)) |
| 89 | + |
| 90 | + require.NoError(t, gc.DropAll()) |
| 91 | + nss := []uint64{} |
| 92 | + for i := 1; i < 2; i++ { |
| 93 | + require.NoError(t, hc.LoginIntoNamespace(dgraphapi.DefaultUser, dgraphapi.DefaultPassword, x.GalaxyNamespace)) |
| 94 | + ns, err := hc.AddNamespace() |
| 95 | + nss = append(nss, ns) |
| 96 | + require.NoError(t, err) |
| 97 | + require.NoError(t, hc.LoginIntoNamespace(dgraphapi.DefaultUser, dgraphapi.DefaultPassword, ns)) |
| 98 | + require.NoError(t, gc.LoginIntoNamespace(context.Background(), dgraphapi.DefaultUser, dgraphapi.DefaultPassword, ns)) |
| 99 | + |
| 100 | + addData(t, gc) |
| 101 | + } |
| 102 | + |
| 103 | + // Drop data from default namespace |
| 104 | + require.NoError(t, gc.LoginIntoNamespace(context.Background(), |
| 105 | + dgraphapi.DefaultUser, dgraphapi.DefaultPassword, x.GalaxyNamespace)) |
| 106 | + |
| 107 | + require.NoError(t, gc.Alter(context.Background(), &api.Operation{DropOp: api.Operation_DATA})) |
| 108 | + |
| 109 | + // verify here that login into the namespace should not fail |
| 110 | + require.NoError(t, gc.LoginIntoNamespace(context.Background(), |
| 111 | + dgraphapi.DefaultUser, dgraphapi.DefaultPassword, x.GalaxyNamespace)) |
| 112 | + require.NoError(t, gc.LoginIntoNamespace(context.Background(), |
| 113 | + dgraphapi.DefaultUser, dgraphapi.DefaultPassword, x.GalaxyNamespace)) |
| 114 | + |
| 115 | + for _, ns := range nss { |
| 116 | + require.NoError(t, gc.LoginIntoNamespace(context.Background(), |
| 117 | + dgraphapi.DefaultUser, dgraphapi.DefaultPassword, ns)) |
| 118 | + query := `{ |
| 119 | + q(func: has(name)) { |
| 120 | + count(uid) |
| 121 | + } |
| 122 | + }` |
| 123 | + resp, err := gc.Query(query) |
| 124 | + require.NoError(t, err) |
| 125 | + require.Contains(t, string(resp.Json), `"count":4`) |
| 126 | + } |
| 127 | +} |
0 commit comments