Skip to content

Commit

Permalink
fix(multi-tenancy): check existence before banning namespace (#7887)
Browse files Browse the repository at this point in the history
Before, the deleting a non-existent namespace would just ban the
namespace. This would essentially not allow creating namespaces after
this banned namespace. Now, we fail instead of banning a namespace that
has not been even created yet.

Co-authored-by: Aman Mangal <aman@dgraph.io>
  • Loading branch information
ahsanbarkati and mangalaman93 committed May 31, 2023
1 parent 871748d commit 9013924
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions edgraph/multi_tenancy_ee.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,8 @@ func createGuardianAndGroot(ctx context.Context, namespace uint64, passwd string
// Authorization is handled by middlewares.
func (s *Server) DeleteNamespace(ctx context.Context, namespace uint64) error {
glog.Info("Deleting namespace", namespace)
if _, ok := schema.State().Namespaces()[namespace]; !ok {
return errors.Errorf("error deleting non-existing namespace %#x", namespace)
}
return worker.ProcessDeleteNsRequest(ctx, namespace)
}
9 changes: 9 additions & 0 deletions systest/multi-tenancy/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,15 @@ func TestDeleteNamespace(t *testing.T) {
err = testutil.DeleteNamespace(t, galaxyToken, x.GalaxyNamespace)
require.Error(t, err)
require.Contains(t, err.Error(), "Cannot delete default namespace")

// Deleting a non-existent namespace should error out
err = testutil.DeleteNamespace(t, galaxyToken, 20)
require.Error(t, err)
require.Contains(t, err.Error(), "error deleting non-existing namespace")
for i := 0; i < 20; i++ {
ns, err = testutil.CreateNamespaceWithRetry(t, galaxyToken)
require.NoError(t, err)
}
}

type liveOpts struct {
Expand Down

0 comments on commit 9013924

Please sign in to comment.