Skip to content
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
2 changes: 1 addition & 1 deletion edgraph/alter.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func executeDropAllInNs(ctx context.Context, startTs uint64, req *apiv25.AlterRe
}

err = x.RetryUntilSuccess(10, 100*time.Millisecond, func() error {
return createGuardianAndGroot(x.AttachNamespace(ctx, nsID), nsID, "password")
return createGuardianAndGroot(x.AttachNamespace(ctx, nsID), "password")
})
if err != nil {
return errors.Wrapf(err, "Failed to create guardian and groot: ")
Expand Down
9 changes: 7 additions & 2 deletions edgraph/multi_tenancy.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,23 @@ func (s *Server) CreateNamespaceInternal(ctx context.Context, passwd string) (ui
}

err = x.RetryUntilSuccess(10, 100*time.Millisecond, func() error {
return createGuardianAndGroot(ctx, ids.StartId, passwd)
return createGuardianAndGroot(ctx, passwd)
})
if err != nil {
return 0, errors.Wrapf(err, "Failed to create guardian and groot: ")
}

glog.V(2).Infof("Created namespace: %d", ns)
return ns, nil
}

// This function is used while creating new namespace. New namespace creation is only allowed
// by the guardians of the galaxy group.
func createGuardianAndGroot(ctx context.Context, namespace uint64, passwd string) error {
func createGuardianAndGroot(ctx context.Context, passwd string) error {
if !x.WorkerConfig.AclEnabled {
return nil
}

if err := upsertGuardian(ctx); err != nil {
return errors.Wrap(err, "While creating Guardian")
}
Expand Down
87 changes: 87 additions & 0 deletions edgraph/ns_query_no_acl_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
//go:build integration2

/*
* SPDX-FileCopyrightText: © Hypermode Inc. <[email protected]>
* SPDX-License-Identifier: Apache-2.0
*/

package edgraph

import (
"context"
"testing"

"github.com/dgraph-io/dgo/v250"
"github.com/stretchr/testify/require"

"github.com/hypermodeinc/dgraph/v25/dgraphtest"
)

func TestNamespaces(t *testing.T) {
conf := dgraphtest.NewClusterConfig().WithNumAlphas(1).WithNumZeros(1).WithReplicas(1)
c, err := dgraphtest.NewLocalCluster(conf)
require.NoError(t, err)
defer func() { c.Cleanup(t.Failed()) }()
require.NoError(t, c.Start())

// ensure that Open works with no ACL
alphaGrpcPort, err := c.GetAlphaGrpcPublicPort(0)
require.NoError(t, err)
_, err = dgo.Open("dgraph://localhost:" + alphaGrpcPort)
require.NoError(t, err)

client, cleanup, err := c.Client()
require.NoError(t, err)
defer cleanup()

// Drop all data
require.NoError(t, client.DropAll())

// Create two namespaces
ctx := context.Background()
require.NoError(t, client.CreateNamespace(ctx, "ns1"))
require.NoError(t, client.CreateNamespace(ctx, "ns2"))

// namespace 1
require.NoError(t, client.SetSchema(ctx, "ns1", `name: string @index(exact) .`))
resp, err := client.RunDQL(ctx, "ns1", `{ set {_:a <name> "Alice" .}}`)
require.NoError(t, err)
require.Equal(t, 1, len(resp.BlankUids))
resp, err = client.RunDQL(ctx, "ns1", `{ q(func: has(name)) { name } }`)
require.NoError(t, err)
require.JSONEq(t, `{"q":[{"name":"Alice"}]}`, string(resp.GetQueryResult()))

// namespace 2
require.NoError(t, client.SetSchema(ctx, "ns2", `name: string @index(exact) .`))
_, err = client.RunDQL(ctx, "ns2", `{ set {_:a <name> "Bob" .}}`)
require.NoError(t, err)
resp, err = client.RunDQL(ctx, "ns2", `{ q(func: has(name)) { name } }`)
require.NoError(t, err)
require.JSONEq(t, `{"q":[{"name":"Bob"}]}`, string(resp.GetQueryResult()))

// rename ns2 namespace
require.NoError(t, client.RenameNamespace(ctx, "ns2", "ns2-new"))

// check if the data is still there
resp, err = client.RunDQL(ctx, "ns2-new", `{ q(func: has(name)) { name } }`)
require.NoError(t, err)
require.JSONEq(t, `{"q":[{"name":"Bob"}]}`, string(resp.GetQueryResult()))

// List Namespaces
nsMaps, err := client.ListNamespaces(ctx)
require.NoError(t, err)
require.Len(t, nsMaps, 3)

// drop ns2-new namespace
require.NoError(t, client.DropNamespace(ctx, "ns2-new"))
_, err = client.RunDQL(ctx, "ns2-new", `{ q(func: has(name)) { name } }`)
require.ErrorContains(t, err, "namespace \"ns2-new\" not found")
nsMaps, err = client.ListNamespaces(ctx)
require.NoError(t, err)
require.Len(t, nsMaps, 2)

// drop ns1 namespace
require.NoError(t, client.DropNamespace(ctx, "ns1"))
_, err = client.RunDQL(ctx, "ns1", `{ q(func: has(name)) { name } }`)
require.ErrorContains(t, err, "namespace \"ns1\" not found")
}
2 changes: 1 addition & 1 deletion x/acl_enc_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func checkAclKeyLength(alg jwt.SigningMethod, key Sensitive) error {

// SHA length has to be smaller or equal to the key length
if sl > len(key)*8 {
return errors.Errorf("ACL key length [%v <= %v] bits for JWT algorithm [%v]", sl, len(key)*8, alg.Alg())
return errors.Errorf("ACL key length [%v <= %v] bits for JWT algorithm [%v]", len(key)*8, sl, alg.Alg())
Comment thread
mangalaman93 marked this conversation as resolved.
}
return nil
}
Expand Down