-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cherry pick: release/v21.03: The Acl cache should be updated on resta…
…rt and restore. (#7964)
- Loading branch information
1 parent
b77c203
commit 592bd6f
Showing
14 changed files
with
329 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
12345678901234567890123456789012 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/dgraph-io/dgo/v210" | ||
"github.com/dgraph-io/dgo/v210/protos/api" | ||
"github.com/dgraph-io/dgraph/graphql/e2e/common" | ||
"github.com/dgraph-io/dgraph/testutil" | ||
"github.com/stretchr/testify/require" | ||
"google.golang.org/grpc" | ||
) | ||
|
||
// disableDraining disables draining mode before each test for increased reliability. | ||
func disableDraining(t *testing.T) { | ||
drainRequest := `mutation draining { | ||
draining(enable: false) { | ||
response { | ||
code | ||
message | ||
} | ||
} | ||
}` | ||
|
||
params := testutil.GraphQLParams{ | ||
Query: drainRequest, | ||
} | ||
b, err := json.Marshal(params) | ||
require.NoError(t, err) | ||
|
||
token := testutil.Login(t, &testutil.LoginParams{UserID: "groot", Passwd: "password", Namespace: 0}) | ||
|
||
client := &http.Client{} | ||
req, err := http.NewRequest("POST", testutil.AdminUrl(), bytes.NewBuffer(b)) | ||
require.Nil(t, err) | ||
req.Header.Add("content-type", "application/json") | ||
req.Header.Add("X-Dgraph-AccessToken", token.AccessJwt) | ||
|
||
resp, err := client.Do(req) | ||
require.NoError(t, err) | ||
buf, err := ioutil.ReadAll(resp.Body) | ||
fmt.Println(string(buf)) | ||
require.NoError(t, err) | ||
require.Contains(t, string(buf), "draining mode has been set to false") | ||
} | ||
|
||
func sendRestoreRequest(t *testing.T, location, backupId string, backupNum int) { | ||
if location == "" { | ||
location = "/data/backup2" | ||
} | ||
params := &testutil.GraphQLParams{ | ||
Query: `mutation restore($location: String!, $backupId: String, $backupNum: Int) { | ||
restore(input: {location: $location, backupId: $backupId, backupNum: $backupNum}) { | ||
code | ||
message | ||
} | ||
}`, | ||
Variables: map[string]interface{}{ | ||
"location": location, | ||
"backupId": backupId, | ||
"backupNum": backupNum, | ||
}, | ||
} | ||
|
||
token := testutil.Login(t, &testutil.LoginParams{UserID: "groot", Passwd: "password", Namespace: 0}) | ||
resp := testutil.MakeGQLRequestWithAccessJwt(t, params, token.AccessJwt) | ||
resp.RequireNoGraphQLErrors(t) | ||
|
||
var restoreResp struct { | ||
Restore struct { | ||
Code string | ||
Message string | ||
RestoreId int | ||
} | ||
} | ||
require.NoError(t, json.Unmarshal(resp.Data, &restoreResp)) | ||
require.Equal(t, restoreResp.Restore.Code, "Success") | ||
} | ||
|
||
func TestAclCacheRestore(t *testing.T) { | ||
disableDraining(t) | ||
conn, err := grpc.Dial(testutil.SockAddr, grpc.WithInsecure()) | ||
require.NoError(t, err) | ||
dg := dgo.NewDgraphClient(api.NewDgraphClient(conn)) | ||
dg.Login(context.Background(), "groot", "password") | ||
|
||
sendRestoreRequest(t, "/backups", "vibrant_euclid5", 1) | ||
testutil.WaitForRestore(t, dg) | ||
|
||
token := testutil.Login(t, | ||
&testutil.LoginParams{UserID: "alice1", Passwd: "password", Namespace: 0}) | ||
params := &common.GraphQLParams{ | ||
Query: `query{ | ||
queryPerson{ | ||
name | ||
age | ||
} | ||
}`, | ||
|
||
Headers: make(http.Header), | ||
} | ||
params.Headers.Set("X-Dgraph-AccessToken", token.AccessJwt) | ||
|
||
resp := params.ExecuteAsPost(t, common.GraphqlURL) | ||
require.Nil(t, resp.Errors) | ||
|
||
expected := ` | ||
{ | ||
"queryPerson": [ | ||
{ | ||
"name": "MinhajSh", | ||
"age": 20 | ||
} | ||
] | ||
} | ||
` | ||
require.JSONEq(t, expected, string(resp.Data)) | ||
} |
Binary file added
BIN
+1.79 KB
systest/acl/restore/data/backups/dgraph.20210730.124449.146/r21-g1.backup
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"Manifests":[ | ||
{ | ||
"type":"full", | ||
"since":0, | ||
"read_ts":21, | ||
"groups":{ | ||
"1":[ | ||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000dgraph.password", | ||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000dgraph.graphql.p_query", | ||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000dgraph.acl.rule", | ||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000dgraph.drop.op", | ||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000dgraph.graphql.xid", | ||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000dgraph.xid", | ||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000dgraph.rule.predicate", | ||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000dgraph.graphql.schema", | ||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000dgraph.rule.permission", | ||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000Person.name", | ||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000dgraph.user.group", | ||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000Person.age", | ||
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000dgraph.type" | ||
] | ||
}, | ||
"backup_id":"vibrant_euclid5", | ||
"backup_num":1, | ||
"version":2103, | ||
"path":"dgraph.20210730.124449.146", | ||
"encrypted":false, | ||
"drop_operations":null, | ||
"compression":"snappy" | ||
} | ||
] | ||
} |
Oops, something went wrong.